Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/base')
-rw-r--r--src/game/base/jumppoint.cc16
-rw-r--r--src/game/base/ship.cc49
-rw-r--r--src/game/base/ship.h4
-rw-r--r--src/game/base/shipmodel.cc35
-rw-r--r--src/game/base/template.cc68
-rw-r--r--src/game/base/template.h5
6 files changed, 116 insertions, 61 deletions
diff --git a/src/game/base/jumppoint.cc b/src/game/base/jumppoint.cc
index 8af39b0..e52873e 100644
--- a/src/game/base/jumppoint.cc
+++ b/src/game/base/jumppoint.cc
@@ -79,11 +79,14 @@ void JumpPoint::validate()
}
set_name(name);
- if (!info()) {
- set_info(new core::Info(core::Entity::infotype(), label().c_str()));
+ // info is const, core::Info::find returns a non-const pointer
+ core::Info *entity_info = core::Info::find(info());
+ if (!entity_info) {
+ entity_info = new core::Info(core::Entity::infotype(), label().c_str());
+ set_info(entity_info);
}
- info()->clear_text();
- info()->add_text("Jumppoint to the " + target()->zone()->name());
+ entity_info->clear_text();
+ entity_info->add_text("Jumppoint to the " + target()->zone()->name());
con_debug << " " << label() << " jumppoint to " << target()->zone()->label() << ":" << target()->label() << std::endl;
@@ -119,8 +122,9 @@ void JumpGate::validate()
}
set_name(name);
- info()->clear_text();
- info()->add_text("Jumpgate to the " + target()->zone()->name());
+ core::Info *entity_info = core::Info::find(info());
+ entity_info->clear_text();
+ entity_info->add_text("Jumpgate to the " + target()->zone()->name());
if (target()) {
set_flag(core::Entity::Dockable);
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index 726729a..f88afd1 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -24,27 +24,27 @@ namespace game
const float MIN_DELTA = 0.000001f;
-Ship::Ship(core::Player *owner, ShipModel *shipmodel) : core::EntityControlable()
+Ship::Ship(core::Player *owner, const ShipModel *shipmodel) : core::EntityControlable()
{
assert(shipmodel);
+ ship_shipmodel = shipmodel;
entity_moduletypeid = ship_enttype;
-
set_radius(0);
// apply template settings
- if (shipmodel->model_template()) {
- shipmodel->model_template()->apply(this);
+ if (ship_shipmodel->model_template()) {
+ ship_shipmodel->model_template()->apply(this);
}
// apply ship model settings
// shipmodel overrides template model and radius
- if (shipmodel->modelname().size()) {
- set_modelname(shipmodel->modelname());
- }
- if (shipmodel->radius()) {
- set_radius(shipmodel->radius());
+ if (ship_shipmodel->modelname().size()) {
+ set_modelname(ship_shipmodel->modelname());
}
+ if (ship_shipmodel->radius()) {
+ set_radius(ship_shipmodel->radius());
+ }
if (!radius()) {
if (model()) {
set_radius(model()->radius());
@@ -53,17 +53,17 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) : core::EntityControlable(
if (!radius()) {
set_radius(0.5f);
}
-
- ship_shipmodel = shipmodel;
- set_info(shipmodel);
- set_name(shipmodel->name());
- ship_jumpdrive = shipmodel->jumpdrive();
+
+ set_name(ship_shipmodel->name());
+ set_info(ship_shipmodel);
+
+ ship_jumpdrive = ship_shipmodel->jumpdrive();
ship_impulsedrive_timer = 0;
ship_jumpdrive_timer = 0;
ship_jumpdepart = 0;
if (owner) {
- // this ship is owned by a player
+ // this ship is owned by a player,
// player colors override template colors
set_owner(owner);
get_color().assign(owner->color());
@@ -74,13 +74,12 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) : core::EntityControlable(
// add an inventory
set_inventory(new core::Inventory());
- inventory()->set_capacity(shipmodel->maxcargo());
+ inventory()->set_capacity(ship_shipmodel->maxcargo());
} else {
- set_name(shipmodel->name());
- set_label(shipmodel->label());
+ set_label(ship_shipmodel->label());
}
- if (shipmodel->dockable()) {
+ if (ship_shipmodel->dockable()) {
using core::MenuDescription;
using core::ButtonDescription;
@@ -98,12 +97,12 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) : core::EntityControlable(
set_flag(core::Entity::Dockable);
}
- set_mass(shipmodel->mass());
- set_impulse_force(shipmodel->impulse_force());
- set_thrust_force(shipmodel->thrust_force());
- set_strafe_force(shipmodel->strafe_force());
- set_turn_force(shipmodel->turn_force());
- set_roll_force(shipmodel->roll_force());
+ set_mass(ship_shipmodel->mass());
+ set_impulse_force(ship_shipmodel->impulse_force());
+ set_thrust_force(ship_shipmodel->thrust_force());
+ set_strafe_force(ship_shipmodel->strafe_force());
+ set_turn_force(ship_shipmodel->turn_force());
+ set_roll_force(ship_shipmodel->roll_force());
reset();
diff --git a/src/game/base/ship.h b/src/game/base/ship.h
index 9da45f4..ade7ff7 100644
--- a/src/game/base/ship.h
+++ b/src/game/base/ship.h
@@ -20,7 +20,7 @@ namespace game
class Ship : public core::EntityControlable
{
public:
- Ship(core::Player *owner, ShipModel *shipmodel);
+ Ship(core::Player *owner, const ShipModel *shipmodel);
~Ship();
/// shipmodel
@@ -111,7 +111,7 @@ public:
private:
JumpPoint *find_closest_jumppoint();
- ShipModel *ship_shipmodel;
+ const ShipModel *ship_shipmodel;
float current_target_direction;
float current_target_pitch;
diff --git a/src/game/base/shipmodel.cc b/src/game/base/shipmodel.cc
index 4c67e72..d9a9ed7 100644
--- a/src/game/base/shipmodel.cc
+++ b/src/game/base/shipmodel.cc
@@ -40,8 +40,12 @@ bool ShipModel::init()
con_print << "^BLoading ships..." << std::endl;
- size_t count = 0;
+ size_t shipmodel_count = 0;
+ size_t template_count = 0;
+
ShipModel *shipmodel = 0;
+ Template *entitytemplate = 0;
+
std::string str;
long l;
float f;
@@ -49,11 +53,24 @@ bool ShipModel::init()
while (inifile.getline()) {
if (inifile.got_key()) {
- if (inifile.section().compare("ship") == 0) {
+
+ if (inifile.section().compare("template") == 0) {
+
+ if (Template::got_template_key(inifile, entitytemplate)) {
+ continue;
+ } else {
+ inifile.unkown_key();
+ }
+
+ } else if (inifile.section().compare("ship") == 0) {
+
if (inifile.got_key_label("label", str)) {
+ if (find(str)) {
+ inifile.unknown_error("duplicate ship type '" + str + "'");
+ }
shipmodel->set_label(str);
- count++;
continue;
+
} else if (inifile.got_key_string("name", str)) {
shipmodel->set_name(str);
continue;
@@ -110,6 +127,12 @@ bool ShipModel::init()
inifile.unkown_key();
}
}
+
+ } else if (inifile.got_section("template")) {
+
+ template_count++;
+ entitytemplate = new Template();
+
} else if (inifile.got_section("ship")) {
// generate info for the last loaded ship model
@@ -124,6 +147,8 @@ bool ShipModel::init()
if (!Default::shipmodel) {
Default::shipmodel = shipmodel;
}
+
+ shipmodel_count++;
} else if (inifile.got_section()) {
inifile.unknown_section();
@@ -135,7 +160,9 @@ bool ShipModel::init()
shipmodel->generate_info();
}
- con_debug << " " << inifile.name() << " " << count << " ship types" << std::endl;
+ con_debug << " " << inifile.name() << " " << template_count << " entity templates" << std::endl;
+ con_debug << " " << inifile.name() << " " << shipmodel_count << " ship types" << std::endl;
+
inifile.close();
diff --git a/src/game/base/template.cc b/src/game/base/template.cc
index f937e22..7327c31 100644
--- a/src/game/base/template.cc
+++ b/src/game/base/template.cc
@@ -33,6 +33,47 @@ void Template::list()
core::Info::list(template_infotype);
}
+bool Template::got_template_key(filesystem::IniFile &inifile, Template *entitytemplate)
+{
+ std::string strvalue;
+ math::Color colorvalue;
+ float floatvalue;
+
+ if (inifile.got_key_label("label", strvalue)) {
+ if (find(strvalue)) {
+ inifile.unknown_error("duplicate template '" + strvalue + "'");
+ }
+ entitytemplate->set_label(strvalue);
+ return true;
+
+ } else if (inifile.got_key_string("name", strvalue)) {
+ entitytemplate->set_name(strvalue);
+ return true;
+
+ } else if (inifile.got_key_string("model", strvalue)) {
+ entitytemplate->set_modelname(strvalue);
+ return true;
+
+ } else if (inifile.got_key_string("info", strvalue)) {
+ entitytemplate->add_text(strvalue);
+ return true;
+
+ } else if (inifile.got_key_color("color", colorvalue)) {
+ entitytemplate->set_color(colorvalue);
+ return true;
+
+ } else if (inifile.got_key_color("colorsecond", colorvalue)) {
+ entitytemplate->set_color_second(colorvalue);
+ return true;
+
+ } else if (inifile.got_key_float("radius", floatvalue)) {
+ entitytemplate->set_radius(floatvalue);
+ return true;
+ } else {
+ return false;
+ }
+}
+
bool Template::init()
{
// initialize template InfoType
@@ -52,10 +93,7 @@ bool Template::init()
size_t count = 0;
Template *entitytemplate = 0;
- std::string strvalue;
- math::Color colorvalue;
- float floatvalue;
-
+
while (inifile.getline()) {
if (inifile.got_section()) {
@@ -74,26 +112,8 @@ bool Template::init()
if (inifile.in_section("template")) {
- if (inifile.got_key_label("label", strvalue)) {
- entitytemplate->set_label(strvalue);
-
- } else if (inifile.got_key_string("name", strvalue)) {
- entitytemplate->set_name(strvalue);
-
- } else if (inifile.got_key_string("model", strvalue)) {
- entitytemplate->set_modelname(strvalue);
-
- } else if (inifile.got_key_string("info", strvalue)) {
- entitytemplate->add_text(strvalue);
-
- } else if (inifile.got_key_color("color", colorvalue)) {
- entitytemplate->set_color(colorvalue);
-
- } else if (inifile.got_key_color("colorsecond", colorvalue)) {
- entitytemplate->set_color_second(colorvalue);
-
- } else if (inifile.got_key_float("radius", floatvalue)) {
- entitytemplate->set_radius(floatvalue);
+ if (got_template_key(inifile, entitytemplate)) {
+ continue;
} else {
inifile.unkown_key();
}
diff --git a/src/game/base/template.h b/src/game/base/template.h
index 5780e9c..7934a7f 100644
--- a/src/game/base/template.h
+++ b/src/game/base/template.h
@@ -50,6 +50,11 @@ public:
* @brief apply a template to an entity
*/
void apply(core::Entity *entity) const;
+
+ /**
+ * @brief read template keys from an ini file
+ */
+ static bool got_template_key(filesystem::IniFile &inifile, Template *entitytemplate);
protected: