-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathiuse_test.cpp
1056 lines (847 loc) · 40.3 KB
/
iuse_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
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <cstdlib>
#include <iosfwd>
#include <memory>
#include <string>
#include "avatar.h"
#include "calendar.h"
#include "cata_catch.h"
#include "flag.h"
#include "item.h"
#include "itype.h"
#include "map_helpers.h"
#include "morale_types.h"
#include "player_helpers.h"
#include "type_id.h"
#include "value_ptr.h"
static const efftype_id effect_antifungal( "antifungal" );
static const efftype_id effect_asthma( "asthma" );
static const efftype_id effect_bile_irritant( "bile_irritant" );
static const efftype_id effect_bloodworms( "bloodworms" );
static const efftype_id effect_boomered( "boomered" );
static const efftype_id effect_brainworms( "brainworms" );
static const efftype_id effect_conjunctivitis( "conjunctivitis" );
static const efftype_id effect_cureall( "cureall" );
static const efftype_id effect_dermatik( "dermatik" );
static const efftype_id effect_foodpoison( "foodpoison" );
static const efftype_id effect_fungus( "fungus" );
static const efftype_id effect_glowing( "glowing" );
static const efftype_id effect_hallu( "hallu" );
static const efftype_id effect_high( "high" );
static const efftype_id effect_paincysts( "paincysts" );
static const efftype_id effect_shakes( "shakes" );
static const efftype_id effect_slimed( "slimed" );
static const efftype_id effect_smoke_lungs( "smoke_lungs" );
static const efftype_id effect_spores( "spores" );
static const efftype_id effect_tapeworm( "tapeworm" );
static const efftype_id effect_teargas( "teargas" );
static const efftype_id effect_took_anticonvulsant_visible( "took_anticonvulsant_visible" );
static const efftype_id effect_took_prozac( "took_prozac" );
static const efftype_id effect_took_prozac_visible( "took_prozac_visible" );
static const efftype_id effect_took_thorazine( "took_thorazine" );
static const efftype_id effect_took_xanax( "took_xanax" );
static const efftype_id effect_took_xanax_visible( "took_xanax_visible" );
static const efftype_id effect_valium( "valium" );
static const efftype_id effect_visuals( "visuals" );
static const furn_str_id furn_f_toilet( "f_toilet" );
static const itype_id itype_55gal_drum( "55gal_drum" );
static const itype_id itype_albuterol( "albuterol" );
static const itype_id itype_antifungal( "antifungal" );
static const itype_id itype_antiparasitic( "antiparasitic" );
static const itype_id itype_backpack( "backpack" );
static const itype_id itype_diazepam( "diazepam" );
static const itype_id itype_pur_tablets( "pur_tablets" );
static const itype_id itype_thorazine( "thorazine" );
static const itype_id itype_towel_wet( "towel_wet" );
static const itype_id itype_water( "water" );
static const itype_id itype_water_clean( "water_clean" );
static const itype_id itype_water_purifying( "water_purifying" );
static const morale_type morale_wet( "morale_wet" );
static const ter_str_id ter_t_grass( "t_grass" );
TEST_CASE( "eyedrops", "[iuse][eyedrops]" )
{
avatar dummy;
//Give eyes to our dummy
dummy.set_body();
REQUIRE( dummy.has_part( bodypart_id( "eyes" ) ) );
dummy.normalize();
item eyedrops( "saline", calendar::turn_zero, item::default_charges_tag{} );
int charges_before = eyedrops.charges;
REQUIRE( charges_before > 0 );
GIVEN( "avatar is boomered" ) {
dummy.add_effect( effect_boomered, 1_hours );
REQUIRE( dummy.has_effect( effect_boomered ) );
WHEN( "they use eye drops" ) {
dummy.consume( eyedrops );
THEN( "one dose is depleted" ) {
CHECK( eyedrops.charges == charges_before - 1 );
AND_THEN( "it removes the boomered effect" ) {
CHECK_FALSE( dummy.has_effect( effect_boomered ) );
}
}
}
}
charges_before = eyedrops.charges;
REQUIRE( charges_before > 0 );
GIVEN( "avatar gets conjunctivitis" ) {
dummy.add_effect( effect_conjunctivitis, 72_hours, bodypart_id( "eyes" ) );
REQUIRE( dummy.has_effect( effect_conjunctivitis, bodypart_id( "eyes" ) ) );
REQUIRE( dummy.get_effect_dur( effect_conjunctivitis, bodypart_id( "eyes" ) ) > 24_hours );
WHEN( "they use eye drops" ) {
dummy.consume( eyedrops );
THEN( "one dose is depleted" ) {
CHECK( eyedrops.charges == charges_before - 1 );
AND_THEN( "it shortens the duration of conjunctivitis" ) {
CHECK( dummy.get_effect_dur( effect_conjunctivitis, bodypart_id( "eyes" ) ) <= 24_hours );
}
}
}
}
charges_before = eyedrops.charges;
REQUIRE( charges_before > 0 );
GIVEN( "avatar is underwater" ) {
dummy.set_underwater( true );
WHEN( "they try to use eye drops" ) {
dummy.consume( eyedrops );
THEN( "None were used" ) {
CHECK( eyedrops.charges == charges_before );
}
}
}
}
TEST_CASE( "antifungal", "[iuse][antifungal]" )
{
avatar dummy;
dummy.normalize();
item_location antifungal = dummy.i_add( item( itype_antifungal, calendar::turn ) );
REQUIRE( dummy.has_item_with( []( const item & it ) {
return it.typeId() == itype_antifungal;
} ) );
GIVEN( "avatar has a fungal infection" ) {
dummy.add_effect( effect_fungus, 1_hours );
REQUIRE( dummy.has_effect( effect_fungus ) );
WHEN( "they take an antifungal drug" ) {
dummy.consume( antifungal );
THEN( "antifungal is used up" ) {
CHECK_FALSE( dummy.has_item_with( []( const item & it ) {
return it.typeId() == itype_antifungal;
} ) );
AND_THEN( "it applies the antifungal effect" ) {
CHECK( dummy.has_effect( effect_antifungal ) );
}
AND_WHEN( "time passes" ) {
const time_duration fungal_clock = dummy.get_effect_dur( effect_fungus );
REQUIRE( fungal_clock == 1_hours );
dummy.process_effects();
THEN( "duration of fungal infection shortens" ) {
CHECK( fungal_clock > dummy.get_effect_dur( effect_fungus ) );
}
}
}
}
}
GIVEN( "avatar has fungal spores" ) {
dummy.add_effect( effect_spores, 1_hours );
REQUIRE( dummy.has_effect( effect_spores ) );
WHEN( "they take an antifungal drug" ) {
dummy.consume( antifungal );
THEN( "antifungal is used up" ) {
CHECK_FALSE( dummy.has_item_with( []( const item & it ) {
return it.typeId() == itype_antifungal;
} ) );
AND_THEN( "it has no effect on the spores" ) {
CHECK( dummy.has_effect( effect_spores ) );
}
}
}
}
}
TEST_CASE( "antiparasitic", "[iuse][antiparasitic]" )
{
avatar dummy;
dummy.normalize();
item_location antiparasitic = dummy.i_add( item( itype_antiparasitic, calendar::turn ) );
REQUIRE( dummy.has_item_with( []( const item & it ) {
return it.typeId() == itype_antiparasitic;
} ) );
GIVEN( "avatar has parasite infections" ) {
dummy.add_effect( effect_dermatik, 1_hours );
dummy.add_effect( effect_tapeworm, 1_hours );
dummy.add_effect( effect_bloodworms, 1_hours );
dummy.add_effect( effect_brainworms, 1_hours );
dummy.add_effect( effect_paincysts, 1_hours );
REQUIRE( dummy.has_effect( effect_dermatik ) );
REQUIRE( dummy.has_effect( effect_tapeworm ) );
REQUIRE( dummy.has_effect( effect_bloodworms ) );
REQUIRE( dummy.has_effect( effect_brainworms ) );
REQUIRE( dummy.has_effect( effect_paincysts ) );
WHEN( "they use an antiparasitic drug" ) {
dummy.consume( antiparasitic );
THEN( "antiparasitic was used up" ) {
CHECK_FALSE( dummy.has_item_with( []( const item & it ) {
return it.typeId() == itype_antiparasitic;
} ) );
AND_THEN( "it cures all parasite infections" ) {
CHECK_FALSE( dummy.has_effect( effect_dermatik ) );
CHECK_FALSE( dummy.has_effect( effect_tapeworm ) );
CHECK_FALSE( dummy.has_effect( effect_bloodworms ) );
CHECK_FALSE( dummy.has_effect( effect_brainworms ) );
CHECK_FALSE( dummy.has_effect( effect_paincysts ) );
}
}
}
}
GIVEN( "avatar has a fungal infection" ) {
REQUIRE( dummy.has_item_with( []( const item & it ) {
return it.typeId() == itype_antiparasitic;
} ) );
dummy.add_effect( effect_fungus, 1_hours );
REQUIRE( dummy.has_effect( effect_fungus ) );
WHEN( "they use an antiparasitic drug" ) {
dummy.consume( antiparasitic );
THEN( "antiparasitic was used up" ) {
CHECK_FALSE( dummy.has_item_with( []( const item & it ) {
return it.typeId() == itype_antiparasitic;
} ) );
AND_THEN( "it has no effect on the fungal infection" ) {
CHECK( dummy.has_effect( effect_fungus ) );
}
}
}
}
}
TEST_CASE( "anticonvulsant", "[iuse][anticonvulsant]" )
{
avatar dummy;
dummy.normalize();
item_location anticonvulsant = dummy.i_add( item( itype_diazepam, calendar::turn ) );
REQUIRE( dummy.has_item_with( []( const item & it ) {
return it.typeId() == itype_diazepam;
} ) );
GIVEN( "avatar has the shakes" ) {
dummy.add_effect( effect_shakes, 1_hours );
REQUIRE( dummy.has_effect( effect_shakes ) );
WHEN( "they use an anticonvulsant drug" ) {
dummy.consume( anticonvulsant );
THEN( "anticonvulsant was used up" ) {
CHECK_FALSE( dummy.has_item_with( []( const item & it ) {
return it.typeId() == itype_diazepam;
} ) );
AND_THEN( "it cures the shakes" ) {
CHECK_FALSE( dummy.has_effect( effect_shakes ) );
AND_THEN( "it has side-effects" ) {
CHECK( dummy.has_effect( effect_valium ) );
CHECK( dummy.has_effect( effect_high ) );
CHECK( dummy.has_effect( effect_took_anticonvulsant_visible ) );
}
}
}
}
}
}
// test the `iuse::oxygen_bottle` function
TEST_CASE( "oxygen_tank", "[iuse][oxygen_bottle]" )
{
avatar dummy;
dummy.normalize();
item oxygen( "oxygen_tank" );
itype_id o2_ammo( "oxygen" );
oxygen.ammo_set( o2_ammo );
int charges_before = oxygen.ammo_remaining();
REQUIRE( charges_before > 0 );
// Ensure baseline painkiller value to measure painkiller effects
dummy.set_painkiller( 0 );
REQUIRE( dummy.get_painkiller() == 0 );
GIVEN( "avatar is suffering from smoke inhalation" ) {
dummy.add_effect( effect_smoke_lungs, 1_hours );
REQUIRE( dummy.has_effect( effect_smoke_lungs ) );
THEN( "a dose of oxygen relieves the smoke inhalation" ) {
dummy.invoke_item( &oxygen );
CHECK( oxygen.ammo_remaining() == charges_before - 1 );
CHECK_FALSE( dummy.has_effect( effect_smoke_lungs ) );
AND_THEN( "it acts as a mild painkiller" ) {
CHECK( dummy.get_painkiller() == 2 );
}
}
}
GIVEN( "avatar is suffering from tear gas" ) {
dummy.add_effect( effect_teargas, 1_hours );
REQUIRE( dummy.has_effect( effect_teargas ) );
THEN( "a dose of oxygen relieves the effects of tear gas" ) {
dummy.invoke_item( &oxygen );
CHECK( oxygen.ammo_remaining() == charges_before - 1 );
CHECK_FALSE( dummy.has_effect( effect_teargas ) );
AND_THEN( "it acts as a mild painkiller" ) {
CHECK( dummy.get_painkiller() == 2 );
}
}
}
GIVEN( "avatar is suffering from asthma" ) {
dummy.add_effect( effect_asthma, 1_hours );
REQUIRE( dummy.has_effect( effect_asthma ) );
THEN( "a dose of oxygen relieves the effects of asthma" ) {
dummy.invoke_item( &oxygen );
CHECK( oxygen.ammo_remaining() == charges_before - 1 );
CHECK_FALSE( dummy.has_effect( effect_asthma ) );
AND_THEN( "it acts as a mild painkiller" ) {
CHECK( dummy.get_painkiller() == 2 );
}
}
}
GIVEN( "avatar has no ill effects for the oxygen to treat" ) {
REQUIRE_FALSE( dummy.has_effect( effect_smoke_lungs ) );
REQUIRE_FALSE( dummy.has_effect( effect_teargas ) );
REQUIRE_FALSE( dummy.has_effect( effect_asthma ) );
WHEN( "they are not already stimulated" ) {
dummy.set_stim( 0 );
REQUIRE( dummy.get_stim() == 0 );
THEN( "a dose of oxygen is stimulating" ) {
dummy.invoke_item( &oxygen );
CHECK( oxygen.ammo_remaining() == charges_before - 1 );
// values should match iuse function `oxygen_bottle`
CHECK( dummy.get_stim() == 8 );
AND_THEN( "it acts as a stronger painkiller" ) {
CHECK( dummy.get_painkiller() == 4 );
}
}
}
WHEN( "they are already quite stimulated" ) {
// "quite stimulated" meaning the max-stimulation cutoff defined in
// iuse function `oxygen_bottle`, which should match `max_stim` here:
int max_stim = 16;
dummy.set_stim( max_stim );
REQUIRE( dummy.get_stim() == max_stim );
THEN( "a dose of oxygen has no additional stimulation effects" ) {
dummy.invoke_item( &oxygen );
CHECK( oxygen.ammo_remaining() == charges_before - 1 );
CHECK( dummy.get_stim() == max_stim );
AND_THEN( "it acts as a mild painkiller" ) {
CHECK( dummy.get_painkiller() == 2 );
}
}
}
}
}
// test the `iuse::caff` and `iuse::atomic_caff` functions
TEST_CASE( "caffeine_and_atomic_caffeine", "[iuse][caff][atomic_caff]" )
{
avatar dummy;
dummy.normalize();
// Baseline sleepiness level before caffeinating
int sleepiness_before = 200;
dummy.set_sleepiness( sleepiness_before );
// No stimulants or radiation
dummy.set_stim( 0 );
dummy.set_rad( 0 );
REQUIRE( dummy.get_stim() == 0 );
REQUIRE( dummy.get_rad() == 0 );
SECTION( "coffee reduces sleepiness, but does not give stimulant effect" ) {
item coffee( "coffee", calendar::turn_zero, item::default_charges_tag{} );
dummy.consume( coffee );
CHECK( dummy.get_sleepiness() == sleepiness_before - coffee.get_comestible()->sleepiness_mod );
CHECK( dummy.get_stim() == coffee.get_comestible()->stim );
}
SECTION( "atomic caffeine greatly reduces sleepiness, and increases stimulant effect" ) {
item atomic_coffee( "atomic_coffee", calendar::turn_zero, item::default_charges_tag{} );
dummy.consume( atomic_coffee );
CHECK( dummy.get_sleepiness() == sleepiness_before -
atomic_coffee.get_comestible()->sleepiness_mod );
CHECK( dummy.get_stim() == atomic_coffee.get_comestible()->stim );
}
}
TEST_CASE( "towel", "[iuse][towel]" )
{
avatar dummy;
dummy.normalize();
item towel( "towel", calendar::turn_zero, item::default_charges_tag{} );
GIVEN( "avatar is wet" ) {
// Saturate torso, head, and both arms
dummy.drench( 100, { body_part_torso, body_part_head, body_part_arm_l, body_part_arm_r },
false );
REQUIRE( dummy.get_part_wetness( bodypart_id( "torso" ) ) > 0 );
REQUIRE( dummy.get_part_wetness( bodypart_id( "head" ) ) > 0 );
REQUIRE( dummy.get_part_wetness( bodypart_id( "arm_l" ) ) > 0 );
REQUIRE( dummy.get_part_wetness( bodypart_id( "arm_r" ) ) > 0 );
WHEN( "they use a dry towel" ) {
REQUIRE_FALSE( towel.has_flag( flag_WET ) );
dummy.invoke_item( &towel );
THEN( "it dries them off" ) {
CHECK( dummy.get_part_wetness( bodypart_id( "torso" ) ) == 0 );
CHECK( dummy.get_part_wetness( bodypart_id( "head" ) ) == 0 );
CHECK( dummy.get_part_wetness( bodypart_id( "arm_l" ) ) == 0 );
CHECK( dummy.get_part_wetness( bodypart_id( "arm_r" ) ) == 0 );
AND_THEN( "the towel becomes wet" ) {
CHECK( towel.typeId().str() == "towel_wet" );
}
}
}
WHEN( "they use a wet towel" ) {
towel.convert( itype_towel_wet );
REQUIRE( towel.has_flag( flag_WET ) );
dummy.invoke_item( &towel );
THEN( "it does not dry them off" ) {
CHECK( dummy.get_part_wetness( bodypart_id( "torso" ) ) > 0 );
CHECK( dummy.get_part_wetness( bodypart_id( "head" ) ) > 0 );
CHECK( dummy.get_part_wetness( bodypart_id( "arm_l" ) ) > 0 );
CHECK( dummy.get_part_wetness( bodypart_id( "arm_r" ) ) > 0 );
}
}
}
GIVEN( "avatar has poor morale due to being wet" ) {
dummy.drench( 100, { body_part_torso, body_part_head, body_part_arm_l, body_part_arm_r },
false );
dummy.add_morale( morale_wet, -10, -10, 1_hours, 1_hours );
REQUIRE( dummy.has_morale( morale_wet ) == -10 );
WHEN( "they use a wet towel" ) {
towel.convert( itype_towel_wet );
REQUIRE( towel.has_flag( flag_WET ) );
dummy.invoke_item( &towel );
THEN( "it does not improve their morale" ) {
CHECK( dummy.has_morale( morale_wet ) == -10 );
}
}
WHEN( "they use a dry towel" ) {
REQUIRE_FALSE( towel.has_flag( flag_WET ) );
dummy.invoke_item( &towel );
THEN( "it improves their morale" ) {
CHECK( dummy.has_morale( morale_wet ) == 0 );
AND_THEN( "the towel becomes wet" ) {
CHECK( towel.typeId() == itype_towel_wet );
}
}
}
}
GIVEN( "avatar is slimed, boomered, glowing, and bile irritated." ) {
dummy.add_effect( effect_slimed, 1_hours );
dummy.add_effect( effect_boomered, 1_hours );
dummy.add_effect( effect_glowing, 1_hours );
dummy.add_effect( effect_bile_irritant, 1_hours );
REQUIRE( dummy.has_effect( effect_slimed ) );
REQUIRE( dummy.has_effect( effect_boomered ) );
REQUIRE( dummy.has_effect( effect_glowing ) );
REQUIRE( dummy.has_effect( effect_bile_irritant ) );
WHEN( "they use a dry towel" ) {
REQUIRE_FALSE( towel.has_flag( flag_WET ) );
dummy.invoke_item( &towel );
THEN( "it removes all those effects at once" ) {
CHECK_FALSE( dummy.has_effect( effect_slimed ) );
CHECK_FALSE( dummy.has_effect( effect_boomered ) );
CHECK_FALSE( dummy.has_effect( effect_glowing ) );
CHECK_FALSE( dummy.has_effect( effect_bile_irritant ) );
AND_THEN( "the towel becomes filthy" ) {
CHECK( towel.is_filthy() );
}
}
}
}
GIVEN( "avatar is boomered and wet" ) {
dummy.add_effect( effect_boomered, 1_hours );
dummy.add_morale( morale_wet, -10, -10, 1_hours, 1_hours );
REQUIRE( std::abs( dummy.has_morale( morale_wet ) ) );
WHEN( "they use a dry towel" ) {
REQUIRE_FALSE( towel.has_flag( flag_WET ) );
dummy.invoke_item( &towel );
THEN( "it removes the boomered effect, but not the wetness" ) {
CHECK_FALSE( dummy.has_effect( effect_boomered ) );
CHECK( std::abs( dummy.has_morale( morale_wet ) ) );
AND_THEN( "the towel becomes filthy" ) {
CHECK( towel.is_filthy() );
}
}
}
}
}
TEST_CASE( "thorazine", "[iuse][thorazine]" )
{
avatar dummy;
dummy.normalize();
item_location thorazine = dummy.i_add( item( itype_thorazine, calendar::turn ) );
REQUIRE( dummy.has_item_with( []( const item & it ) {
return it.typeId() == itype_thorazine;
} ) );
dummy.set_sleepiness( 0 );
GIVEN( "avatar has hallucination, visuals, and high effects" ) {
dummy.add_effect( effect_hallu, 1_hours );
dummy.add_effect( effect_visuals, 1_hours );
dummy.add_effect( effect_high, 1_hours );
REQUIRE( dummy.has_effect( effect_hallu ) );
REQUIRE( dummy.has_effect( effect_visuals ) );
REQUIRE( dummy.has_effect( effect_high ) );
WHEN( "they take some thorazine" ) {
dummy.consume( thorazine );
THEN( "it relieves all those effects with a single dose" ) {
CHECK_FALSE( dummy.has_item_with( []( const item & it ) {
return it.typeId() == itype_thorazine;
} ) );
REQUIRE_FALSE( dummy.has_effect( effect_hallu ) );
REQUIRE_FALSE( dummy.has_effect( effect_visuals ) );
REQUIRE_FALSE( dummy.has_effect( effect_high ) );
AND_THEN( "it causes some sleepiness" ) {
CHECK( dummy.get_sleepiness() >= 5 );
}
}
}
}
GIVEN( "avatar has already taken some thorazine" ) {
item thora( itype_thorazine, calendar::turn );
dummy.consume( thora );
REQUIRE( dummy.has_item_with( []( const item & it ) {
return it.typeId() == itype_thorazine;
} ) );
REQUIRE( dummy.has_effect( effect_took_thorazine ) );
WHEN( "they take more thorazine" ) {
dummy.consume( thorazine );
THEN( "it only causes more sleepiness" ) {
CHECK_FALSE( dummy.has_item_with( []( const item & it ) {
return it.typeId() == itype_thorazine;
} ) );
CHECK( dummy.get_sleepiness() >= 20 );
}
}
}
}
TEST_CASE( "prozac", "[iuse][prozac]" )
{
avatar dummy;
dummy.normalize();
item prozac( "prozac", calendar::turn_zero, item::default_charges_tag{} );
SECTION( "prozac gives prozac and visible prozac effect" ) {
REQUIRE_FALSE( dummy.has_effect( effect_took_prozac ) );
REQUIRE_FALSE( dummy.has_effect( effect_took_prozac_visible ) );
dummy.consume( prozac );
CHECK( dummy.has_effect( effect_took_prozac ) );
CHECK( dummy.has_effect( effect_took_prozac_visible ) );
}
SECTION( "taking prozac twice gives a stimulant effect" ) {
dummy.set_stim( 0 );
dummy.consume( prozac );
CHECK( dummy.get_stim() == -5 ); // The iuse action gives +0 and item itself -5
dummy.consume( prozac );
CHECK( dummy.get_stim() == -7 ); // Second iuse gives +3
}
}
TEST_CASE( "inhaler", "[iuse][inhaler]" )
{
clear_avatar();
avatar &dummy = get_avatar();
item inhaler( "inhaler" );
inhaler.ammo_set( itype_albuterol );
REQUIRE( inhaler.ammo_remaining() > 0 );
item_location inhaler_loc = dummy.i_add( inhaler );
REQUIRE( dummy.has_item( *inhaler_loc ) );
GIVEN( "avatar is suffering from smoke inhalation" ) {
dummy.add_effect( effect_smoke_lungs, 1_hours );
REQUIRE( dummy.has_effect( effect_smoke_lungs ) );
THEN( "inhaler relieves it" ) {
dummy.use( inhaler_loc );
CHECK_FALSE( dummy.has_effect( effect_smoke_lungs ) );
}
}
GIVEN( "avatar is suffering from asthma" ) {
dummy.add_effect( effect_asthma, 1_hours );
REQUIRE( dummy.has_effect( effect_asthma ) );
THEN( "inhaler relieves the effects of asthma" ) {
dummy.use( inhaler_loc );
CHECK_FALSE( dummy.has_effect( effect_asthma ) );
}
}
GIVEN( "avatar is not suffering from asthma" ) {
REQUIRE_FALSE( dummy.has_effect( effect_asthma ) );
THEN( "inhaler reduces sleepiness" ) {
dummy.set_sleepiness( 10 );
dummy.use( inhaler_loc );
CHECK( dummy.get_sleepiness() < 10 );
}
}
}
TEST_CASE( "panacea", "[iuse][panacea]" )
{
avatar dummy;
dummy.normalize();
item panacea( "panacea", calendar::turn_zero, item::default_charges_tag{} );
SECTION( "panacea gives cure-all effect" ) {
REQUIRE_FALSE( dummy.has_effect( effect_cureall ) );
dummy.consume( panacea );
CHECK( dummy.has_effect( effect_cureall ) );
}
}
TEST_CASE( "xanax", "[iuse][xanax]" )
{
avatar dummy;
dummy.normalize();
item xanax( "xanax", calendar::turn_zero, item::default_charges_tag{} );
SECTION( "xanax gives xanax and visible xanax effects" ) {
REQUIRE_FALSE( dummy.has_effect( effect_took_xanax ) );
REQUIRE_FALSE( dummy.has_effect( effect_took_xanax_visible ) );
dummy.consume( xanax );
CHECK( dummy.has_effect( effect_took_xanax ) );
CHECK( dummy.has_effect( effect_took_xanax_visible ) );
}
}
static item_location give_tablets( avatar &dummy, int count, bool in_inventory )
{
const int existing_tablets = dummy.crafting_inventory().count_item( itype_pur_tablets );
item_location tablets;
if( in_inventory ) {
for( int i = 0; i < count; ++i ) {
tablets = dummy.i_add( item( itype_pur_tablets, calendar::turn ) );
}
} else {
// Tablets fail to spawn directly on the ground, so put them in a backpack, then spawn that
item container( itype_backpack );
for( int i = 0; i < count; ++i ) {
container.put_in( item( itype_pur_tablets, calendar::turn ), pocket_type::CONTAINER );
}
item_location container_loc = get_map().add_item_ret_loc( dummy.pos_bub(), container, true );
REQUIRE( container_loc );
std::list<item *> all_tablets = container_loc->all_items_top();
REQUIRE( !all_tablets.empty() );
tablets = item_location( container_loc, all_tablets.front() );
}
REQUIRE( tablets );
// Since we checked it earlier, the crafting inventory needs to be invalidated to force an update
dummy.invalidate_crafting_inventory();
REQUIRE( dummy.crafting_inventory().count_item( itype_pur_tablets ) == count + existing_tablets );
return tablets;
}
static item_location give_water( avatar &dummy, int count, bool in_inventory )
{
item container( itype_55gal_drum );
item_location container_loc;
item water( itype_water );
water.charges = count;
container.put_in( water, pocket_type::CONTAINER );
if( in_inventory ) {
container_loc = dummy.i_add( container );
} else {
container_loc = get_map().add_item_ret_loc( dummy.pos_bub(), container, true );
}
REQUIRE( container_loc );
// Spawning a container of water next to the player does not update the crafting inventory, so force an update
dummy.invalidate_crafting_inventory();
REQUIRE( dummy.crafting_inventory().charges_of( itype_water ) == count );
return item_location( dummy, &container_loc->only_item() );
}
TEST_CASE( "water_purification_tablet_activation", "[iuse][pur_tablets]" )
{
avatar dummy;
dummy.normalize();
build_test_map( ter_t_grass );
const tripoint test_origin( 20, 20, 0 );
dummy.setpos( test_origin );
// Give the player a backpack to hold the tablets
dummy.worn.wear_item( dummy, item( itype_backpack ), false, false );
SECTION( "1 tablet in inventory will purify 4 water in inventory" ) {
item_location tablet = give_tablets( dummy, 1, true );
item_location water_location = give_water( dummy, 4, true );
iuse::purify_water( &dummy, tablet.get_item(), water_location );
CHECK( dummy.crafting_inventory().charges_of( itype_water ) == 0 );
CHECK( dummy.crafting_inventory().charges_of( itype_water_purifying ) == 4 );
CHECK( dummy.crafting_inventory().count_item( itype_pur_tablets ) == 0 );
}
SECTION( "1 tablet in inventory will purify 1 water in inventory" ) {
item_location tablet = give_tablets( dummy, 1, true );
item_location water_location = give_water( dummy, 1, true );
iuse::purify_water( &dummy, tablet.get_item(), water_location );
CHECK( dummy.crafting_inventory().charges_of( itype_water ) == 0 );
CHECK( dummy.crafting_inventory().charges_of( itype_water_purifying ) == 1 );
CHECK( dummy.crafting_inventory().count_item( itype_pur_tablets ) == 0 );
}
SECTION( "1 tablet in inventory will not purify 5 water in inventory" ) {
item_location tablet = give_tablets( dummy, 1, true );
item_location water_location = give_water( dummy, 5, true );
iuse::purify_water( &dummy, tablet.get_item(), water_location );
CHECK( dummy.crafting_inventory().charges_of( itype_water ) == 5 );
CHECK( dummy.crafting_inventory().charges_of( itype_water_purifying ) == 0 );
CHECK( dummy.crafting_inventory().count_item( itype_pur_tablets ) == 1 );
}
SECTION( "3 tablets in inventory will purify 12 water in inventory" ) {
item_location tablet = give_tablets( dummy, 3, true );
item_location water_location = give_water( dummy, 12, true );
iuse::purify_water( &dummy, tablet.get_item(), water_location );
CHECK( dummy.crafting_inventory().charges_of( itype_water ) == 0 );
CHECK( dummy.crafting_inventory().charges_of( itype_water_purifying ) == 12 );
CHECK( dummy.crafting_inventory().count_item( itype_pur_tablets ) == 0 );
}
SECTION( "2 tablets in inventory will purify 4 water in inventory" ) {
item_location tablet = give_tablets( dummy, 2, true );
item_location water_location = give_water( dummy, 4, true );
iuse::purify_water( &dummy, tablet.get_item(), water_location );
CHECK( dummy.crafting_inventory().charges_of( itype_water ) == 0 );
CHECK( dummy.crafting_inventory().charges_of( itype_water_purifying ) == 4 );
CHECK( dummy.crafting_inventory().count_item( itype_pur_tablets ) == 1 );
}
SECTION( "1 tablet nearby will purify 4 water nearby" ) {
item_location tablet = give_tablets( dummy, 1, false );
item_location water_location = give_water( dummy, 4, false );
iuse::purify_water( &dummy, tablet.get_item(), water_location );
CHECK( dummy.crafting_inventory().charges_of( itype_water ) == 0 );
CHECK( dummy.crafting_inventory().charges_of( itype_water_purifying ) == 4 );
CHECK( dummy.crafting_inventory().count_item( itype_pur_tablets ) == 0 );
}
SECTION( "2 tablets nearby will purify 5 water nearby" ) {
item_location tablet = give_tablets( dummy, 2, false );
item_location water_location = give_water( dummy, 5, false );
iuse::purify_water( &dummy, tablet.get_item(), water_location );
CHECK( dummy.crafting_inventory().charges_of( itype_water ) == 0 );
CHECK( dummy.crafting_inventory().charges_of( itype_water_purifying ) == 5 );
CHECK( dummy.crafting_inventory().count_item( itype_pur_tablets ) == 0 );
}
SECTION( "3 tablets nearby will not purify 13 water nearby" ) {
item_location tablet = give_tablets( dummy, 3, false );
item_location water_location = give_water( dummy, 13, false );
iuse::purify_water( &dummy, tablet.get_item(), water_location );
CHECK( dummy.crafting_inventory().charges_of( itype_water ) == 13 );
CHECK( dummy.crafting_inventory().charges_of( itype_water_purifying ) == 0 );
CHECK( dummy.crafting_inventory().count_item( itype_pur_tablets ) == 3 );
}
SECTION( "1 tablet in inventory will purify 2 water nearby" ) {
item_location tablet = give_tablets( dummy, 1, true );
item_location water_location = give_water( dummy, 2, false );
iuse::purify_water( &dummy, tablet.get_item(), water_location );
CHECK( dummy.crafting_inventory().charges_of( itype_water ) == 0 );
CHECK( dummy.crafting_inventory().charges_of( itype_water_purifying ) == 2 );
CHECK( dummy.crafting_inventory().count_item( itype_pur_tablets ) == 0 );
}
SECTION( "1 tablet nearby will purify 1 water in inventory" ) {
item_location tablet = give_tablets( dummy, 1, false );
item_location water_location = give_water( dummy, 1, true );
iuse::purify_water( &dummy, tablet.get_item(), water_location );
CHECK( dummy.crafting_inventory().charges_of( itype_water ) == 0 );
CHECK( dummy.crafting_inventory().charges_of( itype_water_purifying ) == 1 );
CHECK( dummy.crafting_inventory().count_item( itype_pur_tablets ) == 0 );
}
SECTION( "1 tablet nearby and 1 tablet in inventory will purify 3 water in inventory" ) {
item_location tablet = give_tablets( dummy, 1, false );
tablet = give_tablets( dummy, 1, true );
item_location water_location = give_water( dummy, 3, true );
iuse::purify_water( &dummy, tablet.get_item(), water_location );
CHECK( dummy.crafting_inventory().charges_of( itype_water ) == 0 );
CHECK( dummy.crafting_inventory().charges_of( itype_water_purifying ) == 3 );
CHECK( dummy.crafting_inventory().count_item( itype_pur_tablets ) == 1 );
}
SECTION( "1 tablet nearby and 1 tablet in inventory will purify 8 water in inventory" ) {
item_location tablet = give_tablets( dummy, 1, false );
tablet = give_tablets( dummy, 1, true );
item_location water_location = give_water( dummy, 8, true );
iuse::purify_water( &dummy, tablet.get_item(), water_location );
CHECK( dummy.crafting_inventory().charges_of( itype_water ) == 0 );
CHECK( dummy.crafting_inventory().charges_of( itype_water_purifying ) == 8 );
CHECK( dummy.crafting_inventory().count_item( itype_pur_tablets ) == 0 );
}
SECTION( "1 tablet nearby and 1 tablet in inventory will purify 2 water nearby" ) {
item_location tablet = give_tablets( dummy, 1, false );
tablet = give_tablets( dummy, 1, true );
item_location water_location = give_water( dummy, 8, false );
iuse::purify_water( &dummy, tablet.get_item(), water_location );
CHECK( dummy.crafting_inventory().charges_of( itype_water ) == 0 );
CHECK( dummy.crafting_inventory().charges_of( itype_water_purifying ) == 8 );
CHECK( dummy.crafting_inventory().count_item( itype_pur_tablets ) == 0 );
}
SECTION( "1 tablet nearby and 1 tablet in inventory will not purify 9 water nearby" ) {
item_location tablet = give_tablets( dummy, 1, false );
tablet = give_tablets( dummy, 1, true );
item_location water_location = give_water( dummy, 9, false );
iuse::purify_water( &dummy, tablet.get_item(), water_location );
CHECK( dummy.crafting_inventory().charges_of( itype_water ) == 9 );
CHECK( dummy.crafting_inventory().charges_of( itype_water_purifying ) == 0 );
CHECK( dummy.crafting_inventory().count_item( itype_pur_tablets ) == 2 );
}
SECTION( "6 tablets will purify a toilet tank" ) {
item_location tablet = give_tablets( dummy, 6, true );
get_map().furn_set( dummy.pos_bub() + tripoint_north, furn_f_toilet );
item water( itype_water );
water.charges = 24;
get_map().add_item( dummy.pos_bub() + tripoint_north, water );
item_location water_location( map_cursor( dummy.pos_bub() + tripoint_north ), &water );
REQUIRE( water_location );
REQUIRE( water_location.get_item()->typeId() == itype_water );
REQUIRE( water_location.get_item()->charges == 24 );
REQUIRE( water_location.where_recursive() == item_location::type::map );
iuse::purify_water( &dummy, tablet.get_item(), water_location );
// TODO: Figure out why the crafting inventory doesn't update to show water_purifying
/*dummy.invalidate_crafting_inventory();
CHECK( dummy.crafting_inventory().charges_of( itype_water ) == 0 );
CHECK( dummy.crafting_inventory().charges_of( itype_water_purifying ) == 24 );
CHECK( dummy.crafting_inventory().count_item( itype_pur_tablets ) == 0 );*/
// Until then, show that it works by checking the item directly:
CHECK( water_location.get_item()->typeId() == itype_water_purifying );
CHECK( water_location.get_item()->charges == 24 );
}
}
TEST_CASE( "water_tablet_purification_test", "[iuse][pur_tablets]" )
{
avatar dummy;
dummy.normalize();
build_test_map( ter_t_grass );
const tripoint test_origin( 20, 20, 0 );
dummy.setpos( test_origin );
SECTION( "Test purifying time" ) {
item_location tablet = give_tablets( dummy, 1, true );
item_location water_location = give_water( dummy, 4, false );
iuse::purify_water( &dummy, tablet.get_item(), water_location );
REQUIRE( dummy.crafting_inventory().charges_of( itype_water_clean ) == 0 );
REQUIRE( dummy.crafting_inventory().charges_of( itype_water_purifying ) == 4 );
SECTION( "Still purifying at ten minutes" ) {
calendar::turn += 10_minutes;
dummy.invoke_item( water_location.get_item() );
CHECK( dummy.crafting_inventory().charges_of( itype_water_clean ) == 0 );
CHECK( dummy.crafting_inventory().charges_of( itype_water_purifying ) == 4 );
}
SECTION( "Still purifying at thirty minutes" ) {
calendar::turn += 30_minutes;
dummy.invoke_item( water_location.get_item() );
CHECK( dummy.crafting_inventory().charges_of( itype_water_clean ) == 0 );
CHECK( dummy.crafting_inventory().charges_of( itype_water_purifying ) == 4 );
}
SECTION( "Clean water at forty minutes" ) {
calendar::turn += 40_minutes;
dummy.invoke_item( water_location.get_item() );
CHECK( dummy.crafting_inventory().charges_of( itype_water_clean ) == 4 );
CHECK( dummy.crafting_inventory().charges_of( itype_water_purifying ) == 0 );
}
}
SECTION( "Test purifying time with old water" ) {
item_location tablet = give_tablets( dummy, 1, true );
item_location water_location = give_water( dummy, 4, false );