1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
2 
3 #ifndef TEAM_H
4 #define TEAM_H
5 
6 #include <string>
7 #include <vector>
8 #include <map>
9 #include <list>
10 #include <boost/utility.hpp> //! boost::noncopyable
11 
12 #include "TeamBase.h"
13 #include "TeamStatistics.h"
14 #include "Sim/Units/UnitSet.h"
15 #include "ExternalAI/SkirmishAIKey.h"
16 #include "Lua/LuaRulesParams.h"
17 #include "System/Sync/SyncedPrimitive.h" //! SyncedFloat
18 
19 
20 class CTeam : public TeamBase, private boost::noncopyable //! cannot allow shallow copying of Teams, contains pointers
21 {
22 	CR_DECLARE(CTeam)
23 public:
24 	CTeam(int _teamNum);
25 
26 	void ResetResourceState();
27 	void SlowUpdate();
28 
29 	void AddMetal(float amount, bool useIncomeMultiplier = true);
30 	void AddEnergy(float amount, bool useIncomeMultiplier = true);
31 	bool UseEnergy(float amount);
32 	bool UseMetal(float amount);
AtUnitLimit()33 	bool AtUnitLimit() const { return (units.size() >= maxUnits); }
34 
35 	void GiveEverythingTo(const unsigned toTeam);
36 
37 	void Died(bool normalDeath = true);
38 	void AddPlayer(int playerNum);
39 	void KillAIs();
40 
41 	void SetDefaultStartPos();
42 	void ClampStartPosInStartBox(float3* pos) const;
43 
SetMaxUnits(unsigned int n)44 	void SetMaxUnits(unsigned int n) { maxUnits = n; }
GetMaxUnits()45 	unsigned int GetMaxUnits() const { return maxUnits; }
46 
47 	CTeam& operator = (const TeamBase& base) {
48 		TeamBase::operator = (base);
49 		return *this;
50 	}
51 
52 	std::string GetControllerName() const;
53 
54 	enum AddType {
55 		AddBuilt,
56 		AddCaptured,
57 		AddGiven
58 	};
59 
60 	enum RemoveType {
61 		RemoveDied,
62 		RemoveCaptured,
63 		RemoveGiven
64 	};
65 
66 	void AddUnit(CUnit* unit, AddType type);
67 	void RemoveUnit(CUnit* unit, RemoveType type);
68 
69 
70 	int teamNum;
71 	unsigned int maxUnits;
72 
73 	bool isDead;
74 	bool gaia;
75 
76 	/// color info is unsynced
77 	unsigned char origColor[4];
78 
79 	CUnitSet units;
80 
81 	SyncedFloat metal;
82 	SyncedFloat energy;
83 
84 	float metalPull,    prevMetalPull;
85 	float metalIncome,  prevMetalIncome;
86 	float metalExpense, prevMetalExpense;
87 
88 	float energyPull,    prevEnergyPull;
89 	float energyIncome,  prevEnergyIncome;
90 	float energyExpense, prevEnergyExpense;
91 
92 	SyncedFloat metalStorage, energyStorage;
93 
94 	float metalShare, energyShare;
95 	SyncedFloat delayedMetalShare, delayedEnergyShare; // excess that might be shared next SlowUpdate
96 
97 	float metalSent,      prevMetalSent;
98 	float metalReceived,  prevMetalReceived;
99 	float energySent,     prevEnergySent;
100 	float energyReceived, prevEnergyReceived;
101 
102 	float prevMetalExcess;
103 	float prevEnergyExcess;
104 
105 	int nextHistoryEntry;
106 	TeamStatistics* currentStats;
107 	std::list<TeamStatistics> statHistory;
108 	typedef TeamStatistics Statistics; //! for easier access via CTeam::Statistics
109 
110 	/// mod controlled parameters
111 	LuaRulesParams::Params  modParams;
112 	LuaRulesParams::HashMap modParamsMap; /// name map for mod parameters
113 
114 	float highlight;
115 };
116 
117 #endif /* TEAM_H */
118