/* base/weapon.cc This file is part of the Osirion project and is distributed under the terms and conditions of the GNU General Public License version 2 */ #include #include #include "sys/sys.h" #include "filesystem/inifile.h" #include "auxiliary/functions.h" #include "core/func.h" #include "base/cargopod.h" #include "base/game.h" #include "base/weapon.h" namespace game { core::InfoType *Weapon::weapon_infotype = 0; void func_list_weapons(const std::string &args) { Weapon::list(); } // load weapon types from ini file 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; return false; } con_print << "^BLoading weapons..." << std::endl; size_t count = 0; Weapon *weapon = 0; std::string str; long l; float f; while (weaponsini.getline()) { if (weaponsini.got_key()) { if (weaponsini.section().compare("mine") == 0) { if (weaponsini.got_key_label("label", str)) { weapon->set_label(str); continue; } else if (weaponsini.got_key_string("name", str)) { weapon->set_name(str); continue; } else if (weaponsini.got_key_string("info", str)) { weapon->add_text(str); continue; } else if (weaponsini.got_key_string("model", str)) { weapon->set_modelname(str); continue; } else if (weaponsini.got_key_long("price", l)) { weapon->set_price(l); continue; } else if (weaponsini.got_key_float("volume", f)) { weapon->set_volume(f); continue; } else if (weaponsini.got_key_long("level", l)) { weapon->set_level(l); continue; } else { weaponsini.unknown_key(); } } else if (weaponsini.section().compare("cannon") == 0) { if (weaponsini.got_key_label("label", str)) { weapon->set_label(str); continue; } else if (weaponsini.got_key_string("name", str)) { weapon->set_name(str); continue; } else if (weaponsini.got_key_string("info", str)) { weapon->add_text(str); continue; } else if (weaponsini.got_key_string("model", str)) { weapon->set_modelname(str); continue; } else if (weaponsini.got_key_long("price", l)) { weapon->set_price(l); continue; } else if (weaponsini.got_key_float("volume", f)) { weapon->set_volume(f); continue; } else if (weaponsini.got_key_long("level", l)) { weapon->set_level(l); continue; } else { weaponsini.unknown_key(); } } else if (weaponsini.section().compare("turret") == 0) { if (weaponsini.got_key_label("label", str)) { weapon->set_label(str); continue; } else if (weaponsini.got_key_string("name", str)) { weapon->set_name(str); continue; } else if (weaponsini.got_key_string("info", str)) { weapon->add_text(str); continue; } else if (weaponsini.got_key_string("model", str)) { weapon->set_modelname(str); continue; } else if (weaponsini.got_key_long("price", l)) { weapon->set_price(l); continue; } else if (weaponsini.got_key_float("volume", f)) { weapon->set_volume(f); continue; } else if (weaponsini.got_key_long("level", l)) { weapon->set_level(l); continue; } else { weaponsini.unknown_key(); } } } else if (weaponsini.got_section()) { if (weaponsini.got_section("mine")) { weapon = new Weapon(); weapon->set_stackable(true); weapon->set_subtype(Mine); count++; } else if (weaponsini.got_section("cannon")) { weapon = new Weapon(); weapon->set_stackable(false); weapon->set_subtype(Cannon); count++; } else if (weaponsini.got_section("turret")) { weapon = new Weapon(); weapon->set_stackable(false); weapon->set_subtype(Turret); count++; } else if (weaponsini.got_section()) { weaponsini.unknown_section(); } } } // add weapon infos con_debug << " " << weaponsini.name() << " " << count << " weapon types" << std::endl; weaponsini.close(); core::Func *func = core::Func::add("list_weapons", func_list_weapons); func->set_info("list available weapon types"); return true; } void Weapon::done() { core::Func::remove("list_weapons"); } Weapon *Weapon::find(const std::string & label) { if (!label.size()) { return 0; } return (Weapon *) core::Info::find(weapon_infotype, label); } void Weapon::list() { core::Info::list(weapon_infotype); } /* ---- class Weapon ------------------------------------------- */ Weapon::Weapon() : core::Info(weapon_infotype) { set_volume(1); set_level(1); set_stackable(false); set_subtype(Ammo); } Weapon::~Weapon() { } void Weapon::set_stackable(bool stackable) { weapon_stackable = stackable; } void Weapon::set_level(const int level) { weapon_level = level; } void Weapon::set_subtype(const SubType subtype) { weapon_subtype = subtype; } } // namespace game