forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iteminfo_test.cpp
2992 lines (2558 loc) · 117 KB
/
iteminfo_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 <iosfwd>
#include <list>
#include <memory>
#include <set>
#include <string>
#include <vector>
#include "avatar.h"
#include "bodypart.h"
#include "calendar.h"
#include "cata_catch.h"
#include "character.h"
#include "flag.h"
#include "item.h"
#include "iteminfo_query.h"
#include "itype.h"
#include "options_helpers.h"
#include "output.h"
#include "player_helpers.h"
#include "recipe.h"
#include "recipe_dictionary.h"
#include "type_id.h"
#include "units.h"
#include "value_ptr.h"
static const itype_id itype_candle_wax( "candle_wax" );
static const itype_id itype_dress_shirt( "dress_shirt" );
static const itype_id itype_match( "match" );
static const itype_id itype_test_armor_chitin( "test_armor_chitin" );
static const itype_id itype_test_armor_chitin_copy( "test_armor_chitin_copy" );
static const itype_id itype_test_armor_chitin_copy_prop( "test_armor_chitin_copy_prop" );
static const itype_id itype_test_armor_chitin_copy_rel( "test_armor_chitin_copy_rel" );
static const itype_id itype_test_armor_chitin_copy_w_armor( "test_armor_chitin_copy_w_armor" );
static const itype_id
itype_test_armor_chitin_copy_w_armor_prop( "test_armor_chitin_copy_w_armor_prop" );
static const itype_id
itype_test_armor_chitin_copy_w_armor_rel( "test_armor_chitin_copy_w_armor_rel" );
static const itype_id itype_textbook_chemistry( "textbook_chemistry" );
static const itype_id itype_tshirt( "tshirt" );
static const itype_id itype_zentai( "zentai" );
static const material_id material_wool( "wool" );
static const recipe_id recipe_pur_tablets( "pur_tablets" );
static const skill_id skill_survival( "survival" );
static const trait_id trait_ANTIFRUIT( "ANTIFRUIT" );
static const trait_id trait_CANNIBAL( "CANNIBAL" );
static const trait_id trait_WOOLALLERGY( "WOOLALLERGY" );
// ITEM INFO
// =========
//
// When looking at the description of any item in the game, the information you see comes from the
// item::info function, which calls functions like basic_info, armor_info, food_info and many others
// to build a complete string describing the item.
//
// The included info depends on:
//
// - Relevancy to current item (damage for weapons, coverage for armor, vitamins for food, etc.)
// - Including one or more appropriate iteminfo_part::PART_NAME flags in the `info` function call
//
// Color-highlighted text in item info uses a semantic markup in the code (ex. "good", "bad") that
// becomes translated to color codes for output:
//
// <bold> <color_c_white>
// <good> <color_c_green>
// <bad> <color_c_red>
// <info> <color_c_cyan>
// <stat> <color_c_light_blue>
// <num> <color_c_yellow>
// <header> <color_c_magenta>
//
// Each xxx_info function takes a std::vector<iteminfo> reference, where each line or snippet of
// info will be appended. The main item::info function assembles all these into a string.
//
// The test cases here mostly test item::info directly, using std::vector<iteminfo_parts> flags to
// request only the parts relevant to the current test.
//
// To run all the tests in this file:
//
// tests/cata_test [iteminfo]
//
// Other tags: [book], [food], [pocket], [quality], [weapon], [volume], [weight], and many others
// Call the info() function on an item with given flags, and return the formatted string.
static std::string item_info_str( const item &it, const std::vector<iteminfo_parts> &part_flags )
{
// Old captures from test_info_equals/contains, in case needed
//int encumber = i.type->armor ? i.type->armor->encumber : -1;
//int max_encumber = i.type->armor ? i.type->armor->max_encumber : -1;
//CAPTURE( encumber );
//CAPTURE( max_encumber );
//CAPTURE( i.typeId() );
//CAPTURE( i.has_flag( "FIT" ) );
//CAPTURE( i.has_flag( "VARSIZE" ) );
//CAPTURE( i.get_clothing_mod_val( clothing_mod_type_encumbrance ) );
//CAPTURE( i.get_sizing( get_avatar(), true ) );
std::vector<iteminfo> info_v;
const iteminfo_query query_v( part_flags );
it.info( info_v, &query_v, 1 );
return format_item_info( info_v, {} );
}
// Related JSON fields:
// "volume"
// "weight"
// "longest_side"
//
// Functions:
// item::basic_info
TEST_CASE( "item volume and weight", "[iteminfo][volume][weight]" )
{
clear_avatar();
item plank( "test_2x4" );
// Volume and weight are shown together, though the units may differ
std::vector<iteminfo_parts> vol_weight = { iteminfo_parts::BASE_VOLUME, iteminfo_parts::BASE_WEIGHT };
SECTION( "metric volume" ) {
override_option opt_volume( "VOLUME_UNITS", "l" );
SECTION( "metric weight" ) {
override_option opt_weight( "USE_METRIC_WEIGHTS", "kg" );
CHECK( item_info_str( plank, vol_weight ) ==
"Volume: <color_c_yellow>4.40</color> L Weight: <color_c_yellow>2.20</color> kg\n" );
}
SECTION( "imperial weight" ) {
override_option opt_weight( "USE_METRIC_WEIGHTS", "lbs" );
CHECK( item_info_str( plank, vol_weight ) ==
"Volume: <color_c_yellow>4.40</color> L Weight: <color_c_yellow>4.85</color> lbs\n" );
}
}
SECTION( "imperial volume" ) {
override_option opt_volume( "VOLUME_UNITS", "qt" );
SECTION( "metric weight" ) {
override_option opt_weight( "USE_METRIC_WEIGHTS", "kg" );
CHECK( item_info_str( plank, vol_weight ) ==
"Volume: <color_c_yellow>4.65</color> qt Weight: <color_c_yellow>2.20</color> kg\n" );
}
SECTION( "imperial weight" ) {
override_option opt_weight( "USE_METRIC_WEIGHTS", "lbs" );
CHECK( item_info_str( plank, vol_weight ) ==
"Volume: <color_c_yellow>4.65</color> qt Weight: <color_c_yellow>4.85</color> lbs\n" );
}
}
SECTION( "imperial length" ) {
override_option opt_dist( "DISTANCE_UNITS", "imperial" );
CHECK( item_info_str( plank, { iteminfo_parts::BASE_LENGTH } ) ==
"Length: <color_c_yellow>51</color> in.\n" );
}
SECTION( "metric length" ) {
override_option opt_dist( "DISTANCE_UNITS", "metric" );
CHECK( item_info_str( plank, { iteminfo_parts::BASE_LENGTH } ) ==
"Length: <color_c_yellow>130</color> cm\n" );
}
}
// Related JSON fields:
// "material"
// "category"
// "description"
//
// Functions:
// item::basic_info
TEST_CASE( "item material, category, description", "[iteminfo][material][category][description]" )
{
clear_avatar();
// TODO: Test magical focus, in-progress crafts (also part of DESCRIPTION)
std::vector<iteminfo_parts> material = { iteminfo_parts::BASE_MATERIAL };
std::vector<iteminfo_parts> category = { iteminfo_parts::BASE_CATEGORY };
std::vector<iteminfo_parts> description = { iteminfo_parts::DESCRIPTION };
SECTION( "fire ax" ) {
item axe( "test_fire_ax" );
CHECK( item_info_str( axe, material ) ==
"Material: <color_c_light_blue>Steel</color>, <color_c_light_blue>Wood</color>\n" );
CHECK( item_info_str( axe, category ) ==
"Category: <color_c_magenta>TOOLS</color>\n" );
CHECK( item_info_str( axe, description ) ==
"--\n"
"This is a large, two-handed pickhead axe normally used by firefighters."
" It makes a powerful melee weapon, but is a bit slow to recover between swings.\n" );
}
SECTION( "plank" ) {
item plank( "test_2x4" );
CHECK( item_info_str( plank, material ) ==
"Material: <color_c_light_blue>Wood</color>\n" );
CHECK( item_info_str( plank, category ) ==
"Category: <color_c_magenta>SPARE PARTS</color>\n" );
CHECK( item_info_str( plank, description ) ==
"--\n"
"A narrow, thick plank of wood, like a 2 by 4 or similar piece of dimensional lumber."
" Makes a decent melee weapon, and can be used for all kinds of construction.\n" );
}
}
// Related JSON fields:
// none
//
// Functions:
// item::basic_info
TEST_CASE( "item owner", "[iteminfo][owner]" )
{
clear_avatar();
SECTION( "item owned by player" ) {
item my_rock( "test_rock" );
my_rock.set_owner( get_player_character() );
REQUIRE_FALSE( my_rock.get_owner().is_null() );
CHECK( item_info_str( my_rock, { iteminfo_parts::BASE_OWNER } ) == "Owner: Your Followers\n" );
}
SECTION( "item with no owner" ) {
item nobodys_rock( "test_rock" );
REQUIRE( nobodys_rock.get_owner().is_null() );
CHECK( item_info_str( nobodys_rock, { iteminfo_parts::BASE_OWNER } ).empty() );
}
}
// Related JSON fields:
// "min_skills"
// "min_strength"
// "min_intelligence"
// "min_perception"
//
// Functions:
// item::basic_info
TEST_CASE( "item requirements", "[iteminfo][requirements]" )
{
// TODO:
// - get_min_str() - type->min_str with special gun/gunmod handling
// NOTE: BOOK_REQUIREMENTS_INT is separate
// NOTE: There are presently no in-game items with min_dex, min_int, or min_per
clear_avatar();
std::vector<iteminfo_parts> reqs = { iteminfo_parts::BASE_REQUIREMENTS };
item compbow( "test_compbow" );
item sonic( "test_sonic_screwdriver" );
REQUIRE( compbow.type->min_str == 6 );
CHECK( item_info_str( compbow, reqs ) ==
"--\n"
"<color_c_white>Minimum requirements</color>:\n"
"strength 6\n" );
REQUIRE( sonic.type->min_int == 9 );
REQUIRE( sonic.type->min_per == 5 );
CHECK( item_info_str( sonic, reqs ) ==
"--\n"
"<color_c_white>Minimum requirements</color>:\n"
"intelligence 9, perception 5, electronics 3, and devices 2\n" );
}
// Functions:
// item::basic_info
TEST_CASE( "item contents", "[iteminfo][contents]" )
{
clear_avatar();
// TODO: Test "Contains:", if it is still possible (couldn't find any items with it)
//std::vector<iteminfo_parts> contents = { iteminfo_parts::BASE_CONTENTS };
// Amount is shown for items having count_by_charges(), and are not food or medication
// This includes all kinds of ammo and arrows, thread, and some chemicals like sulfur.
item ammo( "test_9mm_ammo" );
std::vector<iteminfo_parts> amount = { iteminfo_parts::BASE_AMOUNT };
CHECK( item_info_str( ammo, amount ) == "--\nAmount: <color_c_yellow>50</color>\n" );
}
// Related JSON fields:
// "comestible_type": "MED":
// "quench"
// "fun"
// "stim"
// "charges" (portions)
// "addiction_potential"
//
// Functions:
// item::med_info
TEST_CASE( "med_info", "[iteminfo][med]" )
{
clear_avatar();
// Parts to test
std::vector<iteminfo_parts> quench = { iteminfo_parts::MED_QUENCH };
std::vector<iteminfo_parts> joy = { iteminfo_parts::MED_JOY };
std::vector<iteminfo_parts> stimulation = { iteminfo_parts::MED_STIMULATION };
std::vector<iteminfo_parts> portions = { iteminfo_parts::MED_PORTIONS };
std::vector<iteminfo_parts> consume_time = { iteminfo_parts::MED_CONSUME_TIME };
std::vector<iteminfo_parts> addicting = { iteminfo_parts::DESCRIPTION_MED_ADDICTING };
// Items with comestible_type "MED"
SECTION( "item that is medication shows medicinal attributes in med_info" ) {
item gum( "test_gum" );
REQUIRE( gum.is_medication() );
CHECK( item_info_str( gum, quench ) ==
"--\nQuench: <color_c_yellow>50</color>\n" );
CHECK( item_info_str( gum, joy ) ==
"--\nEnjoyability: <color_c_yellow>5</color>\n" );
CHECK( item_info_str( gum, stimulation ) ==
"--\nStimulation: <color_c_light_blue>Upper</color>\n" );
CHECK( item_info_str( gum, portions ) ==
"--\nPortions: <color_c_yellow>10</color>\n" );
CHECK( item_info_str( gum, consume_time ) ==
"--\nConsume time: 5 seconds\n" );
CHECK( item_info_str( gum, addicting ) ==
"--\n* Consuming this item is <color_c_red>addicting</color>.\n" );
}
SECTION( "item that is not medication does not show med_info" ) {
item apple( "test_apple" );
REQUIRE_FALSE( apple.is_medication() );
CHECK( item_info_str( apple, quench ).empty() );
CHECK( item_info_str( apple, joy ).empty() );
CHECK( item_info_str( apple, stimulation ).empty() );
CHECK( item_info_str( apple, portions ).empty() );
CHECK( item_info_str( apple, consume_time ).empty() );
CHECK( item_info_str( apple, addicting ).empty() );
}
}
// Related JSON fields:
// "price"
// "price_postapoc"
//
// Functions:
// item::final_info
TEST_CASE( "item price and barter value", "[iteminfo][price]" )
{
clear_avatar();
// Price and barter value are displayed together on a single line
std::vector<iteminfo_parts> price_barter = { iteminfo_parts::BASE_PRICE, iteminfo_parts::BASE_BARTER };
SECTION( "item with different price and barter value" ) {
item pipe( "test_pipe" );
REQUIRE( pipe.price( false ) == 7500 );
REQUIRE( pipe.price( true ) == 300 );
CHECK( item_info_str( pipe, price_barter ) ==
"--\n"
"Price: $<color_c_yellow>75.00</color> Barter value: $<color_c_yellow>3.00</color>\n" );
}
SECTION( "item with same price and barter value shows only price" ) {
item nuts( "test_pine_nuts" );
REQUIRE( nuts.price( false ) == 136 );
REQUIRE( nuts.price( true ) == 136 );
CHECK( item_info_str( nuts, price_barter ) ==
"--\n"
"Price: $<color_c_yellow>1.36</color>" );
}
SECTION( "item with no price or barter value" ) {
item rock( "test_rock" );
REQUIRE( rock.price( false ) == 0 );
REQUIRE( rock.price( true ) == 0 );
CHECK( item_info_str( rock, price_barter ) ==
"--\n"
"Price: $<color_c_yellow>0.00</color>" );
}
}
// Related JSON fields:
// "encumbrance"
// "max_encumbrance"
// "pocket_data"
// "coverage"
// - "rigid"
// - "max_contains_volume"
//
// Functions:
// item::armor_info
TEST_CASE( "item rigidity", "[iteminfo][rigidity]" )
{
clear_avatar();
// Rigidity and encumbrance are related; non-rigid items have flexible encumbrance.
std::vector<iteminfo_parts> rigidity = { iteminfo_parts::BASE_RIGIDITY };
std::vector<iteminfo_parts> encumbrance = { iteminfo_parts::ARMOR_ENCUMBRANCE };
SECTION( "items with rigid pockets have a single encumbrance value" ) {
item briefcase( "test_briefcase" );
REQUIRE( briefcase.all_pockets_rigid() );
CHECK( item_info_str( briefcase, encumbrance ) ==
"--\n"
"<color_c_white>Encumbrance</color>"
" <color_c_yellow>30</color>: The <color_c_cyan>arms</color>. The <color_c_cyan>hands</color>.\n" );
}
SECTION( "non-rigid items indicate their flexible volume/encumbrance" ) {
item waterskin( "test_waterskin" );
item backpack( "test_backpack" );
item quiver( "test_quiver" );
item condom( "test_condom" );
SECTION( "rigidity indicator" ) {
REQUIRE_FALSE( waterskin.all_pockets_rigid() );
REQUIRE_FALSE( backpack.all_pockets_rigid() );
REQUIRE_FALSE( quiver.all_pockets_rigid() );
REQUIRE_FALSE( condom.all_pockets_rigid() );
CHECK( item_info_str( waterskin, rigidity ) ==
"--\n"
"* This items pockets are <color_c_cyan>not rigid</color>."
" Its volume and encumbrance increase with contents.\n" );
CHECK( item_info_str( backpack, rigidity ) ==
"--\n"
"* This items pockets are <color_c_cyan>not rigid</color>."
" Its volume and encumbrance increase with contents.\n" );
CHECK( item_info_str( quiver, rigidity ) ==
"--\n"
"* This items pockets are <color_c_cyan>not rigid</color>."
" Its volume and encumbrance increase with contents.\n" );
// Non-armor item - volume increases, but not encumbrance
CHECK( item_info_str( condom, rigidity ) ==
"--\n"
"* This items pockets are <color_c_cyan>not rigid</color>."
" Its volume increases with contents.\n" );
}
SECTION( "encumbrance when empty and full" ) {
// test_waterskin does not define "encumbrance" or "max_encumbrance", so base
// encumbrance is 0, and max_encumbrance is set by the item factory (finalize_post)
// based on the pocket "max_contains_volume" (1 encumbrance per 250 ml).
CHECK( item_info_str( waterskin, encumbrance ) ==
"--\n"
"<color_c_white>Encumbrance</color>"
" <color_c_yellow>0</color>, When full <color_c_yellow>6</color>: The <color_c_cyan>legs</color>.\n" );
// test_backpack has an explicit "encumbrance" and "max_encumbrance"
CHECK( item_info_str( backpack, encumbrance ) ==
"--\n"
"<color_c_white>Encumbrance</color>"
" <color_c_yellow>2</color>, When full <color_c_yellow>15</color>: The <color_c_cyan>torso</color>.\n" );
// quiver has no volume, only an implicit volume via ammo
CHECK( item_info_str( quiver, encumbrance ) ==
"--\n"
"<color_c_white>Encumbrance</color>"
" <color_c_yellow>3</color>, When full <color_c_yellow>11</color>: The <color_c_cyan>legs</color>.\n" );
}
}
}
// Related JSON fields:
// "bashing"
// "cutting"
// "to_hit"
//
// Functions:
// item::combat_info
TEST_CASE( "weapon attack ratings and moves", "[iteminfo][weapon]" )
{
clear_avatar();
Character &player_character = get_player_character();
// new DPS calculations depend on the avatar's stats, so make sure they're consistent
REQUIRE( player_character.get_str() == 8 );
REQUIRE( player_character.get_dex() == 8 );
item rag( "test_rag" );
item rock( "test_rock" );
item halligan( "test_halligan" );
item mr_pointy( "test_pointy_stick" );
item arrow( "test_arrow_wood" );
SECTION( "melee damage" ) {
// Melee damage comes from the "bashing" and "cutting" attributes in JSON
// NOTE: BASE_DAMAGE info has no newline, since BASE_TOHIT always follows it
std::vector<iteminfo_parts> damage = { iteminfo_parts::BASE_DAMAGE };
SECTION( "no damage" ) {
CHECK( item_info_str( rag, damage ).empty() );
}
SECTION( "bash" ) {
CHECK( item_info_str( rock, damage ) ==
"--\n"
"<color_c_white>Melee damage</color>:"
" Bash: <color_c_yellow>7</color>" );
}
SECTION( "bash and cut" ) {
CHECK( item_info_str( halligan, damage ) ==
"--\n"
"<color_c_white>Melee damage</color>:"
" Bash: <color_c_yellow>20</color>"
" Cut: <color_c_yellow>5</color>" );
}
SECTION( "bash and pierce" ) {
// Pierce damage comes from "cut" value, if item has the STAB or SPEAR flag
REQUIRE( mr_pointy.has_flag( flag_SPEAR ) );
CHECK( item_info_str( mr_pointy, damage ) ==
"--\n"
"<color_c_white>Melee damage</color>:"
" Bash: <color_c_yellow>5</color>"
" Pierce: <color_c_yellow>9</color>" );
}
SECTION( "bash and cut (ranged ammo)" ) {
CHECK( item_info_str( arrow, damage ) ==
"--\n"
"<color_c_white>Melee damage</color>:"
" Bash: <color_c_yellow>2</color>"
" Cut: <color_c_yellow>1</color>" );
}
}
SECTION( "to-hit rating" ) {
// To-hit rating comes from the "to_hit" attribute in the item's JSON.
std::vector<iteminfo_parts> to_hit = { iteminfo_parts::BASE_TOHIT };
CHECK( item_info_str( rock, to_hit ) ==
"--\n"
" To-hit bonus: <color_c_yellow>-2</color>\n" );
CHECK( item_info_str( halligan, to_hit ) ==
"--\n"
" To-hit bonus: <color_c_yellow>+2</color>\n" );
CHECK( item_info_str( mr_pointy, to_hit ) ==
"--\n"
" To-hit bonus: <color_c_yellow>-1</color>\n" );
CHECK( item_info_str( arrow, to_hit ) ==
"--\n"
" To-hit bonus: <color_c_yellow>+0</color>\n" );
}
SECTION( "base moves" ) {
// Moves are calculated in item::attack_time based on item volume, weight, and count.
// Those calculations are outside the scope of these tests, but we can at least ensure
// they have expected values before checking the item info string.
// If one of these fails, it suggests attack_time() changed:
REQUIRE( rock.attack_time() == 79 );
REQUIRE( halligan.attack_time() == 145 );
REQUIRE( mr_pointy.attack_time() == 100 );
REQUIRE( arrow.attack_time() == 65 );
std::vector<iteminfo_parts> moves = { iteminfo_parts::BASE_MOVES };
CHECK( item_info_str( rock, moves ) ==
"--\n"
"Base moves per attack: <color_c_yellow>79</color>\n" );
CHECK( item_info_str( halligan, moves ) ==
"--\n"
"Base moves per attack: <color_c_yellow>145</color>\n" );
CHECK( item_info_str( mr_pointy, moves ) ==
"--\n"
"Base moves per attack: <color_c_yellow>100</color>\n" );
CHECK( item_info_str( arrow, moves ) ==
"--\n"
"Base moves per attack: <color_c_yellow>65</color>\n" );
}
SECTION( "base damage per second" ) {
// Damage per second is dynamically calculated in item::dps and item::effective_dps based on
// many different factors, all outside the scope of these tests. Here we just hope they
// have the expected values in the item info summary.
std::vector<iteminfo_parts> dps = { iteminfo_parts::BASE_DPS };
CHECK( item_info_str( rock, dps ) ==
"--\n"
"Typical damage per second:\n"
"Best: <color_c_yellow>4.92</color>"
" Vs. Agile: <color_c_yellow>2.05</color>"
" Vs. Armored: <color_c_yellow>0.15</color>\n" );
CHECK( item_info_str( halligan, dps ) ==
"--\n"
"Typical damage per second:\n"
"Best: <color_c_yellow>9.38</color>"
" Vs. Agile: <color_c_yellow>5.74</color>"
" Vs. Armored: <color_c_yellow>2.84</color>\n" );
CHECK( item_info_str( mr_pointy, dps ) ==
"--\n"
"Typical damage per second:\n"
"Best: <color_c_yellow>6.87</color>"
" Vs. Agile: <color_c_yellow>3.20</color>"
" Vs. Armored: <color_c_yellow>0.12</color>\n" );
CHECK( item_info_str( arrow, dps ) ==
"--\n"
"Typical damage per second:\n"
"Best: <color_c_yellow>4.90</color>"
" Vs. Agile: <color_c_yellow>2.46</color>"
" Vs. Armored: <color_c_yellow>0.00</color>\n" );
}
SECTION( "stamina per swing" ) {
// Stamina cost per swing is dynamically calculated based on many different
// factors, all outside the scope of these tests. Here we just hope they
// have the expected values in the item info summary.
std::vector<iteminfo_parts> stam = { iteminfo_parts::BASE_STAMINA };
CHECK( item_info_str( rock, stam ) ==
"--\n"
"<color_c_white>Stamina use</color>:"
" Costs about <color_c_yellow>1.00</color>%"
" stamina to swing.\n" );
CHECK( item_info_str( halligan, stam ) ==
"--\n"
"<color_c_white>Stamina use</color>:"
" Costs about <color_c_yellow>3.10</color>%"
" stamina to swing.\n" );
CHECK( item_info_str( mr_pointy, stam ) ==
"--\n"
"<color_c_white>Stamina use</color>:"
" Costs about <color_c_yellow>1.20</color>%"
" stamina to swing.\n" );
CHECK( item_info_str( arrow, stam ) ==
"--\n"
"<color_c_white>Stamina use</color>:"
" Costs about <color_c_yellow>0.70</color>%"
" stamina to swing.\n" );
}
SECTION( "base damage per stamina" ) {
// Damage per stamina is dynamically calculated based on many different factors,
// all outside the scope of these tests. Here we just hope they
// have the expected values in the item info summary.
std::vector<iteminfo_parts> dpstam = { iteminfo_parts::BASE_DPSTAM };
CHECK( item_info_str( rock, dpstam ) ==
"--\n"
"Typical damage per stamina:\n"
"Best: <color_c_yellow>5.41</color>"
" Vs. Agile: <color_c_yellow>2.25</color>"
" Vs. Armored: <color_c_yellow>0.16</color>\n" );
CHECK( item_info_str( halligan, dpstam ) ==
"--\n"
"Typical damage per stamina:\n"
"Best: <color_c_yellow>3.41</color>"
" Vs. Agile: <color_c_yellow>2.09</color>"
" Vs. Armored: <color_c_yellow>1.03</color>\n" );
CHECK( item_info_str( mr_pointy, dpstam ) ==
"--\n"
"Typical damage per stamina:\n"
"Best: <color_c_yellow>6.48</color>"
" Vs. Agile: <color_c_yellow>3.02</color>"
" Vs. Armored: <color_c_yellow>0.11</color>\n" );
CHECK( item_info_str( arrow, dpstam ) ==
"--\n"
"Typical damage per stamina:\n"
"Best: <color_c_yellow>7.21</color>"
" Vs. Agile: <color_c_yellow>3.62</color>"
" Vs. Armored: <color_c_yellow>0.00</color>\n" );
}
}
// Related JSON fields:
// "techniques" - list of technique ids, ex. [ "WBLOCK_1", "BRUTAL", "SWEEP" ]
//
// Technique descriptions are defined in data/json/techniques.json
//
// Functions:
// item::combat_info
TEST_CASE( "techniques when wielded", "[iteminfo][weapon][techniques]" )
{
clear_avatar();
item halligan( "test_halligan" );
CHECK( item_info_str( halligan, { iteminfo_parts::DESCRIPTION_TECHNIQUES } ) ==
"--\n"
"<color_c_white>Techniques when wielded</color>:"
" <color_c_light_blue>Brutal Strike</color>:"
" <color_c_cyan>Stun 1 turn, knockback 1 tile, crit only</color>,"
" <color_c_light_blue>Sweep Attack</color>:"
" <color_c_cyan>Down 2 turns</color>, and"
" <color_c_light_blue>Block</color>:"
" <color_c_cyan>Medium blocking ability</color>\n" );
item plank( "test_2x4" );
CHECK( item_info_str( plank, { iteminfo_parts::DESCRIPTION_TECHNIQUES } ) ==
"--\n"
"<color_c_white>Techniques when wielded</color>:"
" <color_c_light_blue>Block</color>:"
" <color_c_cyan>Medium blocking ability</color>\n" );
}
static std::vector<bodypart_id> bodyparts_to_check()
{
return {
bodypart_id( "torso" ),
bodypart_id( "arm_l" ),
bodypart_id( "arm_r" ),
bodypart_id( "leg_l" ),
bodypart_id( "leg_r" ),
bodypart_id( "hand_l" ),
bodypart_id( "hand_r" ),
bodypart_id( "head" ),
bodypart_id( "mouth" ),
bodypart_id( "foot_l" ),
bodypart_id( "foot_r" ),
};
}
static void verify_item_coverage( const item &i, const std::map<bodypart_id, int> &expected )
{
CAPTURE( i.typeId() );
REQUIRE( i.get_covered_body_parts().any() );
for( const bodypart_id &bp : bodyparts_to_check() ) {
CAPTURE( bp.id() );
REQUIRE( i.get_coverage( bp ) == expected.at( bp ) );
}
}
static void verify_item_encumbrance( const item &i, item::encumber_flags flags, int average,
const std::map<bodypart_id, int> &expected )
{
CAPTURE( i.typeId() );
REQUIRE( i.get_avg_encumber( get_player_character(), flags ) == average );
for( const bodypart_id &bp : bodyparts_to_check() ) {
CAPTURE( bp.id() );
REQUIRE( i.get_encumber( get_player_character(), bp, flags ) == expected.at( bp ) );
}
}
// Related JSON fields:
// "covers"
// "coverage"
// "warmth"
// "encumbrance"
//
// Functions:
// item::armor_info
TEST_CASE( "armor coverage, warmth, and encumbrance", "[iteminfo][armor][coverage]" )
{
clear_avatar();
SECTION( "armor with coverage shows covered body parts, warmth, encumbrance, and protection values" ) {
// Long-sleeved shirt covering torso and arms
item longshirt( "test_longshirt" );
verify_item_coverage(
longshirt, {
{ bodypart_id( "torso" ), 90 },
{ bodypart_id( "arm_l" ), 90 },
{ bodypart_id( "arm_r" ), 90 },
{ bodypart_id( "leg_l" ), 0 },
{ bodypart_id( "leg_r" ), 0 },
{ bodypart_id( "hand_l" ), 0 },
{ bodypart_id( "hand_r" ), 0 },
{ bodypart_id( "head" ), 0 },
{ bodypart_id( "mouth" ), 0 },
{ bodypart_id( "foot_l" ), 0 },
{ bodypart_id( "foot_r" ), 0 },
}
);
CHECK( item_info_str( longshirt, { iteminfo_parts::ARMOR_BODYPARTS } ) ==
"--\n"
"<color_c_white>Covers</color>:"
" The <color_c_cyan>arms</color>."
" The <color_c_cyan>torso</color>.\n" );
// Coverage and warmth are displayed together on a single line
std::vector<iteminfo_parts> cov_warm_shirt = {
iteminfo_parts::ARMOR_COVERAGE, iteminfo_parts::ARMOR_WARMTH
};
REQUIRE( longshirt.get_avg_coverage() == 90 );
REQUIRE( longshirt.get_warmth() == 5 );
CHECK( item_info_str( longshirt, cov_warm_shirt )
==
"--\n"
"<color_c_white>Total Coverage</color>"
" <color_c_yellow>90</color>%: The <color_c_cyan>arms</color>. The <color_c_cyan>torso</color>.\n"
"<color_c_white>Warmth</color>"
" <color_c_yellow>5</color>: The <color_c_cyan>arms</color>. The <color_c_cyan>torso</color>.\n" );
verify_item_encumbrance(
longshirt, item::encumber_flags::none, 3, {
{ bodypart_id( "torso" ), 3 },
{ bodypart_id( "arm_l" ), 3 },
{ bodypart_id( "arm_r" ), 3 },
{ bodypart_id( "leg_l" ), 0 },
{ bodypart_id( "leg_r" ), 0 },
{ bodypart_id( "hand_l" ), 0 },
{ bodypart_id( "hand_r" ), 0 },
{ bodypart_id( "head" ), 0 },
{ bodypart_id( "mouth" ), 0 },
{ bodypart_id( "foot_l" ), 0 },
{ bodypart_id( "foot_r" ), 0 },
}
);
verify_item_encumbrance(
longshirt, item::encumber_flags::assume_full, 3, {
{ bodypart_id( "torso" ), 3 },
{ bodypart_id( "arm_l" ), 3 },
{ bodypart_id( "arm_r" ), 3 },
{ bodypart_id( "leg_l" ), 0 },
{ bodypart_id( "leg_r" ), 0 },
{ bodypart_id( "hand_l" ), 0 },
{ bodypart_id( "hand_r" ), 0 },
{ bodypart_id( "head" ), 0 },
{ bodypart_id( "mouth" ), 0 },
{ bodypart_id( "foot_l" ), 0 },
{ bodypart_id( "foot_r" ), 0 },
}
);
CHECK( item_info_str( longshirt, { iteminfo_parts::ARMOR_ENCUMBRANCE } ) ==
"--\n"
"<color_c_white>Size/Fit</color>: <color_c_red>(poor fit)</color>\n"
"<color_c_white>Encumbrance</color>"
" <color_c_yellow>3</color>: The <color_c_cyan>arms</color>. The <color_c_cyan>torso</color>.\n" );
item swat_armor( "test_swat_armor" );
REQUIRE( swat_armor.get_covered_body_parts().any() );
CHECK( item_info_str( swat_armor, { iteminfo_parts::ARMOR_BODYPARTS } ) ==
"--\n"
"<color_c_white>Covers</color>:"
" The <color_c_cyan>arms</color>."
" The <color_c_cyan>legs</color>."
" The <color_c_cyan>torso</color>.\n" );
std::vector<iteminfo_parts> cov_warm_swat = { iteminfo_parts::ARMOR_COVERAGE, iteminfo_parts::ARMOR_WARMTH };
REQUIRE( swat_armor.get_avg_coverage() == 95 );
REQUIRE( swat_armor.get_warmth() == 35 );
CHECK( item_info_str( swat_armor, cov_warm_swat )
==
"--\n"
"<color_c_white>Total Coverage</color>"
" <color_c_yellow>95</color>%: The <color_c_cyan>arms</color>. The <color_c_cyan>legs</color>. The <color_c_cyan>torso</color>.\n"
"<color_c_white>Warmth</color>"
" <color_c_yellow>35</color>: The <color_c_cyan>arms</color>. The <color_c_cyan>legs</color>. The <color_c_cyan>torso</color>.\n" );
verify_item_coverage(
swat_armor, {
{ bodypart_id( "torso" ), 95 },
{ bodypart_id( "leg_l" ), 95 },
{ bodypart_id( "leg_r" ), 95 },
{ bodypart_id( "arm_l" ), 95 },
{ bodypart_id( "arm_r" ), 95 },
{ bodypart_id( "head" ), 0 },
{ bodypart_id( "foot_l" ), 0 },
{ bodypart_id( "foot_r" ), 0 },
{ bodypart_id( "eyes" ), 0 },
{ bodypart_id( "mouth" ), 0 },
{ bodypart_id( "hand_r" ), 0 },
{ bodypart_id( "hand_l" ), 0 },
}
);
verify_item_encumbrance(
swat_armor, item::encumber_flags::none, 12, {
{ bodypart_id( "torso" ), 12 },
{ bodypart_id( "leg_l" ), 12 },
{ bodypart_id( "leg_r" ), 12 },
{ bodypart_id( "arm_l" ), 12 },
{ bodypart_id( "arm_r" ), 12 },
{ bodypart_id( "head" ), 0 },
{ bodypart_id( "foot_l" ), 0 },
{ bodypart_id( "foot_r" ), 0 },
{ bodypart_id( "eyes" ), 0 },
{ bodypart_id( "mouth" ), 0 },
{ bodypart_id( "hand_l" ), 0 },
{ bodypart_id( "hand_r" ), 0 },
}
);
verify_item_encumbrance(
swat_armor, item::encumber_flags::assume_full, 25, {
{ bodypart_id( "torso" ), 25 },
{ bodypart_id( "leg_l" ), 25 },
{ bodypart_id( "leg_r" ), 25 },
{ bodypart_id( "arm_l" ), 25 },
{ bodypart_id( "arm_r" ), 25 },
{ bodypart_id( "foot_l" ), 0 },
{ bodypart_id( "foot_r" ), 0 },
{ bodypart_id( "head" ), 0 },
{ bodypart_id( "eyes" ), 0 },
{ bodypart_id( "mouth" ), 0 },
{ bodypart_id( "hand_l" ), 0 },
{ bodypart_id( "hand_r" ), 0 },
}
);
CHECK( item_info_str( swat_armor, { iteminfo_parts::ARMOR_ENCUMBRANCE } ) ==
"--\n"
"<color_c_white>Encumbrance</color> "
" <color_c_yellow>12</color>, When full <color_c_yellow>25</color>:"
" The <color_c_cyan>arms</color>."
" The <color_c_cyan>legs</color>."
" The <color_c_cyan>torso</color>.\n" );
// Test copy-from
item faux_fur_pants( "test_pants_faux_fur" );
REQUIRE( faux_fur_pants.get_covered_body_parts().any() );
CHECK( item_info_str( faux_fur_pants, { iteminfo_parts::ARMOR_BODYPARTS } ) ==
"--\n"
"<color_c_white>Covers</color>:"
" The <color_c_cyan>legs</color>.\n" );
std::vector<iteminfo_parts> cov_warm_pants = { iteminfo_parts::ARMOR_COVERAGE, iteminfo_parts::ARMOR_WARMTH };
REQUIRE( faux_fur_pants.get_avg_coverage() == 95 );
REQUIRE( faux_fur_pants.get_warmth() == 70 );
CHECK( item_info_str( faux_fur_pants, cov_warm_pants )
==
"--\n"
"<color_c_white>Total Coverage</color> <color_c_yellow>95</color>%: The <color_c_cyan>legs</color>.\n"
"<color_c_white>Warmth</color> <color_c_yellow>70</color>: The <color_c_cyan>legs</color>.\n" );
REQUIRE( faux_fur_pants.get_avg_coverage() == 95 );
verify_item_coverage(
faux_fur_pants, {
{ bodypart_id( "torso" ), 0 },
{ bodypart_id( "leg_l" ), 95 },
{ bodypart_id( "leg_r" ), 95 },
{ bodypart_id( "arm_l" ), 0 },
{ bodypart_id( "arm_r" ), 0 },
{ bodypart_id( "foot_r" ), 0 },
{ bodypart_id( "foot_l" ), 0 },
{ bodypart_id( "head" ), 0 },
{ bodypart_id( "eyes" ), 0 },
{ bodypart_id( "mouth" ), 0 },
{ bodypart_id( "hand_l" ), 0 },
{ bodypart_id( "hand_r" ), 0 },
}
);
verify_item_encumbrance(
faux_fur_pants, item::encumber_flags::none, 16, {
{ bodypart_id( "torso" ), 0 },
{ bodypart_id( "leg_l" ), 16 },
{ bodypart_id( "leg_r" ), 16 },
{ bodypart_id( "arm_l" ), 0 },
{ bodypart_id( "arm_r" ), 0 },
{ bodypart_id( "foot_r" ), 0 },
{ bodypart_id( "foot_l" ), 0 },
{ bodypart_id( "head" ), 0 },
{ bodypart_id( "eyes" ), 0 },
{ bodypart_id( "mouth" ), 0 },
{ bodypart_id( "hand_l" ), 0 },
{ bodypart_id( "hand_r" ), 0 },
}
);
verify_item_encumbrance(
faux_fur_pants, item::encumber_flags::assume_full, 20, {
{ bodypart_id( "torso" ), 0 },
{ bodypart_id( "leg_l" ), 20 },
{ bodypart_id( "leg_r" ), 20 },
{ bodypart_id( "arm_l" ), 0 },
{ bodypart_id( "arm_r" ), 0 },
{ bodypart_id( "foot_r" ), 0 },
{ bodypart_id( "foot_l" ), 0 },
{ bodypart_id( "head" ), 0 },
{ bodypart_id( "eyes" ), 0 },
{ bodypart_id( "mouth" ), 0 },
{ bodypart_id( "hand_l" ), 0 },
{ bodypart_id( "hand_r" ), 0 },
}
);