Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
Diffstat (limited to 'src/game')
-rw-r--r--src/game/base/shipmodel.cc122
-rw-r--r--src/game/base/shipmodel.h6
-rw-r--r--src/game/base/weapon.cc120
3 files changed, 147 insertions, 101 deletions
diff --git a/src/game/base/shipmodel.cc b/src/game/base/shipmodel.cc
index f504107..cb627c6 100644
--- a/src/game/base/shipmodel.cc
+++ b/src/game/base/shipmodel.cc
@@ -62,85 +62,121 @@ bool ShipModel::init()
inifile.unknown_key();
}
- } else if (inifile.section().compare("ship") == 0) {
-
- if (inifile.got_key_label("label", str)) {
- if (find(str)) {
+ } 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);
continue;
- } else if (inifile.got_key_string("name", str)) {
+ } else if (inifile.got_key_string("name", str))
+ {
shipmodel->set_name(str);
continue;
- } else if (inifile.got_key_string("info", str)) {
+ } else if (inifile.got_key_string("info", str))
+ {
shipmodel->add_text(str);
continue;
- } else if (inifile.got_key_string("model", str)) {
+ } else if (inifile.got_key_string("model", str))
+ {
shipmodel->set_modelname(str);
continue;
- } else if (inifile.got_key_long("price", l)) {
+
+ } else if (inifile.got_key("level"))
+ {
+ core::Level level;
+ std::istringstream str(inifile.value());
+ if (str >> level)
+ {
+ shipmodel->set_level(level);
+ } else
+ {
+ inifile.unknown_value();
+ }
+
+ } else if (inifile.got_key_long("price", l))
+ {
shipmodel->set_price(l);
continue;
- } else if (inifile.got_key_float("cargo", f)) {
+ } else if (inifile.got_key_float("cargo", f))
+ {
shipmodel->set_maxcargo(f);
continue;
- } else if (inifile.got_key_bool("jumpdrive", b)) {
+ } else if (inifile.got_key_bool("jumpdrive", b))
+ {
shipmodel->set_jumpdrive(b);
continue;
- } else if (inifile.got_key_bool("dock", b)) {
+ } else if (inifile.got_key_bool("dock", b))
+ {
shipmodel->set_dockable(b);
continue;
-// } else if (inifile.got_key_float("maxspeed", f)) {
-// shipmodel->set_maxspeed(f * 0.01f);
-// continue;
- } else if (inifile.got_key_float("impulse", f)) {
+ } else if (inifile.got_key_float("impulse", f))
+ {
shipmodel->set_impulse_force(f);
continue;
- } else if (inifile.got_key_float("thrust", f)) {
+ } else if (inifile.got_key_float("thrust", f))
+ {
shipmodel->set_thrust_force(f);
continue;
- } else if (inifile.got_key_float("strafe", f)) {
+ } else if (inifile.got_key_float("strafe", f))
+ {
shipmodel->set_strafe_force(f);
continue;
- } else if (inifile.got_key_float("turn", f)) {
+ } else if (inifile.got_key_float("turn", f))
+ {
shipmodel->set_turn_force(f);
continue;
- } else if (inifile.got_key_float("roll", f)) {
+ } else if (inifile.got_key_float("roll", f))
+ {
shipmodel->set_roll_force(f);
continue;
- } else if (inifile.got_key_float("mass", f)) {
+ } else if (inifile.got_key_float("mass", f))
+ {
shipmodel->set_mass(f);
continue;
- } else if (inifile.got_key_float("armor", f)) {
+ } else if (inifile.got_key_float("armor", f))
+ {
shipmodel->set_maxarmor(f);
continue;
- } else if (inifile.got_key_float("shield", f)) {
+ } else if (inifile.got_key_float("shield", f))
+ {
shipmodel->set_maxshield(f);
continue;
- } else if (inifile.got_key_float("radius", f)) {
+ } else if (inifile.got_key_float("radius", f))
+ {
shipmodel->set_radius(f);
continue;
- } else if (inifile.got_key_string("damping", str)) {
+ } else if (inifile.got_key_string("damping", str))
+ {
float linear, angular;
std::istringstream sstr("str");
- if (sstr >> linear) {
- if (sstr >> angular) {
+ if (sstr >> linear)
+ {
+ if (sstr >> angular)
+ {
shipmodel->set_linear_damping(linear);
shipmodel->set_angular_damping(angular);
- } else {
+ } else
+ {
shipmodel->set_linear_damping(linear);
shipmodel->set_angular_damping(linear);
}
- } else {
+ } else
+ {
inifile.unknown_value();
}
- } else if (inifile.got_key_label("template", str)) {
+ } else if (inifile.got_key_label("template", str))
+ {
Template *entitytemplate = Template::find(str);
- if (!entitytemplate) {
+ if (!entitytemplate)
+ {
inifile.unknown_error("unkown template '" + str + "'");
- } else {
+ } else
+ {
// apply the template settings to the shipmodel
shipmodel->set_template(entitytemplate);
if (entitytemplate->radius()) {
@@ -151,20 +187,22 @@ bool ShipModel::init()
shipmodel->set_maxarmor(entitytemplate->maxarmor());
}
}
- } else {
+ } else
+ {
inifile.unknown_key();
}
}
- } else if (inifile.got_section("template")) {
-
+ } else if (inifile.got_section("template"))
+ {
template_count++;
entitytemplate = new Template();
- } else if (inifile.got_section("ship")) {
-
+ } else if (inifile.got_section("ship"))
+ {
// generate info for the last loaded ship model
- if (shipmodel) {
+ if (shipmodel)
+ {
shipmodel->generate_info();
}
@@ -172,26 +210,28 @@ bool ShipModel::init()
shipmodel = new ShipModel();
// the first ship model is set as default, game.ini can override this later
- if (!Default::shipmodel) {
+ if (!Default::shipmodel)
+ {
Default::shipmodel = shipmodel;
}
shipmodel_count++;
- } else if (inifile.got_section()) {
+ } else if (inifile.got_section())
+ {
inifile.unknown_section();
}
}
// generate info for the last loaded ship model
- if (shipmodel) {
+ if (shipmodel)
+ {
shipmodel->generate_info();
}
con_debug << " " << inifile.name() << " " << template_count << " entity templates" << std::endl;
con_debug << " " << inifile.name() << " " << shipmodel_count << " ship types" << std::endl;
-
inifile.close();
core::Func *func = core::Func::add("list_ship", func_list_ship);
diff --git a/src/game/base/shipmodel.h b/src/game/base/shipmodel.h
index 709a1d6..36c2831 100644
--- a/src/game/base/shipmodel.h
+++ b/src/game/base/shipmodel.h
@@ -90,12 +90,6 @@ public:
return shipmodel_angular_damping;
}
-// /// maximum thrust speed
-// inline const float maxspeed() const
-// {
-// return shipmodel_maxspeed;
-// }
-
/// size of the cargo hold, in cubic meters
inline const float maxcargo() const
{
diff --git a/src/game/base/weapon.cc b/src/game/base/weapon.cc
index 416b4c3..28a7ae3 100644
--- a/src/game/base/weapon.cc
+++ b/src/game/base/weapon.cc
@@ -32,10 +32,10 @@ bool Weapon::init()
// initialize weapon InfoType
weapon_infotype = new core::InfoType("weapon");
- filesystem::IniFile weaponsini;
- weaponsini.open("ini/weapons");
- if (!weaponsini.is_open()) {
- con_error << "Could not open " << weaponsini.name() << "!" << std::endl;
+ filesystem::IniFile inifile;
+ inifile.open("ini/weapons");
+ if (!inifile.is_open()) {
+ con_error << "Could not open " << inifile.name() << "!" << std::endl;
return false;
}
@@ -48,185 +48,197 @@ bool Weapon::init()
long l;
float f;
- while (weaponsini.getline()) {
- if (weaponsini.got_key()) {
+ while (inifile.getline()) {
+ if (inifile.got_key()) {
- if (weaponsini.section().compare("mine") == 0) {
- if (weaponsini.got_key_label("label", str)) {
+ if (inifile.section().compare("mine") == 0) {
+ if (inifile.got_key_label("label", str)) {
weapon->set_label(str);
continue;
- } else if (weaponsini.got_key_string("name", str)) {
+ } else if (inifile.got_key_string("name", str)) {
weapon->set_name(str);
continue;
- } else if (weaponsini.got_key_string("info", str)) {
+ } else if (inifile.got_key_string("info", str)) {
weapon->add_text(str);
continue;
- } else if (weaponsini.got_key_string("model", str)) {
+ } else if (inifile.got_key_string("model", str)) {
weapon->set_modelname(str);
continue;
+
+ } else if (inifile.got_key("level"))
+ {
+ core::Level level;
+ std::istringstream str(inifile.value());
+ if (str >> level)
+ {
+ weapon->set_level(level);
+ } else
+ {
+ inifile.unknown_value();
+ }
- } else if (weaponsini.got_key_long("price", l)) {
+ } else if (inifile.got_key_long("price", l)) {
weapon->set_price(l);
continue;
- } else if (weaponsini.got_key_float("volume", f)) {
+ } else if (inifile.got_key_float("volume", f)) {
weapon->set_volume(f);
continue;
- } else if (weaponsini.got_key_long("level", l)) {
+ } else if (inifile.got_key_long("level", l)) {
weapon->set_level(l);
continue;
- } else if (weaponsini.got_key_float("damage", f)) {
+ } else if (inifile.got_key_float("damage", f)) {
weapon->set_damage(f);
continue;
} else {
- weaponsini.unknown_key();
+ inifile.unknown_key();
}
- } else if (weaponsini.section().compare("cannon") == 0) {
- if (weaponsini.got_key_label("label", str)) {
+ } else if (inifile.section().compare("cannon") == 0) {
+ if (inifile.got_key_label("label", str)) {
weapon->set_label(str);
continue;
- } else if (weaponsini.got_key_string("name", str)) {
+ } else if (inifile.got_key_string("name", str)) {
weapon->set_name(str);
continue;
- } else if (weaponsini.got_key_string("info", str)) {
+ } else if (inifile.got_key_string("info", str)) {
weapon->add_text(str);
continue;
- } else if (weaponsini.got_key_string("model", str)) {
+ } else if (inifile.got_key_string("model", str)) {
weapon->set_modelname(str);
continue;
- } else if (weaponsini.got_key_long("price", l)) {
+ } else if (inifile.got_key_long("price", l)) {
weapon->set_price(l);
continue;
- } else if (weaponsini.got_key_float("volume", f)) {
+ } else if (inifile.got_key_float("volume", f)) {
weapon->set_volume(f);
continue;
- } else if (weaponsini.got_key_long("level", l)) {
+ } else if (inifile.got_key_long("level", l)) {
weapon->set_level(l);
continue;
} else {
- weaponsini.unknown_key();
+ inifile.unknown_key();
}
- } else if (weaponsini.section().compare("turret") == 0) {
- if (weaponsini.got_key_label("label", str)) {
+ } else if (inifile.section().compare("turret") == 0) {
+ if (inifile.got_key_label("label", str)) {
weapon->set_label(str);
continue;
- } else if (weaponsini.got_key_string("name", str)) {
+ } else if (inifile.got_key_string("name", str)) {
weapon->set_name(str);
continue;
- } else if (weaponsini.got_key_string("info", str)) {
+ } else if (inifile.got_key_string("info", str)) {
weapon->add_text(str);
continue;
- } else if (weaponsini.got_key_string("model", str)) {
+ } else if (inifile.got_key_string("model", str)) {
weapon->set_modelname(str);
continue;
- } else if (weaponsini.got_key_long("price", l)) {
+ } else if (inifile.got_key_long("price", l)) {
weapon->set_price(l);
continue;
- } else if (weaponsini.got_key_float("volume", f)) {
+ } else if (inifile.got_key_float("volume", f)) {
weapon->set_volume(f);
continue;
- } else if (weaponsini.got_key_long("level", l)) {
+ } else if (inifile.got_key_long("level", l)) {
weapon->set_level(l);
continue;
} else {
- weaponsini.unknown_key();
+ inifile.unknown_key();
}
- } else if (weaponsini.section().compare("projectile") == 0) {
+ } else if (inifile.section().compare("projectile") == 0) {
if (weapon) {
- if (weaponsini.got_key_float("speed", f)) {
+ if (inifile.got_key_float("speed", f)) {
// convert speed from meters/second to game units/second
weapon->set_projectile_speed(f * 0.01f);
continue;
- } else if (weaponsini.got_key_long("interval", l)) {
+ } else if (inifile.got_key_long("interval", l)) {
weapon->set_projectile_interval((unsigned long) l);
continue;
- } else if (weaponsini.got_key_long("lifespan", l)) {
+ } else if (inifile.got_key_long("lifespan", l)) {
// lifespan in milliseconds
weapon->set_projectile_lifespan((unsigned long) l);
continue;
- } else if (weaponsini.got_key_float("range", f)) {
+ } else if (inifile.got_key_float("range", f)) {
// range in meters, one game unit is 100 meters
if (weapon->projectile_speed() == 0) {
- weaponsini.unknown_error("cannot set range if projectile speed is 0!");
+ inifile.unknown_error("cannot set range if projectile speed is 0!");
} else {
weapon->set_projectile_lifespan((unsigned long) (10.0f * f / weapon->projectile_speed()));
}
continue;
- } else if (weaponsini.got_key_float("damage", f)) {
+ } else if (inifile.got_key_float("damage", f)) {
weapon->set_damage(f);
continue;
- } else if (weaponsini.got_key_string("model", str)) {
+ } else if (inifile.got_key_string("model", str)) {
weapon->set_projectile_modelname(str);
continue;
- } else if (weaponsini.got_key_string("sound", str)) {
+ } else if (inifile.got_key_string("sound", str)) {
weapon->set_projectile_soundname(str);
continue;
} else {
- weaponsini.unknown_key();
+ inifile.unknown_key();
}
}
}
- } else if (weaponsini.got_section()) {
+ } else if (inifile.got_section()) {
Weapon *previous = 0;
- if (weaponsini.got_section("mine")) {
+ if (inifile.got_section("mine")) {
previous = weapon;
weapon = new Weapon();
weapon->set_subtype(Mine);
count++;
- } else if (weaponsini.got_section("cannon")) {
+ } else if (inifile.got_section("cannon")) {
previous = weapon;
weapon = new Weapon();
weapon->set_subtype(Cannon);
count++;
- } else if (weaponsini.got_section("turret")) {
+ } else if (inifile.got_section("turret")) {
previous = weapon;
weapon = new Weapon();
weapon->set_subtype(Turret);
count++;
- } else if (weaponsini.got_section("projectile")) {
+ } else if (inifile.got_section("projectile")) {
if (!weapon) {
- weaponsini.unknown_error("projectile section without weapon section");
+ inifile.unknown_error("projectile section without weapon section");
}
- } else if (weaponsini.got_section()) {
- weaponsini.unknown_section();
+ } else if (inifile.got_section()) {
+ inifile.unknown_section();
}
if (previous) {
@@ -240,9 +252,9 @@ bool Weapon::init()
}
// add weapon infos
- con_debug << " " << weaponsini.name() << " " << count << " weapon types" << std::endl;
+ con_debug << " " << inifile.name() << " " << count << " weapon types" << std::endl;
- weaponsini.close();
+ inifile.close();
core::Func *func = core::Func::add("list_weapons", func_list_weapons);
func->set_info("list available weapon types");