-
Notifications
You must be signed in to change notification settings - Fork 8
/
CEconomy.h
146 lines (114 loc) · 4 KB
/
CEconomy.h
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#ifndef CECONOMY_H
#define CECONOMY_H
#include <map>
#include <vector>
#include <stack>
#include "ARegistrar.h"
#include "headers/Defines.h"
#include "CUnitTable.h"
class ATask;
class CGroup;
class CUnit;
class AIClasses;
struct UnitType;
class float3;
const float alpha = 0.2f;
const float beta = 0.05f;
class CEconomy: public ARegistrar {
public:
typedef std::map<unitCategory, unitCategory, UnitCategoryCompare> UnitCategory2UnitCategoryMap;
CEconomy(AIClasses* ai);
/* overal mNow averaged over 5 logical frames */
float mNow, mNowSummed;
/* overal eNow averaged over 5 logical frames */
float eNow, eNowSummed;
/* overal mIncome averaged over 5 logical frames */
float mIncome, mIncomeSummed;
/* overal eIncome averaged over 5 logical frames */
float eIncome, eIncomeSummed;
/* total units mIncome averaged over 5 logical frames */
float uMIncome, uMIncomeSummed;
/* total units eIncome averaged over 5 logical frames */
float uEIncome, uEIncomeSummed;
/* metal usage averaged over 5 logical frames */
float mUsage, mUsageSummed, mStart;
/* energy usage averaged over 5 logical frames */
float eUsage, eUsageSummed, eStart;
/* metal storage */
float mStorage;
/* energy storage */
float eStorage;
/* State, a sort of measurement how far advanced we are */
int state;
/* stalling/exceeding vars, updated in updateIncomes() */
bool mstall, estall, mexceeding, eexceeding, areMMakersEnabled;
/* Returns a fresh CGroup instance */
CGroup* requestGroup();
/* Overload */
void remove(ARegistrar &group);
/* Add a new unit on finished */
void addUnitOnCreated(CUnit &unit);
/* Add a new unit on created */
void addUnitOnFinished(CUnit &unit);
/* Initialize economy module */
void init(CUnit &unit);
/* Update the eco system */
void update();
/* Update averaged incomes */
void updateIncomes();
/* See if this group has finished a building */
bool hasFinishedBuilding(CGroup &group);
/* See if this group begun building */
bool hasBegunBuilding(CGroup &group) const;
/* Can we afford to build this ? */
bool canAffordToBuild(UnitType *builder, UnitType *utToBuild);
bool isInitialized() { return initialized; };
protected:
AIClasses* ai;
private:
/* List of rules "can build where" for environment tags */
static UnitCategory2UnitCategoryMap canBuildEnv;
bool initialized;
bool stallThresholdsReady;
UnitType *utCommander;
std::map<int, float3> takenMexes, takenGeo;
/* Active groups ingame */
std::map<int, CGroup*> activeGroups;
/* Altered by canAfford() */
bool eRequest, mRequest;
/* Is this a windmap ? */
bool windmap;
bool worthBuildingTidal;
/* updateIncomes counter */
unsigned int incomes;
/* Can we afford to assist a factory? */
ATask* canAssistFactory(CGroup& group);
/* See if we can help with a certain task */
ATask* canAssist(buildType t, CGroup& group);
float3 getBestSpot(CGroup& group, std::list<float3>& resources, std::map<int, float3>& tracker, bool metal);
/* Fills takenMexes also */
float3 getClosestOpenMetalSpot(CGroup& group);
float3 getClosestOpenGeoSpot(CGroup& group);
/* Prevent stalling */
void preventStalling();
/* See what is best for our economy */
void controlMetalMakers();
/* Build or assist on a certain task */
void buildOrAssist(CGroup& group, buildType bt, unitCategory include, unitCategory exclude = 0);
/* See if a buildtask is in progress */
bool taskInProgress(buildType bt);
/* Get next allowed factory to build */
unitCategory getNextTypeToBuild(UnitType* ut, unitCategory cats, int maxteachlevel);
unitCategory getNextTypeToBuild(CUnit* unit, unitCategory cats, int maxteachlevel);
bool isTypeRequired(UnitType* builder, unitCategory cats, int maxteachlevel);
void tryBuildingDefense(CGroup*);
void tryBuildingShield(CGroup*);
void tryBuildingStaticAssister(CGroup*);
void tryBuildingJammer(CGroup*);
void tryBuildingAntiNuke(CGroup*);
void tryAssistingFactory(CGroup*);
void tryAssist(CGroup*, buildType bt);
void tryFixingStall(CGroup*);
unitCategory canBuildWhere(unitCategory unitCats, bool strictly = false);
};
#endif