From d8be908233fd7b85492d7a9e87f07bb207173990 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 25 Nov 2012 12:06:13 +0000 Subject: Moved core::EntityGlobe into a separate file, added various methods to core::Item and core::Slot, added r_slots cvar to draw entity slots and docks, added game methods for mounting and umounting of weapons, added playerlist to chat window. --- src/core/Makefile.am | 2 + src/core/entity.cc | 72 ++++++++--------------------------- src/core/entity.h | 89 +++---------------------------------------- src/core/entityglobe.cc | 68 +++++++++++++++++++++++++++++++++ src/core/entityglobe.h | 96 +++++++++++++++++++++++++++++++++++++++++++++++ src/core/netconnection.cc | 2 + src/core/parser.cc | 2 + src/core/slot.cc | 12 ++++++ src/core/slot.h | 36 +++++++++++++++++- 9 files changed, 238 insertions(+), 141 deletions(-) create mode 100644 src/core/entityglobe.cc create mode 100644 src/core/entityglobe.h (limited to 'src/core') diff --git a/src/core/Makefile.am b/src/core/Makefile.am index d198cc4..6f2a505 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -10,6 +10,7 @@ noinst_HEADERS = \ cvar.h \ descriptions.h \ entity.h \ + entityglobe.h \ extension.h \ func.h \ gameconnection.h \ @@ -44,6 +45,7 @@ libcore_la_SOURCES = \ cvar.cc \ descriptions.cc \ entity.cc \ + entityglobe.cc \ extension.cc \ func.cc \ gameconnection.cc \ diff --git a/src/core/entity.cc b/src/core/entity.cc index 462a46d..64546a7 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -278,7 +278,7 @@ void Entity::print_inventory() const return; } - con_print << " ^Nitem info infotype amount" << std::endl; + con_print << " ^Nitem infotype info amount flags" << std::endl; for (Inventory::Items::const_iterator it = entity_inventory->items().begin(); it != entity_inventory->items().end(); it++) { Item *item = (*it); // TODO item flags @@ -286,7 +286,20 @@ void Entity::print_inventory() const << " ^B" << std::setw(4) << item->id() << " ^N" << aux::pad_right((item->info()->type() ? item->info()->type()->label() : "NULL"), 8) << " ^N" << aux::pad_right(item->info()->label(), 24) - << std::setw(5) << item->amount() << std::endl; + << std::setw(5) << item->amount(); + if (item->has_flag(core::Item::Tradeable)) { + con_print << " tradeable"; + } + if (item->has_flag(core::Item::Unique)) { + con_print << " unique"; + } + if (item->has_flag(core::Item::Unrestricted)) { + con_print << " unrestricted"; + } + if (item->has_flag(core::Item::Mounted)) { + con_print << " mounted"; + } + con_print<< std::endl; } con_print << "^B " << entity_inventory->items().size() << " inventory items" << std::endl; } @@ -1460,58 +1473,5 @@ void EntityControlable::frame(const unsigned long elapsed) } } - -/*----- EntityGlobe ------------------------------------------------ */ - -EntityGlobe::EntityGlobe() : Entity() -{ - entity_texture_id = 0; - entity_corona_id = 0; - entity_rotationspeed = 0; - set_shape(Sphere); -} - -EntityGlobe::EntityGlobe(std::istream & is) : Entity(is) -{ - entity_texture_id = 0; - entity_corona_id = 0; - entity_rotationspeed = 0; - set_shape(Sphere); -} - -EntityGlobe::~EntityGlobe() -{ -} - -void EntityGlobe::serialize_server_create(std::ostream & os) const -{ - Entity::serialize_server_create(os); - os << entity_rotationspeed << " \"" << texturename() << "\" \"" << coronaname() << "\" "; -} - -void EntityGlobe::receive_server_create(std::istream &is) -{ - Entity::receive_server_create(is); - - is >> entity_rotationspeed; - - std::string n; - char c; - - // read texture name - while ((is.get(c)) && (c != '"')); - while ((is.get(c)) && (c != '"')) - n += c; - - entity_texturename.assign(n); - - // read corona name - n.clear(); - while ((is.get(c)) && (c != '"')); - while ((is.get(c)) && (c != '"')) - n += c; - entity_coronaname.assign(n); -} - -} +} //namespace core diff --git a/src/core/entity.h b/src/core/entity.h index d3c8522..31ed67b 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -50,16 +50,16 @@ public: * ShowOnMap will make the entity appear on the map * KeepAlive is used by EntityDynamic and marks the entity as deletable in the keepalive run * */ - enum Flags {NonSolid = 2, Bright = 4, Dockable = 8, ShowOnMap = 16, KeepAlive = 32}; + enum Flags { NonSolid = 2, Bright = 4, Dockable = 8, ShowOnMap = 16, KeepAlive = 32 }; /// Entity type constants - enum Type {Default = 0, Dynamic = 1, Controlable = 2, Globe = 3}; + enum Type { Default = 0, Dynamic = 1, Controlable = 2, Globe = 3, Projectile = 4 }; /// Entity shape constants - enum Shape {Diamond = 0, Sphere = 1, Cube = 2, Axis = 3}; + enum Shape { Diamond = 0, Sphere = 1, Cube = 2, Axis = 3 }; /// EntityDynamic State constants - enum State {Normal = 0, NoPower = 1, ImpulseInitiate = 2, Impulse = 3, JumpInitiate = 4, Jump = 5, Docked = 6, Destroyed = 7}; + enum State { Normal = 0, NoPower = 1, ImpulseInitiate = 2, Impulse = 3, JumpInitiate = 4, Jump = 5, Docked = 6, Destroyed = 7 }; /// entity menus collection typedef typedef std::list Menus; @@ -854,86 +854,7 @@ private: }; -/// a Globe entity -class EntityGlobe : public Entity -{ -public: - /// server-side constructor - EntityGlobe(); - EntityGlobe(std::istream & is); - - virtual ~EntityGlobe(); - - /*----- inspectors ----------------------------------------------- */ - /// core type id - virtual inline const unsigned int type() const { - return Entity::Globe; - } - - /// texture name - inline const std::string &texturename() const { - return entity_texturename; - } - - /// texture render id - inline size_t texture_id() const { - return entity_texture_id; - } - - /// corona texture name - inline const std::string &coronaname() const { - return entity_coronaname; - } - - /// corona texture id - inline size_t corona_id() const { - return entity_corona_id; - } - - /// rotation speed in degrees per second - inline float rotationspeed() const { - return entity_rotationspeed; - } - - /*----- mutators -------------------------------------------------- */ - - inline void set_rotationspeed(const float rotationspeed) { - entity_rotationspeed = rotationspeed; - } - - inline void set_texture_id(size_t texture_id) { - entity_texture_id = texture_id; - } - - inline void set_corona_id(size_t texture_id) { - entity_corona_id = texture_id; - } - - inline void set_texturename(const std::string & texturename) { - entity_texturename.assign(texturename); - } - - inline void set_coronaname(const std::string & texturename) { - entity_coronaname.assign(texturename); - } - - /*----- serializers ----------------------------------------------- */ - - /// serialize the entity to a stream - virtual void serialize_server_create(std::ostream & os) const; - - /// receive a server-to-client create from a stream - virtual void receive_server_create(std::istream &is); - -private: - float entity_rotationspeed; - size_t entity_texture_id; - size_t entity_corona_id; - std::string entity_texturename; - std::string entity_coronaname; -}; - -} +} // namespace core #endif // __INCLUDED_CORE_ENTITY_H__ diff --git a/src/core/entityglobe.cc b/src/core/entityglobe.cc new file mode 100644 index 0000000..c27e05c --- /dev/null +++ b/src/core/entityglobe.cc @@ -0,0 +1,68 @@ +/* + core/entityglobe.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2. +*/ + +#include +#include +#include + +#include "core/entityglobe.h" + +namespace core +{ + +/*----- EntityGlobe ------------------------------------------------ */ + +EntityGlobe::EntityGlobe() : Entity() +{ + entity_texture_id = 0; + entity_corona_id = 0; + entity_rotationspeed = 0; + set_shape(Sphere); +} + +EntityGlobe::EntityGlobe(std::istream & is) : Entity(is) +{ + entity_texture_id = 0; + entity_corona_id = 0; + entity_rotationspeed = 0; + set_shape(Sphere); +} + +EntityGlobe::~EntityGlobe() +{ +} + +void EntityGlobe::serialize_server_create(std::ostream & os) const +{ + Entity::serialize_server_create(os); + os << entity_rotationspeed << " \"" << texturename() << "\" \"" << coronaname() << "\" "; +} + +void EntityGlobe::receive_server_create(std::istream &is) +{ + Entity::receive_server_create(is); + + is >> entity_rotationspeed; + + std::string n; + char c; + + // read texture name + while ((is.get(c)) && (c != '"')); + while ((is.get(c)) && (c != '"')) + n += c; + + entity_texturename.assign(n); + + // read corona name + n.clear(); + while ((is.get(c)) && (c != '"')); + while ((is.get(c)) && (c != '"')) + n += c; + entity_coronaname.assign(n); +} + +} // namespace core diff --git a/src/core/entityglobe.h b/src/core/entityglobe.h new file mode 100644 index 0000000..e60f61a --- /dev/null +++ b/src/core/entityglobe.h @@ -0,0 +1,96 @@ +/* + core/entityglobe.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_ENTITYGLOBE_H__ +#define __INCLUDED_CORE_ENTITYGLOBE_H__ + +#include "core/entity.h" + +namespace core +{ + +/// a Globe entity +class EntityGlobe : public Entity +{ +public: + /// server-side constructor + EntityGlobe(); + EntityGlobe(std::istream & is); + + virtual ~EntityGlobe(); + + /*----- inspectors ----------------------------------------------- */ + /// core type id + virtual inline const unsigned int type() const { + return Entity::Globe; + } + + /// texture name + inline const std::string &texturename() const { + return entity_texturename; + } + + /// texture render id + inline size_t texture_id() const { + return entity_texture_id; + } + + /// corona texture name + inline const std::string &coronaname() const { + return entity_coronaname; + } + + /// corona texture id + inline size_t corona_id() const { + return entity_corona_id; + } + + /// rotation speed in degrees per second + inline float rotationspeed() const { + return entity_rotationspeed; + } + + /*----- mutators -------------------------------------------------- */ + + inline void set_rotationspeed(const float rotationspeed) { + entity_rotationspeed = rotationspeed; + } + + inline void set_texture_id(size_t texture_id) { + entity_texture_id = texture_id; + } + + inline void set_corona_id(size_t texture_id) { + entity_corona_id = texture_id; + } + + inline void set_texturename(const std::string & texturename) { + entity_texturename.assign(texturename); + } + + inline void set_coronaname(const std::string & texturename) { + entity_coronaname.assign(texturename); + } + + /*----- serializers ----------------------------------------------- */ + + /// serialize the entity to a stream + virtual void serialize_server_create(std::ostream & os) const; + + /// receive a server-to-client create from a stream + virtual void receive_server_create(std::istream &is); + +private: + float entity_rotationspeed; + size_t entity_texture_id; + size_t entity_corona_id; + std::string entity_texturename; + std::string entity_coronaname; +}; + +} + +#endif // __INCLUDED_CORE_ENTITYGLOBE_H__ diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc index 24f6a3d..ce8fc8c 100644 --- a/src/core/netconnection.cc +++ b/src/core/netconnection.cc @@ -11,6 +11,8 @@ #include "sys/sys.h" #include "core/application.h" +#include "core/entity.h" +#include "core/entityglobe.h" #include "core/gameconnection.h" #include "core/netconnection.h" #include "core/player.h" diff --git a/src/core/parser.cc b/src/core/parser.cc index 01d4dba..1c66888 100644 --- a/src/core/parser.cc +++ b/src/core/parser.cc @@ -5,6 +5,8 @@ */ #include "auxiliary/functions.h" +#include "core/entity.h" +#include "core/entityglobe.h" #include "core/parser.h" #include "sys/sys.h" diff --git a/src/core/slot.cc b/src/core/slot.cc index bb7b622..e1ccd05 100644 --- a/src/core/slot.cc +++ b/src/core/slot.cc @@ -28,6 +28,18 @@ Slot::~Slot() { } +void Slot::set_flag(const Flags flag) +{ + slot_flags = (slot_flags | (unsigned int) flag); + set_timestamp(game() ? game()->timestamp() : 1); +} + +void Slot::unset_flag(const Flags flag) +{ + slot_flags = slot_flags & ~((unsigned int) flag); + set_timestamp(game() ? game()->timestamp() : 1); +} + void Slot::set_projectile_speed(const float projectile_speed) { slot_projectile_speed = projectile_speed; diff --git a/src/core/slot.h b/src/core/slot.h index 2d636b3..5cfeb3e 100644 --- a/src/core/slot.h +++ b/src/core/slot.h @@ -22,7 +22,7 @@ namespace core * */ class Slot { public: - enum Flags {Active = 1}; + enum Flags {Mounted = 1, Active = 2}; /** * @brief default constructor @@ -51,6 +51,30 @@ public: return slot_axis; } + /** + * @brief slot flags + * */ + inline const unsigned int flags() const + { + return slot_flags; + } + + /** + * @brief return true if a specified flag is set + * */ + inline const bool has_flag(const Flags flag) + { + return ( (slot_flags & flag) == flag ); + } + + /** + * @brief the item this slot is holding + * */ + inline core::Item *item() + { + return slot_item; + } + /** * @brief timestamp indicating when the slot was last fired,server-side * This is a server-side property @@ -127,6 +151,16 @@ public: slot_axis.assign(axis); } + /** + * @brief set a specified flags + * */ + void set_flag(const Flags flag); + + /** + * @brief unset a specified flags + * */ + void unset_flag(const Flags flag); + /** * @brief set the slot's timestamp * The timestamp indicates when the slot's configuration was last changed. -- cgit v1.2.3