diff options
Diffstat (limited to 'src/core/reputation.cc')
-rw-r--r-- | src/core/reputation.cc | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/core/reputation.cc b/src/core/reputation.cc index 013fd9e..b3eee43 100644 --- a/src/core/reputation.cc +++ b/src/core/reputation.cc @@ -5,11 +5,13 @@ */ #include "core/reputation.h" +#include "core/application.h" namespace core { Reputation::Reputation() { + reputation_dirty = false; } Reputation::~Reputation() @@ -24,6 +26,8 @@ void Reputation::clear() (*it) = 0; } reputation_factionreps.clear(); + + reputation_dirty = false; } void Reputation::assign(const Reputation &other) @@ -78,26 +82,52 @@ void Reputation::set_reputation(const std::string &label, const float reputation { for (FactionReps::const_iterator it = reputation_factionreps.begin(); it != reputation_factionreps.end(); ++it) { if (((*it)->faction() && (label.compare((*it)->faction()->label()) == 0)) || ((*it)->label().compare(label) == 0)) { - (*it)->set_reputation(reputation); + if ((*it)->reputation() != reputation) { + (*it)->set_reputation(reputation); + reputation_dirty = true; + } return; } } FactionRep *factionrep = new FactionRep(label, reputation); reputation_factionreps.push_back(factionrep); + reputation_dirty = true; } void Reputation::set_reputation(const Info *faction, const float reputation) { for (FactionReps::const_iterator it = reputation_factionreps.begin(); it != reputation_factionreps.end(); ++it) { if ((!(*it)->faction() && ((*it)->label().compare(faction->label()) == 0)) || ((*it)->faction() == faction)) { - (*it)->set_reputation(reputation); + if ((*it)->reputation() != reputation) { + (*it)->set_reputation(reputation); + reputation_dirty = true; + } return; } } FactionRep *factionrep = new FactionRep(faction, reputation); reputation_factionreps.push_back(factionrep); + reputation_dirty = true; +} + +void Reputation::receive_server_update(std::istream &is) +{ + unsigned long id; + float reputation; + + while ((is >> id) && ( is >> reputation)) { + // this is client side and has to create info records as required + set_reputation(game()->request_info(id), reputation); + } +} + +void Reputation::serialize_server_update(std::ostream & os) const +{ + for (FactionReps::const_iterator it = reputation_factionreps.begin(); it != reputation_factionreps.end(); ++it) { + os << (*it)->faction()->id() << " " << roundf((*it)->reputation()) << " "; + } } } // namespace core
\ No newline at end of file |