forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap_extras.cpp
2968 lines (2663 loc) · 119 KB
/
map_extras.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 "map_extras.h"
#include <algorithm>
#include <array>
#include <cstdlib>
#include <functional>
#include <map>
#include <memory>
#include <new>
#include <set>
#include <unordered_map>
#include <utility>
#include <vector>
#include "auto_note.h"
#include "calendar.h"
#include "cata_utility.h"
#include "cellular_automata.h"
#include "character_id.h"
#include "colony.h"
#include "coordinate_conversions.h"
#include "coordinates.h"
#include "creature_tracker.h"
#include "debug.h"
#include "enum_conversions.h"
#include "enums.h"
#include "field_type.h"
#include "fungal_effects.h"
#include "game_constants.h"
#include "generic_factory.h"
#include "item.h"
#include "item_group.h"
#include "json.h"
#include "line.h"
#include "map.h"
#include "map_iterator.h"
#include "mapdata.h"
#include "mapgen.h"
#include "mapgen_functions.h"
#include "mapgendata.h"
#include "mongroup.h"
#include "optional.h"
#include "options.h"
#include "overmap.h"
#include "overmapbuffer.h"
#include "point.h"
#include "regional_settings.h"
#include "rng.h"
#include "sets_intersect.h"
#include "string_formatter.h"
#include "string_id.h"
#include "text_snippets.h"
#include "translations.h"
#include "trap.h"
#include "type_id.h"
#include "ui.h"
#include "units.h"
#include "veh_type.h"
#include "vehicle.h"
#include "vehicle_group.h"
#include "vpart_position.h"
#include "vpart_range.h"
#include "weighted_list.h"
static const flag_id json_flag_FILTHY( "FILTHY" );
static const furn_str_id furn_f_sign_warning( "f_sign_warning" );
static const item_group_id Item_spawn_data_ammo_casings( "ammo_casings" );
static const item_group_id Item_spawn_data_army_bed( "army_bed" );
static const item_group_id Item_spawn_data_everyday_corpse( "everyday_corpse" );
static const item_group_id Item_spawn_data_grenades( "grenades" );
static const item_group_id Item_spawn_data_guns_rifle_milspec( "guns_rifle_milspec" );
static const item_group_id Item_spawn_data_map_extra_casings( "map_extra_casings" );
static const item_group_id Item_spawn_data_map_extra_police( "map_extra_police" );
static const item_group_id Item_spawn_data_mil_armor( "mil_armor" );
static const item_group_id Item_spawn_data_mil_bulk( "mil_bulk" );
static const item_group_id Item_spawn_data_mil_food( "mil_food" );
static const item_group_id
Item_spawn_data_military_standard_assault_rifles( "military_standard_assault_rifles" );
static const item_group_id Item_spawn_data_military_standard_lmgs( "military_standard_lmgs" );
static const item_group_id
Item_spawn_data_military_standard_shotguns( "military_standard_shotguns" );
static const item_group_id
Item_spawn_data_military_standard_sniper_rifles( "military_standard_sniper_rifles" );
static const item_group_id Item_spawn_data_mine_equipment( "mine_equipment" );
static const item_group_id
Item_spawn_data_mon_zombie_soldier_death_drops( "mon_zombie_soldier_death_drops" );
static const item_group_id Item_spawn_data_rare( "rare" );
static const item_group_id Item_spawn_data_remains_human_generic( "remains_human_generic" );
static const item_group_id Item_spawn_data_trash_cart( "trash_cart" );
static const itype_id itype_223_casing( "223_casing" );
static const itype_id itype_762_51_casing( "762_51_casing" );
static const itype_id itype_9mm_casing( "9mm_casing" );
static const itype_id itype_acoustic_guitar( "acoustic_guitar" );
static const itype_id itype_ash( "ash" );
static const itype_id itype_bag_canvas( "bag_canvas" );
static const itype_id itype_bottle_glass( "bottle_glass" );
static const itype_id itype_chunk_sulfur( "chunk_sulfur" );
static const itype_id itype_hatchet( "hatchet" );
static const itype_id itype_jack_small( "jack_small" );
static const itype_id itype_landmine( "landmine" );
static const itype_id itype_lug_wrench( "lug_wrench" );
static const itype_id itype_material_sand( "material_sand" );
static const itype_id itype_material_soil( "material_soil" );
static const itype_id itype_rag( "rag" );
static const itype_id itype_shot_hull( "shot_hull" );
static const itype_id itype_splinter( "splinter" );
static const itype_id itype_stanag30( "stanag30" );
static const itype_id itype_stick( "stick" );
static const itype_id itype_stick_long( "stick_long" );
static const itype_id itype_vodka( "vodka" );
static const itype_id itype_wheel( "wheel" );
static const itype_id itype_withered( "withered" );
static const map_extra_id map_extra_mx_bandits_block( "mx_bandits_block" );
static const map_extra_id map_extra_mx_burned_ground( "mx_burned_ground" );
static const map_extra_id map_extra_mx_casings( "mx_casings" );
static const map_extra_id map_extra_mx_city_trap( "mx_city_trap" );
static const map_extra_id map_extra_mx_clay_deposit( "mx_clay_deposit" );
static const map_extra_id map_extra_mx_clearcut( "mx_clearcut" );
static const map_extra_id map_extra_mx_corpses( "mx_corpses" );
static const map_extra_id map_extra_mx_crater( "mx_crater" );
static const map_extra_id map_extra_mx_dead_vegetation( "mx_dead_vegetation" );
static const map_extra_id map_extra_mx_grove( "mx_grove" );
static const map_extra_id map_extra_mx_helicopter( "mx_helicopter" );
static const map_extra_id map_extra_mx_house_spider( "mx_house_spider" );
static const map_extra_id map_extra_mx_house_wasp( "mx_house_wasp" );
static const map_extra_id map_extra_mx_jabberwock( "mx_jabberwock" );
static const map_extra_id map_extra_mx_looters( "mx_looters" );
static const map_extra_id map_extra_mx_mayhem( "mx_mayhem" );
static const map_extra_id map_extra_mx_minefield( "mx_minefield" );
static const map_extra_id map_extra_mx_null( "mx_null" );
static const map_extra_id map_extra_mx_point_burned_ground( "mx_point_burned_ground" );
static const map_extra_id map_extra_mx_point_dead_vegetation( "mx_point_dead_vegetation" );
static const map_extra_id map_extra_mx_pond( "mx_pond" );
static const map_extra_id map_extra_mx_portal_in( "mx_portal_in" );
static const map_extra_id map_extra_mx_reed( "mx_reed" );
static const map_extra_id map_extra_mx_roadblock( "mx_roadblock" );
static const map_extra_id map_extra_mx_roadworks( "mx_roadworks" );
static const map_extra_id map_extra_mx_shia( "mx_shia" );
static const map_extra_id map_extra_mx_shrubbery( "mx_shrubbery" );
static const map_extra_id map_extra_mx_supplydrop( "mx_supplydrop" );
static const mongroup_id GROUP_FISH( "GROUP_FISH" );
static const mongroup_id GROUP_FUNGI_FUNGALOID( "GROUP_FUNGI_FUNGALOID" );
static const mongroup_id GROUP_NETHER_PORTAL( "GROUP_NETHER_PORTAL" );
static const mongroup_id GROUP_STRAY_DOGS( "GROUP_STRAY_DOGS" );
static const mongroup_id GROUP_WASP_GUARD( "GROUP_WASP_GUARD" );
static const mongroup_id GROUP_WASP_QUEEN( "GROUP_WASP_QUEEN" );
static const mtype_id mon_dermatik( "mon_dermatik" );
static const mtype_id mon_jabberwock( "mon_jabberwock" );
static const mtype_id mon_shia( "mon_shia" );
static const mtype_id mon_spider_cellar_giant( "mon_spider_cellar_giant" );
static const mtype_id mon_spider_widow_giant( "mon_spider_widow_giant" );
static const mtype_id mon_turret_riot( "mon_turret_riot" );
static const mtype_id mon_turret_searchlight( "mon_turret_searchlight" );
static const mtype_id mon_turret_speaker( "mon_turret_speaker" );
static const mtype_id mon_wolf( "mon_wolf" );
static const mtype_id mon_zombie_bio_op( "mon_zombie_bio_op" );
static const mtype_id mon_zombie_military_pilot( "mon_zombie_military_pilot" );
static const mtype_id mon_zombie_scientist( "mon_zombie_scientist" );
static const mtype_id mon_zombie_soldier( "mon_zombie_soldier" );
static const oter_type_str_id oter_type_bridge( "bridge" );
static const oter_type_str_id oter_type_bridgehead_ground( "bridgehead_ground" );
static const oter_type_str_id oter_type_road( "road" );
static const relic_procgen_id relic_procgen_data_alien_reality( "alien_reality" );
static const string_id<class npc_template> npc_template_bandit( "bandit" );
static const ter_str_id ter_t_dirt( "t_dirt" );
static const ter_str_id ter_t_grass_dead( "t_grass_dead" );
static const ter_str_id ter_t_stump( "t_stump" );
static const ter_str_id ter_t_tree_birch_harvested( "t_tree_birch_harvested" );
static const ter_str_id ter_t_tree_dead( "t_tree_dead" );
static const ter_str_id ter_t_tree_deadpine( "t_tree_deadpine" );
static const ter_str_id ter_t_tree_hickory_dead( "t_tree_hickory_dead" );
static const ter_str_id ter_t_trunk( "t_trunk" );
static const trap_str_id tr_caltrops( "tr_caltrops" );
static const trap_str_id tr_engine( "tr_engine" );
static const trap_str_id tr_nailboard( "tr_nailboard" );
static const vgroup_id VehicleGroup_crashed_helicopters( "crashed_helicopters" );
static const vgroup_id VehicleGroup_military_vehicles( "military_vehicles" );
static const vproto_id vehicle_prototype_4x4_car( "4x4_car" );
static const vproto_id vehicle_prototype_car( "car" );
static const vproto_id vehicle_prototype_car_fbi( "car_fbi" );
static const vproto_id vehicle_prototype_excavator( "excavator" );
static const vproto_id vehicle_prototype_humvee( "humvee" );
static const vproto_id vehicle_prototype_limousine( "limousine" );
static const vproto_id vehicle_prototype_military_cargo_truck( "military_cargo_truck" );
static const vproto_id vehicle_prototype_policecar( "policecar" );
static const vproto_id vehicle_prototype_road_roller( "road_roller" );
class npc_template;
namespace io
{
template<>
std::string enum_to_string<map_extra_method>( map_extra_method data )
{
switch( data ) {
// *INDENT-OFF*
case map_extra_method::null: return "null";
case map_extra_method::map_extra_function: return "map_extra_function";
case map_extra_method::mapgen: return "mapgen";
case map_extra_method::update_mapgen: return "update_mapgen";
case map_extra_method::num_map_extra_methods: break;
// *INDENT-ON*
}
cata_fatal( "Invalid map_extra_method" );
}
} // namespace io
namespace
{
generic_factory<map_extra> extras( "map extra" );
} // namespace
/** @relates string_id */
template<>
const map_extra &string_id<map_extra>::obj() const
{
return extras.obj( *this );
}
/** @relates string_id */
template<>
bool string_id<map_extra>::is_valid() const
{
return extras.is_valid( *this );
}
namespace MapExtras
{
const generic_factory<map_extra> &mapExtraFactory()
{
return extras;
}
void clear()
{
extras.reset();
}
static bool mx_null( map &, const tripoint & )
{
debugmsg( "Tried to generate null map extra." );
return false;
}
static void dead_vegetation_parser( map &m, const tripoint &loc )
{
// furniture plants die to withered plants
const furn_t &fid = m.furn( loc ).obj();
if( fid.has_flag( ter_furn_flag::TFLAG_PLANT ) || fid.has_flag( ter_furn_flag::TFLAG_FLOWER ) ||
fid.has_flag( ter_furn_flag::TFLAG_ORGANIC ) ) {
m.i_clear( loc );
m.furn_set( loc, f_null );
m.spawn_item( loc, itype_withered );
}
// terrain specific conversions
const ter_id tid = m.ter( loc );
static const std::map<ter_id, ter_str_id> dies_into {{
{t_grass, ter_t_grass_dead},
{t_grass_long, ter_t_grass_dead},
{t_grass_tall, ter_t_grass_dead},
{t_moss, ter_t_grass_dead},
{t_tree_pine, ter_t_tree_deadpine},
{t_tree_birch, ter_t_tree_birch_harvested},
{t_tree_willow, ter_t_tree_dead},
{t_tree_hickory, ter_t_tree_hickory_dead},
{t_tree_hickory_harvested, ter_t_tree_hickory_dead},
{t_grass_golf, ter_t_grass_dead},
{t_grass_white, ter_t_grass_dead},
}};
const auto iter = dies_into.find( tid );
if( iter != dies_into.end() ) {
m.ter_set( loc, iter->second );
}
// non-specific small vegetation falls into sticks, large dies and randomly falls
const ter_t &tr = tid.obj();
if( tr.has_flag( ter_furn_flag::TFLAG_SHRUB ) ) {
m.ter_set( loc, t_dirt );
if( one_in( 2 ) ) {
m.spawn_item( loc, itype_stick );
}
} else if( tr.has_flag( ter_furn_flag::TFLAG_TREE ) ) {
if( one_in( 4 ) ) {
m.ter_set( loc, ter_t_trunk );
} else if( one_in( 4 ) ) {
m.ter_set( loc, ter_t_stump );
} else {
m.ter_set( loc, ter_t_tree_dead );
}
} else if( tr.has_flag( ter_furn_flag::TFLAG_YOUNG ) ) {
m.ter_set( loc, ter_t_dirt );
if( one_in( 2 ) ) {
m.spawn_item( loc, itype_stick_long );
}
}
}
static bool mx_house_wasp( map &m, const tripoint &loc )
{
for( int i = 0; i < SEEX * 2; i++ ) {
for( int j = 0; j < SEEY * 2; j++ ) {
if( m.ter( point( i, j ) ) == t_door_c || m.ter( point( i, j ) ) == t_door_locked ) {
m.ter_set( point( i, j ), t_door_frame );
}
if( m.ter( point( i, j ) ) == t_window_domestic && !one_in( 3 ) ) {
m.ter_set( point( i, j ), t_window_frame );
}
if( m.ter( point( i, j ) ) == t_wall && one_in( 8 ) ) {
m.ter_set( point( i, j ), t_paper );
}
}
}
const int num_pods = rng( 8, 12 );
for( int i = 0; i < num_pods; i++ ) {
const point pod( rng( 1, SEEX * 2 - 2 ), rng( 1, SEEY * 2 - 2 ) );
point non;
while( non.x == 0 && non.y == 0 ) {
non.x = rng( -1, 1 );
non.y = rng( -1, 1 );
}
for( int x = -1; x <= 1; x++ ) {
for( int y = -1; y <= 1; y++ ) {
if( ( x != non.x || y != non.y ) && ( x != 0 || y != 0 ) ) {
m.ter_set( pod + point( x, y ), t_paper );
}
}
}
m.place_spawns( GROUP_WASP_GUARD, 1, pod, pod, 1, true );
}
m.place_spawns( GROUP_WASP_QUEEN, 1, point_zero, point( SEEX, SEEY ), 1, true );
if( one_in( 5 ) ) {
m.add_spawn( mon_dermatik, rng( 1, 3 ), tripoint( point( SEEX * 2 - 1, SEEY * 2 - 1 ), loc.z ) );
}
return true;
}
static bool mx_house_spider( map &m, const tripoint &loc )
{
auto spider_type = mon_spider_widow_giant;
auto egg_type = f_egg_sackbw;
if( one_in( 2 ) ) {
spider_type = mon_spider_cellar_giant;
egg_type = f_egg_sackcs;
}
for( int i = 0; i < SEEX * 2; i++ ) {
for( int j = 0; j < SEEY * 2; j++ ) {
if( m.ter( point( i, j ) ) == t_floor ) {
if( one_in( 15 ) ) {
m.add_spawn( spider_type, rng( 1, 2 ), tripoint( i, j, loc.z ) );
for( int x = i - 1; x <= i + 1; x++ ) {
for( int y = j - 1; y <= j + 1; y++ ) {
if( m.ter( point( x, y ) ) == t_floor ) {
madd_field( &m, point( x, y ), fd_web, rng( 2, 3 ) );
if( one_in( 4 ) ) {
m.furn_set( point( i, j ), egg_type );
m.remove_field( {i, j, m.get_abs_sub().z()}, fd_web );
}
}
}
}
} else if( m.passable( point( i, j ) ) && one_in( 5 ) ) {
madd_field( &m, point( i, j ), fd_web, 1 );
}
}
}
}
m.place_items( Item_spawn_data_rare, 60, point_zero, point( SEEX * 2 - 1, SEEY * 2 - 1 ),
false, calendar::start_of_cataclysm );
return true;
}
static bool mx_helicopter( map &m, const tripoint &abs_sub )
{
point c( rng( 6, SEEX * 2 - 7 ), rng( 6, SEEY * 2 - 7 ) );
for( int x = 0; x < SEEX * 2; x++ ) {
for( int y = 0; y < SEEY * 2; y++ ) {
if( m.veh_at( tripoint( x, y, abs_sub.z ) ) &&
m.ter( tripoint( x, y, abs_sub.z ) )->has_flag( ter_furn_flag::TFLAG_DIGGABLE ) ) {
m.ter_set( tripoint( x, y, abs_sub.z ), t_dirtmound );
} else {
if( x >= c.x - dice( 1, 5 ) && x <= c.x + dice( 1, 5 ) && y >= c.y - dice( 1, 5 ) &&
y <= c.y + dice( 1, 5 ) ) {
if( one_in( 7 ) &&
m.ter( tripoint( x, y, abs_sub.z ) )->has_flag( ter_furn_flag::TFLAG_DIGGABLE ) ) {
m.ter_set( tripoint( x, y, abs_sub.z ), t_dirtmound );
}
}
if( x >= c.x - dice( 1, 6 ) && x <= c.x + dice( 1, 6 ) && y >= c.y - dice( 1, 6 ) &&
y <= c.y + dice( 1, 6 ) ) {
if( !one_in( 5 ) ) {
m.make_rubble( tripoint( x, y, abs_sub.z ), f_wreckage, true );
if( m.ter( tripoint( x, y, abs_sub.z ) )->has_flag( ter_furn_flag::TFLAG_DIGGABLE ) ) {
m.ter_set( tripoint( x, y, abs_sub.z ), t_dirtmound );
}
} else if( m.is_bashable( point( x, y ) ) ) {
m.destroy( tripoint( x, y, abs_sub.z ), true );
if( m.ter( tripoint( x, y, abs_sub.z ) )->has_flag( ter_furn_flag::TFLAG_DIGGABLE ) ) {
m.ter_set( tripoint( x, y, abs_sub.z ), t_dirtmound );
}
}
} else if( one_in( 4 + ( std::abs( x - c.x ) + std::abs( y -
c.y ) ) ) ) { // 1 in 10 chance of being wreckage anyway
m.make_rubble( tripoint( x, y, abs_sub.z ), f_wreckage, true );
if( !one_in( 3 ) ) {
if( m.ter( tripoint( x, y, abs_sub.z ) )->has_flag( ter_furn_flag::TFLAG_DIGGABLE ) ) {
m.ter_set( tripoint( x, y, abs_sub.z ), t_dirtmound );
}
}
}
}
}
}
units::angle dir1 = random_direction();
auto crashed_hull = VehicleGroup_crashed_helicopters->pick();
// Create the vehicle so we can rotate it and calculate its bounding box, but don't place it on the map.
auto veh = std::make_unique<vehicle>( m, crashed_hull, rng( 1, 33 ), 1 );
veh->turn( dir1 );
// Get the bounding box, centered on mount(0,0)
bounding_box bbox = veh->get_bounding_box();
// Move the wreckage forward/backward half it's length so that it spawns more over the center of the debris area
point length( std::abs( bbox.p2.x - bbox.p1.x ), std::abs( bbox.p2.y - bbox.p1.y ) );
// cont.
point offset( veh->dir_vec().x * length.x / 2, veh->dir_vec().y * length.y / 2 );
point min( std::abs( bbox.p1.x ) + 0, std::abs( bbox.p1.y ) + 0 );
int x_max = SEEX * 2 - bbox.p2.x - 1;
int y_max = SEEY * 2 - bbox.p2.y - 1;
// Clamp x1 & y1 such that no parts of the vehicle extend over the border of the submap.
point p1( clamp( c.x + offset.x, min.x, x_max ), clamp( c.y + offset.y, min.y, y_max ) );
vehicle *wreckage = m.add_vehicle(
crashed_hull, tripoint( p1, abs_sub.z ), dir1, rng( 1, 33 ), 1 );
const auto controls_at = []( vehicle * wreckage, const tripoint & pos ) {
return !wreckage->get_parts_at( pos, "CONTROLS", part_status_flag::any ).empty() ||
!wreckage->get_parts_at( pos, "CTRL_ELECTRONIC", part_status_flag::any ).empty();
};
if( wreckage != nullptr ) {
const int clowncar_factor = dice( 1, 8 );
switch( clowncar_factor ) {
case 1:
case 2:
case 3:
// Full clown car
for( const vpart_reference &vp : wreckage->get_any_parts( VPFLAG_SEATBELT ) ) {
const tripoint pos = vp.pos();
// Spawn pilots in seats with controls.CTRL_ELECTRONIC
if( controls_at( wreckage, pos ) ) {
m.add_spawn( mon_zombie_military_pilot, 1, pos );
} else {
if( one_in( 5 ) ) {
m.add_spawn( mon_zombie_bio_op, 1, pos );
} else if( one_in( 5 ) ) {
m.add_spawn( mon_zombie_scientist, 1, pos );
} else {
m.add_spawn( mon_zombie_soldier, 1, pos );
}
}
// Delete the items that would have spawned here from a "corpse"
for( int sp : wreckage->parts_at_relative( vp.mount(), true ) ) {
vehicle_stack here = wreckage->get_items( sp );
for( auto iter = here.begin(); iter != here.end(); ) {
iter = here.erase( iter );
}
}
}
break;
case 4:
case 5:
// 2/3rds clown car
for( const vpart_reference &vp : wreckage->get_any_parts( VPFLAG_SEATBELT ) ) {
const tripoint pos = vp.pos();
// Spawn pilots in seats with controls.
if( controls_at( wreckage, pos ) ) {
m.add_spawn( mon_zombie_military_pilot, 1, pos );
} else {
if( !one_in( 3 ) ) {
m.add_spawn( mon_zombie_soldier, 1, pos );
}
}
// Delete the items that would have spawned here from a "corpse"
for( int sp : wreckage->parts_at_relative( vp.mount(), true ) ) {
vehicle_stack here = wreckage->get_items( sp );
for( auto iter = here.begin(); iter != here.end(); ) {
iter = here.erase( iter );
}
}
}
break;
case 6:
// Just pilots
for( const vpart_reference &vp : wreckage->get_any_parts( VPFLAG_CONTROLS ) ) {
const tripoint pos = vp.pos();
m.add_spawn( mon_zombie_military_pilot, 1, pos );
// Delete the items that would have spawned here from a "corpse"
for( int sp : wreckage->parts_at_relative( vp.mount(), true ) ) {
vehicle_stack here = wreckage->get_items( sp );
for( auto iter = here.begin(); iter != here.end(); ) {
iter = here.erase( iter );
}
}
}
break;
case 7:
// Empty clown car
case 8:
default:
break;
}
if( !one_in( 4 ) ) {
wreckage->smash( m, 0.8f, 1.2f, 1.0f, point( dice( 1, 8 ) - 5, dice( 1, 8 ) - 5 ), 6 + dice( 1,
10 ) );
} else {
wreckage->smash( m, 0.1f, 0.9f, 1.0f, point( dice( 1, 8 ) - 5, dice( 1, 8 ) - 5 ), 6 + dice( 1,
10 ) );
}
}
return true;
}
static bool mx_roadblock( map &m, const tripoint &abs_sub )
{
// TODO: fix point types
const tripoint_abs_omt abs_omt( sm_to_omt_copy( abs_sub ) );
const oter_id &north = overmap_buffer.ter( abs_omt + point_north );
const oter_id &south = overmap_buffer.ter( abs_omt + point_south );
const oter_id &west = overmap_buffer.ter( abs_omt + point_west );
const oter_id &east = overmap_buffer.ter( abs_omt + point_east );
const bool road_at_north = north->get_type_id() == oter_type_road;
const bool road_at_south = south->get_type_id() == oter_type_road;
const bool road_at_west = west->get_type_id() == oter_type_road;
const bool road_at_east = east->get_type_id() == oter_type_road;
const auto spawn_turret = [&]( const point & p ) {
m.add_spawn( mon_turret_riot, 1, { p, abs_sub.z } );
};
if( one_in( 6 ) ) { //Military doesn't joke around with their barricades!
if( one_in( 2 ) ) {
if( road_at_north ) {
line( &m, t_fence_barbed, point( 4, 3 ), point( 10, 3 ) );
line( &m, t_fence_barbed, point( 13, 3 ), point( 19, 3 ) );
}
if( road_at_east ) {
line( &m, t_fence_barbed, point( SEEX * 2 - 3, 4 ), point( SEEX * 2 - 3, 10 ) );
line( &m, t_fence_barbed, point( SEEX * 2 - 3, 13 ), point( SEEX * 2 - 3, 19 ) );
}
if( road_at_south ) {
line( &m, t_fence_barbed, point( 4, SEEY * 2 - 3 ), point( 10, SEEY * 2 - 3 ) );
line( &m, t_fence_barbed, point( 13, SEEY * 2 - 3 ), point( 19, SEEY * 2 - 3 ) );
}
if( road_at_west ) {
line( &m, t_fence_barbed, point( 3, 4 ), point( 3, 10 ) );
line( &m, t_fence_barbed, point( 3, 13 ), point( 3, 19 ) );
}
} else {
if( road_at_north ) {
line_furn( &m, f_sandbag_half, point( 4, 3 ), point( 10, 3 ) );
line_furn( &m, f_sandbag_half, point( 13, 3 ), point( 19, 3 ) );
}
if( road_at_east ) {
line_furn( &m, f_sandbag_half, point( SEEX * 2 - 3, 4 ), point( SEEX * 2 - 3, 10 ) );
line_furn( &m, f_sandbag_half, point( SEEX * 2 - 3, 13 ), point( SEEX * 2 - 3, 19 ) );
}
if( road_at_south ) {
line_furn( &m, f_sandbag_half, point( 4, SEEY * 2 - 3 ), point( 10, SEEY * 2 - 3 ) );
line_furn( &m, f_sandbag_half, point( 13, SEEY * 2 - 3 ), point( 19, SEEY * 2 - 3 ) );
}
if( road_at_east ) {
line_furn( &m, f_sandbag_half, point( 3, 4 ), point( 3, 10 ) );
line_furn( &m, f_sandbag_half, point( 3, 13 ), point( 3, 19 ) );
}
}
if( one_in( 2 ) ) {
// The truck's wrecked...with fuel. Explosive barrel?
m.add_vehicle( vehicle_prototype_military_cargo_truck, point( 12, SEEY * 2 - 12 ),
0_degrees, 70, -1 );
if( road_at_north ) {
spawn_turret( point( 12, 6 ) );
}
if( road_at_east ) {
spawn_turret( point( 18, 12 ) );
}
if( road_at_south ) {
spawn_turret( point( 12, 18 ) );
}
if( road_at_west ) {
spawn_turret( point( 6, 12 ) );
}
} else { // Vehicle & turrets
m.add_vehicle( VehicleGroup_military_vehicles,
tripoint( 12, SEEY * 2 - 10, abs_sub.z ), 0_degrees, 70, -1 );
if( road_at_north ) {
spawn_turret( point( 12, 6 ) );
}
if( road_at_east ) {
spawn_turret( point( 18, 12 ) );
}
if( road_at_south ) {
spawn_turret( point( 12, 18 ) );
}
if( road_at_west ) {
spawn_turret( point( 6, 12 ) );
}
}
line_furn( &m, f_sandbag_wall, point( 12, 7 ), point( 15, 7 ) );
m.add_spawn( mon_turret_searchlight, 1, { 13, 8, abs_sub.z } );
m.ter_set( point( 14, 8 ), t_plut_generator );
line_furn( &m, f_sandbag_wall, point( 12, 9 ), point( 15, 9 ) );
int num_bodies = dice( 2, 5 );
for( int i = 0; i < num_bodies; i++ ) {
if( const auto p = random_point( m, [&m]( const tripoint & n ) {
return m.passable( n );
} ) ) {
m.add_spawn( mon_zombie_soldier, 1, *p );
// 10% chance of zombie carrying weapon so 90% chance of it being on the ground
if( !one_in( 10 ) ) {
item_group_id group;
// 75% assault rifles, 10% LMGs, 5% shotguns, 5% sniper rifles
if( one_in( 20 ) ) {
group = Item_spawn_data_military_standard_sniper_rifles;
} else if( one_in( 20 ) ) {
group = Item_spawn_data_military_standard_shotguns;
} else if( one_in( 10 ) ) {
group = Item_spawn_data_military_standard_lmgs;
} else {
group = Item_spawn_data_military_standard_assault_rifles;
}
m.place_items( group, 100, *p, *p, true, calendar::start_of_cataclysm );
}
int splatter_range = rng( 1, 3 );
for( int j = 0; j <= splatter_range; j++ ) {
m.add_field( *p + point( -j * 1, j * 1 ), fd_blood, 1, 0_turns );
}
}
}
} else { // Police roadblock
if( road_at_north ) {
line_furn( &m, f_barricade_road, point( 4, 3 ), point( 10, 3 ) );
line_furn( &m, f_barricade_road, point( 13, 3 ), point( 19, 3 ) );
m.add_spawn( mon_turret_riot, 1, { 12, 1, abs_sub.z } );
}
if( road_at_east ) {
line_furn( &m, f_barricade_road, point( SEEX * 2 - 3, 4 ), point( SEEX * 2 - 3, 10 ) );
line_furn( &m, f_barricade_road, point( SEEX * 2 - 3, 13 ), point( SEEX * 2 - 3, 19 ) );
m.add_spawn( mon_turret_riot, 1, { SEEX * 2 - 1, 12, abs_sub.z } );
}
if( road_at_south ) {
line_furn( &m, f_barricade_road, point( 4, SEEY * 2 - 3 ), point( 10, SEEY * 2 - 3 ) );
line_furn( &m, f_barricade_road, point( 13, SEEY * 2 - 3 ), point( 19, SEEY * 2 - 3 ) );
m.add_spawn( mon_turret_riot, 1, { 12, SEEY * 2 - 1, abs_sub.z } );
}
if( road_at_west ) {
line_furn( &m, f_barricade_road, point( 3, 4 ), point( 3, 10 ) );
line_furn( &m, f_barricade_road, point( 3, 13 ), point( 3, 19 ) );
m.add_spawn( mon_turret_riot, 1, { 1, 12, abs_sub.z } );
}
m.add_vehicle( vehicle_prototype_policecar, point( 8, 6 ), 20_degrees );
m.add_vehicle( vehicle_prototype_policecar, point( 16, SEEY * 2 - 6 ), 145_degrees );
line_furn( &m, f_sandbag_wall, point( 6, 10 ), point( 9, 10 ) );
m.add_spawn( mon_turret_searchlight, 1, { 7, 11, abs_sub.z } );
m.ter_set( point( 8, 11 ), t_plut_generator );
line_furn( &m, f_sandbag_wall, point( 6, 12 ), point( 9, 12 ) );
int num_bodies = dice( 1, 6 );
for( int i = 0; i < num_bodies; i++ ) {
if( const auto p = random_point( m, [&m]( const tripoint & n ) {
return m.passable( n );
} ) ) {
m.place_items( Item_spawn_data_map_extra_police, 100, *p, *p, true,
calendar::start_of_cataclysm );
int splatter_range = rng( 1, 3 );
for( int j = 0; j <= splatter_range; j++ ) {
m.add_field( *p + point( j * 1, -j * 1 ), fd_blood, 1, 0_turns );
}
}
}
}
return true;
}
static bool mx_bandits_block( map &m, const tripoint &abs_sub )
{
const tripoint_abs_omt abs_omt( sm_to_omt_copy( abs_sub ) );
const oter_id &north = overmap_buffer.ter( abs_omt + point_north );
const oter_id &south = overmap_buffer.ter( abs_omt + point_south );
const oter_id &west = overmap_buffer.ter( abs_omt + point_west );
const oter_id &east = overmap_buffer.ter( abs_omt + point_east );
const bool forest_at_north = is_ot_match( "forest", north, ot_match_type::prefix );
const bool forest_at_south = is_ot_match( "forest", south, ot_match_type::prefix );
const bool forest_at_west = is_ot_match( "forest", west, ot_match_type::prefix );
const bool forest_at_east = is_ot_match( "forest", east, ot_match_type::prefix );
const bool road_at_north = north->get_type_id() == oter_type_road;
const bool road_at_south = south->get_type_id() == oter_type_road;
const bool road_at_west = west->get_type_id() == oter_type_road;
const bool road_at_east = east->get_type_id() == oter_type_road;
if( forest_at_north && forest_at_south &&
road_at_west && road_at_east ) {
if( one_in( 2 ) ) {
line( &m, t_trunk, point( 1, 3 ), point( 1, 6 ) );
line( &m, t_trunk, point( 1, 8 ), point( 1, 13 ) );
line( &m, t_trunk, point( 2, 14 ), point( 2, 17 ) );
line( &m, t_trunk, point( 1, 18 ), point( 2, 22 ) );
m.ter_set( point( 1, 2 ), t_stump );
m.ter_set( point( 1, 20 ), t_stump );
m.ter_set( point_south_east, t_improvised_shelter );
m.place_npc( point( 2, 19 ), npc_template_bandit );
if( one_in( 2 ) ) {
m.place_npc( point_south_east, npc_template_bandit );
}
} else {
trap_str_id trap_type = one_in( 2 ) ? tr_nailboard : tr_caltrops;
for( int x = SEEX - 1; x < SEEX + 1; x++ ) {
for( int y = 0; y < SEEY * 2 - 1; y += 2 ) {
if( x_in_y( 8, 10 ) ) {
m.trap_set( tripoint_bub_ms{ x, y, abs_sub.z }, trap_type );
}
}
}
rough_circle( &m, t_underbrush, point( 8, 2 ), 2 );
m.ter_set( point( 8, 2 ), t_dirt );
m.place_npc( point( 8, 2 ), npc_template_bandit );
rough_circle( &m, t_underbrush, point( 16, 22 ), 2 );
m.ter_set( point( 16, 22 ), t_dirt );
m.place_npc( point( 16, 22 ), npc_template_bandit );
}
return true;
}
if( forest_at_west && forest_at_east && road_at_north && road_at_south ) {
if( one_in( 2 ) ) {
// NOLINTNEXTLINE(cata-use-named-point-constants)
line( &m, t_trunk, point( 1, 1 ), point( 3, 1 ) );
line( &m, t_trunk, point( 5, 1 ), point( 10, 1 ) );
line( &m, t_trunk, point( 11, 3 ), point( 16, 3 ) );
line( &m, t_trunk, point( 17, 2 ), point( 21, 2 ) );
m.ter_set( point( 22, 2 ), t_stump );
m.ter_set( point_south, t_improvised_shelter );
m.place_npc( point( 20, 3 ), npc_template_bandit );
if( one_in( 2 ) ) {
m.place_npc( point_south, npc_template_bandit );
}
} else {
trap_str_id trap_type = one_in( 2 ) ? tr_nailboard : tr_caltrops;
for( int x = 0; x < SEEX * 2 - 1; x += 2 ) {
for( int y = SEEY - 1; y < SEEY + 1; y++ ) {
if( x_in_y( 8, 10 ) ) {
m.trap_set( tripoint_bub_ms{ x, y, abs_sub.z }, trap_type );
}
}
}
rough_circle( &m, t_underbrush, point( 1, 8 ), 2 );
m.ter_set( point( 1, 8 ), t_dirt );
m.place_npc( point( 1, 8 ), npc_template_bandit );
rough_circle( &m, t_underbrush, point( 22, 15 ), 2 );
m.ter_set( point( 22, 15 ), t_dirt );
m.place_npc( point( 22, 15 ), npc_template_bandit );
}
return true;
}
return false;
}
static bool mx_supplydrop( map &m, const tripoint &/*abs_sub*/ )
{
const bool intact = x_in_y( 40,
std::max( to_days<int>( calendar::turn - calendar::start_of_cataclysm ), 0 ) + 50 );
int num_crates = rng( 1, 5 );
for( int i = 0; i < num_crates; i++ ) {
const auto p = random_point( m, [&m]( const tripoint & n ) {
return m.passable( n );
} );
if( !p ) {
break;
}
if( intact ) {
m.furn_set( p->xy(), f_crate_c );
item_group_id item_group;
switch( rng( 1, 10 ) ) {
case 1:
item_group = Item_spawn_data_mil_bulk;
break;
case 2:
case 3:
case 4:
item_group = Item_spawn_data_mil_food;
break;
case 5:
case 6:
case 7:
item_group = Item_spawn_data_grenades;
break;
case 8:
case 9:
item_group = Item_spawn_data_mil_armor;
break;
case 10:
item_group = Item_spawn_data_guns_rifle_milspec;
break;
}
int items_created = 0;
for( int i = 0; i < 10 && items_created < 2; i++ ) {
items_created +=
m.place_items( item_group, 80, *p, *p, true, calendar::start_of_cataclysm,
100 ).size();
}
if( m.i_at( *p ).empty() ) {
m.destroy( *p, true );
}
} else {
m.furn_set( p->xy(), f_crate_o );
}
}
return true;
}
static void place_trap_if_clear( map &m, const point &target, trap_id trap_type )
{
tripoint tri_target( target, m.get_abs_sub().z() );
if( m.ter( tri_target ).obj().trap == tr_null ) {
mtrap_set( &m, target, trap_type );
}
}
static bool mx_minefield( map &, const tripoint &abs_sub )
{
const tripoint_abs_omt abs_omt( sm_to_omt_copy( abs_sub ) );
const oter_id ¢er = overmap_buffer.ter( abs_omt );
const oter_id &north = overmap_buffer.ter( abs_omt + point_north );
const oter_id &south = overmap_buffer.ter( abs_omt + point_south );
const oter_id &west = overmap_buffer.ter( abs_omt + point_west );
const oter_id &east = overmap_buffer.ter( abs_omt + point_east );
const bool bridgehead_at_center = center->get_type_id() ==
oter_type_bridgehead_ground;
const bool bridge_at_north = north->get_type_id() == oter_type_bridge;
const bool bridge_at_south = south->get_type_id() == oter_type_bridge;
const bool bridge_at_west = west->get_type_id() == oter_type_bridge;
const bool bridge_at_east = east->get_type_id() == oter_type_bridge;
const bool road_at_north = north->get_type_id() == oter_type_road;
const bool road_at_south = south->get_type_id() == oter_type_road;
const bool road_at_west = west->get_type_id() == oter_type_road;
const bool road_at_east = east->get_type_id() == oter_type_road;
const int num_mines = rng( 6, 20 );
const std::string text = _( "DANGER! MINEFIELD!" );
bool did_something = false;
if( !bridgehead_at_center ) {
return false;
}
tinymap m;
if( bridge_at_north && road_at_south ) {
m.load( project_to<coords::sm>( abs_omt + point_south ), false );
//Sandbag block at the left edge
line_furn( &m, f_sandbag_half, point( 3, 4 ), point( 3, 7 ) );
line_furn( &m, f_sandbag_half, point( 3, 7 ), point( 9, 7 ) );
line_furn( &m, f_sandbag_half, point( 9, 4 ), point( 9, 7 ) );
//7.62x51mm casings left from m60 of the humvee
for( const tripoint &loc : m.points_in_radius( tripoint{ 6, 4, abs_sub.z }, 3, 0 ) ) {
if( one_in( 4 ) ) {
m.spawn_item( loc, itype_762_51_casing );
}
}
//50% chance to spawn a humvee in the left block
if( one_in( 2 ) ) {
m.add_vehicle( vehicle_prototype_humvee, point( 5, 3 ), 270_degrees, 70, -1 );
}
//Sandbag block at the right edge
line_furn( &m, f_sandbag_half, point( 15, 3 ), point( 15, 6 ) );
line_furn( &m, f_sandbag_half, point( 15, 6 ), point( 20, 6 ) );
line_furn( &m, f_sandbag_half, point( 20, 3 ), point( 20, 6 ) );
//5.56x45mm casings left from a soldier
for( const tripoint &loc : m.points_in_radius( tripoint{ 17, 4, abs_sub.z }, 2, 0 ) ) {
if( one_in( 4 ) ) {
m.spawn_item( loc, itype_223_casing );
}
}
//50% chance to spawn a dead soldier with a trail of blood
if( one_in( 2 ) ) {
m.add_splatter_trail( fd_blood, { 17, 6, abs_sub.z }, { 19, 3, abs_sub.z } );
item body = item::make_corpse();
m.put_items_from_loc( Item_spawn_data_mon_zombie_soldier_death_drops,
{ 17, 5, abs_sub.z } );
m.add_item_or_charges( tripoint{ 17, 5, abs_sub.z }, body );
}
//33% chance to spawn empty magazines used by soldiers
std::vector<point> empty_magazines_locations = line_to( point( 15, 5 ), point( 20, 5 ) );
for( point &i : empty_magazines_locations ) {
if( one_in( 3 ) ) {
m.spawn_item( { i, abs_sub.z }, itype_stanag30 );
}
}
//Horizontal line of barbed wire fence
line( &m, t_fence_barbed, point( 3, 9 ), point( SEEX * 2 - 4, 9 ) );
std::vector<point> barbed_wire = line_to( point( 3, 9 ), point( SEEX * 2 - 4, 9 ) );
for( point &i : barbed_wire ) {
//10% chance to spawn corpses of bloody people/zombies on every tile of barbed wire fence
if( one_in( 10 ) ) {
m.add_corpse( { i, abs_sub.z } );
m.add_field( { i, abs_sub.z }, fd_blood, rng( 1, 3 ) );
}
}
//Spawn 6-20 mines in the lower submap.
//Spawn ordinary mine on asphalt, otherwise spawn buried mine
for( int i = 0; i < num_mines; i++ ) {
const point p( rng( 3, SEEX * 2 - 4 ), rng( SEEY, SEEY * 2 - 2 ) );
if( m.has_flag( ter_furn_flag::TFLAG_DIGGABLE, p ) ) {
place_trap_if_clear( m, p, tr_landmine_buried );
} else {
place_trap_if_clear( m, p, tr_landmine );
}
}
//Spawn 6-20 puddles of blood on tiles without mines
for( int i = 0; i < num_mines; i++ ) {
const point p2( rng( 3, SEEX * 2 - 4 ), rng( SEEY, SEEY * 2 - 2 ) );
if( m.tr_at( { p2, abs_sub.z } ).is_null() ) {
m.add_field( { p2, abs_sub.z }, fd_blood, rng( 1, 3 ) );
//10% chance to spawn a corpse of dead people/zombie on a tile with blood
if( one_in( 10 ) ) {
m.add_corpse( { p2, abs_sub.z } );
for( const tripoint &loc : m.points_in_radius( { p2, abs_sub.z }, 1 ) ) {