Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-06-01 13:03:45 +0000
committerStijn Buys <ingar@osirion.org>2008-06-01 13:03:45 +0000
commit190cede795ac4c7fcd6865a6c2083b5ce53a154a (patch)
treef1d05ebec665b0fb66ef2448a81ab2ed718ee279 /src/game
parent2a41efa0d43b573e1c8851086268b8a64d51c511 (diff)
entity and shipmodel labels, fixes sort order of shipmodels
Diffstat (limited to 'src/game')
-rw-r--r--src/game/game.cc27
-rw-r--r--src/game/ship.cc1
-rw-r--r--src/game/shipmodel.cc36
-rw-r--r--src/game/shipmodel.h18
4 files changed, 56 insertions, 26 deletions
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);
};