From 5f0958c121a246d445507313984358ff8a6df3fa Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 10 Nov 2013 17:13:41 +0000 Subject: Adjust reputation on NPC kills, refresh reputation window if required. --- src/core/netconnection.cc | 1 + src/core/reputation.cc | 13 +++++++++++++ src/core/reputation.h | 24 ++++++++++++++++++++---- 3 files changed, 34 insertions(+), 4 deletions(-) (limited to 'src/core') diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc index b1a4e77..f87f66e 100644 --- a/src/core/netconnection.cc +++ b/src/core/netconnection.cc @@ -817,6 +817,7 @@ void NetConnection::parse_incoming_message(const std::string & message) } else if (command.compare("rep") == 0) { connection()->localplayer()->reputation().receive_server_update(msgstream); + connection()->localplayer()->reputation().set_timestamp(game()->timestamp()); } else if (command.compare("inf") == 0) { diff --git a/src/core/reputation.cc b/src/core/reputation.cc index b3eee43..ea276a7 100644 --- a/src/core/reputation.cc +++ b/src/core/reputation.cc @@ -43,6 +43,19 @@ void Reputation::assign(const Reputation &other) } +void Reputation::set_dirty(const bool dirty) +{ + reputation_dirty = dirty; + if (reputation_dirty) { + reputation_timestamp = game()->timestamp(); + } +} + +void Reputation::set_timestamp(const unsigned long timestamp) +{ + reputation_timestamp = timestamp; +} + const Info *Reputation::find(const Info *faction) const { for (FactionReps::const_iterator it = reputation_factionreps.begin(); it != reputation_factionreps.end(); ++it) { diff --git a/src/core/reputation.h b/src/core/reputation.h index d20a210..af6b426 100644 --- a/src/core/reputation.h +++ b/src/core/reputation.h @@ -87,15 +87,24 @@ public: void set_reputation(const Info *faction, const float reputation); - inline void set_dirty(const bool dirty = true) - { - reputation_dirty = dirty; - } + void set_dirty(const bool dirty = true); + + void set_timestamp(const unsigned long timestamp); void clear(); void assign(const Reputation &other); + inline FactionReps::const_iterator factionreps_begin() const + { + return reputation_factionreps.begin(); + } + + inline FactionReps::const_iterator factionreps_end() const + { + return reputation_factionreps.end(); + } + inline FactionReps & factionreps() { return reputation_factionreps; @@ -106,6 +115,11 @@ public: return reputation_dirty; } + inline const unsigned long timestamp() const + { + return reputation_timestamp; + } + /* ---- deserializers -------------------------------------- */ /// receive a server-to-client update from a stream @@ -120,6 +134,8 @@ private: FactionReps reputation_factionreps; bool reputation_dirty; + + unsigned long reputation_timestamp; }; } // namespace core -- cgit v1.2.3