-
-
Notifications
You must be signed in to change notification settings - Fork 110
/
collective.h
351 lines (302 loc) · 12.6 KB
/
collective.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
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
/* Copyright (C) 2013-2014 Michal Brzozowski (rusolis@poczta.fm)
This file is part of KeeperRL.
KeeperRL 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 2
of the License, or (at your option) any later version.
KeeperRL 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/ . */
#pragma once
#include "move_info.h"
#include "task_callback.h"
#include "resource_id.h"
#include "event_listener.h"
#include "entity_map.h"
#include "minion_trait.h"
#include "dungeon_level.h"
#include "enemy_id.h"
#include "minion_activity.h"
class CollectiveAttack;
class Creature;
class CollectiveControl;
class Tribe;
class TribeId;
class Level;
class Trigger;
struct AttractionInfo;
class MinionEquipment;
class TaskMap;
class KnownTiles;
class CollectiveTeams;
class ConstructionMap;
class Technology;
class CollectiveConfig;
class CostInfo;
struct TriggerInfo;
class Territory;
struct CollectiveName;
class Workshops;
class Zones;
class CollectiveWarnings;
class Immigration;
class PositionMatching;
class MinionActivities;
class ResourceInfo;
class StoragePositions;
class Furnace;
class Dancing;
class Collective : public TaskCallback, public UniqueEntity<Collective>, public EventListener<Collective> {
public:
static PCollective create(Model* model, TribeId, const optional<CollectiveName>&, bool discoverable,
const ContentFactory*);
void init(CollectiveConfig);
void setWorkshops(unique_ptr<Workshops>);
void setImmigration(PImmigration);
void addCreature(Creature*, EnumSet<MinionTrait>);
Creature* addCreature(PCreature, Position, EnumSet<MinionTrait>);
void setPopulationGroup(const vector<Creature*>&);
void setControl(PCollectiveControl);
void makeConqueredRetired(Collective* conqueror);
void tick();
void update(bool currentlyActive);
TribeId getTribeId() const;
Tribe* getTribe() const;
Model* getModel() const;
Game* getGame() const;
typedef CollectiveResourceId ResourceId;
const ResourceInfo& getResourceInfo(ResourceId) const;
void addNewCreatureMessage(const vector<Creature*>&);
void setTask(Creature*, PTask);
void setPriorityTask(Creature*, PTask);
bool hasTask(const Creature*) const;
void freeFromTask(const Creature*);
void banishCreature(Creature*);
void removeCreature(Creature*);
bool wasBanished(const Creature*) const;
void setVillainType(VillainType);
bool isDiscoverable() const;
void setEnemyId(EnemyId);
VillainType getVillainType() const;
optional<EnemyId> getEnemyId() const;
CollectiveControl* getControl() const;
LocalTime getLocalTime() const;
GlobalTime getGlobalTime() const;
const StoragePositions& getStoragePositions(StorageId) const;
const StoragePositions& getStoragePositions(const vector<StorageId>&) const;
bool usesEfficiency(const Furniture*) const;
SERIALIZATION_DECL(Collective)
const vector<Creature*>& getCreatures() const;
bool isConquered() const;
const vector<Creature*>& getCreatures(MinionTrait) const;
bool hasTrait(const Creature*, MinionTrait) const;
bool setTrait(Creature* c, MinionTrait);
bool removeTrait(Creature* c, MinionTrait);
EnumSet<MinionTrait> getAllTraits(Creature*) const;
bool hasTradeItems() const;
vector<Item*> getTradeItems() const;
PItem buyItem(Item*);
vector<TriggerInfo> getTriggers(const Collective* against) const;
const vector<Creature*>& getLeaders() const;
bool needsToBeKilledToConquer(const Creature*) const;
const Territory& getTerritory() const;
Territory& getTerritory();
bool canClaimSquare(Position pos) const;
void claimSquare(Position, bool includeStairs = false);
void unclaimSquare(Position);
const KnownTiles& getKnownTiles() const;
void retire();
CollectiveWarnings& getWarnings();
CollectiveConfig& getConfig();
bool usesEquipment(const Creature*) const;
virtual ~Collective() override;
int numResource(ResourceId) const;
int numResourcePlusDebt(ResourceId) const;
bool hasResource(const CostInfo&) const;
void takeResource(const CostInfo&);
void returnResource(const CostInfo&);
const ConstructionMap& getConstructions() const;
ConstructionMap& getConstructions();
void setMinionActivity(Creature* c, MinionActivity task);
bool isActivityGood(Creature*, MinionActivity, bool ignoreTaskLock = false);
bool isActivityGoodAssumingHaveTasks(Creature*, MinionActivity, bool ignoreTaskLock = false);
using GroupLockedActivities = EnumSet<MinionActivity>;
bool isActivityGroupLocked(const string& group, MinionActivity activity) const;
void flipGroupLockedActivities(const string& group, GroupLockedActivities);
bool isActivityGroupLocked(const Creature*, MinionActivity activity) const;
vector<Item*> getAllItems(bool includeMinions = true) const;
vector<Item*> getAllItems(ItemIndex, bool includeMinions = true) const;
vector<pair<Position, vector<Item*>>> getStoredItems(ItemIndex, vector<StorageId>) const;
bool canUseEquipmentGroup(const Creature*, const string& group);
bool canAddFurniture(Position, FurnitureType) const;
void addFurniture(Position, FurnitureType, const CostInfo&, bool noCredit);
void removeUnbuiltFurniture(Position, FurnitureLayer);
void destroyOrder(Position, FurnitureLayer);
bool isPlannedTorch(Position) const;
bool canPlaceTorch(Position) const;
void removeTorch(Position);
void addTorch(Position);
void setZone(Position, ZoneId);
void eraseZone(Position, ZoneId);
void assignQuarters(Creature*, Position);
bool minionCanUseQuarters(Creature*);
const Zones& getZones() const;
void cancelMarkedTask(Position);
void orderDestruction(Position pos, const DestroyAction&);
void installBodyPart(Item*, Creature* target);
double getDangerLevel() const;
void setPriorityTasks(Position);
bool hasPriorityTasks(Position) const;
void setSteed(Creature* minion, Creature* steed);
Creature* getSteedOrRider(Creature* minion);
void acquireTech(TechId, bool throughLevelling);
const Technology& getTechnology() const;
void setTechnology(Technology);
bool addKnownTile(Position);
const EntitySet<Creature>& getKills() const;
int getPoints() const;
MinionEquipment& getMinionEquipment();
const MinionEquipment& getMinionEquipment() const;
void autoAssignEquipment(Creature*);
optional<FurnitureType> getMissingTrainingFurniture(const Creature*, AttrType) const;
Workshops& getWorkshops();
const Workshops& getWorkshops() const;
Furnace& getFurnace();
const Furnace& getFurnace() const;
Dancing& getDancing();
Immigration& getImmigration();
const Immigration& getImmigration() const;
const MinionActivities& getMinionActivities() const;
int getPopulationSize() const;
int getMaxPopulation() const;
const DungeonLevel& getDungeonLevel() const;
DungeonLevel& getDungeonLevel();
vector<Creature*> getConsumptionTargets(Creature* consumer) const;
void onRansomPaid();
void onExternalEnemyKilled(const string& name);
void addRecordedEvent(string);
const unordered_set<string>& getRecordedEvents() const;
CollectiveTeams& getTeams();
const CollectiveTeams& getTeams() const;
void freeTeamMembers(const vector<Creature*>& members);
const heap_optional<CollectiveName>& getName() const;
const TaskMap& getTaskMap() const;
TaskMap& getTaskMap();
const Task* getItemTask(const Item*) const;
int getNumItems(ItemIndex, bool includeMinions = true) const;
void addKnownVillain(const Collective*);
bool isKnownVillain(const Collective*) const;
void addKnownVillainLocation(const Collective*);
bool isKnownVillainLocation(const Collective*) const;
void onEvent(const GameEvent&);
struct CurrentActivity {
MinionActivity SERIAL(activity);
LocalTime SERIAL(finishTime);
SERIALIZE_ALL(activity, finishTime)
};
CurrentActivity getCurrentActivity(const Creature*) const;
struct AlarmInfo {
GlobalTime SERIAL(finishTime);
Position SERIAL(position);
SERIALIZE_ALL(finishTime, position)
};
string getMinionGroupName(const Creature*) const;
vector<string> getAutomatonGroupNames(const Creature*) const;
const optional<AlarmInfo>& getAlarmInfo() const;
double getRebellionProbability() const;
// From Task::Callback
virtual void onDestructed(Position, FurnitureType, const DestroyAction&) override;
unordered_map<string, unordered_set<string>> SERIAL(lockedEquipmentGroups);
EntityMap<Creature, EnumSet<MinionTrait>> SERIAL(stunnedMinions);
LocalTime lastMass = -10000_local;
void takePrisoner(Creature*);
bool isDelayed(Position);
private:
struct Private {};
public:
Collective(Private, Model*, TribeId, const optional<CollectiveName>&, const ContentFactory*);
protected:
// From Task::Callback
virtual void onConstructed(Position, FurnitureType) override;
virtual void onAppliedSquare(Creature*, pair<Position, FurnitureLayer>) override;
virtual void onCopulated(Creature* who, Creature* with) override;
virtual bool isConstructionReachable(Position) override;
virtual bool containsCreature(Creature*) override;
private:
void onMinionKilled(Creature* victim, Creature* killer);
void onKilledSomeone(Creature* victim, Creature* killer);
void fetchItems(Position);
void addMoraleForKill(Creature* killer, Creature* victim);
void decreaseMoraleForKill(Creature* killer, Creature* victim);
bool isItemNeeded(const Item*) const;
int getDebt(ResourceId id) const;
double getEfficiency(const Creature*) const;
PPositionMatching SERIAL(positionMatching);
HeapAllocated<MinionEquipment> SERIAL(minionEquipment);
HashMap<ResourceId, int> SERIAL(credit);
HeapAllocated<TaskMap> SERIAL(taskMap);
HeapAllocated<Technology> SERIAL(technology);
void markItem(const Item*, const Task*);
void unmarkItem(UniqueEntity<Item>::Id);
HeapAllocated<KnownTiles> SERIAL(knownTiles);
EntityMap<Creature, CurrentActivity> SERIAL(currentActivity);
optional<Position> getTileToExplore(const Creature*, MinionActivity) const;
void handleSurprise(Position);
int getTaskDuration(const Creature*, MinionActivity) const;
vector<Creature*> SERIAL(creatures);
vector<vector<Creature*>> SERIAL(populationGroups);
EnumMap<MinionTrait, vector<Creature*>> SERIAL(byTrait);
PCollectiveControl SERIAL(control);
HeapAllocated<TribeId> SERIAL(tribe);
Model* SERIAL(model) = nullptr;
HeapAllocated<Territory> SERIAL(territory);
optional<AlarmInfo> SERIAL(alarmInfo);
HeapAllocated<ConstructionMap> SERIAL(constructions);
EntityMap<Item, WeakPointer<const Task>> SERIAL(markedItems);
void updateConstructions();
void delayDangerousTasks(const vector<Position>& enemyPos, LocalTime delayTime);
HashMap<Position, LocalTime> SERIAL(delayedPos);
vector<Position> getEnemyPositions() const;
EntitySet<Creature> SERIAL(kills);
int SERIAL(points) = 0;
HeapAllocated<CollectiveTeams> SERIAL(teams);
heap_optional<CollectiveName> SERIAL(name);
HeapAllocated<CollectiveConfig> SERIAL(config);
EntitySet<Creature> SERIAL(banished);
VillainType SERIAL(villainType);
optional<EnemyId> SERIAL(enemyId);
unique_ptr<Workshops> SERIAL(workshops);
HeapAllocated<Furnace> SERIAL(furnace);
HeapAllocated<Zones> SERIAL(zones);
HeapAllocated<CollectiveWarnings> SERIAL(warnings);
PImmigration SERIAL(immigration);
mutable optional<double> dangerLevelCache;
EntitySet<Collective> SERIAL(knownVillains);
EntitySet<Collective> SERIAL(knownVillainLocations);
bool SERIAL(discoverable) = false;
void considerRebellion();
void autoAssignSteeds();
void updateCreatureStatus(Creature*);
void recalculateFurniturePopIncrease();
int SERIAL(populationIncrease) = 0;
DungeonLevel SERIAL(dungeonLevel);
bool SERIAL(hadALeader) = false;
vector<Item*> getAllItemsImpl(optional<ItemIndex>, bool includeMinions) const;
// Remove after alpha 27
void updateBorderTiles();
bool updatedBorderTiles = false;
HeapAllocated<MinionActivities> SERIAL(minionActivities);
unordered_set<string> SERIAL(recordedEvents);
unordered_set<string> SERIAL(allRecordedEvents);
unordered_map<string, GroupLockedActivities> SERIAL(groupLockedAcitivities);
EntityMap<Creature, Creature*> SERIAL(steedAssignments);
bool SERIAL(attackedByPlayer) = false;
void updateGuardTasks();
void updateMinionPromotions();
void updateAutomatonEngines();
bool creatureConsideredPlayer(Creature*) const;
void summonDemon(Creature* summoner);
unique_ptr<Dancing> SERIAL(dancing);
void updateTeamExperience();
};