X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Flevel.cpp;h=134f1f566b564f5ccde0c93f69f6da9892394eb0;hb=a67ce361e348c54f4772bdb3a86c146987ff828c;hp=6c87b816e32e4c5e96a0103e96aa6be824fe346b;hpb=d54bc022663f96293582cfd13b3bb19b7b91b048;p=supertux.git diff --git a/src/level.cpp b/src/level.cpp index 6c87b816e..134f1f566 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -1,7 +1,7 @@ // $Id$ -// +// // SuperTux -// Copyright (C) 2004 SuperTux Development Team, see AUTHORS for details +// Copyright (C) 2006 Matthias Braun // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -12,7 +12,7 @@ // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA @@ -29,7 +29,7 @@ #include #include -#include "video/screen.hpp" +#include "log.hpp" #include "lisp/parser.hpp" #include "lisp/lisp.hpp" #include "lisp/list_iterator.hpp" @@ -45,13 +45,10 @@ #include "object/tilemap.hpp" #include "object/coin.hpp" -// test -#include "flip_level_transformer.hpp" - using namespace std; Level::Level() - : name("noname"), author("Mr. X"), extro_music("leveldone.ogg"), extro_length(7.0) + : name("noname"), author("Mr. X") { } @@ -79,33 +76,23 @@ Level::load(const std::string& filepath) if(token == "version") { iter.value()->get(version); if(version > 2) { - std::cerr << "Warning: level format newer than application.\n"; + log_warning << "level format newer than application" << std::endl; } } else if(token == "name") { iter.value()->get(name); } else if(token == "author") { iter.value()->get(author); - } else if(token == "extro") { - const lisp::Lisp* ext = iter.lisp(); - lisp::ListIterator ext_iter(ext); - while(ext_iter.next()) { - const std::string& ext_token = ext_iter.item(); - if(ext_token == "music") { - ext_iter.value()->get(extro_music); - } else if(ext_token == "length") { - ext_iter.value()->get(extro_length); - } - } + } else if(token == "on-menukey-script") { + iter.value()->get(on_menukey_script); } else if(token == "sector") { - Sector* sector = new Sector; + Sector* sector = new Sector(this); sector->parse(*(iter.lisp())); add_sector(sector); } else { - std::cerr << "Unknown token '" << token << "' in level file.\n"; - continue; + log_warning << "Unknown token '" << token << "' in level file" << std::endl; } } - + } catch(std::exception& e) { std::stringstream msg; msg << "Problem when reading level '" << filepath << "': " << e.what(); @@ -119,7 +106,7 @@ Level::load_old_format(const lisp::Lisp& reader) reader.get("name", name); reader.get("author", author); - Sector* sector = new Sector; + Sector* sector = new Sector(this); sector->parse_old_format(reader); add_sector(sector); } @@ -138,6 +125,8 @@ Level::save(const std::string& filename) writer->write_string("name", name, true); writer->write_string("author", author); + if(on_menukey_script != "") + writer->write_string("on-menukey-script", on_menukey_script); for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i) { Sector* sector = *i; @@ -192,15 +181,6 @@ Level::get_sector(size_t num) } int -Level::get_total_badguys() -{ - int total_badguys = 0; - for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i) - total_badguys += (*i)->get_total_badguys(); - return total_badguys; -} - -int Level::get_total_coins() { // FIXME not really correct as coins can also be inside blocks... @@ -217,3 +197,11 @@ Level::get_total_coins() return total_coins; } +int +Level::get_total_badguys() +{ + int total_badguys = 0; + for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i) + total_badguys += (*i)->get_total_badguys(); + return total_badguys; +}