From 8f393ff70e60172c632efc81694433568df2862b Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 25 Dec 2014 15:58:24 +0000 Subject: Added a core::Level type, added a level attribute to core::Entity and core::Info, updated core::Player to use the new type. --- src/core/Makefile.am | 1 + src/core/commandbuffer.cc | 17 +++++- src/core/entity.cc | 78 +++++++++++++++++++------- src/core/entity.h | 77 +++++++++++++++++++------- src/core/info.cc | 9 ++- src/core/info.h | 121 +++++++++++++++++++++++++++++----------- src/core/level.h | 28 ++++++++++ src/core/parser.cc | 138 ++++++++++++++++++++++++++++++++-------------- src/core/player.cc | 4 +- src/core/player.h | 27 +++++---- 10 files changed, 371 insertions(+), 129 deletions(-) create mode 100644 src/core/level.h (limited to 'src/core') 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 #include +#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,50 +160,67 @@ 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 @@ -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 #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 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 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; } @@ -129,6 +155,11 @@ public: void set_modelname(const char *modelname); + /** + * @brief set level + * */ + void set_level(const Level level); + /** * @brief associated price, in credits */ @@ -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 +#include +#include +#include + +#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(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; -- cgit v1.2.3