From 4896428eefa6e621523168a42dceda4f8f2b0097 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 7 Nov 2013 13:38:11 +0000 Subject: Added core:: support for entity factions and player reputation (single-player only). --- src/core/Makefile.am | 2 ++ src/core/entity.cc | 6 ++++++ src/core/entity.h | 30 +++++++++++++++++++++++++----- src/core/player.cc | 2 ++ src/core/player.h | 31 +++++++++++++++++++++++++++---- 5 files changed, 62 insertions(+), 9 deletions(-) (limited to 'src/core') diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 1a7c0ac..3f7094d 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -32,6 +32,7 @@ noinst_HEADERS = \ physics.h \ player.h \ range.h \ + reputation.h \ signals.h \ slot.h \ slots.h \ @@ -65,6 +66,7 @@ libcore_la_SOURCES = \ parser.cc \ physics.cc \ player.cc \ + reputation.cc \ signals.cc \ slot.cc \ slots.cc \ diff --git a/src/core/entity.cc b/src/core/entity.cc index 89c78d8..89e494a 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -165,6 +165,8 @@ Entity::Entity() : entity_inventory = 0; entity_slots = 0; entity_info = 0; + + entity_faction = 0; memset(entity_extension, 0, sizeof(entity_extension)); @@ -193,6 +195,8 @@ Entity::Entity(std::istream & is) entity_inventory = 0; entity_slots = 0; entity_info = 0; + + entity_faction = 0; memset(entity_extension, 0, sizeof(entity_extension)); } @@ -1070,6 +1074,7 @@ void EntityControlable::ActionInterface::debugDraw(btIDebugDraw* debugDrawer) /*----- EntityControlable ------------------------------------------ */ +// server-side constructor EntityControlable::EntityControlable() : EntityDynamic() { entity_thrust = 0; @@ -1088,6 +1093,7 @@ EntityControlable::EntityControlable() : EntityDynamic() entity_health = 100.0f; } +// client-side constructor EntityControlable::EntityControlable(std::istream & is) : EntityDynamic(is) { diff --git a/src/core/entity.h b/src/core/entity.h index e1a952d..adeac0f 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -250,6 +250,12 @@ public: return entity_keepalive; } + + inline const Info *faction() const + { + return entity_faction; + } + /* ---- mutators -------------------------------------------------- */ /// assign shape @@ -384,9 +390,18 @@ public: /** * @brief set the timestamp when the entity was last alive * */ - void set_keepalive(unsigned long timestamp) { + inline void set_keepalive(unsigned long timestamp) + { entity_keepalive = timestamp; } + + /** + * @brief set the faction this entity belongs to. + * */ + inline void set_faction(const Info *faction) + { + entity_faction = faction; + } /* ---- actors ---------------------------------------------------- */ @@ -558,6 +573,8 @@ private: unsigned long entity_keepalive; + const Info *entity_faction; + static Registry entity_registry; static size_t entity_nextid; @@ -821,12 +838,16 @@ public: /// receive a server-to-client update from a stream virtual void receive_server_update(std::istream &is); - /// set the player who owns this entity + /** + * @brief set the player who owns this entity + * */ void set_owner(Player *owner); - /// set thrust + /** + * @brief set thrust + * */ void set_thrust(float thrust); - + protected: /// physics action interface callback @@ -878,7 +899,6 @@ protected: private: /// owner of the entity Player *entity_owner; - }; } // namespace core diff --git a/src/core/player.cc b/src/core/player.cc index 87640ac..e7fb024 100644 --- a/src/core/player.cc +++ b/src/core/player.cc @@ -47,6 +47,8 @@ void Player::clear() player_warningtime = 0; player_admin_level = 0; + + player_reputation.clear(); } diff --git a/src/core/player.h b/src/core/player.h index 117de56..91d66c5 100644 --- a/src/core/player.h +++ b/src/core/player.h @@ -17,6 +17,7 @@ class Player; #include "core/uid.h" #include "core/zone.h" #include "core/netclient.h" +#include "core/reputation.h" #include "math/mathlib.h" #include @@ -117,25 +118,45 @@ public: void print() const; /// player level - const int level() const { + inline const int level() const + { return player_level; } /// player admin level - const int admin_level() const { + inline const int admin_level() const + { return player_admin_level; } /// player global unique id - UID & guid() { + inline UID & guid() + { return player_guid; } /// network client associated with this player - NetClient *client() { + inline NetClient *client() + { return player_client; } + /** + * @brief player reputation + * */ + inline Reputation & reputation() + { + return player_reputation; + } + + /** + * @brief player reputation with a specific faction + * */ + inline const float reputation(const Info *faction) const + { + return player_reputation.reputation(faction); + } + /*----- server-side mesage functions ------------------------------ */ /// send a message to the player on one of the message channels @@ -282,6 +303,8 @@ private: bool player_zonechange; float player_warningtime; + + Reputation player_reputation; }; -- cgit v1.2.3