Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: d20a2101519e12511ef164376d1dccd87424f3e3 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
   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);
	
	inline void set_dirty(const bool dirty = true)
	{
		reputation_dirty = dirty;
	}
	
	void clear();
	
	void assign(const Reputation &other);
	
	inline FactionReps & factionreps()
	{
		return reputation_factionreps;
	}
	
	inline const bool dirty() const
	{
		return reputation_dirty;
	}
	
	/* ---- deserializers -------------------------------------- */
	
	/// receive a server-to-client update from a stream
	void receive_server_update(std::istream &is);
	
	/* ---- serializers ---------------------------------------- */
	
	/// serialize a server-to-client update on a stream
	void serialize_server_update(std::ostream & os) const;
	
private:
	FactionReps		reputation_factionreps;
	
	bool			reputation_dirty;
};

} // namespace core
#endif // __INCLUDED_CORE_REPUTATION_H__