// $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 "app/globals.h"
-#include "app/setup.h"
-#include "video/screen.h"
-#include "lisp/parser.h"
-#include "lisp/lisp.h"
-#include "lisp/list_iterator.h"
-#include "lisp/writer.h"
-#include "level.h"
-#include "math/physic.h"
-#include "sector.h"
-#include "tile.h"
-#include "resources.h"
-#include "object/gameobjs.h"
-#include "object/camera.h"
-#include "object/tilemap.h"
-#include "object/coin.h"
-
-// test
-#include "flip_level_transformer.h"
+#include "log.hpp"
+#include "lisp/parser.hpp"
+#include "lisp/lisp.hpp"
+#include "lisp/list_iterator.hpp"
+#include "lisp/writer.hpp"
+#include "level.hpp"
+#include "physic.hpp"
+#include "sector.hpp"
+#include "tile.hpp"
+#include "resources.hpp"
+#include "file_system.hpp"
+#include "object/gameobjs.hpp"
+#include "object/camera.hpp"
+#include "object/tilemap.hpp"
+#include "object/coin.hpp"
+#include "object/block.hpp"
using namespace std;
Level::Level()
- : name("noname"), author("Mr. X"), timelimit(500)
+ : name("noname"), author("Mr. X")
{
}
{
try {
lisp::Parser parser;
- std::auto_ptr<lisp::Lisp> root (parser.parse(filepath));
+ const lisp::Lisp* root = parser.parse(filepath);
const lisp::Lisp* level = root->get_lisp("supertux-level");
if(!level)
level->get("version", version);
if(version == 1) {
load_old_format(*level);
-
-#if 0
- // test for now
- FlipLevelTransformer* transformer = new FlipLevelTransformer();
- transformer->transform(this);
-#endif
-
return;
}
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 == "time") {
- iter.value()->get(timelimit);
+ } 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();
{
reader.get("name", name);
reader.get("author", author);
- reader.get("time", timelimit);
- Sector* sector = new Sector;
+ Sector* sector = new Sector(this);
sector->parse_old_format(reader);
add_sector(sector);
}
void
Level::save(const std::string& filename)
{
- std::string filepath = "levels/" + filename;
- int last_slash = filepath.find_last_of('/');
- FileSystem::fcreatedir(filepath.substr(0,last_slash).c_str());
- filepath = user_dir + "/" + filepath;
- ofstream file(filepath.c_str(), ios::out);
- lisp::Writer* writer = new lisp::Writer(file);
+ lisp::Writer* writer = new lisp::Writer(filename);
writer->write_comment("Level made using SuperTux's built-in Level Editor");
writer->write_string("name", name, true);
writer->write_string("author", author);
- writer->write_int("time", timelimit);
+ 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;
writer->end_list("supertux-level");
delete writer;
- file.close();
}
Level::~Level()
}
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;
+}