-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathevents-battle.cpp
More file actions
476 lines (410 loc) · 14.3 KB
/
events-battle.cpp
File metadata and controls
476 lines (410 loc) · 14.3 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
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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
#include "logger.hpp"
#include "events.h"
#include "rng.hpp"
#include <memory>
#include <stdexcept>
#include <sstream>
#include "strings_util.hpp"
static const std::vector<std::string> ADJECTIVE = {
"A few",
"Handful",
"Some",
"Many",
"Numerous",
"Multiple",
"Several",
"Dozen"
};
static const std::vector<std::string> REPORTING = {
"traders",
"merchants",
"pilgrims",
"travelers",
"wanderers",
"adventurers",
"peasants",
"bards",
"druids",
"scouts",
"dockers",
"refugees",
"locals",
"commoners"
};
static const std::vector<std::string> CHANNEL = {
"are talking",
"are rumoring",
"are worried",
"have heard",
"are whispering",
"are discussing"
};
static const std::vector<std::string> BATTLE = {
"an encounter",
"a fight",
"a conflict",
"a clash",
"the skirmish",
"the battle"
};
static const std::vector<std::string> ONE_SIDE = {
"a faction",
"a rebels",
"a villans",
"an opposition",
"a partisans"
};
static const std::vector<std::string> TWO_SIDES = {
"hostile forces",
"enemies",
"two armies",
"combatants"
};
static const std::vector<std::string> HUNTERS = {
"adventurers",
"hunters",
"daredevils",
"witchers",
"rangers"
};
static const std::vector<std::string> ACTION_SUCCESS = {
"slew",
"murdered",
"killed",
"extinguished",
"destroyed",
"decimated",
"annihilated",
"massacred",
"put to the sword",
"expelled"
};
static const std::vector<std::string> ACTION_ATTEMPT = {
"attacked",
"ambushed",
"tried to cast out",
"tried to expel"
};
static const std::vector<std::string> FEAR_NOUN = {
"terror",
"fear",
"anxiety",
"horror",
"dread"
};
static constexpr int sizeRating(const int size) {
if (size <= 100) return 1;
if (size <= 500) return 2;
if (size <= 2500) return 3;
return 5;
}
static constexpr int combinedRating(const int attackerSize, const int defenderSize) {
int att = sizeRating(attackerSize);
int def = sizeRating(defenderSize);
int minRating = std::min(att, def);
if (minRating == 1) {
return minRating;
}
int delta = std::abs(att - def);
return delta >= 2 ? minRating + 1 : minRating;
}
static Event cityCapture(BattleFact* fact) {
std::ostringstream buffer;
if (fact->outcome == BATTLE_WON) {
buffer
<< rng::one_of(ADJECTIVE)
<< " " << rng::one_of(REPORTING)
<< " " << rng::one_of(CHANNEL)
<< " about the " << townType(fact->location.settlementType)
<< " of " << fact->location.settlement
<< " that lies in the " << fact->location.province
<< " " << fact->location.GetTerrainName(true)
<< ", where" << " " << rng::one_of(ONE_SIDE)
<< " " << rng::one_of(ACTION_SUCCESS)
<< " guards.";
}
else {
buffer
<< rng::one_of(ADJECTIVE)
<< " " << rng::one_of(REPORTING)
<< " " << rng::one_of(CHANNEL)
<< " about the " << townType(fact->location.settlementType)
<< " of " << fact->location.settlement
<< " that lies in the " << fact->location.province
<< " " << fact->location.GetTerrainName(true)
<< ", where " << rng::one_of(ONE_SIDE)
<< " " << rng::one_of(ACTION_ATTEMPT)
<< " guards but were unsuccessful.";
}
return {
.category = EventCategory::EVENT_CITY_CAPTURE,
.score = fact->location.settlementType + 2,
.text = buffer.str()
};
}
static Event monsterHunt(BattleFact* fact) {
std::ostringstream buffer;
auto mark = fact->location.GetSignificantLandmark();
if (fact->outcome == BATTLE_WON) {
buffer
<< rng::one_of(ADJECTIVE)
<< " " << rng::one_of(REPORTING)
<< " " << rng::one_of(CHANNEL)
<< " about " << rng::one_of(HUNTERS)
<< " who have " << rng::one_of(ACTION_SUCCESS)
<< " " << fact->defender.unitName;
if (mark) {
buffer << " near " << mark->title << ".";
}
buffer
<< " Freeing the " << fact->location.GetTerrainName(true)
<< " of " << fact->location.province
<< " from their " << rng::one_of(FEAR_NOUN) << ".";
}
else {
buffer
<< rng::one_of(ADJECTIVE)
<< " " << rng::one_of(REPORTING)
<< " " << rng::one_of(CHANNEL)
<< " about " << rng::one_of(HUNTERS)
<< " who attempted to " << rng::one_of(ACTION_SUCCESS)
<< " " << fact->defender.unitName
<< " roaming the " << fact->location.GetTerrainName(true)
<< " of " << fact->location.province;
if (mark) {
buffer << " near " << mark->title << ".";
}
buffer << " But all of them were slain by their prey.";
}
return {
.category = EventCategory::EVENT_MONSTER_HUNT,
.score = 1,
.text = buffer.str()
};
}
static Event monsterAggresion(BattleFact* fact) {
std::ostringstream buffer;
auto mark = fact->location.GetSignificantLandmark();
if (fact->outcome == BATTLE_WON) {
buffer
<< "In the " << fact->location.GetTerrainName(true)
<< " of " << fact->location.province;
if (mark) {
buffer << ", near " << mark->title << ",";
}
buffer
<< " " << fact->attacker.unitName
<< " who continue to cause "
<< rng::one_of(FEAR_NOUN)
<< " to local inhabitants.";
} else {
buffer
<< "A group of " << rng::one_of(HUNTERS)
<< " " << rng::one_of(ACTION_SUCCESS)
<< " the " << fact->attacker.unitName
<< " who inflicted " << rng::one_of(FEAR_NOUN)
<< " on the inhabitants of the " << fact->location.province
<< " " << fact->location.GetTerrainName(true)
;
if (mark) {
buffer << " near " << mark->title;
}
buffer << ".";
}
return {
.category = EventCategory::EVENT_MONSTER_AGGRESSION,
.score = 1,
.text = buffer.str()
};
}
static Event pvpBattle(BattleFact* fact) {
std::ostringstream buffer;
int total = fact->attacker.total + fact->defender.total;
int totalLost = fact->attacker.lost + fact->defender.lost;
int totalMages = fact->attacker.mages + fact->defender.mages;
int totalMonsters = fact->attacker.monsters + fact->defender.monsters;
int totalUndead = fact->attacker.undead + fact->defender.undead;
int totalFMI = fact->attacker.fmi + fact->defender.fmi;
int minLost = std::min(fact->attacker.lost, fact->defender.lost);
int maxLost = std::max(fact->attacker.lost, fact->defender.lost);
bool isSlaughter = total > 10 && (minLost == 0 || (maxLost / minLost) > 10);
int score = combinedRating(fact->attacker.total, fact->attacker.total);
buffer
<< rng::one_of(ADJECTIVE)
<< " " << rng::one_of(REPORTING)
<< " " << rng::one_of(CHANNEL)
<< " about";
if (total <= 100) {
// encounter
// location known
buffer
<< " " << rng::one_of(BATTLE)
<< " between " << rng::one_of(TWO_SIDES)
<< " happened in the " << fact->location.GetTerrainName(true)
<< " of " << fact->location.province;
if (fact->outcome == BATTLE_DRAW) {
buffer << " where neither side won.";
}
else if (isSlaughter) {
buffer << " where battle ended in a slaughter of one of the sides.";
}
else {
if (totalLost > total / 2) buffer << " where some men died.";
else buffer << " where many soldiers will never fight again.";
}
} else if (total <= 500) {
// local conflict
// location known
// number of looses known
int unceretanity = totalLost / 3; // 33%
int lost = totalLost + rng::get_random(unceretanity) - (unceretanity / 2);
buffer
<< " " << rng::one_of(BATTLE)
<< " between " << rng::one_of(TWO_SIDES)
<< " happened in the " << fact->location.GetTerrainName(true)
<< " of " << fact->location.province
<< " where " << lost << " " << strings::plural(lost, "combatant", "combatants")
<< " " << strings::plural(lost, "was", "were") << " killed.";
if (isSlaughter) {
buffer << (
fact->outcome == BATTLE_WON ?
" The attackers slaughtered all defenders." :
" The defenders were furious and put all attackers to the sword."
);
}
else {
if (fact->outcome == BATTLE_DRAW) buffer << " Neither side won.";
else buffer << (
fact->outcome == BATTLE_WON ? " The attackers were victorious.." : " The defenders stood firm."
);
}
} else if (total <= 2500) {
// regional conflict
// location known
// number of looses known
// mages, monsters, fmi
int unceretanity = totalLost / 5; // 20%
int lost = totalLost + rng::get_random(unceretanity) - (unceretanity / 2);
buffer
<< " " << rng::one_of(BATTLE)
<< " between";
int roll = rng::get_random(10);
if (roll >= 8) {
// 20 %
buffer
<< " " << fact->attacker.factionName
<< " and " << fact->defender.factionName;
} else if (roll >= 6) {
// 20%
buffer
<< " " << (rng::get_random(2) ? fact->attacker.factionName : fact->defender.factionName)
<< " and " << rng::one_of(ONE_SIDE);
} else {
// 60%
buffer << " " << rng::one_of(TWO_SIDES);
}
buffer
<< " happened in the " << fact->location.GetTerrainName(true)
<< " of " << fact->location.province
<< " where " << lost << " " << strings::plural(lost, "combatant", "combatants")
<< " " << strings::plural(lost, "was", "were") << " killed.";
std::string specials;
if (totalFMI + totalMages + totalMonsters + totalUndead) {
if (totalMages) buffer << " Powerful magic was used in the battle.";
if (totalFMI) buffer << " War engines were decimating the battlefield.";
if (totalUndead) buffer << " Disgusting undead caused fear in the combatants.";
if (totalMonsters) buffer << " Fearsome magical monsters were collecting their prey.";
}
if (isSlaughter) {
buffer << (
fact->outcome == BATTLE_WON ?
" The attackers slaughtered all defenders." :
" The defenders were furious and put all attackers to the sword."
);
} else {
if (fact->outcome == BATTLE_DRAW) buffer << " Neither side won.";
else buffer << (
fact->outcome == BATTLE_WON ? " The attackers were victorious.." : " The defenders stood firm."
);
}
} else {
// continental conflict / epic conflict
// location known
// number of looses known
// mages, monsters, fmi
int unceretanity = totalLost / 10; // 10%
int lost = totalLost + rng::get_random(unceretanity) - (unceretanity / 2);
buffer
<< " an epic battle between"
<< " " << fact->attacker.factionName
<< " and " << fact->defender.factionName
<< " happened in the " << fact->location.GetTerrainName(true)
<< " of " << fact->location.province
<< " where " << lost << " " << strings::plural(lost, "combatant", "combatants")
<< " " << strings::plural(lost, "was", "were") << " killed."
;
std::string specials;
if (totalFMI + totalMages + totalMonsters + totalUndead) {
if (totalMages) buffer << " Powerful magic was used in the battle.";
if (totalFMI) buffer << " War engines were decimating the battlefield.";
if (totalUndead) buffer << " Disgusting undead caused fear in the combatants.";
if (totalMonsters) buffer << " Fearsome magical monsters were collecting their prey.";
}
if (isSlaughter) {
buffer << (
fact->outcome == BATTLE_WON ?
" The attackers slaughtered all defenders." :
" The defenders were furious and put all attackers to the sword."
);
} else {
if (fact->outcome == BATTLE_DRAW) buffer << " Neither side won.";
else buffer << (
fact->outcome == BATTLE_WON ? " The attackers were victorious.." : " The defenders stood firm."
);
}
}
auto mark = fact->location.GetSignificantLandmark();
if (!fact->fortification.empty()) {
buffer
<< " This battle will be known as Siege of the"
<< " " << ObjectDefs[fact->fortificationType].name
<< " " << fact->fortification << ".";
} else if (mark) {
buffer
<< " This battle will be known as Battle"
<< " " <<(mark->distance == 0 ? "of" : "near");
if (mark->type == events::LandmarkType::FORD) buffer << " the " << mark->name << " wade";
else buffer << " the " << mark->title;
buffer << ".";
} else {
buffer
<< " This battle will known as Battle in the"
<< " " << fact->location.province
<< " " << fact->location.GetTerrainName(true)
<< ".";
}
if (totalMages > 0) score *= 2;
if (totalMonsters > 0) score += 1;
if (totalUndead > 0) score += 1;
if (totalFMI > 0) score += 1;
return {
.category = EventCategory::EVENT_BATTLE,
.score = score,
.text = buffer.str()
};
}
void BattleFact::GetEvents(std::list<Event> &events) {
if (this->defender.factionNum == 1) {
events.push_back(cityCapture(this));
return;
}
if (this->defender.factionNum == 2) {
events.push_back(monsterHunt(this));
return;
}
if (this->attacker.factionNum == 2) {
events.push_back(monsterAggresion(this));
return;
}
events.push_back(pvpBattle(this));
}