diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/entity.cc | 13 | ||||
-rw-r--r-- | src/core/entity.h | 4 | ||||
-rw-r--r-- | src/game/game.cc | 27 | ||||
-rw-r--r-- | src/game/ship.cc | 1 | ||||
-rw-r--r-- | src/game/shipmodel.cc | 36 | ||||
-rw-r--r-- | src/game/shipmodel.h | 18 |
6 files changed, 72 insertions, 27 deletions
diff --git a/src/core/entity.cc b/src/core/entity.cc index 46231d8..e9985c3 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -71,7 +71,7 @@ void Entity::list() con_print << " id " << std::setw(4) << entity->id() << " type " << std::setw(4) << entity->type() << ":" << std::setw(4) << entity->moduletype() - << " " << entity->name() << std::endl; + << " " << entity->label() << std::endl; } con_print << registry.size() << " registered entities" << std::endl; } @@ -95,6 +95,7 @@ Entity::Entity(unsigned int flags) : entity_model = 0; entity_modelname.clear(); + entity_label.clear(); entity_name.clear(); entity_clientstate = 0; @@ -123,12 +124,21 @@ Entity::Entity(std::istream & is) entity_shape = (Shape) s ; char c; + // read label + while ( (is.get(c)) && (c != '"')); + while ( (is.get(c)) && (c != '"')) + n += c; + entity_label = n; + n.clear(); + + // read name while ( (is.get(c)) && (c != '"')); while ( (is.get(c)) && (c != '"')) n += c; entity_name = n; n.clear(); + // read model name while ( (is.get(c)) && (c != '"')); while ( (is.get(c)) && (c != '"')) n += c; @@ -164,6 +174,7 @@ void Entity::serialize(std::ostream & os) const << entity_radius << " " << entity_axis.forward() << " " << entity_axis.left() << " " + << "\"" << entity_label << "\" " << "\"" << entity_name << "\" " << "\"" << entity_modelname << "\""; } diff --git a/src/core/entity.h b/src/core/entity.h index c93d059..bf35bfe 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -68,6 +68,9 @@ public: /// entity flags inline unsigned int flags() const { return entity_flags; } + /// entity label (can not contain double quotes ") + inline std::string const & label() { return entity_label; } + /// entity name (can not contain double qoutes ") inline std::string const & name() { return entity_name; } @@ -145,6 +148,7 @@ public: float entity_radius; std::string entity_name; + std::string entity_label; std::string entity_modelname; model::Model *entity_model; Shape entity_shape; diff --git a/src/game/game.cc b/src/game/game.cc index 15ae029..6d85f0f 100644 --- a/src/game/game.cc +++ b/src/game/game.cc @@ -77,15 +77,15 @@ void func_buy(core::Player *player, std::string const &args) aux::to_lowercase(shipname); ShipModel *shipmodel = 0; - for (std::list<ShipModel *>::iterator smit = ShipModel::registry.begin(); smit != ShipModel::registry.end(); smit++) { - if (shipname == (*smit)->modelname()) { - shipmodel = (*smit); + for (ShipModel::iterator smit = ShipModel::registry.begin(); smit != ShipModel::registry.end(); smit++) { + if (shipname == (*smit).first) { + shipmodel = (*smit).second; break; } if (helpstr.size()) helpstr.append("^N|^B"); - helpstr.append((*smit)->modelname()); + helpstr.append((*smit).second->label()); } if (shipmodel) { @@ -168,7 +168,9 @@ void Game::init() while (worldini.getline()) { if (worldini.got_key()) { if (worldini.section().compare("star") == 0) { - if (worldini.got_key_string("name", star->entity_name)) + if (worldini.got_key_string("label", star->entity_label)) + continue; + else if (worldini.got_key_string("name", star->entity_name)) continue; else if (worldini.got_key_vector3f("location", star->entity_location )) continue; @@ -180,7 +182,9 @@ void Game::init() con_warn << worldini.name() << " unknown key '" << worldini.key() << "' at line " << worldini.line() << std::endl; } else if (worldini.section().compare("planet") == 0) { - if (worldini.got_key_string("name", planet->entity_name)) + if (worldini.got_key_string("label", planet->entity_label)) + continue; + else if (worldini.got_key_string("name", planet->entity_name)) continue; else if (worldini.got_key_string("texture", planet->entity_texture)) continue; @@ -196,7 +200,6 @@ void Game::init() } else if (worldini.section().compare("entity") == 0) { std::string shapename; - if (worldini.got_key_string("shape", shapename)) { if (shapename.compare("axis") == 0) { entity->entity_shape = core::Entity::Axis; @@ -210,7 +213,9 @@ void Game::init() con_warn << worldini.name() << " unknown shape '" << shapename << "' at line " << worldini.line() << std::endl; } continue; - } else if (worldini.got_key_string("name", entity->entity_name)) + } else if (worldini.got_key_string("label", entity->entity_label)) + continue; + else if (worldini.got_key_string("name", entity->entity_name)) continue; else if (worldini.got_key_string("model", entity->entity_modelname)) continue; @@ -265,8 +270,10 @@ void Game::init() while (shipsini.getline()) { if (shipsini.got_key()) { if (shipsini.section().compare("ship") == 0) { - - if (shipsini.got_key_string("name",shipmodel->shipmodel_name)) { + if (shipsini.got_key_string("label", shipmodel->shipmodel_label)) { + ShipModel::add(shipmodel); + continue; + } else if (shipsini.got_key_string("name",shipmodel->shipmodel_name)) { continue; } else if (shipsini.got_key_string("model", shipmodel->shipmodel_modelname)) { continue; diff --git a/src/game/ship.cc b/src/game/ship.cc index bf71215..66d8b52 100644 --- a/src/game/ship.cc +++ b/src/game/ship.cc @@ -22,6 +22,7 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) : { entity_modelname = "ships/" + shipmodel->modelname(); entity_name = shipmodel->name() + ": <^B" + owner->name() + "^N>"; + entity_label = shipmodel->label(); ship_shipmodel = shipmodel; entity_moduletypeid = ship_enttype; diff --git a/src/game/shipmodel.cc b/src/game/shipmodel.cc index 8e97970..aa0c2c9 100644 --- a/src/game/shipmodel.cc +++ b/src/game/shipmodel.cc @@ -10,7 +10,7 @@ namespace game { // the ship model registry -std::list<ShipModel *> ShipModel::registry; +std::map<std::string, ShipModel *> ShipModel::registry; ShipModel::ShipModel() { @@ -19,7 +19,6 @@ ShipModel::ShipModel() shipmodel_maxspeed = 3.0f; shipmodel_turnspeed = 0.1f; - add(this); } ShipModel::~ShipModel() @@ -29,29 +28,44 @@ ShipModel::~ShipModel() // clear the ship model registry void ShipModel::clear() { - for (std::list< ShipModel *>::iterator smit=registry.begin(); smit != registry.end(); smit++) { - delete (*smit); + for (iterator smit = registry.begin(); smit != registry.end(); smit++) { + delete (*smit).second; } registry.clear(); } void ShipModel::list() { - for (std::list< ShipModel *>::iterator smit=registry.begin(); smit != registry.end(); smit++) { + for (iterator smit = registry.begin(); smit != registry.end(); smit++) { con_print << - " " << (*smit)->modelname() << - " " << (*smit)->name() << - " accel " << (*smit)->acceleration() << - " max " << (*smit)->maxspeed() << - " turn " << (*smit)->turnspeed() << "\n"; + " " << (*smit).second->label() << + " " << (*smit).second->name() << + " accel " << (*smit).second->acceleration() << + " max " << (*smit).second->maxspeed() << + " turn " << (*smit).second->turnspeed() << "\n"; } con_print << registry.size() << " registered ship models\n"; } +ShipModel *ShipModel::find(const std::string label) +{ + std::map<std::string, ShipModel *>::iterator it = registry.find(label); + if (it == registry.end()) + return 0; + else + return (*it).second; +} + // add a new ship model void ShipModel::add(ShipModel *shipmodel) { - registry.push_back(shipmodel); + ShipModel *m = find(shipmodel->label()); + if (m) { + con_warn << "Duplicate ship model " << shipmodel->label() << "!\n"; + delete m; + } + + registry[shipmodel->label()] = shipmodel; } } diff --git a/src/game/shipmodel.h b/src/game/shipmodel.h index fd42c81..686d736 100644 --- a/src/game/shipmodel.h +++ b/src/game/shipmodel.h @@ -7,7 +7,7 @@ #ifndef __INCLUDED_GAME_SHIPMODEL_H__ #define __INCLUDED_GAME_SHIPMODEL_H__ -#include <list> +#include <map> #include <string> namespace game { @@ -28,27 +28,35 @@ public: /// turn speed in rotations per second inline float turnspeed() const { return shipmodel_turnspeed; } - /// name of the model to use - inline std::string const & modelname() const { return shipmodel_modelname; } + /// label of the ship model + inline std::string const &label() const { return shipmodel_label; } /// name of the ship model inline std::string const & name() const { return shipmodel_name; } + /// name of the model of the ship + inline std::string const & modelname() const { return shipmodel_modelname; } + float shipmodel_acceleration; float shipmodel_maxspeed; float shipmodel_turnspeed; + std::string shipmodel_label; std::string shipmodel_name; std::string shipmodel_modelname; + static ShipModel *find(const std::string label); + /// the ship model registry - static std::list<ShipModel *> registry; + static std::map<std::string, ShipModel *> registry; + + typedef std::map<std::string, ShipModel *>::iterator iterator; /// clear the ship model registry static void clear(); /// list the ship model registry static void list(); -private: + /// add a new ship model static void add(ShipModel *shipmodel); }; |