Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2014-12-25 15:58:24 +0000
committerStijn Buys <ingar@osirion.org>2014-12-25 15:58:24 +0000
commit8f393ff70e60172c632efc81694433568df2862b (patch)
treeac87596d59ccf27dff0896c97e410643d21185bf /src/game/base/weapon.cc
parent8f28c82e2fb26b453a2cfe976e48f74d97d6388a (diff)
Added a core::Level type, added a level attribute to core::Entity and core::Info, updated core::Player to use the new type.
Diffstat (limited to 'src/game/base/weapon.cc')
-rw-r--r--src/game/base/weapon.cc120
1 files changed, 66 insertions, 54 deletions
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");