Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2013-11-08 18:25:59 +0000
committerStijn Buys <ingar@osirion.org>2013-11-08 18:25:59 +0000
commitc8336c0fb110f8b23707c755e7ebaabdde62c8ea (patch)
tree59b1c8373a390d2c061b1d68fe49ab1fc428d7e8 /src/core/reputation.cc
parent995a12fca267302d267ea59cf1c7c631b9e1075f (diff)
Added missing core::reputation files.
Diffstat (limited to 'src/core/reputation.cc')
-rw-r--r--src/core/reputation.cc103
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