Repository navigation
Expand file tree
/
Copy pathcorescript.h
More file actions
executable file
·197 lines (157 loc) · 5.86 KB
/
Copy pathcorescript.h
File metadata and controls
executable file
·197 lines (157 loc) · 5.86 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CORESCRIPT_INCLUDED
#define CORESCRIPT_INCLUDED
#include "../xegame/cticker.h"
#include "../game/gamelimits.h"
#include "../xegame/component.h"
#include "../xegame/chitbag.h"
#define SPAWN_MOBS 1
class WorldMap;
class WorkQueue;
class LumosChitBag;
class CoreScript;
class Model;
class ChitContext;
#define CCoreArray grinliz::CArray<CoreScript*, 32 >
struct CoreAchievement
{
void Clear() { techLevel = 0; gold = 0; population = 0; civTechScore = 0; }
void Serialize(XStream* xs);
static const char* CivTechDescription(int score);
int techLevel;
int gold;
int population;
int civTechScore;
};
class CoreScript : public Component
{
typedef Component super;
public:
CoreScript();
virtual ~CoreScript();
virtual void Serialize( XStream* xs );
virtual void OnAdd(Chit* chit, bool init);
virtual void OnRemove();
virtual int DoTick( U32 delta );
virtual const char* Name() const { return "CoreScript"; }
virtual CoreScript* ToCoreScript() { return this; }
virtual void OnChitMsg(Chit* chit, const ChitMsg& msg);
int GetPave();
void AddCitizen(Chit* chit);
bool IsCitizen(Chit* chit);
bool IsCitizen(int id);
bool IsCitizenItemID(int id);
int Citizens(CChitArray* arr);
// 0-3, -1 if not in squad
int SquadID(int chitID);
int Squaddies(int squadID, CChitArray* arr);
bool IsSquaddieOnMission(int chitID, int* squadID);
bool ChangeSquad(Chit* chit, int targetSquad);
bool WantsToConquer(const grinliz::Vector2I& sector);
static int MaxCitizens(int nTemples);
int MaxCitizens();
int NumTemples();
int CorePower(); // approximation of the military strength of the core
int CoreWealth(); // amount of money in the core's treasury
float CivTech(); // current civtech score, from 0-1
/* Controls flags are simple "denizen attractors"
in the same domain. When a denizen arrives
the flag is cleared. They are assigned to the
first available denizen.
*/
void AddFlag(const grinliz::Vector2I& pos);
void RemoveFlag(const grinliz::Vector2I& pos);
void ToggleFlag(const grinliz::Vector2I& pos);
// Get a flag in the CoreScript's sector that is
// not yet in the list.
grinliz::Vector2I GetAvailableFlag();
/* Waypoints are destinations that may involve
grid travel. Waypoints are assigned to
a particular squad, and movement
can be coordinated.
*/
void SetWaypoints(int squadID, const grinliz::Vector2I& dest);
grinliz::Vector2I GetWaypoint(int squadID); // gets the current waypoint
grinliz::Vector2I GetLastWaypoint(int squadID);
const grinliz::CDynArray<grinliz::Vector2I>& GetWaypoints(int squadID) const {
GLASSERT(squadID >= 0 && squadID < MAX_SQUADS);
return waypoints[squadID];
}
void PopWaypoint(int squadID);
bool InUse() const;
WorkQueue* GetWorkQueue() { return workQueue; }
const CoreAchievement& GetAchievement() const { return achievement; }
// Current tech:
float GetTech() const { return float(tech); }
// The number of temples+1:
int MaxTech();
void AddTech();
// Each task pushes a position for that task,
// and removes it when done/cancelled. (Some careful
// code there.) May be a simpler way to see if
// someone is assigned to a task at location. However,
// approximate, since nothing but the location is tracked.
void AddTask(const grinliz::Vector2I& pos2i);
void RemoveTask(const grinliz::Vector2I& pos2i);
bool HasTask(const grinliz::Vector2I& pos2i);
static CoreScript* GetCore(const grinliz::Vector2I& sector) {
GLASSERT(sector.x >= 0 && sector.x < NUM_SECTORS);
GLASSERT(sector.y >= 0 && sector.y < NUM_SECTORS);
return coreArr[sector.y*NUM_SECTORS + sector.x];
}
static CoreScript* GetCoreFromTeam(int team);
static CoreScript** GetCoreList(int *n);
static CoreScript* CreateCore(const grinliz::Vector2I& sector, int team, const ChitContext* context);
static void Init();
static void Free();
private:
void UpdateAI();
void UpdateScore(int n);
bool RecruitNeutral();
void DoTickNeutral(int delta, int nSpawnTicks);
void DoTickInUse(int delta, int nSpawnTicks);
bool SquadAtRest(int squadID);
void AssignToSquads();
void DoStrategicTick();
void NewWaypointChits(int squadID);
void AssignDefaultSpawns();
Chit* CitizenFilter(int id);
WorkQueue* workQueue;
grinliz::Vector2I sector;
CTicker aiTicker; // use to update the core info, every couple of seconds.
CTicker scoreTicker;
CTicker strategicTicker;
CoreAchievement achievement;
// serialized
CTicker spawnTick;
double tech;
int summonGreater;
bool autoRebuild;
int pave;
grinliz::CDynArray< int > citizens;
grinliz::CArray<int, SQUAD_SIZE> squads[MAX_SQUADS];
grinliz::CDynArray< grinliz::Vector2I > tasks;
struct Flag {
grinliz::Vector2I pos;
int chitID;
void Serialize(XStream* xs);
const bool operator==(const Flag& rhs) { return rhs.pos == pos; }
};
grinliz::CDynArray< Flag > flags;
grinliz::CDynArray<grinliz::Vector2I> waypoints[MAX_SQUADS];
static CoreScript* coreArr[NUM_SECTORS*NUM_SECTORS];
static grinliz::HashTable<int, int>* teamToCoreInfo;
static grinliz::CArray<CoreScript*, NUM_SECTORS*NUM_SECTORS> coreList;
};
#endif // CORESCRIPT_INCLUDED