forked from miki151/keeperrl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
collective.h
392 lines (335 loc) · 14 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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
/* Copyright (C) 2013-2014 Michal Brzozowski ([email protected])
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/ . */
#ifndef _COLLECTIVE_H
#define _COLLECTIVE_H
#include "move_info.h"
#include "task_callback.h"
#include "minion_task.h"
#include "square_apply_type.h"
#include "resource_id.h"
#include "square_type.h"
#include "attack_trigger.h"
#include "collective_warning.h"
class CollectiveAttack;
class Creature;
class CollectiveControl;
class Tribe;
class Deity;
class Level;
class Trigger;
struct ImmigrantInfo;
struct AttractionInfo;
class Spell;
class MinionEquipment;
class TaskMap;
class KnownTiles;
class CollectiveTeams;
class ConstructionMap;
class Technology;
class CollectiveConfig;
class MinionAttraction;
struct CostInfo;
struct TriggerInfo;
class Territory;
class Collective : public TaskCallback {
public:
void addCreature(Creature*, EnumSet<MinionTrait>);
void addCreature(PCreature, Position, EnumSet<MinionTrait>);
MoveInfo getMove(Creature*);
void setControl(PCollectiveControl);
void tick(double time);
const Tribe* getTribe() const;
Tribe* getTribe();
double getStanding(const Deity*) const;
Level* getLevel();
const Level* getLevel() const;
double getTime() const;
void update(Creature*);
void addNewCreatureMessage(const vector<Creature*>&);
void setTask(const Creature*, PTask, bool priority = false);
bool hasTask(const Creature*) const;
void cancelTask(const Creature*);
void banishCreature(Creature*);
bool wasBanished(const Creature*) const;
void ownItem(const Creature*, const Item*);
typedef CollectiveWarning Warning;
typedef CollectiveResourceId ResourceId;
SERIALIZATION_DECL(Collective);
const vector<Creature*>& getCreatures() const;
bool isConquered() const;
const vector<Creature*>& getCreatures(SpawnType) const;
const vector<Creature*>& getCreatures(MinionTrait) const;
vector<Creature*> getCreaturesAnyOf(EnumSet<MinionTrait>) const;
vector<Creature*> getCreatures(EnumSet<MinionTrait> with, EnumSet<MinionTrait> without = {}) const;
bool hasTrait(const Creature*, MinionTrait) const;
bool hasAnyTrait(const Creature*, EnumSet<MinionTrait>) const;
void setTrait(Creature* c, MinionTrait);
void removeTrait(Creature* c, MinionTrait);
double getTechCostMultiplier() const;
double getCraftingMultiplier() const;
double getBeastMultiplier() const;
double getUndeadMultiplier() const;
vector<Creature*> getRecruits() const;
void recruit(Creature*, Collective* to);
vector<Item*> getTradeItems() const;
PItem buyItem(Item*);
vector<TriggerInfo> getTriggers(const Collective* against) const;
double getEfficiency(const Creature*) const;
const Creature* getLeader() const;
Creature* getLeader();
bool hasLeader() const;
const set<Position>& getSquares(SquareType) const;
const set<Position>& getSquares(SquareApplyType) const;
vector<SquareType> getSquareTypes() const;
vector<Position> getAllSquares(const vector<SquareType>&, bool centerOnly = false) const;
const Territory& getTerritory() const;
void claimSquare(Position);
void changeSquareType(Position pos, SquareType from, SquareType to);
bool isKnownSquare(Position pos) const;
double getEfficiency(Position) const;
bool hasEfficiency(Position) const;
bool usesEquipment(const Creature*) const;
bool isKnownVillain(const Collective*);
bool isKnownVillainLocation(const Collective*);
virtual ~Collective();
void setWarning(Warning, bool state = true);
bool isWarning(Warning) const;
struct ResourceInfo;
struct MinionTaskInfo;
map<MinionTask, MinionTaskInfo> getTaskInfo() const;
struct ResourceInfo {
vector<SquareType> storageType;
optional<ItemIndex> itemIndex;
ItemId itemId;
string name;
bool dontDisplay;
};
const static map<ResourceId, ResourceInfo> resourceInfo;
int numResource(ResourceId) const;
int numResourcePlusDebt(ResourceId) const;
bool hasResource(const CostInfo&) const;
void takeResource(const CostInfo&);
void returnResource(const CostInfo&);
struct ItemFetchInfo;
const ConstructionMap& getConstructions() const;
void setMinionTask(const Creature* c, MinionTask task);
optional<MinionTask> getMinionTask(const Creature*) const;
bool isMinionTaskPossible(Creature* c, MinionTask task);
set<TrapType> getNeededTraps() const;
vector<Item*> getAllItems(bool includeMinions = true) const;
vector<Item*> getAllItems(ItemPredicate predicate, bool includeMinions = true) const;
vector<Item*> getAllItems(ItemIndex, bool includeMinions = true) const;
static void sortByEquipmentValue(vector<Item*>&);
static SquareType getHatcheryType(Tribe* tribe);
static vector<SquareType> getEquipmentStorageSquares();
vector<pair<Item*, Position>> getTrapItems(TrapType, const vector<Position>&) const;
void orderExecution(Creature*);
void orderSacrifice(Creature*);
void orderTorture(Creature*);
void orderWhipping(Creature*);
bool canWhip(Creature*) const;
void addTrap(Position, TrapType);
void removeTrap(Position);
void addConstruction(Position, SquareType, const CostInfo&, bool immediately, bool noCredit);
void removeConstruction(Position);
void destroySquare(Position);
bool isPlannedTorch(Position) const;
bool canPlaceTorch(Position) const;
void removeTorch(Position);
void addTorch(Position);
void fetchAllItems(Position);
void dig(Position);
void cancelMarkedTask(Position);
void cutTree(Position);
double getDangerLevel() const;
bool isMarked(Position) const;
HighlightType getMarkHighlight(Position) const;
void setPriorityTasks(Position);
bool hasPriorityTasks(Position) const;
bool hasTech(TechId id) const;
void acquireTech(Technology*, bool free = false);
vector<Technology*> getTechnologies() const;
double getTechCost(Technology*);
static vector<Spell*> getSpellLearning(const Technology*);
vector<Spell*> getAllSpells() const;
vector<Spell*> getAvailableSpells() const;
TechId getNeededTech(Spell*) const;
void addKnownTile(Position);
vector<const Creature*> getKills() const;
int getPoints() const;
MinionEquipment& getMinionEquipment();
const MinionEquipment& getMinionEquipment() const;
struct DormInfo;
static const EnumMap<SpawnType, DormInfo>& getDormInfo();
static optional<SquareType> getSecondarySquare(SquareType);
struct MinionPaymentInfo;
int getNextPayoutTime() const;
int getSalary(const Creature*) const;
int getNextSalaries() const;
bool hasMinionDebt() const;
int getPopulationSize() const;
int getMaxPopulation() const;
bool tryLockingDoor(Position);
void orderConsumption(Creature* consumer, Creature* who);
vector<Creature*>getConsumptionTargets(Creature* consumer);
void addAttack(const CollectiveAttack&);
void onRansomPaid();
void onKilled(Creature* victim, Creature* killer);
void onAlarm(Position);
void onTorture(const Creature* who, const Creature* torturer);
void onSurrender(Creature* who);
void onTrapTrigger(Position);
void onTrapDisarm(const Creature*, Position);
void onSquareDestroyed(Position);
void onEquip(const Creature*, const Item*);
CollectiveTeams& getTeams();
const CollectiveTeams& getTeams() const;
void freeTeamMembers(TeamId);
void ownItems(const Creature* who, const vector<Item*>);
string getFullName() const;
string getShortName() const;
string getTribeName() const;
const TaskMap& getTaskMap() const;
template <class Archive>
static void registerTypes(Archive& ar, int version);
protected:
// From Task::Callback
virtual void onAppliedItem(Position, Item* item) override;
virtual void onAppliedItemCancel(Position) override;
virtual void onPickedUp(Position, EntitySet<Item>) override;
virtual void onCantPickItem(EntitySet<Item> items) override;
virtual void onConstructed(Position, const SquareType&) override;
virtual void onTorchBuilt(Position, Trigger*) override;
virtual void onAppliedSquare(Position) override;
virtual void onKillCancelled(Creature*) override;
virtual void onBedCreated(Position, const SquareType& fromType, const SquareType& toType) override;
virtual void onCopulated(Creature* who, Creature* with) override;
virtual void onConsumed(Creature* consumer, Creature* who) override;
virtual bool isConstructionReachable(Position) override;
virtual void onWhippingDone(Creature* whipped, Position postPosition) override;
private:
friend class CollectiveBuilder;
Collective(Level*, const CollectiveConfig&, Tribe*, EnumMap<ResourceId, int> credit, const optional<string>& name);
void addCreatureInTerritory(PCreature, EnumSet<MinionTrait>);
void updateEfficiency(Position, SquareType);
int getPaymentAmount(const Creature*) const;
void makePayouts();
void cashPayouts();
void removeCreature(Creature*);
const vector<ItemFetchInfo>& getFetchInfo() const;
void fetchItems(Position, const ItemFetchInfo&);
void addMoraleForKill(const Creature* killer, const Creature* victim);
void decreaseMoraleForKill(const Creature* killer, const Creature* victim);
void decreaseMoraleForBanishing(const Creature*);
double getAttractionValue(const MinionAttraction&);
double getImmigrantChance(const ImmigrantInfo&);
bool isItemNeeded(const Item*) const;
void addProducesMessage(const Creature*, const vector<PItem>&);
int getNumKilled(double afterT);
HeapAllocated<MinionEquipment> SERIAL(minionEquipment);
EnumMap<ResourceId, int> SERIAL(credit);
HeapAllocated<TaskMap> SERIAL(taskMap);
vector<TechId> SERIAL(technologies);
int SERIAL(numFreeTech) = 0;
bool isItemMarked(const Item*) const;
void markItem(const Item*);
void unmarkItem(UniqueEntity<Item>::Id);
HeapAllocated<KnownTiles> SERIAL(knownTiles);
struct CurrentTaskInfo;
map<UniqueEntity<Creature>::Id, CurrentTaskInfo> SERIAL(currentTasks);
optional<Position> getTileToExplore(const Creature*, MinionTask) const;
PTask getStandardTask(Creature* c);
PTask getEquipmentTask(Creature* c);
PTask getHealingTask(Creature* c);
bool isTaskGood(const Creature*, MinionTask, bool ignoreTaskLock = false) const;
PTask generateMinionTask(Creature*, MinionTask);
void setRandomTask(const Creature*);
void handleSurprise(Position);
EnumSet<Warning> SERIAL(warnings);
MoveInfo getDropItems(Creature*);
MoveInfo getWorkerMove(Creature*);
MoveInfo getTeamMemberMove(Creature*);
void autoEquipment(Creature* creature, bool replace);
Item* getWorstItem(const Creature*, vector<Item*> items) const;
int getTaskDuration(const Creature*, MinionTask) const;
double getStanding(EpithetId id) const;
void onEpithetWorship(Creature*, WorshipType, EpithetId);
void considerHealingLeader();
bool considerImmigrant(const ImmigrantInfo&);
void considerBuildingBeds();
bool considerNonSpawnImmigrant(const ImmigrantInfo&, vector<PCreature>);
void considerSpawningGhosts();
vector<Position> getSpawnPos(const vector<Creature*>&);
void considerImmigration();
int tryBuildingBeds(SpawnType spawnType, int numBeds);
void considerBirths();
void considerWeaponWarning();
void considerMoraleWarning();
void considerSendingGuardian();
void decayMorale();
vector<Creature*> SERIAL(creatures);
Creature* SERIAL(leader) = nullptr;
EnumMap<MinionTrait, vector<Creature*>> SERIAL(byTrait);
EnumMap<SpawnType, vector<Creature*>> SERIAL(bySpawnType);
PCollectiveControl SERIAL(control);
Tribe* SERIAL(tribe) = nullptr;
map<const Deity*, double> SERIAL(deityStanding);
Level* SERIAL(level) = nullptr;
unordered_map<SquareType, set<Position>> SERIAL(mySquares);
unordered_map<SquareApplyType, set<Position>, CustomHash<SquareApplyType>> SERIAL(mySquares2);
map<Position, int> SERIAL(squareEfficiency);
HeapAllocated<Territory> SERIAL(territory);
struct AlarmInfo {
double SERIAL(finishTime);
Position SERIAL(position);
template<class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar & SVAR(finishTime) & SVAR(position);
}
};
optional<AlarmInfo> SERIAL(alarmInfo);
MoveInfo getAlarmMove(Creature* c);
HeapAllocated<ConstructionMap> SERIAL(constructions);
EntitySet<Item> SERIAL(markedItems);
set<Position> SERIAL(squaresInUse);
ItemPredicate unMarkedItems() const;
set<Creature*> SERIAL(surrendering);
void updateConstructions();
void delayDangerousTasks(const vector<Position>& enemyPos, double delayTime);
bool isDelayed(Position);
unordered_map<Position, double, CustomHash<Position>> SERIAL(delayedPos);
vector<Position> getEnemyPositions() const;
double manaRemainder = 0;
double getKillManaScore(const Creature*) const;
void addMana(double);
vector<const Creature*> SERIAL(kills);
int SERIAL(points) = 0;
map<const Creature*, MinionPaymentInfo> SERIAL(minionPayment);
int SERIAL(nextPayoutTime);
unordered_map<const Creature*, vector<AttractionInfo>> SERIAL(minionAttraction);
double getAttractionOccupation(const MinionAttraction&);
Creature* getCopulationTarget(Creature* succubus);
Creature* getConsumptionTarget(Creature* consumer);
deque<Creature*> SERIAL(pregnancies);
mutable vector<ItemFetchInfo> itemFetchInfo;
HeapAllocated<CollectiveTeams> SERIAL(teams);
set<const Location*> SERIAL(knownLocations);
set<const Collective*> SERIAL(knownVillains);
set<const Collective*> SERIAL(knownVillainLocations);
optional<string> SERIAL(name);
HeapAllocated<CollectiveConfig> SERIAL(config);
vector<const Creature*> SERIAL(banished);
EntitySet<Creature> SERIAL(equipmentUpdates);
vector<Creature*> SERIAL(deadCreatures);
optional<double> SERIAL(spawnGhosts);
Creature* SERIAL(lastGuardian) = nullptr;
};
#endif