-
Notifications
You must be signed in to change notification settings - Fork 280
/
modify_morale_test.cpp
458 lines (387 loc) · 16.6 KB
/
modify_morale_test.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
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
#include "catch/catch.hpp"
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "avatar.h"
#include "flag.h"
#include "game.h"
#include "item.h"
#include "map.h"
#include "map_helpers.h"
#include "morale_types.h"
#include "point.h"
#include "type_id.h"
static const trait_id trait_ANTIFRUIT( "ANTIFRUIT" );
static const trait_id trait_ANTIJUNK( "ANTIJUNK" );
static const trait_id trait_ANTIWHEAT( "ANTIWHEAT" );
static const trait_id trait_BADTEMPER( "BADTEMPER" );
static const trait_id trait_CANNIBAL( "CANNIBAL" );
static const trait_id trait_CARNIVORE( "CARNIVORE" );
static const trait_id trait_CLAWS( "CLAWS" );
static const trait_id trait_FAT( "FAT" );
static const trait_id trait_HIBERNATE( "HIBERNATE" );
static const trait_id trait_LACTOSE( "LACTOSE" );
static const trait_id trait_LARGE( "LARGE" );
static const trait_id trait_MEATARIAN( "MEATARIAN" );
static const trait_id trait_PADDED_FEET( "PADDED_FEET" );
static const trait_id trait_PROJUNK( "PROJUNK" );
static const trait_id trait_PROJUNK2( "PROJUNK2" );
static const trait_id trait_PSYCHOPATH( "PSYCHOPATH" );
static const trait_id trait_SAPIOVORE( "SAPIOVORE" );
static const trait_id trait_SAPROPHAGE( "SAPROPHAGE" );
static const trait_id trait_THRESH_URSINE( "THRESH_URSINE" );
static const trait_id trait_URSINE_EYE( "URSINE_EYE" );
static const trait_id trait_URSINE_FUR( "URSINE_FUR" );
static const trait_id trait_VEGETARIAN( "VEGETARIAN" );
// Test cases for `Character::modify_morale` defined in `src/consumption.cpp`
TEST_CASE( "food enjoyability", "[food][modify_morale][fun]" )
{
avatar dummy;
std::pair<int, int> fun;
GIVEN( "food with positive fun" ) {
detached_ptr<item> det = item::spawn( "jihelucake", calendar::start_of_cataclysm,
item::default_charges_tag{} );
item &jihelucake = *det;
dummy.i_add( std::move( det ) );
fun = dummy.fun_for( jihelucake );
REQUIRE( fun.first > 0 );
THEN( "character gets a morale bonus becase it tastes good" ) {
dummy.modify_morale( jihelucake );
CHECK( dummy.get_morale( MORALE_FOOD_GOOD ) >= fun.first );
}
}
GIVEN( "food with negative fun" ) {
detached_ptr<item> det = item::spawn( "garlic", calendar::start_of_cataclysm,
item::default_charges_tag{} );
item &garlic = *det;
dummy.i_add( std::move( det ) );
fun = dummy.fun_for( garlic );
REQUIRE( fun.first < 0 );
THEN( "character gets a morale penalty because it tastes bad" ) {
dummy.modify_morale( garlic );
CHECK( dummy.get_morale( MORALE_FOOD_BAD ) <= fun.first );
}
}
}
TEST_CASE( "drugs", "[food][modify_morale][drug]" )
{
avatar dummy;
const std::vector<std::string> drugs_to_test = {
{
"gum",
"caff_gum",
"nic_gum",
"cigar",
// TODO: Change those to effects
"lsd",
"heroin",
"morphine"
}
};
GIVEN( "avatar has baseline morale" ) {
dummy.clear_morale();
dummy.clear_effects();
REQUIRE( dummy.get_morale_level() == 0 );
for( std::string drug_name : drugs_to_test ) {
item &drug = *item::spawn_temporary( drug_name );
std::pair<int, int> fun = dummy.fun_for( drug );
REQUIRE( fun.first > 0 );
THEN( "they enjoy " + drug_name ) {
dummy.modify_morale( drug );
CHECK( dummy.get_morale_level() >= fun.first );
}
}
}
}
TEST_CASE( "cannibalism", "[food][modify_morale][cannibal]" )
{
avatar dummy;
detached_ptr<item> det = item::spawn( "bone_human", calendar::start_of_cataclysm,
item::default_charges_tag{} );
item &human = *det;
dummy.i_add( std::move( det ) );
REQUIRE( human.has_flag( flag_CANNIBALISM ) );
GIVEN( "character is not a cannibal or sapiovore" ) {
REQUIRE_FALSE( dummy.has_trait( trait_CANNIBAL ) );
REQUIRE_FALSE( dummy.has_trait( trait_SAPIOVORE ) );
THEN( "they get a large morale penalty for eating humans" ) {
dummy.clear_morale();
dummy.modify_morale( human );
CHECK( dummy.get_morale( MORALE_CANNIBAL ) <= -60 );
}
WHEN( "character is a psychopath" ) {
dummy.toggle_trait( trait_PSYCHOPATH );
REQUIRE( dummy.has_trait( trait_PSYCHOPATH ) );
THEN( "their morale is unffected by eating humans" ) {
dummy.clear_morale();
dummy.modify_morale( human );
CHECK( dummy.get_morale( MORALE_CANNIBAL ) == 0 );
}
}
}
WHEN( "character is a cannibal" ) {
dummy.toggle_trait( trait_CANNIBAL );
REQUIRE( dummy.has_trait( trait_CANNIBAL ) );
THEN( "they get a morale bonus for eating humans" ) {
dummy.clear_morale();
dummy.modify_morale( human );
CHECK( dummy.get_morale( MORALE_CANNIBAL ) >= 20 );
}
}
}
TEST_CASE( "sweet junk food", "[food][modify_morale][junk][sweet]" )
{
avatar dummy;
GIVEN( "some sweet junk food" ) {
detached_ptr<item> det = item::spawn( "neccowafers", calendar::start_of_cataclysm,
item::default_charges_tag{} );
item &necco = *det;
dummy.i_add( std::move( det ) );
WHEN( "character has a sweet tooth" ) {
dummy.toggle_trait( trait_PROJUNK );
REQUIRE( dummy.has_trait( trait_PROJUNK ) );
THEN( "they get a morale bonus from its sweetness" ) {
dummy.clear_morale();
dummy.modify_morale( necco );
CHECK( dummy.get_morale( MORALE_SWEETTOOTH ) >= 5 );
CHECK( dummy.get_morale( MORALE_SWEETTOOTH ) <= 5 );
AND_THEN( "they enjoy it" ) {
CHECK( dummy.get_morale( MORALE_FOOD_GOOD ) > 0 );
}
}
}
WHEN( "character is sugar-loving" ) {
dummy.toggle_trait( trait_PROJUNK2 );
REQUIRE( dummy.has_trait( trait_PROJUNK2 ) );
THEN( "they get a significant morale bonus from its sweetness" ) {
dummy.clear_morale();
dummy.modify_morale( necco );
CHECK( dummy.get_morale( MORALE_SWEETTOOTH ) >= 10 );
CHECK( dummy.get_morale( MORALE_SWEETTOOTH ) <= 50 );
AND_THEN( "they enjoy it" ) {
CHECK( dummy.get_morale( MORALE_FOOD_GOOD ) > 0 );
}
}
}
WHEN( "character is a carnivore" ) {
dummy.toggle_trait( trait_CARNIVORE );
REQUIRE( dummy.has_trait( trait_CARNIVORE ) );
THEN( "they get an morale penalty due to indigestion" ) {
dummy.clear_morale();
dummy.modify_morale( necco );
CHECK( dummy.get_morale( MORALE_NO_DIGEST ) <= -25 );
}
}
}
}
TEST_CASE( "junk food that is not ingested", "[modify_morale][junk][no_ingest]" )
{
avatar dummy;
detached_ptr<item> det = item::spawn( "caff_gum", calendar::start_of_cataclysm,
item::default_charges_tag{} );
item &caff_gum = *det;
dummy.i_add( std::move( det ) );
// This is a regression test for gum having "junk" material, and being
// treated as junk food (despite not being ingested). At the time of
// writing this test, gum and caffeinated gum are made of "junk", and thus
// are treated as junk food, but might not always be so. Here we set the
// relevant flags to cover the scenario we're interested in, namely any
// comestible having both "junk" and "no ingest" flags.
caff_gum.set_flag( flag_ALLERGEN_JUNK );
caff_gum.set_flag( flag_NO_INGEST );
REQUIRE( caff_gum.has_flag( flag_ALLERGEN_JUNK ) );
REQUIRE( caff_gum.has_flag( flag_NO_INGEST ) );
GIVEN( "character has a sweet tooth" ) {
dummy.toggle_trait( trait_PROJUNK );
REQUIRE( dummy.has_trait( trait_PROJUNK ) );
THEN( "they do not get an extra morale bonus for chewing gum" ) {
dummy.clear_morale();
dummy.modify_morale( caff_gum );
CHECK( dummy.get_morale( MORALE_SWEETTOOTH ) == 0 );
AND_THEN( "they still enjoy it" ) {
CHECK( dummy.get_morale( MORALE_FOOD_GOOD ) > 0 );
}
}
}
GIVEN( "character is sugar-loving" ) {
dummy.toggle_trait( trait_PROJUNK2 );
REQUIRE( dummy.has_trait( trait_PROJUNK2 ) );
THEN( "they do not get an extra morale bonus for chewing gum" ) {
dummy.clear_morale();
dummy.modify_morale( caff_gum );
CHECK( dummy.get_morale( MORALE_SWEETTOOTH ) == 0 );
AND_THEN( "they still enjoy it" ) {
CHECK( dummy.get_morale( MORALE_FOOD_GOOD ) > 0 );
}
}
}
GIVEN( "character has junk food intolerance" ) {
dummy.toggle_trait( trait_ANTIJUNK );
REQUIRE( dummy.has_trait( trait_ANTIJUNK ) );
THEN( "they do not get a morale penalty for chewing gum" ) {
dummy.clear_morale();
dummy.modify_morale( caff_gum );
CHECK( dummy.get_morale( MORALE_ANTIJUNK ) == 0 );
AND_THEN( "they still enjoy it" ) {
CHECK( dummy.get_morale( MORALE_FOOD_GOOD ) > 0 );
}
}
}
}
TEST_CASE( "food allergies and intolerances", "[food][modify_morale][allergy]" )
{
avatar dummy;
int penalty = -75;
GIVEN( "character is vegetarian" ) {
dummy.toggle_trait( trait_VEGETARIAN );
REQUIRE( dummy.has_trait( trait_VEGETARIAN ) );
THEN( "they get a morale penalty for eating meat" ) {
detached_ptr<item> det = item::spawn( "meat", calendar::start_of_cataclysm,
item::default_charges_tag{} );
item &meat = *det;
dummy.i_add( std::move( det ) );
REQUIRE( meat.has_flag( flag_ALLERGEN_MEAT ) );
dummy.clear_morale();
dummy.modify_morale( meat );
CHECK( dummy.get_morale( MORALE_VEGETARIAN ) <= penalty );
}
}
GIVEN( "character is lactose intolerant" ) {
dummy.toggle_trait( trait_LACTOSE );
REQUIRE( dummy.has_trait( trait_LACTOSE ) );
THEN( "they get a morale penalty for drinking milk" ) {
detached_ptr<item> det = item::spawn( "milk", calendar::start_of_cataclysm,
item::default_charges_tag{} );
item &milk = *det;
dummy.i_add( std::move( det ) );
REQUIRE( milk.has_flag( flag_ALLERGEN_MILK ) );
dummy.clear_morale();
dummy.modify_morale( milk );
CHECK( dummy.get_morale( MORALE_LACTOSE ) <= penalty );
}
}
GIVEN( "character is grain intolerant" ) {
dummy.toggle_trait( trait_ANTIWHEAT );
REQUIRE( dummy.has_trait( trait_ANTIWHEAT ) );
THEN( "they get a morale penalty for eating wheat" ) {
detached_ptr<item> det = item::spawn( "wheat", calendar::start_of_cataclysm,
item::default_charges_tag{} );
item &wheat = *det;
dummy.i_add( std::move( det ) );
REQUIRE( wheat.has_flag( flag_ALLERGEN_WHEAT ) );
dummy.clear_morale();
dummy.modify_morale( wheat );
CHECK( dummy.get_morale( MORALE_ANTIWHEAT ) <= penalty );
}
}
GIVEN( "character hates vegetables" ) {
dummy.toggle_trait( trait_MEATARIAN );
REQUIRE( dummy.has_trait( trait_MEATARIAN ) );
THEN( "they get a morale penalty for eating vegetables" ) {
detached_ptr<item> det = item::spawn( "broccoli", calendar::start_of_cataclysm,
item::default_charges_tag{} );
item &veggy = *det;
dummy.i_add( std::move( det ) );
REQUIRE( veggy.has_flag( flag_ALLERGEN_VEGGY ) );
dummy.clear_morale();
dummy.modify_morale( veggy );
CHECK( dummy.get_morale( MORALE_MEATARIAN ) <= penalty );
}
}
GIVEN( "character hates fruit" ) {
dummy.toggle_trait( trait_ANTIFRUIT );
REQUIRE( dummy.has_trait( trait_ANTIFRUIT ) );
THEN( "they get a morale penalty for eating fruit" ) {
detached_ptr<item> det = item::spawn( "apple", calendar::start_of_cataclysm,
item::default_charges_tag{} );
item &fruit = *det;
dummy.i_add( std::move( det ) );
REQUIRE( fruit.has_flag( flag_ALLERGEN_FRUIT ) );
dummy.clear_morale();
dummy.modify_morale( fruit );
CHECK( dummy.get_morale( MORALE_ANTIFRUIT ) <= penalty );
}
}
GIVEN( "character has a junk food intolerance" ) {
dummy.toggle_trait( trait_ANTIJUNK );
REQUIRE( dummy.has_trait( trait_ANTIJUNK ) );
THEN( "they get a morale penalty for eating junk food" ) {
detached_ptr<item> det = item::spawn( "neccowafers", calendar::start_of_cataclysm,
item::default_charges_tag{} );
item &junk = *det;
dummy.i_add( std::move( det ) );
REQUIRE( junk.has_flag( flag_ALLERGEN_JUNK ) );
dummy.clear_morale();
dummy.modify_morale( junk );
CHECK( dummy.get_morale( MORALE_ANTIJUNK ) <= penalty );
}
}
}
TEST_CASE( "saprophage character", "[food][modify_morale][saprophage]" )
{
avatar dummy;
GIVEN( "character is a saprophage, preferring rotted food" ) {
dummy.clear_morale();
dummy.toggle_trait( trait_SAPROPHAGE );
REQUIRE( dummy.has_trait( trait_SAPROPHAGE ) );
AND_GIVEN( "some rotten chewable food" ) {
detached_ptr<item> det = item::spawn( "jihelucake", calendar::start_of_cataclysm,
item::default_charges_tag{} );
item &jihelucake = *det;
dummy.i_add( std::move( det ) );
// food rot > 1.0 is rotten
jihelucake.set_relative_rot( 1.5 );
REQUIRE( jihelucake.rotten() );
THEN( "they enjoy it" ) {
dummy.modify_morale( jihelucake );
CHECK( dummy.get_morale( MORALE_FOOD_GOOD ) > 10 );
}
}
AND_GIVEN( "some fresh chewable food" ) {
detached_ptr<item> det = item::spawn( "jihelucake", calendar::start_of_cataclysm,
item::default_charges_tag{} );
item &jihelucake = *det;
dummy.i_add( std::move( det ) );
// food rot < 0.1 is fresh
jihelucake.set_relative_rot( 0.0 );
REQUIRE( jihelucake.is_fresh() );
THEN( "they get a morale penalty due to indigestion" ) {
dummy.modify_morale( jihelucake );
CHECK( dummy.get_morale( MORALE_NO_DIGEST ) <= -25 );
}
}
}
}
TEST_CASE( "ursine honey", "[food][modify_morale][ursine][honey]" )
{
avatar dummy;
detached_ptr<item> det = item::spawn( "honeycomb", calendar::start_of_cataclysm,
item::default_charges_tag{} );
item &honeycomb = *det;
dummy.i_add( std::move( det ) );
REQUIRE( honeycomb.has_flag( flag_URSINE_HONEY ) );
GIVEN( "character is post-threshold ursine" ) {
dummy.toggle_trait( trait_THRESH_URSINE );
REQUIRE( dummy.has_trait( trait_THRESH_URSINE ) );
AND_GIVEN( "they have a lot of ursine mutations" ) {
dummy.mutate_towards( trait_FAT );
dummy.mutate_towards( trait_LARGE );
dummy.mutate_towards( trait_CLAWS );
dummy.mutate_towards( trait_BADTEMPER );
dummy.mutate_towards( trait_HIBERNATE );
dummy.mutate_towards( trait_URSINE_FUR );
dummy.mutate_towards( trait_URSINE_EYE );
dummy.mutate_towards( trait_PADDED_FEET );
REQUIRE( dummy.mutation_category_level[mutation_category_id( "URSINE" )] > 40 );
THEN( "they get an extra honey morale bonus for eating it" ) {
dummy.modify_morale( honeycomb );
CHECK( dummy.get_morale( MORALE_HONEY ) > 0 );
AND_THEN( "they enjoy it" ) {
CHECK( dummy.get_morale( MORALE_FOOD_GOOD ) > 0 );
}
}
}
}
}