diff options
Diffstat (limited to 'src/core/reputation.h')
-rw-r--r-- | src/core/reputation.h | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/src/core/reputation.h b/src/core/reputation.h new file mode 100644 index 0000000..87d3ea9 --- /dev/null +++ b/src/core/reputation.h @@ -0,0 +1,104 @@ +/* + core/reputation.h + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_CORE_REPUTATION_H__ +#define __INCLUDED_CORE_REPUTATION_H__ + +#include <list> + +#include "core/info.h" + +namespace core { + +class Reputation { + + class FactionRep { + public: + inline FactionRep(const std::string &label, const float reputation = 0) + { + factionrep_label.assign(label); + factionrep_faction = 0; + factionrep_reputation = reputation; + } + + inline FactionRep(const Info *faction, const float reputation = 0) + { + factionrep_label.assign(faction->label()); + factionrep_faction = faction; + factionrep_reputation = reputation; + } + + inline ~FactionRep() + { + } + + inline const std::string & label() const + { + return factionrep_label; + } + + inline const Info *faction() const + { + return factionrep_faction; + } + + /** + * @brief reputation with the specified faction. + * Return value is between -100 (hostile) and 100 (friendly), 0 means neutral. + * */ + inline const float reputation() const + { + return factionrep_reputation; + } + + inline void set_faction(const Info *faction) + { + factionrep_faction = faction; + } + + inline void set_reputation(const float reputation) + { + factionrep_reputation = reputation; + math::clamp(factionrep_reputation, -100.0f, 100.0f); + } + + private: + std::string factionrep_label; + const Info *factionrep_faction; + float factionrep_reputation; + }; + +public: + typedef std::list<FactionRep *> FactionReps; + + Reputation(); + ~Reputation(); + + const float reputation(const Info *faction) const; + + const Info *find(const Info *faction) const; + + void set_faction(const std::string &label, const Info *action); + + void set_reputation(const std::string &label, const float reputation); + + void set_reputation(const Info *faction, const float reputation); + + void clear(); + + void assign(const Reputation &other); + + inline FactionReps & factionreps() + { + return reputation_factionreps; + } + +private: + FactionReps reputation_factionreps; +}; + +} // namespace core +#endif // __INCLUDED_CORE_REPUTATION_H__ |