// $Id$
-//
+//
// SuperTux
-// Copyright (C) 2004 SuperTux Development Team, see AUTHORS for details
+// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// 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
#include <memory>
#include <stdexcept>
-#include "video/screen.hpp"
-#include "msg.hpp"
+#include "log.hpp"
#include "lisp/parser.hpp"
#include "lisp/lisp.hpp"
#include "lisp/list_iterator.hpp"
#include "object/camera.hpp"
#include "object/tilemap.hpp"
#include "object/coin.hpp"
-
-// test
-#include "flip_level_transformer.hpp"
+#include "object/block.hpp"
using namespace std;
Level::Level()
- : name("noname"), author("Mr. X"), extro_music("leveldone.ogg"), extro_length(7.0)
+ : name("noname"), author("Mr. X")
{
}
if(token == "version") {
iter.value()->get(version);
if(version > 2) {
- msg_warning("level format newer than application");
+ 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 {
- msg_warning("Unknown token '" << token << "' in level file");
- 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();
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);
}
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;
}
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...
int total_coins = 0;
for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i) {
Sector* sector = *i;
o != sector->gameobjects.end(); ++o) {
Coin* coin = dynamic_cast<Coin*> (*o);
if(coin)
+ {
total_coins++;
+ continue;
+ }
+ BonusBlock *block = dynamic_cast<BonusBlock*> (*o);
+ if(block)
+ {
+ if (block->contents == BonusBlock::CONTENT_COIN)
+ {
+ total_coins++;
+ continue;
+ }
+#if 0
+ // FIXME: do we want this? q.v. src/object/oneup.cpp
+ else if (block->contents == BonusBlock::CONTENT_1UP)
+ {
+ total_coins += 100;
+ continue;
+ }
+#endif
+ }
}
}
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;
+}