forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
monattack.cpp
5891 lines (5240 loc) · 210 KB
/
monattack.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 "monattack.h"
#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <list>
#include <map>
#include <memory>
#include <ostream>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "avatar.h"
#include "ballistics.h"
#include "bionics.h"
#include "bodypart.h"
#include "calendar.h"
#include "character.h"
#include "character_id.h"
#include "character_martial_arts.h"
#include "colony.h"
#include "creature.h"
#include "damage.h"
#include "debug.h"
#include "dispersion.h"
#include "effect.h"
#include "enums.h"
#include "event.h"
#include "event_bus.h"
#include "explosion.h"
#include "field_type.h"
#include "flat_set.h"
#include "fungal_effects.h"
#include "game.h"
#include "game_constants.h"
#include "gun_mode.h"
#include "int_id.h"
#include "item.h"
#include "item_stack.h"
#include "itype.h"
#include "iuse.h"
#include "iuse_actor.h"
#include "line.h"
#include "map.h"
#include "map_iterator.h"
#include "mapdata.h"
#include "martialarts.h"
#include "material.h"
#include "memorial_logger.h"
#include "messages.h"
#include "mondefense.h"
#include "monfaction.h"
#include "monster.h"
#include "morale_types.h"
#include "mtype.h"
#include "name.h"
#include "npc.h"
#include "output.h"
#include "pathfinding.h"
#include "player.h"
#include "point.h"
#include "projectile.h"
#include "ranged.h"
#include "rng.h"
#include "sounds.h"
#include "speech.h"
#include "string_formatter.h"
#include "tileray.h"
#include "timed_event.h"
#include "translations.h"
#include "type_id.h"
#include "ui.h"
#include "ui_manager.h"
#include "units.h"
#include "value_ptr.h"
#include "weighted_list.h"
static const activity_id ACT_RELOAD( "ACT_RELOAD" );
static const ammo_effect_str_id ammo_effect_NO_OVERSHOOT( "NO_OVERSHOOT" );
static const ammo_effect_str_id ammo_effect_BLINDS_EYES( "BLINDS_EYES" );
static const ammo_effect_str_id ammo_effect_NO_DAMAGE_SCALING( "NO_DAMAGE_SCALING" );
static const ammo_effect_str_id ammo_effect_APPLY_SAP( "APPLY_SAP" );
static const efftype_id effect_ai_controlled( "ai_controlled" );
static const efftype_id effect_assisted( "assisted" );
static const efftype_id effect_attention( "attention" );
static const efftype_id effect_bite( "bite" );
static const efftype_id effect_bleed( "bleed" );
static const efftype_id effect_blind( "blind" );
static const efftype_id effect_boomered( "boomered" );
static const efftype_id effect_corroding( "corroding" );
static const efftype_id effect_countdown( "countdown" );
static const efftype_id effect_darkness( "darkness" );
static const efftype_id effect_dazed( "dazed" );
static const efftype_id effect_deaf( "deaf" );
static const efftype_id effect_dermatik( "dermatik" );
static const efftype_id effect_downed( "downed" );
static const efftype_id effect_dragging( "dragging" );
static const efftype_id effect_fearparalyze( "fearparalyze" );
static const efftype_id effect_fungus( "fungus" );
static const efftype_id effect_glowing( "glowing" );
static const efftype_id effect_got_checked( "got_checked" );
static const efftype_id effect_grabbed( "grabbed" );
static const efftype_id effect_grabbing( "grabbing" );
static const efftype_id effect_grown_of_fuse( "grown_of_fuse" );
static const efftype_id effect_has_bag( "has_bag" );
static const efftype_id effect_infected( "infected" );
static const efftype_id effect_laserlocked( "laserlocked" );
static const efftype_id effect_onfire( "onfire" );
static const efftype_id effect_operating( "operating" );
static const efftype_id effect_paid( "paid" );
static const efftype_id effect_paralyzepoison( "paralyzepoison" );
static const efftype_id effect_pet( "pet" );
static const efftype_id effect_raising( "raising" );
static const efftype_id effect_rat( "rat" );
static const efftype_id effect_shrieking( "shrieking" );
static const efftype_id effect_slimed( "slimed" );
static const efftype_id effect_stunned( "stunned" );
static const efftype_id effect_targeted( "targeted" );
static const efftype_id effect_under_op( "under_operation" );
static const itype_id itype_ant_egg( "ant_egg" );
static const itype_id itype_badge_cybercop( "badge_cybercop" );
static const itype_id itype_badge_deputy( "badge_deputy" );
static const itype_id itype_badge_detective( "badge_detective" );
static const itype_id itype_badge_doctor( "badge_doctor" );
static const itype_id itype_badge_marshal( "badge_marshal" );
static const itype_id itype_badge_swat( "badge_swat" );
static const itype_id itype_bot_c4_hack( "bot_c4_hack" );
static const itype_id itype_bot_flashbang_hack( "bot_flashbang_hack" );
static const itype_id itype_bot_gasbomb_hack( "bot_gasbomb_hack" );
static const itype_id itype_bot_grenade_hack( "bot_grenade_hack" );
static const itype_id itype_bot_manhack( "bot_manhack" );
static const itype_id itype_bot_mininuke_hack( "bot_mininuke_hack" );
static const itype_id itype_bot_pacification_hack( "bot_pacification_hack" );
static const itype_id itype_c4( "c4" );
static const itype_id itype_c4armed( "c4armed" );
static const itype_id itype_e_handcuffs( "e_handcuffs" );
static const itype_id itype_mininuke( "mininuke" );
static const itype_id itype_mininuke_act( "mininuke_act" );
static const skill_id skill_gun( "gun" );
static const skill_id skill_launcher( "launcher" );
static const skill_id skill_melee( "melee" );
static const skill_id skill_rifle( "rifle" );
static const skill_id skill_unarmed( "unarmed" );
static const species_id species_BLOB( "BLOB" );
static const species_id LEECH_PLANT( "LEECH_PLANT" );
static const species_id ZOMBIE( "ZOMBIE" );
static const std::string flag_AUTODOC_COUCH( "AUTODOC_COUCH" );
static const trait_id trait_ACIDBLOOD( "ACIDBLOOD" );
static const trait_id trait_MARLOSS( "MARLOSS" );
static const trait_id trait_MARLOSS_BLUE( "MARLOSS_BLUE" );
static const trait_id trait_PARAIMMUNE( "PARAIMMUNE" );
static const trait_id trait_PROF_CHURL( "PROF_CHURL" );
static const trait_id trait_PROF_CYBERCO( "PROF_CYBERCO" );
static const trait_id trait_PROF_FED( "PROF_FED" );
static const trait_id trait_PROF_PD_DET( "PROF_PD_DET" );
static const trait_id trait_PROF_POLICE( "PROF_POLICE" );
static const trait_id trait_PROF_SWAT( "PROF_SWAT" );
static const trait_id trait_TAIL_CATTLE( "TAIL_CATTLE" );
static const trait_id trait_THRESH_MARLOSS( "THRESH_MARLOSS" );
static const trait_id trait_THRESH_MYCUS( "THRESH_MYCUS" );
static const mtype_id mon_ant_acid_larva( "mon_ant_acid_larva" );
static const mtype_id mon_ant_acid_queen( "mon_ant_acid_queen" );
static const mtype_id mon_ant_larva( "mon_ant_larva" );
static const mtype_id mon_biollante( "mon_biollante" );
static const mtype_id mon_blob( "mon_blob" );
static const mtype_id mon_blob_brain( "mon_blob_brain" );
static const mtype_id mon_blob_large( "mon_blob_large" );
static const mtype_id mon_blob_small( "mon_blob_small" );
static const mtype_id mon_breather( "mon_breather" );
static const mtype_id mon_breather_hub( "mon_breather_hub" );
static const mtype_id mon_creeper_hub( "mon_creeper_hub" );
static const mtype_id mon_creeper_vine( "mon_creeper_vine" );
static const mtype_id mon_defective_robot_nurse( "mon_nursebot_defective" );
static const mtype_id mon_dermatik( "mon_dermatik" );
static const mtype_id mon_fungal_hedgerow( "mon_fungal_hedgerow" );
static const mtype_id mon_fungal_tendril( "mon_fungal_tendril" );
static const mtype_id mon_fungal_wall( "mon_fungal_wall" );
static const mtype_id mon_fungaloid( "mon_fungaloid" );
static const mtype_id mon_headless_dog_thing( "mon_headless_dog_thing" );
static const mtype_id mon_hound_tindalos_afterimage( "mon_hound_tindalos_afterimage" );
static const mtype_id mon_leech_blossom( "mon_leech_blossom" );
static const mtype_id mon_leech_root_drone( "mon_leech_root_drone" );
static const mtype_id mon_leech_root_runner( "mon_leech_root_runner" );
static const mtype_id mon_leech_stalk( "mon_leech_stalk" );
static const mtype_id mon_manhack( "mon_manhack" );
static const mtype_id mon_shadow( "mon_shadow" );
static const mtype_id mon_triffid( "mon_triffid" );
static const mtype_id mon_turret_searchlight( "mon_turret_searchlight" );
static const mtype_id mon_zombie_dancer( "mon_zombie_dancer" );
static const mtype_id mon_zombie_gasbag_crawler( "mon_zombie_gasbag_crawler" );
static const mtype_id mon_zombie_gasbag_impaler( "mon_zombie_gasbag_impaler" );
static const mtype_id mon_zombie_jackson( "mon_zombie_jackson" );
static const mtype_id mon_zombie_skeltal_minion( "mon_zombie_skeltal_minion" );
static const bionic_id bio_uncanny_dodge( "bio_uncanny_dodge" );
// shared utility functions
static bool within_visual_range( monster *z, int max_range )
{
return !( rl_dist( z->pos(), g->u.pos() ) > max_range || !z->sees( g->u ) );
}
static bool within_target_range( const monster *const z, const Creature *const target, int range )
{
return target != nullptr &&
rl_dist( z->pos(), target->pos() ) <= range &&
z->sees( *target );
}
static Creature *sting_get_target( monster *z, float range = 5.0f )
{
Creature *target = z->attack_target();
if( target == nullptr ) {
return nullptr;
}
// Can't see/reach target, no attack
if( !z->sees( *target ) ||
!g->m.clear_path( z->pos(), target->pos(), range, 1, 100 ) ) {
return nullptr;
}
return rl_dist( z->pos(), target->pos() ) <= range ? target : nullptr;
}
static bool sting_shoot( monster *z, Creature *target, damage_instance &dam, float range )
{
if( target->uncanny_dodge() ) {
target->add_msg_if_player( m_bad, _( "The %s shoots a dart but you dodge it." ),
z->name() );
return false;
}
projectile proj;
proj.speed = 10;
proj.range = range;
proj.impact.add( dam );
proj.add_effect( ammo_effect_NO_OVERSHOOT );
dealt_projectile_attack atk = projectile_attack( proj, z->pos(), target->pos(),
dispersion_sources{ 500 }, z );
if( atk.dealt_dam.total_damage() > 0 ) {
target->add_msg_if_player( m_bad, _( "The %s shoots a dart into you!" ), z->name() );
return true;
} else {
if( atk.missed_by == 1 ) {
target->add_msg_if_player( m_good,
_( "The %s shoots a dart at you, but misses!" ),
z->name() );
} else {
target->add_msg_if_player( m_good,
_( "The %s shoots a dart but it bounces off your armor." ),
z->name() );
}
return false;
}
}
// Distance == 1 and on the same z-level or with a clear shot up/down.
// If allow_zlev is false, don't allow attacking up/down at all.
// If allow_zlev is true, also allow distance == 1 and on different z-level
// as long as floor/ceiling doesn't exist.
static bool is_adjacent( const monster *z, const Creature *target, const bool allow_zlev )
{
if( target == nullptr ) {
return false;
}
if( rl_dist( z->pos(), target->pos() ) != 1 ) {
return false;
}
if( !z->can_squeeze_to( target->pos() ) ) {
return false;
}
if( z->posz() == target->posz() ) {
return true;
}
if( !allow_zlev ) {
return false;
}
// The square above must have no floor (currently only open air).
// The square below must have no ceiling (i.e. be outside).
const bool target_above = target->posz() > z->posz();
const tripoint &up = target_above ? target->pos() : z->pos();
const tripoint &down = target_above ? z->pos() : target->pos();
return g->m.ter( up ) == t_open_air && g->m.is_outside( down );
}
static npc make_fake_npc( monster *z, int str, int dex, int inte, int per )
{
npc tmp;
tmp.name = _( "The " ) + z->name();
tmp.set_fake( true );
tmp.recoil = 0;
tmp.setpos( z->pos() );
tmp.str_cur = str;
tmp.dex_cur = dex;
tmp.int_cur = inte;
tmp.per_cur = per;
if( z->friendly != 0 ) {
tmp.set_attitude( NPCATT_FOLLOW );
} else {
tmp.set_attitude( NPCATT_KILL );
}
return tmp;
}
bool mattack::none( monster * )
{
return true;
}
bool mattack::eat_crop( monster *z )
{
for( const auto &p : g->m.points_in_radius( z->pos(), 1 ) ) {
if( g->m.has_flag( "PLANT", p ) && one_in( 4 ) ) {
g->m.furn_set( p, furn_str_id( g->m.furn( p )->plant->base ) );
g->m.i_clear( p );
return true;
}
}
return true;
}
bool mattack::eat_food( monster *z )
{
for( const auto &p : g->m.points_in_radius( z->pos(), 1 ) ) {
//Protect crop seeds from carnivores, give omnivores eat_crop special also
if( g->m.has_flag( "PLANT", p ) ) {
continue;
}
// Don't snap up food RIGHT under the player's nose.
if( z->friendly && rl_dist( g->u.pos(), p ) <= 2 ) {
continue;
}
auto items = g->m.i_at( p );
for( auto &item : items ) {
//Fun limit prevents scavengers from eating feces
if( !item.is_food() || item.get_comestible_fun() < -20 ) {
continue;
}
//Don't eat own eggs
if( z->type->baby_egg != item.type->get_id() ) {
int consumed = 1;
if( item.count_by_charges() ) {
g->m.use_charges( p, 0, item.type->get_id(), consumed );
} else {
g->m.use_amount( p, 0, item.type->get_id(), consumed );
}
return true;
}
}
}
return true;
}
bool mattack::antqueen( monster *z )
{
std::vector<tripoint> egg_points;
std::vector<monster *> ants;
// Count up all adjacent tiles the contain at least one egg.
for( const auto &dest : g->m.points_in_radius( z->pos(), 2 ) ) {
if( g->m.impassable( dest ) ) {
continue;
}
if( monster *const mon = g->critter_at<monster>( dest ) ) {
if( mon->type->default_faction == mfaction_id( "ant" ) && mon->type->upgrades ) {
ants.push_back( mon );
}
continue;
}
if( g->is_empty( dest ) && g->m.has_items( dest ) ) {
for( auto &i : g->m.i_at( dest ) ) {
if( i.typeId() == itype_ant_egg ) {
egg_points.push_back( dest );
// Done looking at this tile
break;
}
}
}
}
if( !ants.empty() ) {
// It takes a while
z->moves -= 100;
monster *ant = random_entry( ants );
if( g->u.sees( *z ) && g->u.sees( *ant ) ) {
add_msg( m_warning, _( "The %1$s feeds an %2$s and it grows!" ), z->name(),
ant->name() );
}
ant->poly( ant->type->upgrade_into );
} else if( egg_points.empty() ) {
// There's no eggs nearby--lay one.
if( g->u.sees( *z ) ) {
add_msg( _( "The %s lays an egg!" ), z->name() );
}
g->m.spawn_item( z->pos(), "ant_egg", 1, 0, calendar::turn );
} else {
// There are eggs nearby. Let's hatch some.
// It takes a while
z->moves -= 20 * egg_points.size();
if( g->u.sees( *z ) ) {
add_msg( m_warning, _( "The %s tends nearby eggs, and they hatch!" ), z->name() );
}
for( const tripoint &egg_pos : egg_points ) {
map_stack items = g->m.i_at( egg_pos );
for( map_stack::iterator it = items.begin(); it != items.end(); ) {
if( it->typeId() != itype_ant_egg ) {
++it;
continue;
}
const mtype_id &mt = z->type->id == mon_ant_acid_queen ? mon_ant_acid_larva : mon_ant_larva;
// Max one hatch per tile
if( monster *const mon = g->place_critter_at( mt, egg_pos ) ) {
mon->make_ally( *z );
it = items.erase( it );
break;
}
}
}
}
return true;
}
bool mattack::shriek( monster *z )
{
Creature *target = z->attack_target();
if( target == nullptr ||
rl_dist( z->pos(), target->pos() ) > 4 ||
!z->sees( *target ) ) {
return false;
}
// It takes a while
z->moves -= 240;
sounds::sound( z->pos(), 50, sounds::sound_t::alert, _( "a terrible shriek!" ), false, "shout",
"shriek" );
return true;
}
bool mattack::shriek_alert( monster *z )
{
if( !z->can_act() || z->has_effect( effect_shrieking ) ) {
return false;
}
Creature *target = z->attack_target();
if( target == nullptr || rl_dist( z->pos(), target->pos() ) > 15 ||
!z->sees( *target ) ) {
return false;
}
if( g->u.sees( *z ) ) {
add_msg( _( "The %s begins shrieking!" ), z->name() );
}
z->moves -= 150;
sounds::sound( z->pos(), 120, sounds::sound_t::alert, _( "a piercing wail!" ), false, "shout",
"wail" );
z->add_effect( effect_shrieking, 1_minutes );
return true;
}
bool mattack::shriek_stun( monster *z )
{
if( !z->can_act() || !z->has_effect( effect_shrieking ) ) {
return false;
}
Creature *target = z->attack_target();
if( target == nullptr ) {
return false;
}
int dist = rl_dist( z->pos(), target->pos() );
// Currently the cone is 2D, so don't use it for 3D attacks
if( dist > 7 ||
z->posz() != target->posz() ||
!z->sees( *target ) ) {
return false;
}
units::angle target_angle = coord_to_angle( z->pos(), target->pos() );
units::angle cone_angle = 20_degrees;
map &here = get_map();
for( const tripoint &cone : here.points_in_radius( z->pos(), 4 ) ) {
units::angle tile_angle = coord_to_angle( z->pos(), cone );
units::angle diff = units::fabs( target_angle - tile_angle );
// Skip the target, because it's outside cone or it's the source
if( diff + cone_angle > 360_degrees || diff > cone_angle || cone == z->pos() ) {
continue;
}
// Affect the target
// Small bash to every square, silent to not flood message box
here.bash( cone, 4, true );
// If a monster is there, chance for stun
Creature *target = g->critter_at( cone );
if( target == nullptr ) {
continue;
}
if( one_in( dist / 2 ) && !( target->is_immune_effect( effect_deaf ) ) ) {
target->add_effect( effect_dazed, rng( 1_minutes, 2_minutes ), num_bp, rng( 1,
( 15 - dist ) / 3 ) );
}
}
return true;
}
bool mattack::howl( monster *z )
{
Creature *target = z->attack_target();
if( target == nullptr ||
rl_dist( z->pos(), target->pos() ) > 4 ||
!z->sees( *target ) ) {
return false;
}
// It takes a while
z->moves -= 200;
sounds::sound( z->pos(), 35, sounds::sound_t::alert, _( "an ear-piercing howl!" ), false, "shout",
"howl" );
// TODO: Make this use mon's faction when those are in
if( z->friendly != 0 ) {
for( monster &other : g->all_monsters() ) {
if( other.type != z->type ) {
continue;
}
// Quote KA101: Chance of friendlying other howlers in the area, I'd imagine:
// wolves use howls for communication and can convey that the ape is on Team Wolf.
if( one_in( 4 ) ) {
other.friendly = z->friendly;
break;
}
}
}
return true;
}
bool mattack::rattle( monster *z )
{
// TODO: Let it rattle at non-player friendlies
const int min_dist = z->friendly != 0 ? 1 : 4;
Creature *target = &g->u;
// Can't use attack_target - the snake has no target
if( rl_dist( z->pos(), target->pos() ) > min_dist ||
!z->sees( *target ) ) {
return false;
}
// It takes a very short while
z->moves -= 20;
sounds::sound( z->pos(), 10, sounds::sound_t::alarm, _( "a sibilant rattling sound!" ), false,
"misc", "rattling" );
return true;
}
bool mattack::acid( monster *z )
{
if( !z->can_act() ) {
return false;
}
Creature *target = z->attack_target();
if( target == nullptr ) {
return false;
}
// Can't see/reach target, no attack
if( !z->sees( *target ) ||
!g->m.clear_path( z->pos(), target->pos(), 10, 1, 100 ) ) {
return false;
}
// It takes a while
z->moves -= 300;
sounds::sound( z->pos(), 4, sounds::sound_t::combat, _( "a spitting noise." ), false, "misc",
"spitting" );
projectile proj;
proj.speed = 10;
// Mostly just for momentum
proj.impact.add_damage( DT_ACID, 5 );
proj.range = 10;
proj.add_effect( ammo_effect_NO_OVERSHOOT );
auto dealt = projectile_attack( proj, z->pos(), target->pos(), dispersion_sources{ 5400 }, z );
const tripoint &hitp = dealt.end_point;
const Creature *hit_critter = dealt.hit_critter;
if( hit_critter == nullptr && g->m.hit_with_acid( hitp ) && g->u.sees( hitp ) ) {
add_msg( _( "A glob of acid hits the %s!" ),
g->m.tername( hitp ) );
if( g->m.impassable( hitp ) ) {
// TODO: Allow it to spill on the side it hit from
return true;
}
}
for( int i = -3; i <= 3; i++ ) {
for( int j = -3; j <= 3; j++ ) {
tripoint dest = hitp + tripoint( i, j, 0 );
if( g->m.passable( dest ) &&
g->m.clear_path( dest, hitp, 6, 1, 100 ) &&
( ( one_in( std::abs( j ) ) && one_in( std::abs( i ) ) ) || ( i == 0 && j == 0 ) ) ) {
g->m.add_field( dest, fd_acid, 2 );
}
}
}
return true;
}
bool mattack::acid_barf( monster *z )
{
if( !z->can_act() ) {
return false;
}
// Let it be used on non-player creatures
Creature *target = z->attack_target();
if( target == nullptr || !is_adjacent( z, target, false ) ) {
return false;
}
z->moves -= 80;
// Make sure it happens before uncanny dodge
g->m.add_field( target->pos(), fd_acid, 1 );
bool uncanny = target->uncanny_dodge();
// Can we dodge the attack? Uses player dodge function % chance (melee.cpp)
if( uncanny || dodge_check( z, target ) ) {
auto msg_type = target == &g->u ? m_warning : m_info;
target->add_msg_player_or_npc( msg_type,
_( "The %s barfs acid at you, but you dodge!" ),
_( "The %s barfs acid at <npcname>, but they dodge!" ),
z->name() );
if( !uncanny ) {
target->on_dodge( z, z->type->melee_skill * 2 );
}
return true;
}
body_part hit = target->get_random_body_part()->token;
int dam = rng( 5, 12 );
dam = target->deal_damage( z, convert_bp( hit ).id(), damage_instance( DT_ACID,
dam ) ).total_damage();
target->add_env_effect( effect_corroding, hit, 5, time_duration::from_turns( dam / 2 + 5 ), hit );
if( dam > 0 ) {
auto msg_type = target == &g->u ? m_bad : m_info;
target->add_msg_player_or_npc( msg_type,
//~ 1$s is monster name, 2$s bodypart in accusative
_( "The %1$s barfs acid on your %2$s for %3$d damage!" ),
//~ 1$s is monster name, 2$s bodypart in accusative
_( "The %1$s barfs acid on <npcname>'s %2$s for %3$d damage!" ),
z->name(),
body_part_name_accusative( hit ),
dam );
if( hit == bp_eyes ) {
target->add_env_effect( effect_blind, bp_eyes, 3, 1_minutes );
}
} else {
target->add_msg_player_or_npc(
_( "The %1$s barfs acid on your %2$s, but it washes off the armor!" ),
_( "The %1$s barfs acid on <npcname>'s %2$s, but it washes off the armor!" ),
z->name(),
body_part_name_accusative( hit ) );
}
target->on_hit( z, convert_bp( hit ).id() );
return true;
}
bool mattack::acid_accurate( monster *z )
{
if( !z->can_act() ) {
return false;
}
Creature *target = z->attack_target();
if( target == nullptr ) {
return false;
}
const int range = rl_dist( z->pos(), target->pos() );
if( range > 10 || range < 2 || !z->sees( *target ) ) {
return false;
}
z->moves -= 50;
projectile proj;
proj.speed = 10;
proj.range = 10;
proj.add_effect( ammo_effect_BLINDS_EYES );
proj.add_effect( ammo_effect_NO_DAMAGE_SCALING );
proj.impact.add_damage( DT_ACID, rng( 3, 5 ) );
// Make it arbitrarily less accurate at close ranges
projectile_attack( proj, z->pos(), target->pos(), dispersion_sources{ 8000.0 * range }, z );
return true;
}
bool mattack::shockstorm( monster *z )
{
if( !z->can_act() ) {
return false;
}
Creature *target = z->attack_target();
if( target == nullptr ) {
return false;
}
bool seen = g->u.sees( *z );
// Can't see/reach target, no attack
if( !z->sees( *target ) ||
!g->m.clear_path( z->pos(), target->pos(), 12, 1, 100 ) ) {
return false;
}
// It takes a while
z->moves -= 50;
if( seen ) {
auto msg_type = target == &g->u ? m_bad : m_neutral;
add_msg( msg_type, _( "A bolt of electricity arcs towards %s!" ), target->disp_name() );
}
if( !g->u.is_deaf() ) {
sfx::play_variant_sound( "fire_gun", "bio_lightning", sfx::get_heard_volume( z->pos() ) );
}
tripoint tarp( target->posx() + rng( -1, 1 ) + rng( -1, 1 ),
target->posy() + rng( -1, 1 ) + rng( -1, 1 ),
target->posz() );
std::vector<tripoint> bolt = line_to( z->pos(), tarp, 0, 0 );
// Fill the LOS with electricity
for( auto &i : bolt ) {
if( !one_in( 4 ) ) {
g->m.add_field( i, fd_electricity, rng( 1, 3 ) );
}
}
// 5x5 cloud of electricity at the square hit
for( const auto &dest : g->m.points_in_radius( tarp, 2 ) ) {
if( !one_in( 4 ) ) {
g->m.add_field( dest, fd_electricity, rng( 1, 3 ) );
}
}
return true;
}
bool mattack::shocking_reveal( monster *z )
{
shockstorm( z );
return true;
}
bool mattack::pull_metal_weapon( monster *z )
{
////////////////////////////////////////////////////////////////////////////////////////////////
// Constants and Configuration
// max distance that "pull_metal_weapon" can be applied to the target.
constexpr auto max_distance = 12;
// attack movement costs
constexpr int att_cost_pull = 150;
// minimum str to resist "pull_metal_weapon"
constexpr int min_str = 4;
Creature *target = z->attack_target();
if( target == nullptr ) {
return false;
}
// Can't see/reach target, no attack
if( !z->sees( *target ) || !g->m.clear_path( z->pos(), target->pos(),
max_distance, 1, 100 ) ) {
return false;
}
player *foe = dynamic_cast< player * >( target );
if( foe != nullptr ) {
const item &weapon = foe->primary_weapon();
// Wielded steel or iron items except for built-in things like bionic claws or monomolecular blade
if( !weapon.has_flag( "NO_UNWIELD" ) &&
( weapon.made_of( material_id( "iron" ) ) ||
weapon.made_of( material_id( "hardsteel" ) ) ||
weapon.made_of( material_id( "steel" ) ) ||
weapon.made_of( material_id( "budget_steel" ) ) ) ) {
int wp_skill = foe->get_skill_level( skill_melee );
// It takes a while
z->moves -= att_cost_pull;
int success = 100;
///\EFFECT_STR increases resistance to pull_metal_weapon special attack
if( foe->str_cur > min_str ) {
///\EFFECT_MELEE increases resistance to pull_metal_weapon special attack
success = std::max( 100 - ( 6 * ( foe->str_cur - 6 ) ) - ( 6 * wp_skill ), 0 );
}
auto m_type = foe == &g->u ? m_bad : m_neutral;
if( rng( 1, 100 ) <= success ) {
target->add_msg_player_or_npc( m_type, _( "%s is pulled away from your hands!" ),
_( "%s is pulled away from <npcname>'s hands!" ), weapon.tname() );
z->add_item( foe->remove_weapon() );
if( foe->has_activity( ACT_RELOAD ) ) {
foe->cancel_activity();
}
} else {
target->add_msg_player_or_npc( m_type,
_( "The %s unsuccessfully attempts to pull your weapon away." ),
_( "The %s unsuccessfully attempts to pull <npcname>'s weapon away." ), z->name() );
}
}
}
return true;
}
bool mattack::boomer( monster *z )
{
if( !z->can_act() ) {
return false;
}
Creature *target = z->attack_target();
if( target == nullptr || rl_dist( z->pos(), target->pos() ) > 3 || !z->sees( *target ) ) {
return false;
}
map &here = get_map();
std::vector<tripoint> line = here.find_clear_path( z->pos(), target->pos() );
// It takes a while
z->moves -= 250;
bool u_see = g->u.sees( *z );
if( u_see ) {
add_msg( m_warning, _( "The %s spews bile!" ), z->name() );
}
tripoint prev_point = z->pos();
bool obstructed = false;
for( auto &i : line ) {
if( here.obstructed_by_vehicle_rotation( prev_point, i ) ) {
if( one_in( 2 ) ) {
i.x = prev_point.x;
} else {
i.y = prev_point.y;
}
obstructed = true;
}
here.add_field( i, fd_bile, 1 );
// If bile hit a solid tile, return.
if( obstructed || here.impassable( i ) ) {
here.add_field( i, fd_bile, 3 );
if( g->u.sees( i ) ) {
add_msg( _( "Bile splatters on the %s!" ),
here.tername( i ) );
}
return true;
}
prev_point = i;
}
if( !target->uncanny_dodge() ) {
///\EFFECT_DODGE increases chance to avoid boomer effect
if( rng( 0, 10 ) > target->get_dodge() || one_in( target->get_dodge() ) ) {
target->add_env_effect( effect_boomered, bp_eyes, 3, 12_turns );
} else if( u_see ) {
target->add_msg_player_or_npc( _( "You dodge it!" ),
_( "<npcname> dodges it!" ) );
}
target->on_dodge( z, 5 );
}
return true;
}
bool mattack::boomer_glow( monster *z )
{
if( !z->can_act() ) {
return false;
}
Creature *target = z->attack_target();
if( target == nullptr || rl_dist( z->pos(), target->pos() ) > 3 || !z->sees( *target ) ) {
return false;
}
map &here = get_map();
std::vector<tripoint> line = here.find_clear_path( z->pos(), target->pos() );
// It takes a while
z->moves -= 250;
bool u_see = g->u.sees( *z );
if( u_see ) {
add_msg( m_warning, _( "The %s spews bile!" ), z->name() );
}
tripoint prev_point = z->pos();
bool obstructed = false;
for( auto &i : line ) {
if( here.obstructed_by_vehicle_rotation( prev_point, i ) ) {
if( one_in( 2 ) ) {
i.x = prev_point.x;
} else {
i.y = prev_point.y;
}
obstructed = true;
}
here.add_field( i, fd_bile, 1 );
if( obstructed || here.impassable( i ) ) {
here.add_field( i, fd_bile, 3 );
if( g->u.sees( i ) ) {
add_msg( _( "Bile splatters on the %s!" ), here.tername( i ) );
}
return true;
}
prev_point = i;
}
if( !target->uncanny_dodge() ) {
///\EFFECT_DODGE increases chance to avoid glowing boomer effect
if( rng( 0, 10 ) > target->get_dodge() || one_in( target->get_dodge() ) ) {
target->add_env_effect( effect_boomered, bp_eyes, 5, 25_turns );
target->on_dodge( z, 5 );
for( int i = 0; i < rng( 2, 4 ); i++ ) {
body_part bp = random_body_part();
target->add_env_effect( effect_glowing, bp, 4, 4_minutes );
if( target->has_effect( effect_glowing ) ) {
break;
}
}
} else {
target->add_msg_player_or_npc( _( "You dodge it!" ),
_( "<npcname> dodges it!" ) );
}
}
return true;
}
bool mattack::resurrect( monster *z )
{
// Chance to recover some of our missing speed (yes this will regain
// loses from being revived ourselves as well).
// Multiplying by (current base speed / max speed) means that the
// rate of speed regaining is unaffected by what our current speed is, i.e.
// we will regain the same amount per minute at speed 50 as speed 200.
if( one_in( static_cast<int>( 15 * static_cast<double>( z->get_speed_base() ) / static_cast<double>
( z->type->speed ) ) ) ) {
// Restore 10% of our current speed, capping at our type maximum
z->set_speed_base( std::min( z->type->speed,
static_cast<int>( z->get_speed_base() + .1 * z->type->speed ) ) );
}
int raising_level = 0;
if( z->has_effect( effect_raising ) ) {
raising_level = z->get_effect_int( effect_raising ) * 40;
}
bool sees_necromancer = g->u.sees( *z );
std::vector<std::pair<tripoint, item *>> corpses;
// Find all corpses that we can see within 10 tiles.
int range = 10;
bool found_eligible_corpse = false;
int lowest_raise_score = INT_MAX;
for( const tripoint &p : g->m.points_in_radius( z->pos(), range ) ) {
if( !g->is_empty( p ) || g->m.get_field_intensity( p, fd_fire ) > 1 ||
!g->m.sees( z->pos(), p, -1 ) ) {
continue;
}
for( auto &i : g->m.i_at( p ) ) {