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/shipmodel.cc')
-rw-r--r--src/game/base/shipmodel.cc69
1 files changed, 41 insertions, 28 deletions
diff --git a/src/game/base/shipmodel.cc b/src/game/base/shipmodel.cc
index 77ddb30..4cf55bf 100644
--- a/src/game/base/shipmodel.cc
+++ b/src/game/base/shipmodel.cc
@@ -10,6 +10,7 @@
#include "auxiliary/functions.h"
#include "base/shipmodel.h"
#include "base/game.h"
+#include "base/template.h"
#include "sys/sys.h"
namespace game
@@ -30,10 +31,10 @@ bool ShipModel::init()
using math::Vector3f;
using math::Color;
- filesystem::IniFile shipsini;
- shipsini.open("ini/ships");
- if (!shipsini.is_open()) {
- con_error << "Could not open " << shipsini.name() << "!" << std::endl;
+ filesystem::IniFile inifile;
+ inifile.open("ini/ships");
+ if (!inifile.is_open()) {
+ con_error << "Could not open " << inifile.name() << "!" << std::endl;
return false;
}
@@ -46,60 +47,71 @@ bool ShipModel::init()
float f;
bool b;
- while (shipsini.getline()) {
- if (shipsini.got_key()) {
- if (shipsini.section().compare("ship") == 0) {
- if (shipsini.got_key_label("label", str)) {
+ while (inifile.getline()) {
+ if (inifile.got_key()) {
+ if (inifile.section().compare("ship") == 0) {
+ if (inifile.got_key_label("label", str)) {
shipmodel->set_label(str);
count++;
continue;
- } else if (shipsini.got_key_string("name", str)) {
+ } else if (inifile.got_key_string("name", str)) {
shipmodel->set_name(str);
continue;
- } else if (shipsini.got_key_string("info", str)) {
+ } else if (inifile.got_key_string("info", str)) {
shipmodel->add_text(str);
continue;
- } else if (shipsini.got_key_string("model", str)) {
+ } else if (inifile.got_key_string("model", str)) {
shipmodel->set_modelname(str);
continue;
- } else if (shipsini.got_key_long("price", l)) {
+ } else if (inifile.got_key_long("price", l)) {
shipmodel->set_price(l);
continue;
- } else if (shipsini.got_key_float("cargo", f)) {
+ } else if (inifile.got_key_float("cargo", f)) {
shipmodel->set_maxcargo(f);
continue;
- } else if (shipsini.got_key_bool("jumpdrive", b)) {
+ } else if (inifile.got_key_bool("jumpdrive", b)) {
shipmodel->set_jumpdrive(b);
continue;
- } else if (shipsini.got_key_bool("dock", b)) {
+ } else if (inifile.got_key_bool("dock", b)) {
shipmodel->set_dock(b);
continue;
- } else if (shipsini.got_key_float("maxspeed", f)) {
+ } else if (inifile.got_key_float("maxspeed", f)) {
shipmodel->set_maxspeed(f * 0.01f);
continue;
- } else if (shipsini.got_key_float("impulse", f)) {
+ } else if (inifile.got_key_float("impulse", f)) {
shipmodel->set_impulse_force(f);
continue;
- } else if (shipsini.got_key_float("thrust", f)) {
+ } else if (inifile.got_key_float("thrust", f)) {
shipmodel->set_thrust_force(f);
continue;
- } else if (shipsini.got_key_float("strafe", f)) {
+ } else if (inifile.got_key_float("strafe", f)) {
shipmodel->set_strafe_force(f);
continue;
- } else if (shipsini.got_key_float("turn", f)) {
+ } else if (inifile.got_key_float("turn", f)) {
shipmodel->set_turn_force(f);
continue;
- } else if (shipsini.got_key_float("roll", f)) {
+ } else if (inifile.got_key_float("roll", f)) {
shipmodel->set_roll_force(f);
continue;
- } else if (shipsini.got_key_float("mass", f)) {
+ } else if (inifile.got_key_float("mass", f)) {
shipmodel->set_mass(f);
continue;
+ } else if (inifile.got_key_float("radius", f)) {
+ shipmodel->set_radius(f);
+ continue;
+ } else if (inifile.got_key_label("template", str)) {
+ Template *entitytemplate = Template::find(str);
+ if (!entitytemplate) {
+ inifile.unknown_error("unkown template '" + str + "'");
+ } else {
+ shipmodel->set_template(entitytemplate);
+ }
} else {
- shipsini.unkown_key();
+ inifile.unkown_key();
}
}
- } else if (shipsini.got_section("ship")) {
+ } else if (inifile.got_section("ship")) {
+
// generate info for the last loaded ship model
if (shipmodel) {
shipmodel->generate_info();
@@ -108,12 +120,13 @@ bool ShipModel::init()
// add a new shipmodel
shipmodel = new ShipModel();
+ // the first ship model is set as default, game.ini can override this later
if (!Default::shipmodel) {
Default::shipmodel = shipmodel;
}
- } else if (shipsini.got_section()) {
- shipsini.unknown_section();
+ } else if (inifile.got_section()) {
+ inifile.unknown_section();
}
}
@@ -122,9 +135,9 @@ bool ShipModel::init()
shipmodel->generate_info();
}
- con_debug << " " << shipsini.name() << " " << count << " ship types" << std::endl;
+ con_debug << " " << inifile.name() << " " << count << " ship types" << std::endl;
- shipsini.close();
+ inifile.close();
core::Func *func = core::Func::add("list_ship", func_list_ship);
func->set_info("list available ship types");