blob: 013fd9e10262c3c7c52fdc6a3d860c7cc7608a99 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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
|