forked from Error323/E323AI
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCEconomy.h
140 lines (101 loc) · 3.5 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
#ifndef CECONOMY_H
#define CECONOMY_H
#include <map>
#include <vector>
#include <stack>
#include "ARegistrar.h"
#include "headers/Defines.h"
class ATask;
class CGroup;
class CUnit;
class AIClasses;
class UnitType;
class float3;
const float alpha = 0.2f;
const float beta = 0.05f;
class CEconomy: public ARegistrar {
public:
CEconomy(AIClasses *ai);
~CEconomy();
/* 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;
int latest_factory;
/* 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(int frame);
/* Update averaged incomes */
void updateIncomes(int frame = 100);
/* See if this group has finished a building */
bool hasFinishedBuilding(CGroup &group);
/* See if this group begun building */
bool hasBegunBuilding(CGroup &group);
/* Can we afford to build this ? */
bool canAffordToBuild(UnitType *builder, UnitType *utToBuild, int unitId);
bool isInitialized() { return initialized; };
private:
bool initialized;
AIClasses *ai;
std::map<int, float3> takenMexes, takenGeo, upgradedMexes;
/* Active groups ingame */
std::map<int, CGroup*> activeGroups;
/* Altered by canAfford() */
bool eRequest, mRequest;
/* Is this a windmap ? */
bool windmap;
/* updateIncomes counter */
unsigned int incomes;
/* Can we afford to assist a factory ? */
ATask* canAssistFactory(CGroup &group);
/* Do something with idle builder */
void commandBuilderGroup(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);
/* Fills both takenMexes and upgradedMexes */
float3 getClosestUpgradeableMetalSpot(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 */
bool buildOrAssist(CGroup &group, buildType bt, unsigned include, unsigned exclude = 0);
/* See if a buildtask is in progress */
bool taskInProgress(buildType bt);
/* Get next allowed factory to build */
unsigned int getNextFactoryToBuild(CUnit *unit, int maxteachlevel);
};
#endif