-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
mapdata.cpp
1401 lines (1212 loc) · 49.1 KB
/
mapdata.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 "mapdata.h"
#include <algorithm>
#include <cstdlib>
#include <iterator>
#include <map>
#include <memory>
#include <unordered_map>
#include <utility>
#include "assign.h"
#include "calendar.h"
#include "character.h"
#include "color.h"
#include "debug.h"
#include "enum_conversions.h"
#include "generic_factory.h"
#include "harvest.h"
#include "iexamine.h"
#include "iexamine_actors.h"
#include "item_group.h"
#include "iteminfo_query.h"
#include "json.h"
#include "mod_manager.h"
#include "output.h"
#include "rng.h"
#include "string_formatter.h"
#include "translations.h"
#include "trap.h"
#include "type_id.h"
static furn_id f_null;
static const furn_str_id furn_f_null( "f_null" );
static const item_group_id Item_spawn_data_EMPTY_GROUP( "EMPTY_GROUP" );
static const skill_id skill_survival( "survival" );
namespace
{
generic_factory<ter_t> terrain_data( "terrain" );
generic_factory<furn_t> furniture_data( "furniture" );
} // namespace
/** @relates int_id */
template<>
inline bool int_id<ter_t>::is_valid() const
{
return terrain_data.is_valid( *this );
}
/** @relates int_id */
template<>
const ter_t &int_id<ter_t>::obj() const
{
return terrain_data.obj( *this );
}
/** @relates int_id */
template<>
const string_id<ter_t> &int_id<ter_t>::id() const
{
return terrain_data.convert( *this );
}
/** @relates int_id */
template<>
int_id<ter_t> string_id<ter_t>::id() const
{
return terrain_data.convert( *this, t_null );
}
/** @relates int_id */
template<>
int_id<ter_t>::int_id( const string_id<ter_t> &id ) : _id( id.id() )
{
}
/** @relates string_id */
template<>
const ter_t &string_id<ter_t>::obj() const
{
return terrain_data.obj( *this );
}
/** @relates string_id */
template<>
bool string_id<ter_t>::is_valid() const
{
return terrain_data.is_valid( *this );
}
/** @relates int_id */
template<>
bool int_id<furn_t>::is_valid() const
{
return furniture_data.is_valid( *this );
}
/** @relates int_id */
template<>
const furn_t &int_id<furn_t>::obj() const
{
return furniture_data.obj( *this );
}
/** @relates int_id */
template<>
const string_id<furn_t> &int_id<furn_t>::id() const
{
return furniture_data.convert( *this );
}
/** @relates string_id */
template<>
bool string_id<furn_t>::is_valid() const
{
return furniture_data.is_valid( *this );
}
/** @relates string_id */
template<>
const furn_t &string_id<furn_t>::obj() const
{
return furniture_data.obj( *this );
}
/** @relates string_id */
template<>
int_id<furn_t> string_id<furn_t>::id() const
{
return furniture_data.convert( *this, f_null );
}
/** @relates int_id */
template<>
int_id<furn_t>::int_id( const string_id<furn_t> &id ) : _id( id.id() )
{
}
namespace io
{
template<>
std::string enum_to_string<ter_furn_flag>( ter_furn_flag data )
{
// see mapdata.h for commentary
switch( data ) {
// *INDENT-OFF*
case ter_furn_flag::TFLAG_TRANSPARENT: return "TRANSPARENT";
case ter_furn_flag::TFLAG_FLAMMABLE: return "FLAMMABLE";
case ter_furn_flag::TFLAG_REDUCE_SCENT: return "REDUCE_SCENT";
case ter_furn_flag::TFLAG_SWIMMABLE: return "SWIMMABLE";
case ter_furn_flag::TFLAG_SUPPORTS_ROOF: return "SUPPORTS_ROOF";
case ter_furn_flag::TFLAG_MINEABLE: return "MINEABLE";
case ter_furn_flag::TFLAG_NOITEM: return "NOITEM";
case ter_furn_flag::TFLAG_NO_SIGHT: return "NO_SIGHT";
case ter_furn_flag::TFLAG_NO_SCENT: return "NO_SCENT";
case ter_furn_flag::TFLAG_SEALED: return "SEALED";
case ter_furn_flag::TFLAG_ALLOW_FIELD_EFFECT: return "ALLOW_FIELD_EFFECT";
case ter_furn_flag::TFLAG_LIQUID: return "LIQUID";
case ter_furn_flag::TFLAG_COLLAPSES: return "COLLAPSES";
case ter_furn_flag::TFLAG_FLAMMABLE_ASH: return "FLAMMABLE_ASH";
case ter_furn_flag::TFLAG_DESTROY_ITEM: return "DESTROY_ITEM";
case ter_furn_flag::TFLAG_INDOORS: return "INDOORS";
case ter_furn_flag::TFLAG_LIQUIDCONT: return "LIQUIDCONT";
case ter_furn_flag::TFLAG_FIRE_CONTAINER: return "FIRE_CONTAINER";
case ter_furn_flag::TFLAG_FLAMMABLE_HARD: return "FLAMMABLE_HARD";
case ter_furn_flag::TFLAG_SUPPRESS_SMOKE: return "SUPPRESS_SMOKE";
case ter_furn_flag::TFLAG_SHARP: return "SHARP";
case ter_furn_flag::TFLAG_DIGGABLE: return "DIGGABLE";
case ter_furn_flag::TFLAG_ROUGH: return "ROUGH";
case ter_furn_flag::TFLAG_UNSTABLE: return "UNSTABLE";
case ter_furn_flag::TFLAG_WALL: return "WALL";
case ter_furn_flag::TFLAG_DEEP_WATER: return "DEEP_WATER";
case ter_furn_flag::TFLAG_SHALLOW_WATER: return "SHALLOW_WATER";
case ter_furn_flag::TFLAG_WATER_CUBE: return "WATER_CUBE";
case ter_furn_flag::TFLAG_CURRENT: return "CURRENT";
case ter_furn_flag::TFLAG_HARVESTED: return "HARVESTED";
case ter_furn_flag::TFLAG_PERMEABLE: return "PERMEABLE";
case ter_furn_flag::TFLAG_AUTO_WALL_SYMBOL: return "AUTO_WALL_SYMBOL";
case ter_furn_flag::TFLAG_CONNECT_WITH_WALL: return "CONNECT_WITH_WALL";
case ter_furn_flag::TFLAG_CLIMBABLE: return "CLIMBABLE";
case ter_furn_flag::TFLAG_GOES_DOWN: return "GOES_DOWN";
case ter_furn_flag::TFLAG_GOES_UP: return "GOES_UP";
case ter_furn_flag::TFLAG_NO_FLOOR: return "NO_FLOOR";
case ter_furn_flag::TFLAG_ALLOW_ON_OPEN_AIR: return "ALLOW_ON_OPEN_AIR";
case ter_furn_flag::TFLAG_SEEN_FROM_ABOVE: return "SEEN_FROM_ABOVE";
case ter_furn_flag::TFLAG_RAMP_DOWN: return "RAMP_DOWN";
case ter_furn_flag::TFLAG_RAMP_UP: return "RAMP_UP";
case ter_furn_flag::TFLAG_RAMP: return "RAMP";
case ter_furn_flag::TFLAG_HIDE_PLACE: return "HIDE_PLACE";
case ter_furn_flag::TFLAG_BLOCK_WIND: return "BLOCK_WIND";
case ter_furn_flag::TFLAG_FLAT: return "FLAT";
case ter_furn_flag::TFLAG_RAIL: return "RAIL";
case ter_furn_flag::TFLAG_THIN_OBSTACLE: return "THIN_OBSTACLE";
case ter_furn_flag::TFLAG_SMALL_PASSAGE: return "SMALL_PASSAGE";
case ter_furn_flag::TFLAG_Z_TRANSPARENT: return "Z_TRANSPARENT";
case ter_furn_flag::TFLAG_SUN_ROOF_ABOVE: return "SUN_ROOF_ABOVE";
case ter_furn_flag::TFLAG_FUNGUS: return "FUNGUS";
case ter_furn_flag::TFLAG_LOCKED: return "LOCKED";
case ter_furn_flag::TFLAG_PICKABLE: return "PICKABLE";
case ter_furn_flag::TFLAG_WINDOW: return "WINDOW";
case ter_furn_flag::TFLAG_DOOR: return "DOOR";
case ter_furn_flag::TFLAG_SHRUB: return "SHRUB";
case ter_furn_flag::TFLAG_YOUNG: return "YOUNG";
case ter_furn_flag::TFLAG_PLANT: return "PLANT";
case ter_furn_flag::TFLAG_FISHABLE: return "FISHABLE";
case ter_furn_flag::TFLAG_TREE: return "TREE";
case ter_furn_flag::TFLAG_PLOWABLE: return "PLOWABLE";
case ter_furn_flag::TFLAG_ORGANIC: return "ORGANIC";
case ter_furn_flag::TFLAG_CONSOLE: return "CONSOLE";
case ter_furn_flag::TFLAG_PLANTABLE: return "PLANTABLE";
case ter_furn_flag::TFLAG_GROWTH_HARVEST: return "GROWTH_HARVEST";
case ter_furn_flag::TFLAG_GROWTH_OVERGROWN: return "GROWTH_OVERGROWN";
case ter_furn_flag::TFLAG_MOUNTABLE: return "MOUNTABLE";
case ter_furn_flag::TFLAG_RAMP_END: return "RAMP_END";
case ter_furn_flag::TFLAG_FLOWER: return "FLOWER";
case ter_furn_flag::TFLAG_CAN_SIT: return "CAN_SIT";
case ter_furn_flag::TFLAG_FLAT_SURF: return "FLAT_SURF";
case ter_furn_flag::TFLAG_BUTCHER_EQ: return "BUTCHER_EQ";
case ter_furn_flag::TFLAG_GROWTH_SEEDLING: return "GROWTH_SEEDLING";
case ter_furn_flag::TFLAG_GROWTH_MATURE: return "GROWTH_MATURE";
case ter_furn_flag::TFLAG_WORKOUT_ARMS: return "WORKOUT_ARMS";
case ter_furn_flag::TFLAG_WORKOUT_LEGS: return "WORKOUT_LEGS";
case ter_furn_flag::TFLAG_TRANSLOCATOR: return "TRANSLOCATOR";
case ter_furn_flag::TFLAG_AUTODOC: return "AUTODOC";
case ter_furn_flag::TFLAG_AUTODOC_COUCH: return "AUTODOC_COUCH";
case ter_furn_flag::TFLAG_OPENCLOSE_INSIDE: return "OPENCLOSE_INSIDE";
case ter_furn_flag::TFLAG_SALT_WATER: return "SALT_WATER";
case ter_furn_flag::TFLAG_PLACE_ITEM: return "PLACE_ITEM";
case ter_furn_flag::TFLAG_BARRICADABLE_WINDOW_CURTAINS: return "BARRICADABLE_WINDOW_CURTAINS";
case ter_furn_flag::TFLAG_CLIMB_SIMPLE: return "CLIMB_SIMPLE";
case ter_furn_flag::TFLAG_NANOFAB_TABLE: return "NANOFAB_TABLE";
case ter_furn_flag::TFLAG_ROAD: return "ROAD";
case ter_furn_flag::TFLAG_TINY: return "TINY";
case ter_furn_flag::TFLAG_SHORT: return "SHORT";
case ter_furn_flag::TFLAG_NOCOLLIDE: return "NOCOLLIDE";
case ter_furn_flag::TFLAG_BARRICADABLE_DOOR: return "BARRICADABLE_DOOR";
case ter_furn_flag::TFLAG_BARRICADABLE_DOOR_DAMAGED: return "BARRICADABLE_DOOR_DAMAGED";
case ter_furn_flag::TFLAG_BARRICADABLE_DOOR_REINFORCED: return "BARRICADABLE_DOOR_REINFORCED";
case ter_furn_flag::TFLAG_USABLE_FIRE: return "USABLE_FIRE";
case ter_furn_flag::TFLAG_CONTAINER: return "CONTAINER";
case ter_furn_flag::TFLAG_NO_PICKUP_ON_EXAMINE: return "NO_PICKUP_ON_EXAMINE";
case ter_furn_flag::TFLAG_RUBBLE: return "RUBBLE";
case ter_furn_flag::TFLAG_DIGGABLE_CAN_DEEPEN: return "DIGGABLE_CAN_DEEPEN";
case ter_furn_flag::TFLAG_PIT_FILLABLE: return "PIT_FILLABLE";
case ter_furn_flag::TFLAG_DIFFICULT_Z: return "DIFFICULT_Z";
case ter_furn_flag::TFLAG_ALIGN_WORKBENCH: return "ALIGN_WORKBENCH";
case ter_furn_flag::TFLAG_NO_SPOIL: return "NO_SPOIL";
case ter_furn_flag::TFLAG_EASY_DECONSTRUCT: return "EASY_DECONSTRUCT";
case ter_furn_flag::TFLAG_LADDER: return "LADDER";
case ter_furn_flag::TFLAG_ALARMED: return "ALARMED";
case ter_furn_flag::TFLAG_CHOCOLATE: return "CHOCOLATE";
case ter_furn_flag::TFLAG_SIGN: return "SIGN";
case ter_furn_flag::TFLAG_SIGN_ALWAYS: return "SIGN_ALWAYS";
case ter_furn_flag::TFLAG_DONT_REMOVE_ROTTEN: return "DONT_REMOVE_ROTTEN";
case ter_furn_flag::TFLAG_BLOCKSDOOR: return "BLOCKSDOOR";
case ter_furn_flag::TFLAG_SMALL_HIDE: return "SMALL_HIDE";
case ter_furn_flag::TFLAG_NO_SELF_CONNECT: return "NO_SELF_CONNECT";
case ter_furn_flag::TFLAG_BURROWABLE: return "BURROWABLE";
case ter_furn_flag::TFLAG_MURKY: return "MURKY";
case ter_furn_flag::TFLAG_AMMOTYPE_RELOAD: return "AMMOTYPE_RELOAD";
case ter_furn_flag::TFLAG_TRANSPARENT_FLOOR: return "TRANSPARENT_FLOOR";
case ter_furn_flag::TFLAG_ELEVATOR: return "ELEVATOR";
case ter_furn_flag::TFLAG_ACTIVE_GENERATOR: return "ACTIVE_GENERATOR";
case ter_furn_flag::TFLAG_TRANSLUCENT: return "TRANSLUCENT";
case ter_furn_flag::TFLAG_NO_FLOOR_WATER: return "NO_FLOOR_WATER";
case ter_furn_flag::TFLAG_GRAZABLE: return "GRAZABLE";
case ter_furn_flag::TFLAG_GRAZER_INEDIBLE: return "GRAZER_INEDIBLE";
case ter_furn_flag::TFLAG_BROWSABLE: return "BROWSABLE";
case ter_furn_flag::TFLAG_SINGLE_SUPPORT: return "SINGLE_SUPPORT";
case ter_furn_flag::TFLAG_CLIMB_ADJACENT: return "CLIMB_ADJACENT";
case ter_furn_flag::TFLAG_FLOATS_IN_AIR: return "FLOATS_IN_AIR";
case ter_furn_flag::TFLAG_HARVEST_REQ_CUT1: return "HARVEST_REQ_CUT1";
// *INDENT-ON*
case ter_furn_flag::NUM_TFLAG_FLAGS:
break;
}
cata_fatal( "Invalid ter_furn_flag" );
}
} // namespace io
static std::unordered_map<std::string, connect_group> ter_connects_map;
connect_group get_connect_group( const std::string &name )
{
return ter_connects_map[name];
}
void connect_group::load( const JsonObject &jo )
{
connect_group result;
result.id = connect_group_id( jo.get_string( "id" ) );
result.index = ter_connects_map.find( result.id.str() ) == ter_connects_map.end() ?
ter_connects_map.size() : ter_connects_map[result.id.str()].index;
// Check index overflow for bitsets
if( result.index >= NUM_TERCONN ) {
debugmsg( "Exceeded current maximum of %d connection groups. Increase NUM_TERCONN to allow for more groups!",
NUM_TERCONN );
return;
}
ter_connects_map[ result.id.str() ] = result;
}
void connect_group::reset()
{
ter_connects_map.clear();
}
static void load_map_bash_tent_centers( const JsonArray &ja, std::vector<furn_str_id> ¢ers )
{
centers.clear();
for( const std::string line : ja ) {
centers.emplace_back( line );
}
}
void map_common_bash_info::load( const JsonObject &jo, const bool was_loaded,
const std::string &context )
{
optional( jo, was_loaded, "str_min", str_min, -1 );
optional( jo, was_loaded, "str_max", str_max, -1 );
optional( jo, was_loaded, "str_min_blocked", str_min_blocked, -1 );
optional( jo, was_loaded, "str_max_blocked", str_max_blocked, -1 );
optional( jo, was_loaded, "str_min_supported", str_min_supported, -1 );
optional( jo, was_loaded, "str_max_supported", str_max_supported, -1 );
optional( jo, was_loaded, "explosive", explosive, -1 );
optional( jo, was_loaded, "sound_vol", sound_vol, -1 );
optional( jo, was_loaded, "sound_fail_vol", sound_fail_vol, -1 );
optional( jo, was_loaded, "collapse_radius", collapse_radius, 1 );
optional( jo, was_loaded, "destroy_only", destroy_only, false );
optional( jo, was_loaded, "bash_below", bash_below, false );
optional( jo, was_loaded, "sound", sound, to_translation( "smash!" ) );
optional( jo, was_loaded, "sound_fail", sound_fail, to_translation( "thump!" ) );
if( jo.has_member( "items" ) ) {
drop_group = item_group::load_item_group( jo.get_member( "items" ), "collection",
"map_bash_info for " + context );
} else if( !was_loaded ) {
drop_group = Item_spawn_data_EMPTY_GROUP;
}
if( jo.has_array( "tent_centers" ) ) {
load_map_bash_tent_centers( jo.get_array( "tent_centers" ), tent_centers );
}
}
void map_ter_bash_info::load( const JsonObject &jo, const bool was_loaded,
const std::string &context )
{
map_common_bash_info::load( jo, was_loaded, context );
mandatory( jo, was_loaded, "ter_set", ter_set );
optional( jo, was_loaded, "ter_set_bashed_from_above", ter_set_bashed_from_above, ter_set );
}
void map_furn_bash_info::load( const JsonObject &jo, const bool was_loaded,
const std::string &context )
{
map_common_bash_info::load( jo, was_loaded, context );
optional( jo, was_loaded, "furn_set", furn_set, furn_f_null );
}
void map_fd_bash_info::load( const JsonObject &jo, const bool was_loaded,
const std::string &context )
{
map_common_bash_info::load( jo, was_loaded, context );
optional( jo, was_loaded, "move_cost", fd_bash_move_cost, 100 );
optional( jo, was_loaded, "msg_success", field_bash_msg_success );
}
void map_common_deconstruct_info::load( const JsonObject &jo, const bool was_loaded,
const std::string &context )
{
if( jo.has_object( "skill" ) ) {
JsonObject jos = jo.get_object( "skill" );
skill = { skill_id( jos.get_string( "skill" ) ), jos.get_int( "min", 0 ), jos.get_int( "max", 10 ), jos.get_float( "multiplier", 1.0 ) };
}
optional( jo, was_loaded, "deconstruct_above", deconstruct_above, false );
if( jo.has_member( "items" ) ) {
drop_group = item_group::load_item_group( jo.get_member( "items" ), "collection",
"map_deconstruct_info for " + context );
} else if( !was_loaded ) {
drop_group = Item_spawn_data_EMPTY_GROUP;
}
}
void map_ter_deconstruct_info::load( const JsonObject &jo, const bool was_loaded,
const std::string &context )
{
mandatory( jo, was_loaded, "ter_set", ter_set );
map_common_deconstruct_info::load( jo, was_loaded, context );
}
void map_furn_deconstruct_info::load( const JsonObject &jo, const bool was_loaded,
const std::string &context )
{
optional( jo, was_loaded, "furn_set", furn_set, furn_f_null );
map_common_deconstruct_info::load( jo, was_loaded, context );
}
bool map_shoot_info::load( const JsonObject &jsobj, const std::string_view member, bool was_loaded )
{
JsonObject j = jsobj.get_object( member );
optional( j, was_loaded, "chance_to_hit", chance_to_hit, 100 );
std::pair<int, int> reduce_damage;
std::pair<int, int> reduce_damage_laser;
std::pair<int, int> destroy_damage;
mandatory( j, was_loaded, "reduce_damage", reduce_damage );
mandatory( j, was_loaded, "reduce_damage_laser", reduce_damage_laser );
mandatory( j, was_loaded, "destroy_damage", destroy_damage );
reduce_dmg_min = reduce_damage.first;
reduce_dmg_max = reduce_damage.second;
reduce_dmg_min_laser = reduce_damage_laser.first;
reduce_dmg_max_laser = reduce_damage_laser.second;
destroy_dmg_min = destroy_damage.first;
destroy_dmg_max = destroy_damage.second;
optional( j, was_loaded, "no_laser_destroy", no_laser_destroy, false );
return true;
}
furn_workbench_info::furn_workbench_info() : multiplier( 1.0f ), allowed_mass( units::mass_max ),
allowed_volume( units::volume_max ) {}
bool furn_workbench_info::load( const JsonObject &jsobj, const std::string_view member )
{
JsonObject j = jsobj.get_object( member );
assign( j, "multiplier", multiplier );
assign( j, "mass", allowed_mass );
assign( j, "volume", allowed_volume );
return true;
}
plant_data::plant_data() : transform( furn_str_id::NULL_ID() ), base( furn_str_id::NULL_ID() ),
growth_multiplier( 1.0f ), harvest_multiplier( 1.0f ) {}
bool plant_data::load( const JsonObject &jsobj, const std::string_view member )
{
JsonObject j = jsobj.get_object( member );
assign( j, "transform", transform );
assign( j, "base", base );
assign( j, "growth_multiplier", growth_multiplier );
assign( j, "harvest_multiplier", harvest_multiplier );
return true;
}
furn_t null_furniture_t()
{
furn_t new_furniture;
new_furniture.id = furn_str_id::NULL_ID();
new_furniture.name_ = to_translation( "nothing" );
new_furniture.symbol_.fill( ' ' );
new_furniture.color_.fill( c_white );
new_furniture.light_emitted = 0;
new_furniture.movecost = 0;
new_furniture.move_str_req = -1;
new_furniture.transparent = true;
new_furniture.set_flag( ter_furn_flag::TFLAG_TRANSPARENT );
new_furniture.examine_func = iexamine_functions_from_string( "none" );
new_furniture.max_volume = DEFAULT_TILE_VOLUME;
return new_furniture;
}
ter_t::ter_t() : open( ter_str_id::NULL_ID() ), close( ter_str_id::NULL_ID() ),
transforms_into( ter_str_id::NULL_ID() ),
roof( ter_str_id::NULL_ID() ), trap( tr_null ) {}
ter_t null_terrain_t()
{
ter_t new_terrain;
new_terrain.id = ter_str_id::NULL_ID();
new_terrain.name_ = to_translation( "nothing" );
new_terrain.symbol_.fill( ' ' );
new_terrain.color_.fill( c_white );
new_terrain.light_emitted = 0;
new_terrain.movecost = 0;
new_terrain.transparent = true;
new_terrain.set_flag( ter_furn_flag::TFLAG_TRANSPARENT );
new_terrain.set_flag( ter_furn_flag::TFLAG_DIGGABLE );
new_terrain.examine_func = iexamine_functions_from_string( "none" );
new_terrain.max_volume = DEFAULT_TILE_VOLUME;
return new_terrain;
}
template<typename C, typename F>
void load_season_array( const JsonObject &jo, const std::string &key, const std::string &context,
const bool ignore_absent_key, C &container, F load_func )
{
if( jo.has_string( key ) ) {
container.fill( load_func( jo.get_string( key ) ) );
} else if( jo.has_array( key ) ) {
JsonArray arr = jo.get_array( key );
if( arr.size() == 1 ) {
container.fill( load_func( arr.get_string( 0 ) ) );
} else if( arr.size() == container.size() ) {
for( auto &e : container ) {
e = load_func( arr.next_string() );
}
} else {
jo.throw_error_at( key, "Incorrect number of entries" );
}
} else if( jo.has_member( key ) ) {
jo.throw_error_at(
key, string_format( "Expected '%s' member to be string or array", key ) );
} else if( !ignore_absent_key ) {
jo.throw_error(
string_format( "Expected '%s' member in %s but none was found", key, context ) );
}
}
std::string map_data_common_t::name() const
{
return name_.translated();
}
bool map_data_common_t::can_examine( const tripoint_bub_ms &examp ) const
{
return examine_actor || examine_func.can_examine( examp );
}
bool map_data_common_t::has_examine( iexamine_examine_function func ) const
{
return examine_func.examine == func;
}
bool map_data_common_t::has_examine( const std::string &action ) const
{
return examine_actor && examine_actor->type == action;
}
void map_data_common_t::set_examine( iexamine_functions func )
{
examine_func = func;
}
void map_data_common_t::examine( Character &you, const tripoint_bub_ms &examp ) const
{
if( !examine_actor ) {
examine_func.examine( you, examp );
return;
}
examine_actor->call( you, examp );
}
void map_data_common_t::load_symbol_color( const JsonObject &jo, const std::string &context )
{
const bool no_copy_symbol_color = jo.has_member( "copy-from" );
load_season_array( jo, "symbol", context, no_copy_symbol_color,
symbol_, [&jo]( const std::string_view str ) {
if( str.length() != 1 ) {
jo.throw_error_at( "symbol", "Symbol string must be exactly 1 character long." );
}
return static_cast<int>( str[0] );
} );
const bool has_color = jo.has_member( "color" );
const bool has_bgcolor = jo.has_member( "bgcolor" );
if( has_color && has_bgcolor ) {
jo.throw_error( "Found both color and bgcolor, only one of these is allowed." );
} else if( has_color ) {
load_season_array( jo, "color", context, no_copy_symbol_color,
color_, []( const std::string_view str ) {
// has to use a lambda because of default params
return color_from_string( str );
} );
} else if( has_bgcolor ) {
load_season_array( jo, "bgcolor", context, no_copy_symbol_color, color_, bgcolor_from_string );
} else if( !no_copy_symbol_color ) {
jo.throw_error( R"(Missing member: one of: "color", "bgcolor" must exist.)" );
}
}
int map_data_common_t::symbol() const
{
return symbol_[season_of_year( calendar::turn )];
}
nc_color map_data_common_t::color() const
{
return color_[season_of_year( calendar::turn )];
}
const harvest_id &map_data_common_t::get_harvest() const
{
return harvest_by_season[season_of_year( calendar::turn )];
}
const std::set<std::string> &map_data_common_t::get_harvest_names() const
{
static const std::set<std::string> null_names = {};
const harvest_id &hid = get_harvest();
return hid.is_null() ? null_names : hid->names();
}
std::vector<std::string> ter_t::extended_description() const
{
std::vector<std::string> ret;
ret.emplace_back( get_origin( src ) );
ret.emplace_back( "--" );
std::vector<std::string> tmp = map_data_common_t::extended_description();
ret.insert( ret.end(), tmp.begin(), tmp.end() );
return ret;
}
std::vector<std::string> furn_t::extended_description() const
{
std::vector<std::string> ret;
ret.emplace_back( get_origin( src ) );
ret.emplace_back( "--" );
std::vector<std::string> tmp = map_data_common_t::extended_description();
ret.insert( ret.end(), tmp.begin(), tmp.end() );
// If this furniture has a crafting pseudo item, check for tool qualities and print them
if( !crafting_pseudo_item.is_empty() ) {
const item pseudo( crafting_pseudo_item );
std::vector<iteminfo_parts> quality_part = { iteminfo_parts::QUALITIES };
const iteminfo_query quality_query( quality_part );
std::vector<iteminfo> info_vec;
pseudo.qualities_info( info_vec, &quality_query, 1, false );
// A bit of cargo-culting here, pre-imgui printing code was adapted
// to split string with line breaks into single-line strings
std::string quality_string = format_item_info( info_vec, {} );
size_t strpos = 0;
while( ( strpos = quality_string.find( '\n' ) ) != std::string::npos ) {
// \n character is skipped
ret.emplace_back( quality_string.substr( 0, strpos ) );
quality_string.erase( 0, strpos + 1 );
}
}
return ret;
}
std::vector<std::string> map_data_common_t::extended_description() const
{
std::vector<std::string> tmp;
tmp.emplace_back( string_format( _( "<header>That is a %s.</header>" ), name() ) );
tmp.emplace_back( description.translated() );
bool has_any_harvest = std::any_of( harvest_by_season.begin(), harvest_by_season.end(),
[]( const harvest_id & hv ) {
return !hv.obj().empty();
} );
if( has_any_harvest ) {
tmp.emplace_back( "--" );
int player_skill = get_player_character().get_greater_skill_or_knowledge_level( skill_survival );
tmp.emplace_back( _( "You could harvest the following things from it:" ) );
// Group them by identical ids to avoid repeating same blocks of data
// First, invert the mapping: season->id to id->seasons
std::multimap<harvest_id, season_type> identical_harvest;
for( size_t season = SPRING; season <= WINTER; season++ ) {
const auto &hv = harvest_by_season[season];
if( hv.obj().empty() ) {
continue;
}
identical_harvest.insert( std::make_pair( hv, static_cast<season_type>( season ) ) );
}
// Now print them in order of seasons
// TODO: Highlight current season
for( size_t season = SPRING; season <= WINTER; season++ ) {
const auto range = identical_harvest.equal_range( harvest_by_season[season] );
if( range.first == range.second ) {
continue;
}
// List the seasons first
std::string seasons = enumerate_as_string( range.first, range.second,
[]( const std::pair<harvest_id, season_type> &pr ) {
if( pr.second == season_of_year( calendar::turn ) ) {
return "<good>" + calendar::name_season( pr.second ) + "</good>";
}
return "<dark>" + calendar::name_season( pr.second ) + "</dark>";
} );
seasons += ":";
tmp.emplace_back( seasons );
// List the drops
// They actually describe what player can get from it now, so it isn't spoily
// TODO: Allow spoily listing of everything
tmp.emplace_back( range.first->first.obj().describe( player_skill ) );
// Remove the range from the multimap so that it isn't listed twice
identical_harvest.erase( range.first, range.second );
}
}
tmp.emplace_back( "--" );
tmp.emplace_back( string_format( _( "Concealment: %d%%" ), coverage ) );
if( has_flag( ter_furn_flag::TFLAG_TREE ) ) {
tmp.emplace_back( _( "Can be <color_green>cut down</color> with the right tools." ) );
}
// todo: generalize, copied from map::features which combines terrain and furniture info
std::string result;
const auto add = [&]( const std::string & text ) {
if( !result.empty() ) {
result += " ";
}
result += text;
};
const auto add_if = [&]( const bool cond, const std::string & text ) {
if( cond ) {
add( text );
}
};
add_if( is_smashable(), _( "Smashable." ) );
add_if( has_flag( ter_furn_flag::TFLAG_DIGGABLE ), _( "Diggable." ) );
add_if( has_flag( ter_furn_flag::TFLAG_PLOWABLE ), _( "Plowable." ) );
add_if( has_flag( ter_furn_flag::TFLAG_ROUGH ), _( "Rough." ) );
add_if( has_flag( ter_furn_flag::TFLAG_UNSTABLE ), _( "Unstable." ) );
add_if( has_flag( ter_furn_flag::TFLAG_SHARP ), _( "Sharp." ) );
add_if( has_flag( ter_furn_flag::TFLAG_FLAT ), _( "Flat." ) );
add_if( has_flag( ter_furn_flag::TFLAG_EASY_DECONSTRUCT ), _( "Simple." ) );
add_if( has_flag( ter_furn_flag::TFLAG_MOUNTABLE ), _( "Mountable." ) );
add_if( is_flammable(), _( "Flammable." ) );
tmp.emplace_back( result );
std::vector<std::string> ret;
ret.reserve( tmp.size() );
for( const std::string &s : tmp ) {
ret.emplace_back( replace_colors( s ) );
}
return ret;
}
void load_furniture( const JsonObject &jo, const std::string &src )
{
if( furniture_data.empty() ) {
furniture_data.insert( null_furniture_t() );
}
furniture_data.load( jo, src );
}
void load_terrain( const JsonObject &jo, const std::string &src )
{
if( terrain_data.empty() ) { // TODO: This shouldn't live here
terrain_data.insert( null_terrain_t() );
}
terrain_data.load( jo, src );
}
void map_data_common_t::set_flag( const std::string &flag )
{
flags.insert( flag );
std::optional<ter_furn_flag> f = io::string_to_enum_optional<ter_furn_flag>( flag );
if( f.has_value() ) {
bitflags.set( f.value() );
transparent |= f.value() == ter_furn_flag::TFLAG_TRANSPARENT ||
f.value() == ter_furn_flag::TFLAG_TRANSLUCENT;
}
}
void map_data_common_t::set_flag( const ter_furn_flag flag )
{
flags.insert( io::enum_to_string<ter_furn_flag>( flag ) );
bitflags.set( flag );
transparent |= flag == ter_furn_flag::TFLAG_TRANSPARENT || flag == ter_furn_flag::TFLAG_TRANSLUCENT;
}
void map_data_common_t::unset_flag( const std::string &flag )
{
if( auto it_flag = flags.find( flag ); it_flag != flags.end() ) {
flags.erase( it_flag );
} //else return false?
std::optional<ter_furn_flag> f = io::string_to_enum_optional<ter_furn_flag>( flag );
if( f.has_value() ) {
bitflags.reset( f.value() );
if( transparent ) {
transparent = f.value() != ter_furn_flag::TFLAG_TRANSPARENT;
}
}
}
void map_data_common_t::unset_flags()
{
flags.clear();
bitflags.reset();
transparent = false; //?
}
void map_data_common_t::set_connect_groups( const std::vector<std::string>
&connect_groups_vec )
{
set_groups( connect_groups, connect_groups_vec );
}
void map_data_common_t::set_connects_to( const std::vector<std::string> &connect_groups_vec )
{
set_groups( connect_to_groups, connect_groups_vec );
}
void map_data_common_t::set_rotates_to( const std::vector<std::string> &connect_groups_vec )
{
set_groups( rotate_to_groups, connect_groups_vec );
}
void map_data_common_t::set_groups( std::bitset<NUM_TERCONN> &bits,
const std::vector<std::string> &connect_groups_vec )
{
for( const std::string &group : connect_groups_vec ) {
if( group.empty() ) {
debugmsg( "Can't use empty string for terrain groups" );
continue;
}
std::string grp = group;
bool remove = false;
if( grp.at( 0 ) == '~' ) {
grp = grp.substr( 1 );
remove = true;
}
const auto it = ter_connects_map.find( grp );
if( it != ter_connects_map.end() ) {
if( remove ) {
bits.reset( it->second.index );
} else {
bits.set( it->second.index );
}
} else {
debugmsg( "can't find terrain group %s", group.c_str() );
}
}
}
ter_id t_null;
void set_ter_ids()
{
t_null = ter_id( "t_null" );
for( const ter_t &elem : terrain_data.get_all() ) {
ter_t &ter = const_cast<ter_t &>( elem );
if( ter.trap_id_str.empty() ) {
ter.trap = tr_null;
} else {
ter.trap = trap_str_id( ter.trap_id_str );
}
}
}
void reset_furn_ter()
{
terrain_data.reset();
furniture_data.reset();
}
void set_furn_ids()
{
f_null = furn_id( "f_null" );
}
size_t ter_t::count()
{
return terrain_data.size();
}
namespace io
{
template<>
std::string enum_to_string<season_type>( season_type data )
{
switch( data ) {
// *INDENT-OFF*
case season_type::SPRING: return "spring";
case season_type::SUMMER: return "summer";
case season_type::AUTUMN: return "autumn";
case season_type::WINTER: return "winter";
// *INDENT-ON*
case season_type::NUM_SEASONS:
break;
}
cata_fatal( "Invalid season_type" );
}
} // namespace io
static std::map<std::string, cata::clone_ptr<iexamine_actor>> examine_actors;
static void add_actor( std::unique_ptr<iexamine_actor> ptr )
{
std::string type = ptr->type;
examine_actors[type] = cata::clone_ptr<iexamine_actor>( std::move( ptr ) );
}
static cata::clone_ptr<iexamine_actor> iexamine_actor_from_jsobj( const JsonObject &jo )
{
std::string type = jo.get_string( "type" );
try {
return examine_actors.at( type );
} catch( const std::exception & ) {
jo.throw_error( string_format( "Invalid iexamine actor %s", type ) );
}
}
void init_mapdata()
{
add_actor( std::make_unique<appliance_convert_examine_actor>() );
add_actor( std::make_unique<cardreader_examine_actor>() );
add_actor( std::make_unique<eoc_examine_actor>() );
}
void map_data_common_t::load( const JsonObject &jo, const std::string &src )
{
mandatory( jo, was_loaded, "name", name_ );
mandatory( jo, was_loaded, "description", description );
if( jo.has_member( "copy-from" ) ) {
looks_like = jo.get_string( "copy-from" );
}
optional( jo, was_loaded, "looks_like", looks_like );
optional( jo, was_loaded, "comfort", comfort, 0 );
if( jo.has_member( "connect_groups" ) ) {
connect_groups.reset();
set_connect_groups( jo.get_as_string_array( "connect_groups" ) );
}
if( jo.has_member( "connects_to" ) ) {
connect_to_groups.reset();
set_connects_to( jo.get_as_string_array( "connects_to" ) );
}
if( jo.has_member( "rotates_to" ) ) {
rotate_to_groups.reset();
set_rotates_to( jo.get_as_string_array( "rotates_to" ) );
}
optional( jo, was_loaded, "coverage", coverage );
optional( jo, was_loaded, "curtain_transform", curtain_transform );
optional( jo, was_loaded, "emissions", emissions );
if( jo.has_string( "examine_action" ) ) {
examine_actor = nullptr;
examine_func = iexamine_functions_from_string( jo.get_string( "examine_action" ) );
} else if( jo.has_object( "examine_action" ) ) {
JsonObject data = jo.get_object( "examine_action" );
examine_actor = iexamine_actor_from_jsobj( data );
examine_actor->load( data, src );
examine_func = iexamine_functions_from_string( "invalid" );
} else if( !was_loaded ) {
examine_actor = nullptr;
examine_func = iexamine_functions_from_string( "none" );
}
if( was_loaded && jo.has_member( "flags" ) ) {
unset_flags();
}
for( auto &flag : jo.get_string_array( "flags" ) ) {
set_flag( flag );
}
if( was_loaded && jo.has_member( "extend" ) ) {
JsonObject joe = jo.get_object( "extend" );
for( auto &flag : joe.get_string_array( "flags" ) ) {
set_flag( flag );
}
}
if( was_loaded && jo.has_member( "delete" ) ) {
JsonObject jod = jo.get_object( "delete" );
for( auto &flag : jod.get_string_array( "flags" ) ) {
unset_flag( flag );
}
}
if( jo.has_array( "harvest_by_season" ) ) {
for( JsonObject harvest_jo : jo.get_array( "harvest_by_season" ) ) {
auto season_strings = harvest_jo.get_tags( "seasons" );
std::set<season_type> seasons;
std::transform( season_strings.begin(), season_strings.end(), std::inserter( seasons,
seasons.begin() ), io::string_to_enum<season_type> );
harvest_id hl;
harvest_jo.read( "id", hl );