diff options
author | Stijn Buys <ingar@osirion.org> | 2008-09-10 19:17:52 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-09-10 19:17:52 +0000 |
commit | 83fb219e62113a9f41888af4f2726e5ce5305970 (patch) | |
tree | 3ba9780192fc7aa7d1fe7988b30a85c5ba08d422 /src/game/game.cc | |
parent | 033bd59cfc2dff93529ad448459ad6348ea29c8d (diff) |
serverside entities
Diffstat (limited to 'src/game/game.cc')
-rw-r--r-- | src/game/game.cc | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/game/game.cc b/src/game/game.cc index 3b13767..0502ece 100644 --- a/src/game/game.cc +++ b/src/game/game.cc @@ -5,6 +5,7 @@ */ #include <vector> +#include <string> #include "auxiliary/functions.h" #include "core/gameserver.h" @@ -12,6 +13,7 @@ #include "filesystem/inifile.h" #include "game/game.h" #include "game/navpoint.h" +#include "game/jumppoint.h" #include "game/planet.h" #include "game/racetrack.h" #include "game/ship.h" @@ -289,6 +291,12 @@ bool Game::load_world() } } + for (core::Zone::Registry::iterator it = core::Zone::registry().begin(); it != core::Zone::registry().end(); it++) { + if (!validate_zone((*it).second)) { + return false; + } + } + if (!default_zone) { con_error << "No default zone found!" << std::endl; return false; @@ -318,6 +326,7 @@ bool Game::load_zone(core::Zone *zone) Planet *planet = 0; Star *star = 0; NavPoint *navpoint = 0; + JumpPoint *jumppoint = 0; RaceTrack *racetrack = 0; CheckPoint *checkpoint = 0; core::Entity *entity = 0; @@ -385,6 +394,20 @@ bool Game::load_zone(core::Zone *zone) } else { con_warn << zoneini.name() << " unknown key '" << zoneini.key() << "' at line " << zoneini.line() << std::endl; } + } else if (zoneini.section().compare("jumppoint") == 0) { + if (zoneini.got_key_string("label", strval)) { + aux::to_label(strval); + jumppoint->entity_label.assign(strval); + continue; + } else if (zoneini.got_key_string("name", jumppoint->entity_name)) { + continue; + } else if (zoneini.got_key_string("target", jumppoint->jumppoint_targetlabel)) { + continue; + } else if (zoneini.got_key_vector3f("location", jumppoint->entity_location )) { + continue; + } else { + con_warn << zoneini.name() << " unknown key '" << zoneini.key() << "' at line " << zoneini.line() << std::endl; + } } else if (zoneini.section().compare("planet") == 0) { if (zoneini.got_key_string("label", strval)) { aux::to_label(strval); @@ -513,6 +536,11 @@ bool Game::load_zone(core::Zone *zone) navpoint->set_zone(zone); count ++; + } else if (zoneini.got_section("jumppoint")) { + jumppoint = new JumpPoint(); + jumppoint->set_zone(zone); + count ++; + } else if(zoneini.got_section("racetrack")) { racetrack = new RaceTrack(); racetrack->set_zone(zone); @@ -542,6 +570,54 @@ bool Game::load_zone(core::Zone *zone) con_debug << " " << zoneini.name() << " " << zone->content().size() << " entities" << std::endl; + + return true; +} + +bool Game::validate_zone(core::Zone *zone) +{ + for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) { + core::Entity *entity = (*it); + + if (entity->entity_moduletypeid == jumppoint_enttype) { + JumpPoint *jumppoint = static_cast<JumpPoint *>(entity); + + if (jumppoint->targetlabel().size() < 3) { + con_warn << " Jumppoint with invalid target label '" << jumppoint->targetlabel() << "'\n"; + continue; + } + size_t pos = jumppoint->targetlabel().find(':'); + if ((pos < 1 ) || (pos >= (jumppoint->targetlabel().size()-1))) { + con_warn << " Jumppoint with invalid target label '" << jumppoint->targetlabel() << "'\n"; + continue; + } + + std::string zonelabel(jumppoint->targetlabel().substr(0, pos)); + std::string entitylabel(jumppoint->targetlabel().substr(pos+1, jumppoint->targetlabel().size()-pos)); + + core::Zone *targetzone = core::Zone::find(zonelabel); + if (!targetzone) { + con_warn << " Jumppoint with invalid target zone '" << zonelabel << "'\n"; + continue; + } + + core::Entity *targetentity = targetzone->find_entity(entitylabel); + if (!targetentity) { + con_warn << " Could not find target jumppoint '" << entitylabel << "'\n"; + continue; + } + + if (targetentity->moduletype() != jumppoint_enttype) { + con_warn << " Jumppoint with invalid target jumppoint '" << entitylabel << "'\n"; + continue; + } + + jumppoint->jumppoint_target = static_cast<JumpPoint *>(targetentity); + + con_debug << " Jump point " << zone->label() << ":" << jumppoint->label() << " with target " << jumppoint->targetlabel() << std::endl; + } + } + return true; } |