diff options
Diffstat (limited to 'src/game/base')
-rw-r--r-- | src/game/base/game.cc | 82 | ||||
-rw-r--r-- | src/game/base/game.h | 4 |
2 files changed, 63 insertions, 23 deletions
diff --git a/src/game/base/game.cc b/src/game/base/game.cc index e198d42..315f1fa 100644 --- a/src/game/base/game.cc +++ b/src/game/base/game.cc @@ -1947,7 +1947,8 @@ bool Game::load_world() filesystem::IniFile inifile; inifile.open(inifilename); - if (!inifile.is_open()) { + if (!inifile.is_open()) + { con_error << "Could not open " << inifile.name() << std::endl; return false; } @@ -1958,49 +1959,69 @@ bool Game::load_world() std::string label; math::Color color; - while (inifile.getline()) { - - if (inifile.got_section()) { + while (inifile.getline()) + { + if (inifile.got_section()) + { zone = 0; - if (inifile.got_section("world")) { + if (inifile.got_section("world")) + { continue; - } else { + } else + { inifile.unknown_section(); } - } else if (inifile.got_key()) { - - if (inifile.in_section("world")) { - - if (inifile.got_key_label("zone", label)) { + } else if (inifile.got_key()) + { + if (inifile.in_section("world")) + { + if (inifile.got_key_label("zone", label)) + { zone = new core::Zone(label); core::Zone::add(zone); - } else { + } else + { inifile.unknown_key(); - } + } } } } inifile.close(); - if (!core::Zone::registry().size()) { + if (!core::Zone::registry().size()) + { con_error << "No zones found!" << std::endl; return false; } con_debug << " " << inifile.name() << " " << core::Zone::registry().size() << " zones" << std::endl; - for (core::Zone::Registry::iterator it = core::Zone::registry().begin(); it != core::Zone::registry().end(); it++) { - if (!load_zone((*it).second)) { + for (core::Zone::Registry::iterator it = core::Zone::registry().begin(); it != core::Zone::registry().end(); it++) + { + if (!load_zone((*it).second)) + { return false; } } - for (core::Zone::Registry::iterator it = core::Zone::registry().begin(); it != core::Zone::registry().end(); it++) { - if (!validate_zone((*it).second)) { + // phase 1 validation + for (core::Zone::Registry::iterator it = core::Zone::registry().begin(); it != core::Zone::registry().end(); it++) + { + if (!validate_zone_phase1((*it).second)) + { + return false; + } + } + + // phase 2 validation + for (core::Zone::Registry::iterator it = core::Zone::registry().begin(); it != core::Zone::registry().end(); it++) + { + if (!validate_zone_phase2((*it).second)) + { return false; } } @@ -2652,7 +2673,7 @@ bool Game::load_zone(core::Zone *zone) return true; } -bool Game::validate_zone(core::Zone *zone) +bool Game::validate_zone_phase1(core::Zone *zone) { con_print << "^BValidating zone " << zone->label() << "..." << std::endl; @@ -2667,9 +2688,7 @@ bool Game::validate_zone(core::Zone *zone) JumpGate *jumpgate = static_cast<JumpGate *>(entity); jumpgate->validate(); } else if (entity->entity_moduletypeid == patrol_enttype) { - // validate jump gate - Patrol *patrol = static_cast<Patrol *>(entity); - patrol->validate(); + // validating patrols happens in phase 2 } else { if (entity->has_flag(core::Entity::Dockable)) { generate_entity_menus(entity); @@ -2701,6 +2720,25 @@ bool Game::validate_zone(core::Zone *zone) return true; } +bool Game::validate_zone_phase2(core::Zone *zone) +{ + con_print << "^BValidating zone " << zone->label() << " patrols..." << std::endl; + + // patrols can reference things like jumpgates) in other zones that have to be validated in the first phas + for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) + { + core::Entity *entity = (*it); + if (entity->entity_moduletypeid == patrol_enttype) + { + // validate patrol + Patrol *patrol = static_cast<Patrol *>(entity); + patrol->validate(); + } + } + + return true; +} + bool Game::generate_entity_menus(core::Entity *entity) { using core::MenuDescription; diff --git a/src/game/base/game.h b/src/game/base/game.h index 444916c..76d7797 100644 --- a/src/game/base/game.h +++ b/src/game/base/game.h @@ -118,7 +118,9 @@ private: bool load_zone(core::Zone *zone); - bool validate_zone(core::Zone *zone); + bool validate_zone_phase1(core::Zone *zone); + + bool validate_zone_phase2(core::Zone *zone); bool generate_entity_menus(core::Entity *entity); |