-
-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathcollective_config.cpp
365 lines (320 loc) · 13.6 KB
/
collective_config.cpp
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
#include "stdafx.h"
#include "util.h"
#include "creature.h"
#include "collective_config.h"
#include "tribe.h"
#include "game.h"
#include "technology.h"
#include "collective_warning.h"
#include "item_type.h"
#include "resource_id.h"
#include "inventory.h"
#include "workshops.h"
#include "lasting_effect.h"
#include "item.h"
#include "view_id.h"
#include "furniture_type.h"
#include "minion_activity.h"
#include "furniture_usage.h"
#include "creature_attributes.h"
#include "collective.h"
#include "zones.h"
#include "construction_map.h"
#include "item_class.h"
#include "villain_type.h"
#include "furniture.h"
#include "tutorial_highlight.h"
#include "spell.h"
#include "creature_factory.h"
#include "resource_info.h"
#include "workshop_item.h"
#include "body.h"
#include "view_id.h"
#include "view_object.h"
#include "territory.h"
#include "furniture_factory.h"
#include "storage_id.h"
#include "immigrant_info.h"
#include "conquer_condition.h"
#include "content_factory.h"
#include "content_factory.h"
#include "bed_type.h"
#include "item_types.h"
#include "furnace.h"
template <class Archive>
void CollectiveConfig::serialize(Archive& ar, const unsigned int version) {
ar(OPTION(immigrantInterval), OPTION(maxPopulation), OPTION(conquerCondition), OPTION(canEnemyRetire));
ar(SKIP(type), OPTION(leaderAsFighter), OPTION(spawnGhosts), OPTION(ghostProb), OPTION(guardianInfo));
ar(SKIP(populationString), OPTION(prisoners), OPTION(alwaysMount), OPTION(discoverAchievement));
ar(SKIP(requireQuartersForExp));
}
SERIALIZABLE(CollectiveConfig);
SERIALIZATION_CONSTRUCTOR_IMPL(CollectiveConfig);
template <class Archive>
void GuardianInfo::serialize(Archive& ar, const unsigned int version) {
ar(creature, probability, minEnemies, minVictims);
}
SERIALIZABLE(GuardianInfo);
BedType CollectiveConfig::getPrisonBedType(const Creature* c) {
return c->getBody().isHumanoid() ? BedType::PRISON : BedType::CAGE;
}
static optional<BedType> getBedType(const Creature* c, const ContentFactory* factory) {
if (c->getBody().isImmuneTo(LastingEffect::SLEEP, factory))
return none;
if (c->isAffected(LastingEffect::STEED))
return BedType::STABLE;
if (c->getStatus().contains(CreatureStatus::PRISONER))
return CollectiveConfig::getPrisonBedType(c);
if (c->getBody().isUndead(factory))
return BedType::COFFIN;
if (c->getBody().isHumanoid())
return BedType::BED;
else
return BedType::CAGE;
}
void CollectiveConfig::addBedRequirementToImmigrants(vector<ImmigrantInfo>& immigrantInfo, ContentFactory* factory) {
for (auto& info : immigrantInfo) {
PCreature c = factory->getCreatures().fromId(info.getId(0), TribeId::getDarkKeeper());
if (info.getInitialRecruitment() == 0)
if (auto bedType = getBedType(c.get(), factory)) {
bool hasBed = false;
info.visitRequirements(makeVisitor(
[&](const AttractionInfo& attraction) -> void {
for (auto& type : attraction.types)
if (auto fType = type.getValueMaybe<FurnitureType>())
if (factory->furniture.getData(*fType).getBedType() == *bedType)
hasBed = true;
},
[&](const auto&) {}
));
if (!hasBed) {
info.addRequirement(AttractionInfo(1, factory->furniture.getBedFurniture(*bedType)[0]));
}
}
}
}
CollectiveConfig::CollectiveConfig(TimeInterval interval, CollectiveType t, int maxPop, ConquerCondition conquerCondition)
: immigrantInterval(interval), maxPopulation(maxPop), type(t),
conquerCondition(conquerCondition) {
}
CollectiveConfig CollectiveConfig::keeper(TimeInterval immigrantInterval, int maxPopulation,
string populationString, bool prisoners, ConquerCondition conquerCondition, bool requireQuartersForExp) {
auto ret = CollectiveConfig(immigrantInterval, KEEPER, maxPopulation, conquerCondition);
ret.populationString = populationString;
ret.prisoners = prisoners;
ret.requireQuartersForExp = requireQuartersForExp;
return ret;
}
CollectiveConfig CollectiveConfig::noImmigrants() {
return CollectiveConfig(TimeInterval {}, VILLAGE, 10000, ConquerCondition::KILL_FIGHTERS_AND_LEADER);
}
int CollectiveConfig::getNumGhostSpawns() const {
return spawnGhosts;
}
TimeInterval CollectiveConfig::getImmigrantTimeout() const {
return 500_visible;
}
double CollectiveConfig::getGhostProb() const {
return ghostProb;
}
bool CollectiveConfig::isLeaderFighter() const {
return leaderAsFighter;
}
bool CollectiveConfig::getManageEquipment() const {
return type == KEEPER;
}
bool CollectiveConfig::getFollowLeaderIfNoTerritory() const {
return type == KEEPER;
}
bool CollectiveConfig::stayInTerritory() const {
return type != KEEPER;
}
bool CollectiveConfig::hasVillainSleepingTask() const {
return type != KEEPER;
}
bool CollectiveConfig::allowHealingTaskOutsideTerritory() const {
return type == KEEPER;
}
bool CollectiveConfig::hasImmigrantion(bool currentlyActiveModel) const {
return type != KEEPER || currentlyActiveModel;
}
TimeInterval CollectiveConfig::getImmigrantInterval() const {
return immigrantInterval;
}
bool CollectiveConfig::getStripSpawns() const {
return type == KEEPER;
}
bool CollectiveConfig::getEnemyPositions() const {
return type == KEEPER;
}
bool CollectiveConfig::getWarnings() const {
return type == KEEPER;
}
bool CollectiveConfig::getConstructions() const {
return type == KEEPER;
}
int CollectiveConfig::getMaxPopulation() const {
return maxPopulation;
}
const string& CollectiveConfig::getPopulationString() const {
return populationString;
}
const optional<GuardianInfo>& CollectiveConfig::getGuardianInfo() const {
return guardianInfo;
}
bool CollectiveConfig::isConquered(const Collective* collective) const {
switch (conquerCondition) {
case ConquerCondition::KILL_LEADER:
return collective->getLeaders().empty();
case ConquerCondition::KILL_FIGHTERS_AND_LEADER:
return collective->getCreatures(MinionTrait::FIGHTER).empty() && collective->getLeaders().empty();
case ConquerCondition::DESTROY_BUILDINGS:
for (auto& elem : collective->getConstructions().getAllFurniture())
if (auto f = elem.first.getFurniture(elem.second))
if (f->isWall())
return false;
return true;
case ConquerCondition::NEVER:
return false;
}
}
bool CollectiveConfig::xCanEnemyRetire() const {
return canEnemyRetire && type != KEEPER;
}
CollectiveConfig& CollectiveConfig::setConquerCondition(ConquerCondition c) {
conquerCondition = c;
return *this;
}
bool CollectiveConfig::canCapturePrisoners() const {
return prisoners;
}
bool CollectiveConfig::alwaysMountSteeds() const {
return alwaysMount;
}
bool CollectiveConfig::minionsRequireQuarters() const {
return type == KEEPER && requireQuartersForExp;
}
MinionActivityInfo::MinionActivityInfo(Type t) : type(t) {
CHECK(type != FURNITURE);
}
MinionActivityInfo::MinionActivityInfo() {}
MinionActivityInfo::MinionActivityInfo(FurnitureType type, Task::SearchType searchType)
: type(FURNITURE), furniturePredicate(
[type](const ContentFactory*, const Collective*, const Creature*, FurnitureType t) { return t == type;}),
searchType(searchType) {
}
MinionActivityInfo::MinionActivityInfo(BuiltinUsageId usage)
: type(FURNITURE), furniturePredicate(
[usage](const ContentFactory* f, const Collective*, const Creature*, FurnitureType t) {
return f->furniture.getData(t).hasUsageType(usage);
})
{
}
MinionActivityInfo::MinionActivityInfo(UsagePredicate pred, SecondaryPredicate pred2, Task::SearchType searchType)
: type(FURNITURE), furniturePredicate(std::move(pred)), secondaryPredicate(std::move(pred2)),
searchType(searchType) {
}
CollectiveConfig::CollectiveConfig(const CollectiveConfig&) = default;
CollectiveConfig::CollectiveConfig(CollectiveConfig&&) noexcept = default;
CollectiveConfig::~CollectiveConfig() {
}
static auto getTrainingPredicate(AttrType experienceType) {
return [experienceType] (const ContentFactory* contentFactory, const Collective*, const Creature* c, FurnitureType t) {
if (auto maxIncrease = contentFactory->furniture.getData(t).getMaxTraining(experienceType))
return !c || (c->getAttributes().getExpLevel(experienceType) < maxIncrease &&
!c->getAttributes().isTrainingMaxedOut(experienceType));
else
return false;
};
}
const MinionActivityInfo& CollectiveConfig::getActivityInfo(MinionActivity task) {
static EnumMap<MinionActivity, MinionActivityInfo> map([](MinionActivity task) -> MinionActivityInfo {
switch (task) {
case MinionActivity::IDLE: return {MinionActivityInfo::IDLE};
case MinionActivity::CONSTRUCTION: return {MinionActivityInfo::WORKER};
case MinionActivity::HAULING: return {MinionActivityInfo::WORKER};
case MinionActivity::WORKING: return {MinionActivityInfo::WORKER};
case MinionActivity::DIGGING: return {MinionActivityInfo::WORKER};
case MinionActivity::TRAIN: return {getTrainingPredicate(AttrType("DAMAGE"))};
case MinionActivity::SLEEP:
return {[](const ContentFactory* f, const Collective*, const Creature* c, FurnitureType t) {
if (!c)
return !!f->furniture.getData(t).getBedType();
return getBedType(c, f) == f->furniture.getData(t).getBedType();
}};
case MinionActivity::EAT:
return {[](const ContentFactory* factory, const Collective* col, const Creature* c, FurnitureType t) {
auto f = factory->furniture.getData(t);
if (!c)
return !!f.getDiningFurnitureType();
return f.getDiningFurnitureType() == c->getBody().getDiningFurniture();
}};
case MinionActivity::PHYLACTERY: return {FurnitureType("PHYLACTERY")};
case MinionActivity::GUARDING1: return {MinionActivityInfo::GUARD1};
case MinionActivity::GUARDING2: return {MinionActivityInfo::GUARD2};
case MinionActivity::GUARDING3: return {MinionActivityInfo::GUARD3};
case MinionActivity::POETRY:
return {[](const ContentFactory* f, const Collective*, const Creature* c, FurnitureType t) {
return t == FurnitureType("POETRY_TABLE")
|| t == FurnitureType("PAINTING_N")
|| t == FurnitureType("PAINTING_S")
|| t == FurnitureType("PAINTING_E")
|| t == FurnitureType("PAINTING_W");
}, [](const Furniture* f, const Collective* col) {
CHECK(f);
auto id = f->getViewObject()->id().data();
return !startsWith(id, "painting") && (!startsWith(id, "canvas") || !NOTNULL(col)->getRecordedEvents().empty());
}};
case MinionActivity::STUDY: return {getTrainingPredicate(AttrType("SPELL_DAMAGE"))};
case MinionActivity::DISTILLATION: return {FurnitureType("DISTILLERY")};
case MinionActivity::HEARING_CONFESSION: return {
[](const ContentFactory* f, const Collective* col, const Creature* c, FurnitureType t) {
return t == FurnitureType("CONFESSIONAL") || t == FurnitureType("LUXURIOUS_CONFESSIONAL");
},
nullptr, Task::SearchType::LAZY};
case MinionActivity::CONFESSION: return {MinionActivityInfo::CONFESSION};
case MinionActivity::CROPS: return {FurnitureType("CROPS")};
case MinionActivity::RITUAL: return {BuiltinUsageId::DEMON_RITUAL};
case MinionActivity::ARCHERY: return {MinionActivityInfo::ARCHERY};
case MinionActivity::COPULATE: return {MinionActivityInfo::COPULATE};
case MinionActivity::EXPLORE: return {MinionActivityInfo::EXPLORE};
case MinionActivity::SPIDER: return {MinionActivityInfo::SPIDER};
case MinionActivity::MINION_ABUSE: return {MinionActivityInfo::MINION_ABUSE};
case MinionActivity::EXPLORE_NOCTURNAL: return {MinionActivityInfo::EXPLORE};
case MinionActivity::EXPLORE_CAVES: return {MinionActivityInfo::EXPLORE};
case MinionActivity::BE_WHIPPED: return {FurnitureType("WHIPPING_POST")};
case MinionActivity::BE_TORTURED: return {FurnitureType("TORTURE_TABLE")};
case MinionActivity::BE_EXECUTED: return {FurnitureType("GALLOWS")};
case MinionActivity::CRAFT:
return {[](const ContentFactory* f, const Collective* col, const Creature* c, FurnitureType t) {
PROFILE_BLOCK("Crafting predicate");
if (t == FurnitureType("FURNACE")) {
if (!c || !col)
return true;
auto skill = c->getAttr(AttrType("FURNACE"));
return skill > 0 && !col->getFurnace().isIdle();
} else
if (auto type = f->getWorkshopType(t)) {
if (!c || !col)
return true;
auto workshop = getReferenceMaybe(col->getWorkshops().types, *type);
auto& info = f->workshopInfo.at(*type);
return !!workshop && !workshop->isIdle(col, c->getAttr(info.attr));
} else
return false;
}};
case MinionActivity::PREACHING: return {[](const ContentFactory*, const Collective*, const Creature*, FurnitureType t) {
return isOneOf(t, FurnitureType("ROSTRUM_WOOD"), FurnitureType("ROSTRUM_IRON"), FurnitureType("ROSTRUM_GOLD"));}};
case MinionActivity::MASS: return {[](const ContentFactory*, const Collective*, const Creature*, FurnitureType t) {
return isOneOf(t, FurnitureType("PEW_WOOD"), FurnitureType("PEW_IRON"), FurnitureType("PEW_GOLD"));}, nullptr,
Task::SearchType::LAZY};
case MinionActivity::PRAYER: return {getTrainingPredicate(AttrType("DIVINITY")), nullptr, Task::SearchType::LAZY};
}
});
return map[task];
}
#include "pretty_archive.h"
template
void CollectiveConfig::serialize(PrettyInputArchive& ar1, unsigned);
template
void GuardianInfo::serialize(PrettyInputArchive& ar1, unsigned);