forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
character_modifier_test.cpp
582 lines (537 loc) · 28.6 KB
/
character_modifier_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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
#include "bodypart.h"
#include "cata_catch.h"
#include "character.h"
#include "character_modifier.h"
#include "damage.h"
#include "magic_enchantment.h"
#include "mutation.h"
#include "player_helpers.h"
static const bodypart_str_id body_part_test_bird_foot_l( "test_bird_foot_l" );
static const bodypart_str_id body_part_test_bird_foot_r( "test_bird_foot_r" );
static const bodypart_str_id body_part_test_bird_wing_l( "test_bird_wing_l" );
static const bodypart_str_id body_part_test_bird_wing_r( "test_bird_wing_r" );
static const bodypart_str_id body_part_test_corvid_beak( "test_corvid_beak" );
static const bodypart_str_id body_part_test_tail( "test_tail" );
static const character_modifier_id
character_modifier_test_add_limbscores_mod( "test_add_limbscores_mod" );
static const character_modifier_id character_modifier_test_char_cost_mod( "test_char_cost_mod" );
static const character_modifier_id
character_modifier_test_mult_limbscores_mod( "test_mult_limbscores_mod" );
static const character_modifier_id
character_modifier_test_ranged_dispersion_manip_mod( "test_ranged_dispersion_manip_mod" );
static const character_modifier_id
character_modifier_test_slip_prevent_mod( "test_slip_prevent_mod" );
static const character_modifier_id character_modifier_test_thrown_dex_mod( "test_thrown_dex_mod" );
static const character_modifier_id
character_modifier_test_thrown_dex_mod_hand( "test_thrown_dex_mod_hand" );
static const enchantment_id enchantment_ENCH_TEST_BIRD_PARTS( "ENCH_TEST_BIRD_PARTS" );
static const enchantment_id enchantment_ENCH_TEST_TAIL( "ENCH_TEST_TAIL" );
static const itype_id itype_test_tail_encumber( "test_tail_encumber" );
static const limb_score_id limb_score_test( "test" );
static const trait_id trait_TEST_ARMOR_MUTATION( "TEST_ARMOR_MUTATION" );
static void create_char( Character &dude )
{
clear_character( dude, true );
dude.enchantment_cache->force_add( *enchantment_ENCH_TEST_TAIL );
dude.recalculate_bodyparts();
REQUIRE( dude.has_part( body_part_test_tail ) );
}
static void create_bird_char( Character &dude )
{
clear_character( dude, true );
dude.enchantment_cache->force_add( *enchantment_ENCH_TEST_BIRD_PARTS );
dude.recalculate_bodyparts();
REQUIRE( dude.has_part( body_part_test_corvid_beak ) );
REQUIRE( dude.has_part( body_part_test_bird_wing_l ) );
REQUIRE( dude.has_part( body_part_test_bird_wing_r ) );
REQUIRE( dude.has_part( body_part_test_bird_foot_l ) );
REQUIRE( dude.has_part( body_part_test_bird_foot_r ) );
REQUIRE( !dude.has_part( body_part_mouth ) );
REQUIRE( !dude.has_part( body_part_hand_l ) );
REQUIRE( !dude.has_part( body_part_hand_r ) );
REQUIRE( !dude.has_part( body_part_foot_l ) );
REQUIRE( !dude.has_part( body_part_foot_r ) );
}
TEST_CASE( "Basic limb score test", "[character][encumbrance]" )
{
standard_npc dude( "Test NPC" );
create_char( dude );
const bodypart *test_bp = dude.get_part( body_part_test_tail );
REQUIRE( test_bp != nullptr );
GIVEN( "limb is not encumbered" ) {
WHEN( "limb is not wounded" ) {
THEN( "modified limb score equals unmodified limb score" ) {
CHECK( test_bp->get_id()->get_limb_score( limb_score_test ) == Approx( 0.8 ).epsilon( 0.001 ) );
CHECK( dude.get_limb_score( limb_score_test ) == Approx( 0.8 ).epsilon( 0.001 ) );
}
}
WHEN( "limb is wounded" ) {
dude.apply_damage( nullptr, test_bp->get_id(), test_bp->get_hp_max() / 2, true );
THEN( "modified limb score is less than unmodified limb score" ) {
CHECK( test_bp->get_id()->get_limb_score( limb_score_test ) == Approx( 0.8 ).epsilon( 0.001 ) );
CHECK( dude.get_limb_score( limb_score_test ) == Approx( 0.53333 ).epsilon( 0.001 ) );
}
}
}
GIVEN( "limb is encumbered" ) {
item it( itype_test_tail_encumber );
dude.wear_item( it, false );
WHEN( "limb is not wounded" ) {
THEN( "modified limb score is less than unmodified limb score" ) {
CHECK( test_bp->get_id()->get_limb_score( limb_score_test ) == Approx( 0.8 ).epsilon( 0.001 ) );
CHECK( dude.get_limb_score( limb_score_test ) == Approx( 0.4701 ).epsilon( 0.001 ) );
}
}
WHEN( "limb is wounded" ) {
dude.apply_damage( nullptr, test_bp->get_id(), test_bp->get_hp_max() / 2, true );
THEN( "modified limb score is less than unmodified limb score" ) {
CHECK( test_bp->get_id()->get_limb_score( limb_score_test ) == Approx( 0.8 ).epsilon( 0.001 ) );
CHECK( dude.get_limb_score( limb_score_test ) == Approx( 0.3134 ).epsilon( 0.001 ) );
}
}
}
}
TEST_CASE( "Basic character modifier test", "[character][encumbrance]" )
{
standard_npc dude( "Test NPC" );
create_char( dude );
const bodypart *test_bp = dude.get_part( body_part_test_tail );
REQUIRE( test_bp != nullptr );
REQUIRE( character_modifier_test_char_cost_mod->use_limb_scores().find( limb_score_test ) !=
character_modifier_test_char_cost_mod->use_limb_scores().end() );
GIVEN( "limb is not encumbered" ) {
WHEN( "limb is not wounded" ) {
THEN( "modified limb score equals unmodified limb score" ) {
CHECK( dude.get_modifier( character_modifier_test_char_cost_mod ) == Approx( 7.5 ).epsilon(
0.001 ) );
}
}
WHEN( "limb is wounded" ) {
dude.apply_damage( nullptr, test_bp->get_id(), test_bp->get_hp_max() / 2, true );
THEN( "modified limb score is less than unmodified limb score" ) {
CHECK( dude.get_modifier( character_modifier_test_char_cost_mod ) == Approx( 26.25 ).epsilon(
0.001 ) );
}
}
}
GIVEN( "limb is encumbered" ) {
item it( itype_test_tail_encumber );
dude.wear_item( it, false );
WHEN( "limb is not wounded" ) {
THEN( "modified limb score is less than unmodified limb score" ) {
CHECK( dude.get_modifier( character_modifier_test_char_cost_mod ) == Approx( 33.81579 ).epsilon(
0.001 ) );
}
}
WHEN( "limb is wounded" ) {
dude.apply_damage( nullptr, test_bp->get_id(), test_bp->get_hp_max() / 2, true );
THEN( "modified limb score is less than unmodified limb score" ) {
CHECK( dude.get_modifier( character_modifier_test_char_cost_mod ) == Approx( 65.72368 ).epsilon(
0.001 ) );
}
}
}
}
TEST_CASE( "Body part armor vs. damage", "[character]" )
{
standard_npc dude( "Test NPC" );
create_char( dude );
const bodypart *test_bp = dude.get_part( body_part_test_tail );
REQUIRE( test_bp != nullptr );
GIVEN( "Body part with 5 bash / 5 acid / 0 cut" ) {
CHECK( test_bp->get_id()->damage_resistance( damage_type::BASH ) == Approx( 5.0 ).epsilon(
0.001 ) );
CHECK( test_bp->get_id()->damage_resistance( damage_type::ACID ) == Approx( 5.0 ).epsilon(
0.001 ) );
CHECK( test_bp->get_id()->damage_resistance( damage_type::CUT ) == Approx( 0.0 ).epsilon( 0.001 ) );
WHEN( "Receiving bash damage" ) {
damage_unit du( damage_type::BASH, 10.f, 0.f );
dude.passive_absorb_hit( body_part_test_tail, du );
THEN( "Absorb hit" ) {
CHECK( dude.get_armor_bash( body_part_test_tail ) == 5 );
CHECK( du.amount == Approx( 5.0 ).epsilon( 0.001 ) );
}
}
WHEN( "Receiving acid damage" ) {
damage_unit du( damage_type::ACID, 10.f, 0.f );
dude.passive_absorb_hit( body_part_test_tail, du );
THEN( "Absorb hit" ) {
CHECK( dude.get_armor_acid( body_part_test_tail ) == 5 );
CHECK( du.amount == Approx( 5.0 ).epsilon( 0.001 ) );
}
}
WHEN( "Receiving cut damage" ) {
damage_unit du( damage_type::CUT, 10.f, 0.f );
dude.passive_absorb_hit( body_part_test_tail, du );
THEN( "Absorb hit" ) {
CHECK( dude.get_armor_cut( body_part_test_tail ) == 0 );
CHECK( du.amount == Approx( 10.0 ).epsilon( 0.001 ) );
}
}
}
}
static double get_limbtype_modval( const double &val, const bodypart_id &id,
const std::set<body_part_type::type> &bp_types )
{
double ret = 0.0;
for( const body_part_type::type &bp_type : bp_types ) {
if( id->has_type( bp_type ) ) {
ret += val * id->limbtypes.at( bp_type );
}
}
return ret;
}
TEST_CASE( "Mutation armor vs. damage", "[character][mutation]" )
{
standard_npc dude( "Test NPC" );
clear_character( dude, true );
dude.toggle_trait( trait_TEST_ARMOR_MUTATION );
REQUIRE( dude.has_trait( trait_TEST_ARMOR_MUTATION ) );
static const std::set<body_part_type::type> affected_bptypes = {
body_part_type::type::arm,
body_part_type::type::torso,
body_part_type::type::tail
};
GIVEN( "5 bash on arms, torso and tail / 1 cut on ALL" ) {
for( const auto &res : trait_TEST_ARMOR_MUTATION->armor ) {
if( res.first->has_type( body_part_type::type::arm ) ||
res.first->has_type( body_part_type::type::torso ) ||
res.first->has_type( body_part_type::type::tail ) ) {
CAPTURE( res.first.c_str() );
const double bash_res = get_limbtype_modval( 5.0, res.first, affected_bptypes );
CHECK( res.second.type_resist( damage_type::BASH ) == Approx( bash_res ).epsilon( 0.001 ) );
CHECK( res.second.type_resist( damage_type::ACID ) == Approx( 0.0 ).epsilon( 0.001 ) );
CHECK( res.second.type_resist( damage_type::CUT ) == Approx( 1.0 ).epsilon( 0.001 ) );
} else {
CAPTURE( res.first.c_str() );
CHECK( res.second.type_resist( damage_type::BASH ) == Approx( 0.0 ).epsilon( 0.001 ) );
CHECK( res.second.type_resist( damage_type::ACID ) == Approx( 0.0 ).epsilon( 0.001 ) );
CHECK( res.second.type_resist( damage_type::CUT ) == Approx( 1.0 ).epsilon( 0.001 ) );
}
}
WHEN( "Receiving bash damage" ) {
for( const body_part_type &bp : body_part_type::get_all() ) {
if( !dude.has_part( bp.id ) ) {
continue;
}
const bool has_res = bp.id->has_type( body_part_type::type::arm ) ||
bp.id->has_type( body_part_type::type::torso ) ||
bp.id->has_type( body_part_type::type::tail );
double res_val = get_limbtype_modval( 5.0, bp.id, affected_bptypes );
const int res_amt = has_res ? static_cast<int>( res_val ) : 0;
damage_unit du( damage_type::BASH, 10.f, 0.f );
dude.passive_absorb_hit( bp.id, du );
THEN( "Absorb hit" ) {
CAPTURE( bp.id.c_str() );
CHECK( dude.get_armor_bash( bp.id ) == res_amt );
CHECK( du.amount == Approx( 10.0 - res_amt ).epsilon( 0.001 ) );
}
}
}
WHEN( "Receiving acid damage" ) {
for( const body_part_type &bp : body_part_type::get_all() ) {
if( !dude.has_part( bp.id ) ) {
continue;
}
damage_unit du( damage_type::ACID, 10.f, 0.f );
dude.passive_absorb_hit( bp.id, du );
THEN( "Absorb hit" ) {
CAPTURE( bp.id.c_str() );
CHECK( dude.get_armor_acid( bp.id ) == 0 );
CHECK( du.amount == Approx( 10.0 ).epsilon( 0.001 ) );
}
}
}
WHEN( "Receiving cut damage" ) {
for( const body_part_type &bp : body_part_type::get_all() ) {
if( !dude.has_part( bp.id ) ) {
continue;
}
damage_unit du( damage_type::CUT, 10.f, 0.f );
dude.passive_absorb_hit( bp.id, du );
THEN( "Absorb hit" ) {
CAPTURE( bp.id.c_str() );
CHECK( dude.get_armor_cut( bp.id ) == 1 );
CHECK( du.amount == Approx( 9.0 ).epsilon( 0.001 ) );
}
}
}
}
GIVEN( "+ body part with 5 bash / 5 acid" ) {
dude.enchantment_cache->force_add( *enchantment_ENCH_TEST_TAIL );
dude.recalculate_bodyparts();
REQUIRE( dude.has_part( body_part_test_tail ) );
WHEN( "Receiving bash damage" ) {
for( const body_part_type &bp : body_part_type::get_all() ) {
if( !dude.has_part( bp.id ) ) {
continue;
}
const bool has_mut_res = bp.id->has_type( body_part_type::type::arm ) ||
bp.id->has_type( body_part_type::type::torso ) ||
bp.id->has_type( body_part_type::type::tail );
const bool has_bp_res = bp.id == body_part_test_tail;
double res_val = get_limbtype_modval( 5.0, bp.id, affected_bptypes );
const int res_amt = ( has_mut_res ? static_cast<int>( res_val ) : 0 ) + ( has_bp_res ? 5 : 0 );
damage_unit du( damage_type::BASH, 10.f, 0.f );
dude.passive_absorb_hit( bp.id, du );
THEN( "Absorb hit" ) {
CAPTURE( bp.id.c_str() );
CHECK( dude.get_armor_bash( bp.id ) == res_amt );
CHECK( du.amount == Approx( 10.0 - res_amt ).epsilon( 0.001 ) );
}
}
}
WHEN( "Receiving acid damage" ) {
for( const body_part_type &bp : body_part_type::get_all() ) {
if( !dude.has_part( bp.id ) ) {
continue;
}
const int res_amt = bp.id == body_part_test_tail ? 5 : 0;
damage_unit du( damage_type::ACID, 10.f, 0.f );
dude.passive_absorb_hit( bp.id, du );
THEN( "Absorb hit" ) {
CAPTURE( bp.id.c_str() );
CHECK( dude.get_armor_acid( bp.id ) == res_amt );
CHECK( du.amount == Approx( 10.0 - res_amt ).epsilon( 0.001 ) );
}
}
}
WHEN( "Receiving cut damage" ) {
for( const body_part_type &bp : body_part_type::get_all() ) {
if( !dude.has_part( bp.id ) ) {
continue;
}
const int res_amt = bp.id == body_part_test_tail ? 6 : 1;
damage_unit du( damage_type::CUT, 10.f, 0.f );
dude.passive_absorb_hit( bp.id, du );
THEN( "Absorb hit" ) {
CAPTURE( bp.id.c_str() );
CHECK( dude.get_armor_cut( bp.id ) == res_amt );
CHECK( du.amount == Approx( 10.0 - res_amt ).epsilon( 0.001 ) );
}
}
}
}
}
TEST_CASE( "Multi-limbscore modifiers", "[character]" )
{
standard_npc dude( "Test NPC" );
create_char( dude );
WHEN( "Character is uninjured / unencumbered" ) {
CHECK( dude.get_modifier( character_modifier_test_add_limbscores_mod ) == Approx( 2.0 ).epsilon(
0.001 ) );
CHECK( dude.get_modifier( character_modifier_test_mult_limbscores_mod ) == Approx( 1.0 ).epsilon(
0.001 ) );
}
WHEN( "Character has high eye encumbrance" ) {
item eyecover( "test_goggles_welding" );
dude.wear_item( eyecover );
REQUIRE( dude.encumb( dude.get_all_body_parts_of_type( body_part_type::type::sensor,
get_body_part_flags::primary_type ).front() ) == 60 );
CHECK( dude.get_modifier( character_modifier_test_add_limbscores_mod ) == Approx( 2.0 ).epsilon(
0.001 ) );
CHECK( dude.get_modifier( character_modifier_test_mult_limbscores_mod ) == Approx( 0.1 ).epsilon(
0.001 ) );
}
WHEN( "Character has broken arms" ) {
for( const bodypart_id &bid : dude.get_all_body_parts_of_type( body_part_type::type::arm,
get_body_part_flags::primary_type ) ) {
dude.set_part_hp_cur( bid, 0 );
}
REQUIRE( dude.get_working_arm_count() == 0 );
CHECK( dude.get_modifier( character_modifier_test_add_limbscores_mod ) == Approx( 1.4 ).epsilon(
0.001 ) );
CHECK( dude.get_modifier( character_modifier_test_mult_limbscores_mod ) == Approx( 0.1 ).epsilon(
0.001 ) );
}
WHEN( "Character has high eye encumbrance and broken arms" ) {
item eyecover( "test_goggles_welding" );
dude.wear_item( eyecover );
for( const bodypart_id &bid : dude.get_all_body_parts_of_type( body_part_type::type::arm,
get_body_part_flags::primary_type ) ) {
dude.set_part_hp_cur( bid, 0 );
}
REQUIRE( dude.get_working_arm_count() == 0 );
REQUIRE( dude.encumb( dude.get_all_body_parts_of_type( body_part_type::type::sensor,
get_body_part_flags::primary_type ).front() ) == 60 );
CHECK( dude.get_modifier( character_modifier_test_add_limbscores_mod ) == Approx( 0.4 ).epsilon(
0.001 ) );
CHECK( dude.get_modifier( character_modifier_test_mult_limbscores_mod ) == Approx( 0.1 ).epsilon(
0.001 ) );
}
}
TEST_CASE( "Slip prevention modifier / weighted-list multi-score modifiers", "[character]" )
{
standard_npc dude( "Test NPC" );
create_char( dude );
WHEN( "Character is uninjured / unencumbered" ) {
CHECK( dude.get_modifier( character_modifier_test_slip_prevent_mod ) == Approx( 1.0 ).epsilon(
0.001 ) );
}
WHEN( "Character has broken arms" ) {
for( const bodypart_id &bid : dude.get_all_body_parts_of_type( body_part_type::type::arm,
get_body_part_flags::primary_type ) ) {
dude.set_part_hp_cur( bid, 0 );
}
REQUIRE( dude.get_working_arm_count() == 0 );
CHECK( dude.get_modifier( character_modifier_test_slip_prevent_mod ) == Approx( 2.0 / 3.0 ).epsilon(
0.001 ) );
}
WHEN( "Character is heavily encumbered" ) {
item hazmat_suit( "test_hazmat_suit" );
dude.wear_item( hazmat_suit );
REQUIRE( dude.encumb( dude.get_all_body_parts_of_type( body_part_type::type::foot,
get_body_part_flags::primary_type ).front() ) == 37 );
REQUIRE( dude.encumb( dude.get_all_body_parts_of_type( body_part_type::type::hand,
get_body_part_flags::primary_type ).front() ) == 37 );
CHECK( dude.get_modifier( character_modifier_test_slip_prevent_mod ) == Approx( 0.623 ).epsilon(
0.001 ) );
}
WHEN( "Character has broken arms and is heavily encumbered" ) {
item hazmat_suit( "test_hazmat_suit" );
dude.wear_item( hazmat_suit );
for( const bodypart_id &bid : dude.get_all_body_parts_of_type( body_part_type::type::arm,
get_body_part_flags::primary_type ) ) {
dude.set_part_hp_cur( bid, 0 );
}
REQUIRE( dude.encumb( dude.get_all_body_parts_of_type( body_part_type::type::foot,
get_body_part_flags::primary_type ).front() ) == 37 );
REQUIRE( dude.encumb( dude.get_all_body_parts_of_type( body_part_type::type::hand,
get_body_part_flags::primary_type ).front() ) == 37 );
REQUIRE( dude.get_working_arm_count() == 0 );
CHECK( dude.get_modifier( character_modifier_test_slip_prevent_mod ) == Approx( 0.41 ).epsilon(
0.001 ) );
}
}
TEST_CASE( "Weighted limb types", "[character]" )
{
item boxing_gloves( "test_boxing_gloves" );
item wing_covers( "test_winglets" );
standard_npc dude( "Test NPC" );
clear_character( dude, true );
GIVEN( "Character has normal limbs" ) {
REQUIRE( dude.get_all_body_parts().size() == 12 );
REQUIRE( dude.get_all_body_parts_of_type( body_part_type::type::hand ).size() == 2 );
WHEN( "Uninjured / unencumbered" ) {
REQUIRE( dude.get_hp() == dude.get_hp_max() );
REQUIRE( dude.get_part_hp_cur( body_part_hand_l ) == dude.get_part_hp_max( body_part_hand_l ) );
REQUIRE( dude.get_part_hp_cur( body_part_hand_r ) == dude.get_part_hp_max( body_part_hand_r ) );
REQUIRE( dude.avg_encumb_of_limb_type( body_part_type::type::hand ) == 0 );
CHECK( dude.get_modifier( character_modifier_test_ranged_dispersion_manip_mod ) == Approx(
0.0 ).epsilon( 0.01 ) );
CHECK( dude.get_modifier( character_modifier_test_thrown_dex_mod ) == Approx( 1.0 ).epsilon(
0.01 ) );
CHECK( dude.get_modifier( character_modifier_test_thrown_dex_mod_hand ) == Approx( 1.0 ).epsilon(
0.01 ) );
}
WHEN( "Damaged hands / unencumbered" ) {
dude.set_part_hp_cur( body_part_hand_l, dude.get_part_hp_max( body_part_hand_l ) / 2 );
dude.set_part_hp_cur( body_part_hand_r, dude.get_part_hp_max( body_part_hand_l ) / 2 );
REQUIRE( dude.get_part_hp_cur( body_part_hand_l ) == dude.get_part_hp_max( body_part_hand_l ) / 2 );
REQUIRE( dude.get_part_hp_cur( body_part_hand_r ) == dude.get_part_hp_max( body_part_hand_l ) / 2 );
REQUIRE( dude.avg_encumb_of_limb_type( body_part_type::type::hand ) == 0 );
CHECK( dude.get_modifier( character_modifier_test_ranged_dispersion_manip_mod ) == Approx(
11.4 ).epsilon( 0.01 ) );
CHECK( dude.get_modifier( character_modifier_test_thrown_dex_mod ) == Approx( 0.667 ).epsilon(
0.01 ) );
CHECK( dude.get_modifier( character_modifier_test_thrown_dex_mod_hand ) == Approx( 0.667 ).epsilon(
0.01 ) );
}
WHEN( "Uninjured / hands encumbered" ) {
dude.wear_item( boxing_gloves, false );
REQUIRE( dude.get_hp() == dude.get_hp_max() );
REQUIRE( dude.get_part_hp_cur( body_part_hand_l ) == dude.get_part_hp_max( body_part_hand_l ) );
REQUIRE( dude.get_part_hp_cur( body_part_hand_r ) == dude.get_part_hp_max( body_part_hand_r ) );
REQUIRE( dude.avg_encumb_of_limb_type( body_part_type::type::hand ) == 70 );
CHECK( dude.get_modifier( character_modifier_test_ranged_dispersion_manip_mod ) == Approx(
28.0 ).epsilon( 0.01 ) );
CHECK( dude.get_modifier( character_modifier_test_thrown_dex_mod ) == Approx( 0.449 ).epsilon(
0.01 ) );
CHECK( dude.get_modifier( character_modifier_test_thrown_dex_mod_hand ) == Approx( 0.449 ).epsilon(
0.01 ) );
}
WHEN( "Damaged hands / hands encumbered" ) {
dude.wear_item( boxing_gloves, false );
dude.set_part_hp_cur( body_part_hand_l, dude.get_part_hp_max( body_part_hand_l ) / 2 );
dude.set_part_hp_cur( body_part_hand_r, dude.get_part_hp_max( body_part_hand_l ) / 2 );
REQUIRE( dude.get_part_hp_cur( body_part_hand_l ) == dude.get_part_hp_max( body_part_hand_l ) / 2 );
REQUIRE( dude.get_part_hp_cur( body_part_hand_r ) == dude.get_part_hp_max( body_part_hand_l ) / 2 );
REQUIRE( dude.avg_encumb_of_limb_type( body_part_type::type::hand ) == 70 );
CHECK( dude.get_modifier( character_modifier_test_ranged_dispersion_manip_mod ) == Approx(
53.4 ).epsilon( 0.01 ) );
CHECK( dude.get_modifier( character_modifier_test_thrown_dex_mod ) == Approx( 0.299 ).epsilon(
0.01 ) );
CHECK( dude.get_modifier( character_modifier_test_thrown_dex_mod_hand ) == Approx( 0.299 ).epsilon(
0.01 ) );
}
}
GIVEN( "Character has mutated limbs" ) {
create_bird_char( dude );
REQUIRE( dude.get_all_body_parts().size() == 12 );
REQUIRE( dude.get_all_body_parts_of_type( body_part_type::type::hand ).size() == 5 );
WHEN( "Uninjured / unencumbered" ) {
REQUIRE( dude.get_hp() == dude.get_hp_max() );
REQUIRE( dude.get_part_hp_cur( body_part_test_bird_wing_l ) == dude.get_part_hp_max(
body_part_test_bird_wing_l ) );
REQUIRE( dude.get_part_hp_cur( body_part_test_bird_wing_r ) == dude.get_part_hp_max(
body_part_test_bird_wing_r ) );
REQUIRE( dude.avg_encumb_of_limb_type( body_part_type::type::wing ) == 0 );
CHECK( dude.get_modifier( character_modifier_test_ranged_dispersion_manip_mod ) == Approx(
129.2 ).epsilon( 0.01 ) );
CHECK( dude.get_modifier( character_modifier_test_thrown_dex_mod ) == Approx( 0.8 ).epsilon(
0.01 ) );
CHECK( dude.get_modifier( character_modifier_test_thrown_dex_mod_hand ) == Approx( 0.15 ).epsilon(
0.01 ) );
}
WHEN( "Damaged wings / unencumbered" ) {
dude.set_part_hp_cur( body_part_test_bird_wing_l,
dude.get_part_hp_max( body_part_test_bird_wing_l ) / 2 );
dude.set_part_hp_cur( body_part_test_bird_wing_r,
dude.get_part_hp_max( body_part_test_bird_wing_r ) / 2 );
REQUIRE( dude.get_part_hp_cur( body_part_test_bird_wing_l ) == dude.get_part_hp_max(
body_part_test_bird_wing_l ) / 2 );
REQUIRE( dude.get_part_hp_cur( body_part_test_bird_wing_r ) == dude.get_part_hp_max(
body_part_test_bird_wing_r ) / 2 );
REQUIRE( dude.avg_encumb_of_limb_type( body_part_type::type::wing ) == 0 );
CHECK( dude.get_modifier( character_modifier_test_ranged_dispersion_manip_mod ) == Approx(
140.057 ).epsilon( 0.01 ) );
CHECK( dude.get_modifier( character_modifier_test_thrown_dex_mod ) == Approx( 0.533 ).epsilon(
0.01 ) );
CHECK( dude.get_modifier( character_modifier_test_thrown_dex_mod_hand ) == Approx( 0.14 ).epsilon(
0.01 ) );
}
WHEN( "Uninjured / wings encumbered" ) {
dude.wear_item( wing_covers, false );
REQUIRE( dude.get_hp() == dude.get_hp_max() );
REQUIRE( dude.get_part_hp_cur( body_part_test_bird_wing_l ) == dude.get_part_hp_max(
body_part_test_bird_wing_l ) );
REQUIRE( dude.get_part_hp_cur( body_part_test_bird_wing_r ) == dude.get_part_hp_max(
body_part_test_bird_wing_r ) );
REQUIRE( dude.avg_encumb_of_limb_type( body_part_type::type::wing ) == 70 );
CHECK( dude.get_modifier( character_modifier_test_ranged_dispersion_manip_mod ) == Approx(
173.641 ).epsilon( 0.01 ) );
CHECK( dude.get_modifier( character_modifier_test_thrown_dex_mod ) == Approx( 0.4 ).epsilon(
0.01 ) );
CHECK( dude.get_modifier( character_modifier_test_thrown_dex_mod_hand ) == Approx( 0.116 ).epsilon(
0.01 ) );
}
WHEN( "Damaged wings / wings encumbered" ) {
dude.wear_item( wing_covers, false );
dude.set_part_hp_cur( body_part_test_bird_wing_l,
dude.get_part_hp_max( body_part_test_bird_wing_l ) / 2 );
dude.set_part_hp_cur( body_part_test_bird_wing_r,
dude.get_part_hp_max( body_part_test_bird_wing_r ) / 2 );
REQUIRE( dude.get_part_hp_cur( body_part_test_bird_wing_l ) == dude.get_part_hp_max(
body_part_test_bird_wing_l ) / 2 );
REQUIRE( dude.get_part_hp_cur( body_part_test_bird_wing_r ) == dude.get_part_hp_max(
body_part_test_bird_wing_r ) / 2 );
REQUIRE( dude.avg_encumb_of_limb_type( body_part_type::type::wing ) == 70 );
CHECK( dude.get_modifier( character_modifier_test_ranged_dispersion_manip_mod ) == Approx(
211.341 ).epsilon( 0.01 ) );
CHECK( dude.get_modifier( character_modifier_test_thrown_dex_mod ) == Approx( 0.4 ).epsilon(
0.01 ) );
CHECK( dude.get_modifier( character_modifier_test_thrown_dex_mod_hand ) == Approx( 0.097 ).epsilon(
0.01 ) );
}
}
}