-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
map_extras.cpp
2903 lines (2646 loc) · 115 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 <cstdlib>
#include <memory>
#include <set>
#include <unordered_map>
#include <utility>
#include <vector>
#include <map>
#include "auto_note.h"
#include "cellular_automata.h"
#include "debug.h"
#include "field.h"
#include "fungal_effects.h"
#include "game.h"
#include "generic_factory.h"
#include "map.h"
#include "map_iterator.h"
#include "mapdata.h"
#include "mapgen_functions.h"
#include "overmapbuffer.h"
#include "overmap.h"
#include "rng.h"
#include "trap.h"
#include "veh_type.h"
#include "mapgendata.h"
#include "vehicle.h"
#include "vehicle_group.h"
#include "vpart_position.h"
#include "vpart_range.h"
#include "calendar.h"
#include "cata_utility.h"
#include "enums.h"
#include "game_constants.h"
#include "int_id.h"
#include "item.h"
#include "line.h"
#include "optional.h"
#include "string_id.h"
#include "translations.h"
#include "type_id.h"
#include "coordinate_conversions.h"
#include "options.h"
#include "colony.h"
#include "item_group.h"
#include "json.h"
#include "mapgen.h"
#include "point.h"
#include "string_formatter.h"
#include "weighted_list.h"
#include "rng.h"
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*
}
debugmsg( "Invalid map_extra_method" );
abort();
}
} // 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 );
}
namespace MapExtras
{
static const mongroup_id GROUP_NETHER_CAPTURED( "GROUP_NETHER_CAPTURED" );
static const mongroup_id GROUP_NETHER_PORTAL( "GROUP_NETHER_PORTAL" );
static const mongroup_id GROUP_MAYBE_MIL( "GROUP_MAYBE_MIL" );
static const mongroup_id GROUP_FISH( "GROUP_FISH" );
static const mongroup_id GROUP_FUNGI_FUNGALOID( "GROUP_FUNGI_FUNGALOID" );
static const mongroup_id GROUP_MI_GO_CAMP_OM( "GROUP_MI-GO_CAMP_OM" );
static const mtype_id mon_zombie_tough( "mon_zombie_tough" );
static const mtype_id mon_marloss_zealot_f( "mon_marloss_zealot_f" );
static const mtype_id mon_marloss_zealot_m( "mon_marloss_zealot_m" );
static const mtype_id mon_zombie_smoker( "mon_zombie_smoker" );
static const mtype_id mon_zombie_scientist( "mon_zombie_scientist" );
static const mtype_id mon_chickenbot( "mon_chickenbot" );
static const mtype_id mon_dispatch( "mon_dispatch" );
static const mtype_id mon_tankbot( "mon_tankbot" );
static const mtype_id mon_turret_bmg( "mon_turret_bmg" );
static const mtype_id mon_turret_rifle( "mon_turret_rifle" );
static const mtype_id mon_zombie_spitter( "mon_zombie_spitter" );
static const mtype_id mon_zombie_soldier( "mon_zombie_soldier" );
static const mtype_id mon_zombie_military_pilot( "mon_zombie_military_pilot" );
static const mtype_id mon_zombie_bio_op( "mon_zombie_bio_op" );
static const mtype_id mon_shia( "mon_shia" );
static const mtype_id mon_spider_web( "mon_spider_web" );
static const mtype_id mon_spider_widow_giant( "mon_spider_widow_giant" );
static const mtype_id mon_spider_cellar_giant( "mon_spider_cellar_giant" );
static const mtype_id mon_wasp( "mon_wasp" );
static const mtype_id mon_jabberwock( "mon_jabberwock" );
static const mtype_id mon_wolf( "mon_wolf" );
const generic_factory<map_extra> &mapExtraFactory()
{
return extras;
}
static void mx_null( map &, const tripoint & )
{
debugmsg( "Tried to generate null map extra." );
}
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( "PLANT" ) || fid.has_flag( "FLOWER" ) || fid.has_flag( "ORGANIC" ) ) {
m.i_clear( loc );
m.furn_set( loc, f_null );
m.spawn_item( loc, "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_str_id( "t_grass_dead" )},
{t_grass_long, ter_str_id( "t_grass_dead" )},
{t_grass_tall, ter_str_id( "t_grass_dead" )},
{t_moss, ter_str_id( "t_grass_dead" )},
{t_tree_pine, ter_str_id( "t_tree_deadpine" )},
{t_tree_birch, ter_str_id( "t_tree_birch_harvested" )},
{t_tree_willow, ter_str_id( "t_tree_dead" )},
{t_tree_hickory, ter_str_id( "t_tree_hickory_dead" )},
{t_tree_hickory_harvested, ter_str_id( "t_tree_hickory_dead" )},
{t_grass_golf, ter_str_id( "t_grass_dead" )},
{t_grass_white, ter_str_id( "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( "SHRUB" ) ) {
m.ter_set( loc, t_dirt );
if( one_in( 2 ) ) {
m.spawn_item( loc, "stick" );
}
} else if( tr.has_flag( "TREE" ) ) {
if( one_in( 4 ) ) {
m.ter_set( loc, ter_str_id( "t_trunk" ) );
} else if( one_in( 4 ) ) {
m.ter_set( loc, ter_str_id( "t_stump" ) );
} else {
m.ter_set( loc, ter_str_id( "t_tree_dead" ) );
}
} else if( tr.has_flag( "YOUNG" ) ) {
m.ter_set( loc, ter_str_id( "t_dirt" ) );
if( one_in( 2 ) ) {
m.spawn_item( loc, "stick_long" );
}
}
}
static void mx_house_wasp( map &m, const tripoint & )
{
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 int podx = rng( 1, SEEX * 2 - 2 );
const int pody = rng( 1, SEEY * 2 - 2 );
int nonx = 0;
int nony = 0;
while( nonx == 0 && nony == 0 ) {
nonx = rng( -1, 1 );
nony = rng( -1, 1 );
}
for( int x = -1; x <= 1; x++ ) {
for( int y = -1; y <= 1; y++ ) {
if( ( x != nonx || y != nony ) && ( x != 0 || y != 0 ) ) {
m.ter_set( point( podx + x, pody + y ), t_paper );
}
}
}
m.add_spawn( mon_wasp, 1, point( podx, pody ) );
}
m.place_items( "rare", 70, point_zero, point( SEEX * 2 - 1, SEEY * 2 - 1 ), false,
calendar::start_of_cataclysm );
}
static void mx_house_spider( map &m, const tripoint & )
{
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 ), point( i, j ) );
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, 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, i, j, fd_web, 1 );
}
}
}
}
m.place_items( "rare", 60, point_zero, point( SEEX * 2 - 1, SEEY * 2 - 1 ), false,
calendar::start_of_cataclysm );
}
static void mx_helicopter( map &m, const tripoint &abs_sub )
{
int cx = rng( 6, SEEX * 2 - 7 );
int cy = 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( TFLAG_DIGGABLE ) ) {
m.ter_set( tripoint( x, y, abs_sub.z ), t_dirtmound );
} else {
if( x >= cx - dice( 1, 5 ) && x <= cx + dice( 1, 5 ) && y >= cy - dice( 1, 5 ) &&
y <= cy + dice( 1, 5 ) ) {
if( one_in( 7 ) && m.ter( tripoint( x, y, abs_sub.z ) )->has_flag( TFLAG_DIGGABLE ) ) {
m.ter_set( tripoint( x, y, abs_sub.z ), t_dirtmound );
}
}
if( x >= cx - dice( 1, 6 ) && x <= cx + dice( 1, 6 ) && y >= cy - dice( 1, 6 ) &&
y <= cy + 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( 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( TFLAG_DIGGABLE ) ) {
m.ter_set( tripoint( x, y, abs_sub.z ), t_dirtmound );
}
}
} else if( one_in( 4 + ( abs( x - cx ) + ( abs( y -
cy ) ) ) ) ) { // 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( TFLAG_DIGGABLE ) ) {
m.ter_set( tripoint( x, y, abs_sub.z ), t_dirtmound );
}
}
}
}
}
}
int dir1 = rng( 0, 359 );
auto crashed_hull = vgroup_id( "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>( 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
int x_length = std::abs( bbox.p2.x - bbox.p1.x );
int y_length = std::abs( bbox.p2.y - bbox.p1.y );
// cont.
int x_offset = veh->dir_vec().x * x_length / 2;
int y_offset = veh->dir_vec().y * y_length / 2;
int x_min = abs( bbox.p1.x ) + 0;
int y_min = 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.
int x1 = clamp( cx + x_offset, x_min, x_max );
int y1 = clamp( cy + y_offset, y_min, y_max );
vehicle *wreckage = m.add_vehicle( crashed_hull, tripoint( x1, y1, 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.xy() );
} else {
if( one_in( 5 ) ) {
m.add_spawn( mon_zombie_bio_op, 1, pos.xy() );
} else if( one_in( 5 ) ) {
m.add_spawn( mon_zombie_scientist, 1, pos.xy() );
} else {
m.add_spawn( mon_zombie_soldier, 1, pos.xy() );
}
}
// Delete the items that would have spawned here from a "corpse"
for( auto 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.xy() );
} else {
if( !one_in( 3 ) ) {
m.add_spawn( mon_zombie_soldier, 1, pos.xy() );
}
}
// Delete the items that would have spawned here from a "corpse"
for( auto 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.xy() );
// Delete the items that would have spawned here from a "corpse"
for( auto 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:
break;
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 ) );
}
}
}
static void mx_military( map &m, const tripoint & )
{
int num_bodies = dice( 2, 6 );
for( int i = 0; i < num_bodies; i++ ) {
if( const auto p = random_point( m, [&m]( const tripoint & n ) {
return m.passable( n );
} ) ) {
if( one_in( 10 ) ) {
m.add_spawn( mon_zombie_soldier, 1, p->xy() );
} else if( one_in( 25 ) ) {
if( one_in( 2 ) ) {
m.add_spawn( mon_zombie_bio_op, 1, p->xy() );
} else {
m.add_spawn( mon_dispatch, 1, p->xy() );
}
} else {
m.place_items( "map_extra_military", 100, *p, *p, true, calendar::start_of_cataclysm );
}
}
}
int num_monsters = rng( 0, 3 );
for( int i = 0; i < num_monsters; i++ ) {
int mx = rng( 1, SEEX * 2 - 2 ), my = rng( 1, SEEY * 2 - 2 );
m.place_spawns( GROUP_NETHER_CAPTURED, 1, point( mx, my ), point( mx, my ), 1, true );
}
m.place_spawns( GROUP_MAYBE_MIL, 2, point_zero, point( SEEX * 2 - 1, SEEY * 2 - 1 ),
0.1f ); //0.1 = 1-5
m.place_items( "rare", 25, point_zero, point( SEEX * 2 - 1, SEEY * 2 - 1 ), true,
calendar::start_of_cataclysm );
}
static void mx_science( map &m, const tripoint & )
{
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 );
} ) ) {
if( one_in( 10 ) ) {
m.add_spawn( mon_zombie_scientist, 1, p->xy() );
} else {
m.place_items( "map_extra_science", 100, *p, *p, true, calendar::start_of_cataclysm );
}
}
}
int num_monsters = rng( 0, 3 );
for( int i = 0; i < num_monsters; i++ ) {
int mx = rng( 1, SEEX * 2 - 2 ), my = rng( 1, SEEY * 2 - 2 );
m.place_spawns( GROUP_NETHER_CAPTURED, 1, point( mx, my ), point( mx, my ), 1, true );
}
m.place_items( "rare", 45, point_zero, point( SEEX * 2 - 1, SEEY * 2 - 1 ), true,
calendar::start_of_cataclysm );
}
static void mx_collegekids( map &m, const tripoint & )
{
//college kids that got into trouble
int num_bodies = dice( 2, 6 );
int type = dice( 1, 10 );
for( int i = 0; i < num_bodies; i++ ) {
if( const auto p = random_point( m, [&m]( const tripoint & n ) {
return m.passable( n );
} ) ) {
if( one_in( 10 ) ) {
m.add_spawn( mon_zombie_tough, 1, p->xy() );
} else {
if( type < 6 ) { // kids going to a cabin in the woods
m.place_items( "map_extra_college_camping", 100, *p, *p, true, calendar::start_of_cataclysm );
} else if( type < 9 ) { // kids going to a sporting event
m.place_items( "map_extra_college_sports", 100, *p, *p, true, calendar::start_of_cataclysm );
} else { // kids going to a lake
m.place_items( "map_extra_college_lake", 100, *p, *p, true, calendar::start_of_cataclysm );
}
}
}
}
int num_monsters = rng( 0, 3 );
for( int i = 0; i < num_monsters; i++ ) {
int mx = rng( 1, SEEX * 2 - 2 ), my = rng( 1, SEEY * 2 - 2 );
m.place_spawns( GROUP_NETHER_CAPTURED, 1, point( mx, my ), point( mx, my ), 1, true );
}
}
static void mx_roadblock( map &m, const tripoint &abs_sub )
{
const tripoint 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 = is_ot_match( "road", north, ot_match_type::type );
const bool road_at_south = is_ot_match( "road", south, ot_match_type::type );
const bool road_at_west = is_ot_match( "road", west, ot_match_type::type );
const bool road_at_east = is_ot_match( "road", east, ot_match_type::type );
const auto spawn_turret = [&]( int x, int y ) {
if( one_in( 2 ) ) {
m.add_spawn( mon_turret_bmg, 1, point( x, y ) );
} else {
m.add_spawn( mon_turret_rifle, 1, point( x, y ) );
}
};
bool mil = false;
if( one_in( 3 ) ) {
mil = true;
}
if( mil ) { //Military doesn't joke around with their barricades!
if( one_in( 2 ) ) {
if( road_at_north ) {
line( &m, t_fence_barbed, 4, 3, 10, 3 );
line( &m, t_fence_barbed, 13, 3, 19, 3 );
}
if( road_at_east ) {
line( &m, t_fence_barbed, SEEX * 2 - 3, 4, SEEX * 2 - 3, 10 );
line( &m, t_fence_barbed, SEEX * 2 - 3, 13, SEEX * 2 - 3, 19 );
}
if( road_at_south ) {
line( &m, t_fence_barbed, 4, SEEY * 2 - 3, 10, SEEY * 2 - 3 );
line( &m, t_fence_barbed, 13, SEEY * 2 - 3, 19, SEEY * 2 - 3 );
}
if( road_at_east ) {
line( &m, t_fence_barbed, 3, 4, 3, 10 );
line( &m, t_fence_barbed, 3, 13, 3, 19 );
}
} else {
if( road_at_north ) {
line_furn( &m, f_sandbag_half, 4, 3, 10, 3 );
line_furn( &m, f_sandbag_half, 13, 3, 19, 3 );
}
if( road_at_east ) {
line_furn( &m, f_sandbag_half, SEEX * 2 - 3, 4, SEEX * 2 - 3, 10 );
line_furn( &m, f_sandbag_half, SEEX * 2 - 3, 13, SEEX * 2 - 3, 19 );
}
if( road_at_south ) {
line_furn( &m, f_sandbag_half, 4, SEEY * 2 - 3, 10, SEEY * 2 - 3 );
line_furn( &m, f_sandbag_half, 13, SEEY * 2 - 3, 19, SEEY * 2 - 3 );
}
if( road_at_east ) {
line_furn( &m, f_sandbag_half, 3, 4, 3, 10 );
line_furn( &m, f_sandbag_half, 3, 13, 3, 19 );
}
}
if( one_in( 3 ) ) { // Chicken delivery
m.add_vehicle( vgroup_id( "military_vehicles" ), tripoint( 12, SEEY * 2 - 7, abs_sub.z ), 0, 70,
-1 );
m.add_spawn( mon_chickenbot, 1, point( 12, 12 ) );
} else if( one_in( 2 ) ) { // TAAANK
// The truck's wrecked...with fuel. Explosive barrel?
m.add_vehicle( vproto_id( "military_cargo_truck" ), point( 12, SEEY * 2 - 8 ), 0, 70, -1 );
m.add_spawn( mon_tankbot, 1, point( 12, 12 ) );
} else { // Vehicle & turrets
m.add_vehicle( vgroup_id( "military_vehicles" ), tripoint( 12, SEEY * 2 - 10, abs_sub.z ), 0, 70,
-1 );
if( road_at_north ) {
spawn_turret( 12, 6 );
}
if( road_at_east ) {
spawn_turret( 18, 12 );
}
if( road_at_south ) {
spawn_turret( 12, 18 );
}
if( road_at_west ) {
spawn_turret( 6, 12 );
}
}
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.place_items( "map_extra_military", 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, 4, 3, 10, 3 );
line_furn( &m, f_barricade_road, 13, 3, 19, 3 );
m.add_spawn( mon_turret_rifle, 1, point( 12, 1 ) );
}
if( road_at_east ) {
line_furn( &m, f_barricade_road, SEEX * 2 - 3, 4, SEEX * 2 - 3, 10 );
line_furn( &m, f_barricade_road, SEEX * 2 - 3, 13, SEEX * 2 - 3, 19 );
m.add_spawn( mon_turret_rifle, 1, point( SEEX * 2 - 1, 12 ) );
}
if( road_at_south ) {
line_furn( &m, f_barricade_road, 4, SEEY * 2 - 3, 10, SEEY * 2 - 3 );
line_furn( &m, f_barricade_road, 13, SEEY * 2 - 3, 19, SEEY * 2 - 3 );
m.add_spawn( mon_turret_rifle, 1, point( 12, SEEY * 2 - 1 ) );
}
if( road_at_west ) {
line_furn( &m, f_barricade_road, 3, 4, 3, 10 );
line_furn( &m, f_barricade_road, 3, 13, 3, 19 );
m.add_spawn( mon_turret_rifle, 1, point( 1, 12 ) );
}
m.add_vehicle( vproto_id( "policecar" ), point( 8, 6 ), 20 );
m.add_vehicle( vproto_id( "policecar" ), point( 16, SEEY * 2 - 6 ), 145 );
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( "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 );
}
}
}
}
}
static void mx_marloss_pilgrimage( map &m, const tripoint &abs_sub )
{
const tripoint leader_pos( rng( 4, 19 ), rng( 4, 19 ), abs_sub.z );
const int max_followers = rng( 3, 12 );
const int rad = 3;
tripoint_range spawnzone = m.points_in_radius( leader_pos, rad );
m.place_npc( leader_pos.xy(), string_id<npc_template>( "marloss_voice" ) );
for( int spawned = 0 ; spawned <= max_followers ; spawned++ ) {
tripoint where = random_entry( spawnzone );
/// @todo wrong: this access the main game map, not m. Also accesses creatures currently loaded.
if( g->is_empty( where ) ) {
one_in( 2 ) ? m.add_spawn( mon_marloss_zealot_f, 1,
where.xy() ) : m.add_spawn( mon_marloss_zealot_m, 1, where.xy() );
}
}
}
static void mx_bandits_block( map &m, const tripoint &abs_sub )
{
const tripoint 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 = is_ot_match( "road", north, ot_match_type::type );
const bool road_at_south = is_ot_match( "road", south, ot_match_type::type );
const bool road_at_west = is_ot_match( "road", west, ot_match_type::type );
const bool road_at_east = is_ot_match( "road", east, ot_match_type::type );
if( forest_at_north && forest_at_south &&
road_at_west && road_at_east ) {
line( &m, t_trunk, 1, 3, 1, 6 );
line( &m, t_trunk, 1, 8, 1, 13 );
line( &m, t_trunk, 2, 14, 2, 17 );
line( &m, t_trunk, 1, 18, 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 ), string_id<npc_template>( "bandit" ) );
if( one_in( 2 ) ) {
m.place_npc( point_south_east, string_id<npc_template>( "bandit" ) );
}
} else if( forest_at_west && forest_at_east &&
road_at_north && road_at_south ) {
line( &m, t_trunk, 1, 1, 3, 1 );
line( &m, t_trunk, 5, 1, 10, 1 );
line( &m, t_trunk, 11, 3, 16, 3 );
line( &m, t_trunk, 17, 2, 21, 2 );
m.ter_set( point( 22, 2 ), t_stump );
m.ter_set( point_south, t_improvised_shelter );
m.place_npc( point( 20, 3 ), string_id<npc_template>( "bandit" ) );
if( one_in( 2 ) ) {
m.place_npc( point_south, string_id<npc_template>( "bandit" ) );
}
}
}
static void mx_drugdeal( map &m, const tripoint &abs_sub )
{
// Decide on a drug type
int num_drugs = 0;
itype_id drugtype;
switch( rng( 1, 10 ) ) {
case 1:
// Weed
num_drugs = rng( 20, 30 );
drugtype = "weed";
break;
case 2:
case 3:
case 4:
case 5:
// Cocaine
num_drugs = rng( 10, 20 );
drugtype = "coke";
break;
case 6:
case 7:
case 8:
// Meth
num_drugs = rng( 8, 14 );
drugtype = "meth";
break;
case 9:
case 10:
// Heroin
num_drugs = rng( 6, 12 );
drugtype = "heroin";
break;
}
int num_bodies_a = dice( 3, 3 );
int num_bodies_b = dice( 3, 3 );
bool north_south = one_in( 2 );
bool a_has_drugs = one_in( 2 );
for( int i = 0; i < num_bodies_a; i++ ) {
int x = 0;
int y = 0;
int x_offset = 0;
int y_offset = 0;
int tries = 0;
do { // Loop until we find a valid spot to dump a body, or we give up
if( north_south ) {
x = rng( 0, SEEX * 2 - 1 );
y = rng( 0, SEEY - 4 );
x_offset = 0;
y_offset = -1;
} else {
x = rng( 0, SEEX - 4 );
y = rng( 0, SEEY * 2 - 1 );
x_offset = -1;
y_offset = 0;
}
tries++;
} while( tries < 10 && m.impassable( point( x, y ) ) );
if( tries < 10 ) { // We found a valid spot!
if( a_has_drugs && num_drugs > 0 ) {
int drugs_placed = rng( 2, 6 );
if( drugs_placed > num_drugs ) {
drugs_placed = num_drugs;
num_drugs = 0;
}
m.spawn_item( point( x, y ), drugtype, 0, drugs_placed );
}
if( one_in( 10 ) ) {
m.add_spawn( mon_zombie_spitter, 1, point( x, y ) );
} else {
m.place_items( "map_extra_drugdeal", 100, point( x, y ), point( x, y ), true,
calendar::start_of_cataclysm );
int splatter_range = rng( 1, 3 );
for( int j = 0; j <= splatter_range; j++ ) {
m.add_field( {x + j * x_offset, y + j * y_offset, abs_sub.z}, fd_blood, 1, 0_turns );
}
}
}
}
for( int i = 0; i < num_bodies_b; i++ ) {
int x = 0;
int y = 0;
int x_offset = 0;
int y_offset = 0;
int tries = 0;
do { // Loop until we find a valid spot to dump a body, or we give up
if( north_south ) {
x = rng( 0, SEEX * 2 - 1 );
y = rng( SEEY + 3, SEEY * 2 - 1 );
x_offset = 0;
y_offset = 1;
} else {
x = rng( SEEX + 3, SEEX * 2 - 1 );
y = rng( 0, SEEY * 2 - 1 );
x_offset = 1;
y_offset = 0;
}
tries++;
} while( tries < 10 && m.impassable( point( x, y ) ) );
if( tries < 10 ) { // We found a valid spot!
if( one_in( 20 ) ) {
m.add_spawn( mon_zombie_smoker, 1, point( x, y ) );
} else {
m.place_items( "map_extra_drugdeal", 100, point( x, y ), point( x, y ), true,
calendar::start_of_cataclysm );
int splatter_range = rng( 1, 3 );
for( int j = 0; j <= splatter_range; j++ ) {
m.add_field( {x + j * x_offset, y + j * y_offset, abs_sub.z}, fd_blood, 1, 0_turns );
}
if( !a_has_drugs && num_drugs > 0 ) {
int drugs_placed = rng( 2, 6 );
if( drugs_placed > num_drugs ) {
drugs_placed = num_drugs;
num_drugs = 0;
}
m.spawn_item( point( x, y ), drugtype, 0, drugs_placed );
}
}
}
}
int num_monsters = rng( 0, 3 );
for( int i = 0; i < num_monsters; i++ ) {
int mx = rng( 1, SEEX * 2 - 2 ), my = rng( 1, SEEY * 2 - 2 );
m.place_spawns( GROUP_NETHER_CAPTURED, 1, point( mx, my ), point( mx, my ), 1, true );
}
}
static void mx_supplydrop( map &m, const tripoint &/*abs_sub*/ )
{
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;
}
m.furn_set( p->xy(), f_crate_c );
std::string item_group;
switch( rng( 1, 10 ) ) {
case 1:
case 2:
case 3:
case 4:
item_group = "mil_food";
break;
case 5:
case 6:
case 7:
item_group = "grenades";
break;
case 8:
case 9:
item_group = "mil_armor";
break;
case 10:
item_group = "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 );
}
}
}
static void mx_portal( map &m, const tripoint &abs_sub )
{
// All points except the borders are valid--we need the 1 square buffer so that we can do a 1 unit radius
// around our chosen portal point without clipping against the edge of the map.
const tripoint_range points = m.points_in_rectangle( { 1, 1, abs_sub.z }, { SEEX * 2 - 2, SEEY * 2 - 2, abs_sub.z } );
// Get a random point in our collection that does not have a trap and does not have the NO_FLOOR flag.
const cata::optional<tripoint> portal_pos = random_point( points, [&]( const tripoint & p ) {
return !m.has_flag_ter( TFLAG_NO_FLOOR, p ) && m.tr_at( p ).is_null();
} );
// If we can't get a point to spawn the portal (e.g. we're triggered in entirely open air) we're done here.
if( !portal_pos ) {
return;
}
// For our portal point and every adjacent location, make rubble if it doesn't have the NO_FLOOR flag.
for( const tripoint &p : m.points_in_radius( *portal_pos, 1 ) ) {
if( !m.has_flag_ter( TFLAG_NO_FLOOR, p ) ) {
m.make_rubble( p, f_rubble_rock, true );
}
}
m.trap_set( *portal_pos, tr_portal );
// We'll make between 0 and 4 attempts to spawn monsters here.
int num_monsters = rng( 0, 4 );
for( int i = 0; i < num_monsters; i++ ) {
// Get a random location from our points that is not the portal location, does not have the
// NO_FLOOR flag, and isn't currently occupied by a creature.
const cata::optional<tripoint> mon_pos = random_point( points, [&]( const tripoint & p ) {
/// @todo wrong: this checks for creatures on the main game map. Not within the map m.
return !m.has_flag_ter( TFLAG_NO_FLOOR, p ) && *portal_pos != p && !g->critter_at( p );
} );
// If we couldn't get a random location, we can't place a monster and we know that there are no
// more possible valid locations, so just bail.
if( !mon_pos ) {
break;
}
// Make rubble here--it's not necessarily a location that is directly adjacent to the portal.
m.make_rubble( *mon_pos, f_rubble_rock, true );
// Spawn a single monster from our group here.
m.place_spawns( GROUP_NETHER_PORTAL, 1, mon_pos->xy(), mon_pos->xy(), 1, true );
}
}
static void mx_minefield( map &m, const tripoint &abs_sub )
{
const tripoint 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 bridge_at_center = is_ot_match( "bridge", center, ot_match_type::type );
const bool bridge_at_north = is_ot_match( "bridge", north, ot_match_type::type );
const bool bridge_at_south = is_ot_match( "bridge", south, ot_match_type::type );
const bool bridge_at_west = is_ot_match( "bridge", west, ot_match_type::type );
const bool bridge_at_east = is_ot_match( "bridge", east, ot_match_type::type );
const bool road_at_north = is_ot_match( "road", north, ot_match_type::type );
const bool road_at_south = is_ot_match( "road", south, ot_match_type::type );
const bool road_at_west = is_ot_match( "road", west, ot_match_type::type );
const bool road_at_east = is_ot_match( "road", east, ot_match_type::type );
const int num_mines = rng( 6, 20 );
const std::string text = _( "DANGER! MINEFIELD!" );
int x, y, x1, y1 = 0;
if( bridge_at_north && !bridge_at_center && road_at_south ) {
//Sandbag block at the left edge
line_furn( &m, f_sandbag_half, 3, 4, 3, 7 );
line_furn( &m, f_sandbag_half, 3, 7, 9, 7 );
line_furn( &m, f_sandbag_half, 9, 4, 9, 7 );
//7.62x51mm casings left from m60 of the humvee
for( const auto &loc : m.points_in_radius( { 6, 4, abs_sub.z }, 3, 0 ) ) {
if( one_in( 4 ) ) {
m.spawn_item( loc, "762_51_casing" );
}
}
//50% chance to spawn a humvee in the left block
if( one_in( 2 ) ) {
m.add_vehicle( vproto_id( "humvee" ), point( 5, 3 ), 270, 70, -1 );
}
//Sandbag block at the right edge
line_furn( &m, f_sandbag_half, 15, 3, 15, 6 );
line_furn( &m, f_sandbag_half, 15, 6, 20, 6 );
line_furn( &m, f_sandbag_half, 20, 3, 20, 6 );
//5.56x45mm casings left from a soldier
for( const auto &loc : m.points_in_radius( { 17, 4, abs_sub.z }, 2, 0 ) ) {
if( one_in( 4 ) ) {
m.spawn_item( loc, "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( "mon_zombie_soldier_death_drops", { 17, 5, abs_sub.z } );
m.add_item_or_charges( { 17, 5, abs_sub.z }, body );
}