#include <level.hpp>
Public Types | |
typedef std::vector< Sector * > | Sectors |
Public Member Functions | |
Level () | |
~Level () | |
void | load (const std::string &filename) |
const std::string & | get_name () const |
const std::string & | get_author () const |
void | add_sector (Sector *sector) |
Sector * | get_sector (const std::string &name) |
size_t | get_sector_count () |
Sector * | get_sector (size_t num) |
const TileSet * | get_tileset () const |
int | get_total_coins () |
int | get_total_badguys () |
int | get_total_secrets () |
Public Attributes | |
std::string | name |
std::string | author |
std::string | contact |
std::string | license |
std::string | filename |
std::string | on_menukey_script |
Sectors | sectors |
Statistics | stats |
TileSet * | tileset |
bool | free_tileset |
Private Member Functions | |
void | load_old_format (const Reader &reader) |
Level (const Level &) | |
Level & | operator= (const Level &) |
Each Sector in turn contains GameObjects, e.g. Badguys and Players.
Definition at line 31 of file level.hpp.
typedef std::vector<Sector*> Level::Sectors |
Level::Level | ( | ) |
Level::~Level | ( | ) |
Definition at line 47 of file level.cpp.
References free_tileset, sectors, and tileset.
00048 { 00049 for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i) 00050 delete *i; 00051 if(free_tileset) 00052 delete tileset; 00053 }
Level::Level | ( | const Level & | ) | [private] |
void Level::load | ( | const std::string & | filename | ) |
Definition at line 56 of file level.cpp.
References add_sector(), author, contact, current_tileset, filename, free_tileset, lisp::Lisp::get(), lisp::Lisp::get_lisp(), TileManager::get_tileset(), lisp::ListIterator::item(), license, lisp::ListIterator::lisp(), load_old_format(), log_info, log_warning, name, lisp::ListIterator::next(), on_menukey_script, Sector::parse(), lisp::Parser::parse(), TileManager::parse_tileset_definition(), tile_manager, tileset, and lisp::ListIterator::value().
00057 { 00058 try { 00059 filename = filepath; 00060 lisp::Parser parser; 00061 const lisp::Lisp* root = parser.parse(filepath); 00062 00063 const lisp::Lisp* level = root->get_lisp("supertux-level"); 00064 if(!level) 00065 throw std::runtime_error("file is not a supertux-level file."); 00066 00067 int version = 1; 00068 level->get("version", version); 00069 if(version == 1) { 00070 log_info << "level uses old format: version 1" << std::endl; 00071 tileset = tile_manager->get_tileset("images/tiles.strf"); 00072 load_old_format(*level); 00073 return; 00074 } 00075 00076 const lisp::Lisp* tilesets_lisp = level->get_lisp("tilesets"); 00077 if(tilesets_lisp != NULL) { 00078 tileset = tile_manager->parse_tileset_definition(*tilesets_lisp); 00079 free_tileset = true; 00080 } 00081 std::string tileset_name; 00082 if(level->get("tileset", tileset_name)) { 00083 if(tileset != NULL) { 00084 log_warning << "multiple tilesets specified in level" << std::endl; 00085 } else { 00086 tileset = tile_manager->get_tileset(tileset_name); 00087 } 00088 } 00089 /* load default tileset */ 00090 if(tileset == NULL) { 00091 tileset = tile_manager->get_tileset("images/tiles.strf"); 00092 } 00093 current_tileset = tileset; 00094 00095 contact = ""; 00096 license = ""; 00097 00098 lisp::ListIterator iter(level); 00099 while(iter.next()) { 00100 const std::string& token = iter.item(); 00101 if(token == "version") { 00102 iter.value()->get(version); 00103 if(version > 2) { 00104 log_warning << "level format newer than application" << std::endl; 00105 } 00106 } else if(token == "tileset" || token == "tilesets") { 00107 continue; 00108 } else if(token == "name") { 00109 iter.value()->get(name); 00110 } else if(token == "author") { 00111 iter.value()->get(author); 00112 } else if(token == "contact") { 00113 iter.value()->get(contact); 00114 } else if(token == "license") { 00115 iter.value()->get(license); 00116 } else if(token == "on-menukey-script") { 00117 iter.value()->get(on_menukey_script); 00118 } else if(token == "sector") { 00119 Sector* sector = new Sector(this); 00120 sector->parse(*(iter.lisp())); 00121 add_sector(sector); 00122 } else { 00123 log_warning << "Unknown token '" << token << "' in level file" << std::endl; 00124 } 00125 } 00126 00127 if (license == "") { 00128 log_warning << "The level author did not specify a license for this level. You might not be allowed to share it." << std::endl; 00129 00130 } 00131 } catch(std::exception& e) { 00132 std::stringstream msg; 00133 msg << "Problem when reading level '" << filepath << "': " << e.what(); 00134 throw std::runtime_error(msg.str()); 00135 } 00136 00137 current_tileset = NULL; 00138 }
const std::string& Level::get_name | ( | ) | const [inline] |
Definition at line 54 of file level.hpp.
References name.
Referenced by LevelIntro::draw().
00055 { return name; }
const std::string& Level::get_author | ( | ) | const [inline] |
Definition at line 57 of file level.hpp.
References author.
Referenced by LevelIntro::draw().
00058 { return author; }
void Level::add_sector | ( | Sector * | sector | ) |
Definition at line 152 of file level.cpp.
References Sector::get_name(), get_sector(), and sectors.
Referenced by load(), and load_old_format().
00153 { 00154 Sector* test = get_sector(sector->get_name()); 00155 if(test != 0) { 00156 throw std::runtime_error("Trying to add 2 sectors with same name"); 00157 } 00158 sectors.push_back(sector); 00159 }
Sector * Level::get_sector | ( | const std::string & | name | ) |
Definition at line 162 of file level.cpp.
References sectors.
Referenced by add_sector(), and LevelTransformer::transform().
00163 { 00164 for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i) { 00165 Sector* sector = *i; 00166 if(sector->get_name() == name) 00167 return sector; 00168 } 00169 00170 return 0; 00171 }
size_t Level::get_sector_count | ( | ) |
Definition at line 174 of file level.cpp.
References sectors.
Referenced by LevelTransformer::transform().
00175 { 00176 return sectors.size(); 00177 }
Sector * Level::get_sector | ( | size_t | num | ) |
const TileSet* Level::get_tileset | ( | ) | const [inline] |
Definition at line 67 of file level.hpp.
References tileset.
Referenced by Sector::parse_old_format().
00068 { return tileset; }
int Level::get_total_coins | ( | ) |
Definition at line 186 of file level.cpp.
References BonusBlock::CONTENT_1UP, BonusBlock::CONTENT_COIN, BonusBlock::contents, and sectors.
00187 { 00188 int total_coins = 0; 00189 for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i) { 00190 Sector* sector = *i; 00191 for(Sector::GameObjects::iterator o = sector->gameobjects.begin(); 00192 o != sector->gameobjects.end(); ++o) { 00193 Coin* coin = dynamic_cast<Coin*> (*o); 00194 if(coin) 00195 { 00196 total_coins++; 00197 continue; 00198 } 00199 BonusBlock *block = dynamic_cast<BonusBlock*> (*o); 00200 if(block) 00201 { 00202 if (block->contents == BonusBlock::CONTENT_COIN) 00203 { 00204 total_coins++; 00205 continue; 00206 } 00207 #if 0 00208 // FIXME: do we want this? q.v. src/object/oneup.cpp 00209 else if (block->contents == BonusBlock::CONTENT_1UP) 00210 { 00211 total_coins += 100; 00212 continue; 00213 } 00214 #endif 00215 } 00216 } 00217 } 00218 return total_coins; 00219 }
int Level::get_total_badguys | ( | ) |
int Level::get_total_secrets | ( | ) |
void Level::load_old_format | ( | const Reader & | reader | ) | [private] |
Definition at line 141 of file level.cpp.
References add_sector(), author, lisp::Lisp::get(), name, and Sector::parse_old_format().
Referenced by load().
00142 { 00143 reader.get("name", name); 00144 reader.get("author", author); 00145 00146 Sector* sector = new Sector(this); 00147 sector->parse_old_format(reader); 00148 add_sector(sector); 00149 }
std::string Level::name |
Definition at line 36 of file level.hpp.
Referenced by GameMenu::GameMenu(), get_name(), load(), and load_old_format().
std::string Level::author |
std::string Level::contact |
std::string Level::license |
std::string Level::filename |
std::string Level::on_menukey_script |
Definition at line 42 of file level.hpp.
Referenced by add_sector(), get_sector(), get_sector_count(), get_total_badguys(), get_total_coins(), get_total_secrets(), and ~Level().
Definition at line 43 of file level.hpp.
Referenced by Coin::collect(), OneUp::collision(), LevelIntro::draw(), SecretAreaTrigger::event(), worldmap::WorldMap::finished_level(), BadGuy::run_dead_script(), and BonusBlock::try_open().
bool Level::free_tileset |