File: CEconomy.h

package info (click to toggle)
spring 0.81.2.1%2Bdfsg1-6
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 28,496 kB
  • ctags: 37,096
  • sloc: cpp: 238,659; ansic: 13,784; java: 12,175; awk: 3,428; python: 1,159; xml: 738; perl: 405; sh: 297; makefile: 267; pascal: 228; objc: 192
file content (141 lines) | stat: -rw-r--r-- 3,432 bytes parent folder | download
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
#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;

		/* 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);

		bool isInitialized() { return initialized; };

	private:
		bool initialized;
		AIClasses *ai;

		std::map<int, float3> takenMexes;

		/* The group container */
		std::vector<CGroup*> groups;

		/* The <unitid, vectoridx> table */
		std::map<int, int>  lookup;

		/* The free slots (CUnit instances that are zombie-ish) */
		std::stack<int>     free;

		/* Active groups ingame */
		std::map<int, CGroup*> activeGroups;

		/* Altered by canAfford() */
		bool eRequest, mRequest;

		/* Is this a windmap ? */
		bool windmap;

		/* Primary unit category (KBOT or VEHICLE) */
		unitCategory type;

		/* 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);

		/* Fills takenMexes also */
		float3 getClosestOpenMetalSpot(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, unsigned include, unsigned exclude = 0);

		/* Determine which factory we don't have yet */
		unsigned getAllowedFactory();

		/* See if a buildtask is in progress */
		bool taskInProgress(buildType bt);
};

#endif