diff options
Diffstat (limited to 'src/core/reputation.cc')
-rw-r--r-- | src/core/reputation.cc | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/src/core/reputation.cc b/src/core/reputation.cc new file mode 100644 index 0000000..013fd9e --- /dev/null +++ b/src/core/reputation.cc @@ -0,0 +1,103 @@ +/* + core/reputation.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#include "core/reputation.h" + +namespace core { + +Reputation::Reputation() +{ +} + +Reputation::~Reputation() +{ + clear(); +} + +void Reputation::clear() +{ + for (FactionReps::iterator it = reputation_factionreps.begin(); it != reputation_factionreps.end(); ++it) { + delete (*it); + (*it) = 0; + } + reputation_factionreps.clear(); +} + +void Reputation::assign(const Reputation &other) +{ + clear(); + + for (FactionReps::const_iterator it = other.reputation_factionreps.begin(); it != other.reputation_factionreps.end(); ++it) { + + FactionRep *factionrep = new FactionRep((*it)->faction(), (*it)->reputation()); + reputation_factionreps.push_back(factionrep); + + } + +} + +const Info *Reputation::find(const Info *faction) const +{ + for (FactionReps::const_iterator it = reputation_factionreps.begin(); it != reputation_factionreps.end(); ++it) { + if ((*it)->faction() == faction) { + return (*it)->faction(); + } + } + + return 0; +} + +const float Reputation::reputation(const Info *faction) const +{ + if (!faction) { + return 0.0f; + } + + for (FactionReps::const_iterator it = reputation_factionreps.begin(); it != reputation_factionreps.end(); ++it) { + if ((*it)->faction() == faction) { + return (*it)->reputation(); + } + } + + return 0.0f; +} + +void Reputation::set_faction(const std::string &label, const Info *faction) +{ + for (FactionReps::const_iterator it = reputation_factionreps.begin(); it != reputation_factionreps.end(); ++it) { + if ((*it)->label().compare(label) == 0) { + (*it)->set_faction(faction); + } + } +} + +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); + return; + } + } + + FactionRep *factionrep = new FactionRep(label, reputation); + reputation_factionreps.push_back(factionrep); +} + +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); + return; + } + } + + FactionRep *factionrep = new FactionRep(faction, reputation); + reputation_factionreps.push_back(factionrep); +} + +} // namespace core
\ No newline at end of file |