diff options
-rw-r--r-- | src/core/Makefile.am | 1 | ||||
-rw-r--r-- | src/core/commandbuffer.cc | 17 | ||||
-rw-r--r-- | src/core/entity.cc | 78 | ||||
-rw-r--r-- | src/core/entity.h | 77 | ||||
-rw-r--r-- | src/core/info.cc | 9 | ||||
-rw-r--r-- | src/core/info.h | 121 | ||||
-rw-r--r-- | src/core/level.h | 28 | ||||
-rw-r--r-- | src/core/parser.cc | 138 | ||||
-rw-r--r-- | src/core/player.cc | 4 | ||||
-rw-r--r-- | src/core/player.h | 27 | ||||
-rw-r--r-- | src/game/base/shipmodel.cc | 122 | ||||
-rw-r--r-- | src/game/base/shipmodel.h | 6 | ||||
-rw-r--r-- | src/game/base/weapon.cc | 120 |
13 files changed, 518 insertions, 230 deletions
diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 2485ee9..dab8a0d 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -20,6 +20,7 @@ noinst_HEADERS = \ info.h \ inventory.h \ item.h \ + level.h \ label.h \ loader.h \ message.h \ diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc index 11a48b4..4234f0e 100644 --- a/src/core/commandbuffer.cc +++ b/src/core/commandbuffer.cc @@ -61,13 +61,27 @@ void func_list_info(std::string const &args) InfoType *infotype = InfoType::find(typestr); if(!(argstream >> labelstr)) { - // a single argument + // single argument - infotype label if (infotype) { // list all the records of a single type Info::list(infotype); return; } + // single argument - info record id + std::istringstream idstream(typestr); + unsigned int id; + if (idstream >> id) + { + info = Info::find(id); + if (info) { + // list a single record + info->print(); + return; + } + } + + // single argument - info record exact label match info = Info::find(typestr); if (info) { // list a single record @@ -75,6 +89,7 @@ void func_list_info(std::string const &args) return; } + // single argument - info recrod label search info = Info::search(typestr); if (info) { // list a single record diff --git a/src/core/entity.cc b/src/core/entity.cc index f4a29dd..41ead7e 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -155,6 +155,8 @@ Entity::Entity() : entity_died = false; entity_dirty = false; entity_keepalive = 0; + + entity_level = 1; entity_zone = 0; entity_oldzone = 0; @@ -181,6 +183,8 @@ Entity::Entity(std::istream & is) entity_oldzone = 0; entity_visible = true; entity_keepalive = 0; + + entity_level = 1; entity_model = 0; @@ -265,11 +269,6 @@ void Entity::print() const // print header print_header(); - // faction - if (faction()) { - con_print << " ^Nfaction ^B" << faction()->label() << std::endl; - } - // entity type id con_print << " ^Ntype ^B"; switch (type()) { @@ -299,27 +298,66 @@ void Entity::print() const // print entity flags con_print << " ^Nflags ^B"; - if (has_flag(NonSolid)) { - con_print << " ^Bnonsolid"; - } - if (has_flag(Bright)) { - con_print << " ^Bbright"; - } - if (has_flag(Dockable)) { - con_print << " ^Bdockable"; - } - if (has_flag(ShowOnMap)) { - con_print << " ^Bshownmap"; - } - if (has_flag(KeepAlive)) { - con_print << " ^Bkeepalive"; + if (flags() == 0) + { + if (has_flag(NonSolid)) { + con_print << " ^Bnonsolid"; + } + if (has_flag(Bright)) { + con_print << " ^Bbright"; + } + if (has_flag(Dockable)) { + con_print << " ^Bdockable"; + } + if (has_flag(ShowOnMap)) { + con_print << " ^Bshownmap"; + } + if (has_flag(KeepAlive)) { + con_print << " ^Bkeepalive"; + } + } else + { + con_print << " ^Bnone"; } con_print << std::endl; + + // level + con_print << " ^Nlevel ^B" << level() << std::endl; + + // faction + if (faction()) { + con_print << " ^Nfaction ^Nid ^B" << faction()->id() << " ^Nlabel ^B" << faction()->label() << std::endl; + } // info record if (info()) { - con_print << " ^Ninfo id ^B" << info()->id() << std::endl; + con_print << " ^Ninfo ^Nid ^B" << info()->id() << " ^Nlabel ^B" << info()->label() << std::endl; + } + + // model or shape + if (model()) + { + con_print << " ^Nmodel ^B" << model()->name() << std::endl; + } else + { + con_print << " ^Nshape ^B"; + switch (shape()) + { + case Diamond: + con_print << "diamond"; + break; + case Sphere: + con_print << "sphere"; + break; + case Cube: + con_print << "cube"; + break; + case Axis: + con_print << "axis"; + break; + } } + // slots if (slots() && slots()->size()) { diff --git a/src/core/entity.h b/src/core/entity.h index 5a028bf..27d888c 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -12,6 +12,7 @@ #include <map> #include <list> +#include "core/level.h" #include "model/model.h" #include "math/axis.h" #include "math/mathlib.h" @@ -118,32 +119,38 @@ public: /*----- inspectors ------------------------------------------------ */ /// entity id - inline const unsigned int id() const { + inline const unsigned int id() const + { return entity_id; } /// module type id - inline const unsigned int moduletype() const { + inline const unsigned int moduletype() const + { return entity_moduletypeid; } /// core type id - virtual inline const unsigned int type() const { + virtual inline const unsigned int type() const + { return Default; } /// entity flags - inline const unsigned int flags() const { + inline const unsigned int flags() const + { return entity_flags; } /// returns true of a flag is set - inline const bool has_flag(const Flags flag) const { + inline const bool has_flag(const Flags flag) const + { return ((entity_flags & (unsigned int)flag) == (unsigned int)flag); } /// pointer to the model, is used client-side - inline model::Model * model() const { + inline model::Model * model() const + { return entity_model; } @@ -153,51 +160,68 @@ public: } /// pointer to the zone the entity belongs to - inline Zone *zone() const { + inline Zone *zone() const + { return entity_zone; } /// the zone the entity left in case of a zone change - inline Zone *oldzone() const { + inline Zone *oldzone() const + { return entity_oldzone; } /// dirty flag - inline bool dirty() const { + inline bool dirty() const + { return entity_dirty; } /// entity location - inline const math::Vector3f& location() const { + inline const math::Vector3f& location() const + { return entity_location; } - /// local coordinate system of the entity - inline const math::Axis& axis() const { + /// local coordinates system of the entity + inline const math::Axis& axis() const + { return entity_axis; } - /// primary color of the entity - inline const math::Color& color() const { + /// primary entity color + inline const math::Color& color() const + { return entity_color; } - /// secondary - inline const math::Color& color_second() const { + /// secondary entity color + inline const math::Color& color_second() const + { return entity_color_second; } /// base shape of the entity - inline const Shape shape() const { + inline const Shape shape() const + { return entity_shape; } /// base radius of the entity - inline const float radius() const { + inline const float radius() const + { return entity_radius; } /** + * @brief current entity level + * */ + inline const Level level() const + { + return entity_level; + } + + /** * @brief current speed of the entity in game units per second * For a normal entity, speed is always 0. Use the EntityDynamic * and EntityControlable classes to create moving entities @@ -335,14 +359,24 @@ public: * and removes it to the new one, if it is not 0 */ virtual void set_zone(Zone *zone); + + /** + * @brief set the entity level + * */ + inline void set_level(const Level level) + { + entity_level = level; + } /// set visibility - inline void set_visible(const bool visible = true) { + inline void set_visible(const bool visible = true) + { entity_visible = visible; } /// set as server-side entity - inline void set_serverside(const bool serverside = true) { + inline void set_serverside(const bool serverside = true) + { entity_serverside = serverside; } @@ -584,9 +618,10 @@ private: math::Color entity_color; math::Color entity_color_second; + + Level entity_level; std::string entity_modelname; - model::Model* entity_model; Menus entity_menus; diff --git a/src/core/info.cc b/src/core/info.cc index ad630a9..3d1b6cc 100644 --- a/src/core/info.cc +++ b/src/core/info.cc @@ -77,9 +77,10 @@ Info::Info(const InfoType *type, const char *label) : Label(label) info_id_counter++; info_id = info_id_counter; info_type = type; - info_registry.push_back(this); + info_registry.push_back(this); info_timestamp = 0; + info_level = 1; info_price = 0; info_volume = 0; } @@ -92,6 +93,7 @@ Info::Info(const unsigned int id) info_registry.push_back(this); info_timestamp = 1; + info_level = 1; info_price = 0; info_volume = 0; @@ -127,6 +129,11 @@ void Info::set_modelname(const char *modelname) info_modelname.assign(modelname); } +void Info::set_level(const Level level) +{ + info_level = level; +} + void Info::set_price(const long price) { info_price = price; diff --git a/src/core/info.h b/src/core/info.h index 2859dac..5aca5b2 100644 --- a/src/core/info.h +++ b/src/core/info.h @@ -13,6 +13,7 @@ #include <deque> #include "core/label.h" +#include "core/level.h" #include "model/model.h" namespace core @@ -25,7 +26,9 @@ namespace core class InfoType : public Label { public: - /// info registry type definition + /** + * @brief info type registry type definition + * */ typedef std::vector<InfoType*> Registry; /** @@ -36,19 +39,26 @@ public: virtual ~InfoType(); - /* ---- static infoclass registry ---------------------------------- */ + /* ---- static inf type registry ----------------------------------- */ - /// clear infotype registry + /** + * @brief clear info type registry + * */ static void clear(); - /// search the infotype registry for a label + /** + * @brief search the info type registry for a label + * */ static InfoType *find(const std::string & label); - inline static const Registry ®istry() { + inline static const Registry ®istry() + { return infotype_registry; } - /// list the infotypes + /** + * @brief list the info types + * */ static void list(); private: @@ -64,42 +74,56 @@ private: class Info : public Label { public: - /// type definition for the text description + /** + * @brief type definition for the text description + * */ typedef std::deque<std::string> Text; /** - * @brief create a new server-side information card + * @brief server-side constructor * This constructor assigns an id */ Info(const InfoType *type, const char *label = 0); /** - * @brief create a new client-side information card + * @brief client-side constructor */ Info(const unsigned int id); - /// delete the information record + /** + * @brief default constructor + **/ virtual ~Info(); /* ---- inspectors ------------------------------------------------- */ - inline const unsigned int id() const { + inline const unsigned int id() const + { return info_id; } - inline const InfoType* type() const { + inline const InfoType* type() const + { return info_type; } - inline const std::string & modelname() const { + inline const std::string & modelname() const + { return info_modelname; } - inline const long price() const { + inline const Level level() const + { + return info_level; + } + + inline const long price() const + { return info_price; } - inline const float volume() const { + inline const float volume() const + { return info_volume; } @@ -110,14 +134,16 @@ public: * If the info has been received from the server, the timestamp * is set to 0 */ - inline const unsigned long ×tamp() const { + inline const unsigned long ×tamp() const + { return info_timestamp; } /** - * @brief text description + * @brief info description text */ - inline const Text & text() const { + inline const Text & text() const + { return info_text; } @@ -130,6 +156,11 @@ public: void set_modelname(const char *modelname); /** + * @brief set level + * */ + void set_level(const Level level); + + /** * @brief associated price, in credits */ void set_price(const long price); @@ -139,47 +170,74 @@ public: */ void set_volume(const float volume); - /// set the timestamp + /** + * @brief set the timestamp + * */ void set_timestamp(const unsigned long timestamp); - /// add a line of info text + /** + * @brief append a line of text to the info description + * add_line() adds a newline character + * */ void add_line(const std::string & text); - /// add a line of info text + /** + * @brief append a line of text to the info description + * add_line() adds a newline character + * */ void add_line(const char *text); - /// add info text without newline + /** + * @brief append text to the info description + * add_text() does not add a newline character + * */ void add_text(const std::string & text); - /// add info text without newline + /** + * @brief append text to the info description + * add_text() does not add a newline character + * */ void add_text(const char *text); - - /// clear the info text + /** + * @brief clear the info description text + * */ void clear_text(); - /// print info to the system console + /** + * @brief print the content of the info record to the system console + * */ virtual void print() const; - /// clear the timestamp + /** + * @brief clear the timestamp + * */ void clear_timestamp(); - /// set the info class type + /** + * @brief set the info type + * */ void set_type(const InfoType *type); public: /* ---- serializers ------------------------------------------------ */ - /// serialize a server-to-client update on a stream + /** + * @brief serialize a server-to-client update on a stream + * */ void serialize_server_update(std::ostream & os) const; - /// receive a server-to-client update from a stream + /** + * @brief receive a server-to-client update from a stream + * */ void receive_server_update(std::istream &is); private: const InfoType* info_type; unsigned int info_id; + Level info_level; + long info_price; float info_volume; unsigned long info_timestamp; @@ -187,8 +245,7 @@ private: Text info_text; - /* ---- static info registry --------------------------------------- */ - + /* ---- static info registry --------------------------------------- */ public: /** * @brief info registry type definition diff --git a/src/core/level.h b/src/core/level.h new file mode 100644 index 0000000..20acaee --- /dev/null +++ b/src/core/level.h @@ -0,0 +1,28 @@ +/* + core/level.h + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_CORE_LEVEL_H__ +#define __INCLUDED_CORE_LEVEL_H__ + +#include <iostream> +#include <string> +#include <vector> +#include <deque> + +#include "core/label.h" +#include "model/model.h" + +namespace core +{ + /** + * @brief type definition for a player or entity level + * */ + typedef unsigned int Level; + + +} // namespace core + +#endif // __INCLUDED_CORE_LEVEL_H__ diff --git a/src/core/parser.cc b/src/core/parser.cc index a260c19..4e471aa 100644 --- a/src/core/parser.cc +++ b/src/core/parser.cc @@ -17,9 +17,11 @@ Info *get_entity_info(Entity *entity) { Info *info = Info::find(entity->info()); - if (!info) { + if (!info) + { std::string labelstr; - if (entity->zone()) { + if (entity->zone()) + { labelstr.append(entity->zone()->label()); labelstr += ':'; } @@ -34,7 +36,9 @@ Info *get_entity_info(Entity *entity) bool Parser::got_entity_key(filesystem::IniFile &inifile, Entity *entity) { if (!entity) + { return false; + } math::Vector3f v; math::Color color; @@ -47,138 +51,188 @@ bool Parser::got_entity_key(filesystem::IniFile &inifile, Entity *entity) bool blnval; - if (inifile.got_key_string("shape", shapename)) { - - if (shapename.compare("axis") == 0) { + if (inifile.got_key_string("shape", shapename)) + { + if (shapename.compare("axis") == 0) + { entity->set_shape(core::Entity::Axis); return true; - } else if (shapename.compare("cube") == 0) { + } else if (shapename.compare("cube") == 0) + { entity->set_shape(core::Entity::Cube); return true; - } else if (shapename.compare("diamond") == 0) { + } else if (shapename.compare("diamond") == 0) + { entity->set_shape(core::Entity::Diamond); return true; - } else if (shapename.compare("sphere") == 0) { + } else if (shapename.compare("sphere") == 0) + { entity->set_shape(core::Entity::Sphere); return true; - } else { + } else + { con_warn << inifile.name() << " unknown shape '" << shapename << "' at line " << inifile.line() << std::endl; return false; } - } else if (inifile.got_key_string("info", strval)) { + } else if (inifile.got_key_string("info", strval)) + { Info *info = get_entity_info(entity); info->add_text(strval); return true; - } else if (inifile.got_key_string("infoname", strval)) { + } else if (inifile.got_key_string("infoname", strval)) + { Info *info = get_entity_info(entity); info->set_name(strval); return true; - } else if (inifile.got_key_label("label", strval)) { + } else if (inifile.got_key_label("label", strval)) + { entity->set_label(strval); return true; - } else if (inifile.got_key_string("name", strval)) { + } else if (inifile.got_key_string("name", strval)) + { entity->set_name(strval); return true; + + } else if (inifile.got_key("level")) + { + Level level; + std::istringstream str(inifile.value()); + if (str >> level) + { + entity->set_level(level); + } else + { + inifile.unknown_value(); + } - } else if (inifile.got_key_string("model", strval)) { + } else if (inifile.got_key_string("model", strval)) + { entity->set_modelname(strval); return true; - } else if (inifile.got_key_bool("showonmap", blnval)) { + } else if (inifile.got_key_bool("showonmap", blnval)) + { if (blnval) + { entity->set_flag(Entity::ShowOnMap); - else + } else + { entity->unset_flag(Entity::ShowOnMap); + } return true; - } else if (inifile.got_key_bool("nonsolid", blnval)) { + } else if (inifile.got_key_bool("nonsolid", blnval)) + { if (blnval) + { entity->set_flag(Entity::NonSolid); - else + } else + { entity->unset_flag(Entity::NonSolid); + } return true; - } else if (inifile.got_key_float("angle", yaw)) { - - if (yaw == model::ANGLEUP) { + } else if (inifile.got_key_float("angle", yaw)) + { + if (yaw == model::ANGLEUP) + { entity->get_axis().change_pitch(-90.0f); - } else if (yaw == model::ANGLEDOWN) { + } else if (yaw == model::ANGLEDOWN) + { entity->get_axis().change_pitch(90.0f); - } else { + } else + { entity->get_axis().change_direction(yaw); } return true; - } else if (inifile.got_key("angles")) { - + } else if (inifile.got_key("angles")) + { std::istringstream str(inifile.value()); - if (str >> pitch >> yaw >> roll) { + if (str >> pitch >> yaw >> roll) + { entity->get_axis().assign(yaw, pitch, roll); - } else { + } else + { inifile.unknown_value(); } return true; - } else if (inifile.got_key_angle("yaw", yaw)) { + } else if (inifile.got_key_angle("yaw", yaw)) + { entity->get_axis().change_direction(yaw); return true; - } else if (inifile.got_key_angle("pitch", pitch)) { + } else if (inifile.got_key_angle("pitch", pitch)) + { entity->get_axis().change_pitch(-pitch); return true; - } else if (inifile.got_key_angle("roll", roll)) { + } else if (inifile.got_key_angle("roll", roll)) + { entity->get_axis().change_roll(-roll); return true; - } else if (inifile.got_key_angle("radius", f)) { + } else if (inifile.got_key_angle("radius", f)) + { entity->set_radius(f); return true; - } else if (inifile.got_key_vector3f("location", v)) { + } else if (inifile.got_key_vector3f("location", v)) + { entity->get_location().assign(v); return true; - } else if (inifile.got_key_color("colorsecond", color)) { + } else if (inifile.got_key_color("colorsecond", color)) + { entity->get_color_second().assign(color); return true; - } else if (inifile.got_key_color("color", color)) { + } else if (inifile.got_key_color("color", color)) + { entity->get_color().assign(color); return true; } // special globe keys - if (entity->type() == Entity::Globe) { + if (entity->type() == Entity::Globe) + { EntityGlobe *globe = static_cast<EntityGlobe *>(entity); - if (inifile.got_key_string("texture", strval)) { + if (inifile.got_key_string("texture", strval)) + { globe->set_texturename(strval); return true; - } else if (inifile.got_key_string("corona", strval)) { + } else if (inifile.got_key_string("corona", strval)) + { globe->set_coronaname(strval); return true; - } else if (inifile.got_key_string("rings", strval)) { + } else if (inifile.got_key_string("rings", strval)) + { globe->set_ringsname(strval); return true; - } else if (inifile.got_key_float("rotationspeed", f)) { + } else if (inifile.got_key_float("rotationspeed", f)) + { globe->set_rotationspeed(f); return true; - } else if (inifile.got_key_bool("bright", blnval)) { - if (blnval) { + } else if (inifile.got_key_bool("bright", blnval)) + { + if (blnval) + { globe->set_flag(core::Entity::Bright); - } else { + } else + { globe->unset_flag(core::Entity::Bright); } return true; diff --git a/src/core/player.cc b/src/core/player.cc index 7511e06..b7ff92d 100644 --- a/src/core/player.cc +++ b/src/core/player.cc @@ -183,12 +183,12 @@ void Player::set_ping(const long ping) player_ping = ping; } -void Player::set_level(const int level) +void Player::set_level(const Level level) { player_level = level; } -void Player::set_admin_level(const int admin_level) +void Player::set_admin_level(const Level admin_level) { player_admin_level = admin_level; } diff --git a/src/core/player.h b/src/core/player.h index e68a219..39170a4 100644 --- a/src/core/player.h +++ b/src/core/player.h @@ -12,6 +12,7 @@ namespace core class Player; } +#include "core/level.h" #include "core/entity.h" #include "core/message.h" #include "core/uid.h" @@ -128,13 +129,13 @@ public: void print() const; /// player level - inline const int level() const + inline const Level level() const { return player_level; } /// player admin level - inline const int admin_level() const + inline const Level admin_level() const { return player_admin_level; } @@ -294,21 +295,27 @@ public: void set_ping(const long ping); - /// set the player level - void set_level(const int level); + /** + * @brief set the player level + * */ + void set_level(const Level level); /// set the admin level - void set_admin_level(const int admin_level); + void set_admin_level(const Level admin_level); void set_guid(const std::string & guid); /// set the dirty bit - inline void set_dirty(const bool dirty = true) { + inline void set_dirty(const bool dirty = true) + { player_dirty = dirty; } - /// set the zonechange bit - inline void set_zonechange(const bool dirty = true) { + /** + * @brief set the zonechange bit + * */ + inline void set_zonechange(const bool dirty = true) + { player_zonechange = dirty; } @@ -362,11 +369,11 @@ private: long player_credits; // in-game level - int player_level; + Level player_level; long player_ping; std::string player_rconpassword; - int player_admin_level; + Level player_admin_level; // global unique id UID player_guid; 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"); |