-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
monattack.cpp
5355 lines (4766 loc) · 193 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 <assert.h>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <map>
#include <array>
#include <list>
#include <memory>
#include <ostream>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "avatar.h"
#include "ballistics.h"
#include "bodypart.h"
#include "debug.h"
#include "effect.h"
#include "timed_event.h"
#include "field.h"
#include "fungal_effects.h"
#include "game.h"
#include "gun_mode.h"
#include "itype.h"
#include "iuse_actor.h"
#include "line.h"
#include "map.h"
#include "map_iterator.h"
#include "mapdata.h"
#include "martialarts.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 "npc.h"
#include "name.h"
#include "output.h"
#include "projectile.h"
#include "rng.h"
#include "sounds.h"
#include "speech.h"
#include "text_snippets.h"
#include "translations.h"
#include "ui.h"
#include "weighted_list.h"
#include "calendar.h"
#include "creature.h"
#include "damage.h"
#include "enums.h"
#include "explosion.h"
#include "game_constants.h"
#include "int_id.h"
#include "item.h"
#include "item_stack.h"
#include "iuse.h"
#include "optional.h"
#include "pathfinding.h"
#include "player.h"
#include "string_formatter.h"
#include "tileray.h"
#include "type_id.h"
#include "colony.h"
#include "flat_set.h"
#include "material.h"
#include "point.h"
#include "units.h"
const mtype_id mon_ant( "mon_ant" );
const mtype_id mon_ant_acid( "mon_ant_acid" );
const mtype_id mon_ant_acid_larva( "mon_ant_acid_larva" );
const mtype_id mon_ant_acid_soldier( "mon_ant_acid_soldier" );
const mtype_id mon_ant_acid_queen( "mon_ant_acid_queen" );
const mtype_id mon_ant_larva( "mon_ant_larva" );
const mtype_id mon_ant_soldier( "mon_ant_soldier" );
const mtype_id mon_biollante( "mon_biollante" );
const mtype_id mon_blob( "mon_blob" );
const mtype_id mon_blob_brain( "mon_blob_brain" );
const mtype_id mon_blob_large( "mon_blob_large" );
const mtype_id mon_blob_small( "mon_blob_small" );
const mtype_id mon_breather( "mon_breather" );
const mtype_id mon_breather_hub( "mon_breather_hub" );
const mtype_id mon_creeper_hub( "mon_creeper_hub" );
const mtype_id mon_creeper_vine( "mon_creeper_vine" );
const mtype_id mon_dermatik( "mon_dermatik" );
const mtype_id mon_defective_robot_nurse( "mon_nursebot_defective" );
const mtype_id mon_fungal_hedgerow( "mon_fungal_hedgerow" );
const mtype_id mon_fungaloid( "mon_fungaloid" );
const mtype_id mon_fungaloid_young( "mon_fungaloid_young" );
const mtype_id mon_fungal_tendril( "mon_fungal_tendril" );
const mtype_id mon_fungal_wall( "mon_fungal_wall" );
const mtype_id mon_headless_dog_thing( "mon_headless_dog_thing" );
const mtype_id mon_manhack( "mon_manhack" );
const mtype_id mon_shadow( "mon_shadow" );
const mtype_id mon_hound_tindalos_afterimage( "mon_hound_tindalos_afterimage" );
const mtype_id mon_triffid( "mon_triffid" );
const mtype_id mon_zombie_gasbag_impaler( "mon_zombie_gasbag_impaler" );
const mtype_id mon_zombie_gasbag_crawler( "mon_zombie_gasbag_crawler" );
const mtype_id mon_turret_searchlight( "mon_turret_searchlight" );
const mtype_id mon_zombie_dancer( "mon_zombie_dancer" );
const mtype_id mon_zombie_jackson( "mon_zombie_jackson" );
const mtype_id mon_zombie_skeltal_minion( "mon_zombie_skeltal_minion" );
const skill_id skill_melee( "melee" );
const skill_id skill_gun( "gun" );
const skill_id skill_unarmed( "unarmed" );
const skill_id skill_rifle( "rifle" );
const skill_id skill_launcher( "launcher" );
const species_id ZOMBIE( "ZOMBIE" );
const species_id BLOB( "BLOB" );
const efftype_id effect_assisted( "assisted" );
const efftype_id effect_bite( "bite" );
const efftype_id effect_bleed( "bleed" );
const efftype_id effect_blind( "blind" );
const efftype_id effect_boomered( "boomered" );
const efftype_id effect_controlled( "controlled" );
const efftype_id effect_corroding( "corroding" );
const efftype_id effect_countdown( "countdown" );
const efftype_id effect_darkness( "darkness" );
const efftype_id effect_dazed( "dazed" );
const efftype_id effect_deaf( "deaf" );
const efftype_id effect_dermatik( "dermatik" );
const efftype_id effect_downed( "downed" );
const efftype_id effect_dragging( "dragging" );
const efftype_id effect_fearparalyze( "fearparalyze" );
const efftype_id effect_fungus( "fungus" );
const efftype_id effect_glowing( "glowing" );
const efftype_id effect_got_checked( "got_checked" );
const efftype_id effect_grabbed( "grabbed" );
const efftype_id effect_grabbing( "grabbing" );
const efftype_id effect_has_bag( "has_bag" );
const efftype_id effect_infected( "infected" );
const efftype_id effect_laserlocked( "laserlocked" );
const efftype_id effect_onfire( "onfire" );
const efftype_id effect_operating( "operating" );
const efftype_id effect_paralyzepoison( "paralyzepoison" );
const efftype_id effect_paid( "paid" );
const efftype_id effect_pet( "pet" );
const efftype_id effect_raising( "raising" );
const efftype_id effect_rat( "rat" );
const efftype_id effect_shrieking( "shrieking" );
const efftype_id effect_slimed( "slimed" );
const efftype_id effect_stunned( "stunned" );
const efftype_id effect_targeted( "targeted" );
const efftype_id effect_teleglow( "teleglow" );
const efftype_id effect_under_op( "under_operation" );
static const trait_id trait_ACIDBLOOD( "ACIDBLOOD" );
static const trait_id trait_MARLOSS_BLUE( "MARLOSS_BLUE" );
static const trait_id trait_MARLOSS( "MARLOSS" );
static const trait_id trait_PARAIMMUNE( "PARAIMMUNE" );
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" );
// 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;
}
if( !z->sees( *target ) ||
!g->m.clear_path( z->pos(), target->pos(), range, 1, 100 ) ) {
return nullptr; // Can't see/reach target, no attack
}
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.proj_effects.insert( "NO_OVERSHOOT" );
dealt_projectile_attack atk = projectile_attack( proj, z->pos(), target->pos(), { 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->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 (ie. 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;
}
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() == "ant_egg" ) {
egg_points.push_back( dest );
// Done looking at this tile
break;
}
}
}
}
if( !ants.empty() ) {
z->moves -= 100; // It takes a while
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.
z->moves -= 20 * egg_points.size(); // It takes a while
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() != "ant_egg" ) {
++it;
continue;
}
it = items.erase( it );
monster tmp( z->type->id == mon_ant_acid_queen ? mon_ant_acid_larva : mon_ant_larva, egg_pos );
tmp.make_ally( *z );
g->add_zombie( tmp );
break; // Max one hatch per tile
}
}
}
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;
}
z->moves -= 240; // It takes a while
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;
}
int target_angle = coord_to_angle( z->pos(), target->pos() );
int cone_angle = 20;
for( const tripoint &cone : g->m.points_in_radius( z->pos(), 4 ) ) {
int tile_angle = coord_to_angle( z->pos(), cone );
int diff = abs( target_angle - tile_angle );
if( diff + cone_angle > 360 || diff > cone_angle || cone == z->pos() ) {
continue; // skip the target, because it's outside cone or it's the source
}
// affect the target
g->m.bash( cone, 4, true ); //Small bash to every square, silent to not flood message box
Creature *target = g->critter_at( cone ); //If a monster is there, chance for stun
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, false, 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;
}
z->moves -= 200; // It takes a while
sounds::sound( z->pos(), 35, sounds::sound_t::alert, _( "an ear-piercing howl!" ), false, "shout",
"howl" );
if( z->friendly != 0 ) { // TODO: Make this use mon's faction when those are in
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( target == nullptr ||
rl_dist( z->pos(), target->pos() ) > min_dist ||
!z->sees( *target ) ) {
return false;
}
z->moves -= 20; // It takes a very short while
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;
}
if( !z->sees( *target ) ||
!g->m.clear_path( z->pos(), target->pos(), 10, 1, 100 ) ) {
return false; // Can't see/reach target, no attack
}
z->moves -= 300; // It takes a while
sounds::sound( z->pos(), 4, sounds::sound_t::combat, _( "a spitting noise." ), false, "misc",
"spitting" );
projectile proj;
proj.speed = 10;
proj.impact.add_damage( DT_ACID, 5 ); // Mostly just for momentum
proj.range = 10;
proj.proj_effects.insert( "NO_OVERSHOOT" );
auto dealt = projectile_attack( proj, z->pos(), target->pos(), { 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( abs( j ) ) && one_in( 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();
int dam = rng( 5, 12 );
dam = target->deal_damage( z, hit, 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, hit, z->type->melee_skill );
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.proj_effects.insert( "BLINDS_EYES" );
proj.proj_effects.insert( "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(), { 8000.0 * static_cast<double>( 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 );
if( !z->sees( *target ) ||
!g->m.clear_path( z->pos(), target->pos(), 12, 1, 100 ) ) {
return false; // Can't see/reach target, no attack
}
z->moves -= 50; // It takes a while
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 );
for( auto &i : bolt ) { // Fill the LOS with electricity
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 );
std::string WHAT_A_SCOOP = SNIPPET.random_from_category( "clickbait" );
sounds::sound( z->pos(), 10, sounds::sound_t::alert,
string_format( _( "the %s obnoxiously yelling \"%s!!!\"" ),
z->name(), WHAT_A_SCOOP ) );
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;
}
if( !z->sees( *target ) || !g->m.clear_path( z->pos(), target->pos(),
max_distance, 1, 100 ) ) {
return false; // Can't see/reach target, no attack
}
player *foe = dynamic_cast< player * >( target );
if( foe != nullptr ) {
// Wielded steel or iron items except for built-in things like bionic claws or monomolecular blade
if( !foe->weapon.has_flag( "NO_UNWIELD" ) &&
( foe->weapon.made_of( material_id( "iron" ) ) ||
foe->weapon.made_of( material_id( "steel" ) ) ||
foe->weapon.made_of( material_id( "budget_steel" ) ) ) ) {
int wp_skill = foe->get_skill_level( skill_melee );
z->moves -= att_cost_pull; // It takes a while
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!" ), foe->weapon.tname() );
z->add_item( foe->remove_weapon() );
} 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;
}
std::vector<tripoint> line = g->m.find_clear_path( z->pos(), target->pos() );
z->moves -= 250; // It takes a while
bool u_see = g->u.sees( *z );
if( u_see ) {
add_msg( m_warning, _( "The %s spews bile!" ), z->name() );
}
for( auto &i : line ) {
g->m.add_field( i, fd_bile, 1 );
// If bile hit a solid tile, return.
if( g->m.impassable( i ) ) {
g->m.add_field( i, fd_bile, 3 );
if( g->u.sees( i ) ) {
add_msg( _( "Bile splatters on the %s!" ),
g->m.tername( i ) );
}
return true;
}
}
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, 10 );
}
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;
}
std::vector<tripoint> line = g->m.find_clear_path( z->pos(), target->pos() );
z->moves -= 250; // It takes a while
bool u_see = g->u.sees( *z );
if( u_see ) {
add_msg( m_warning, _( "The %s spews bile!" ), z->name() );
}
for( auto &i : line ) {
g->m.add_field( i, fd_bile, 1 );
if( g->m.impassable( i ) ) {
g->m.add_field( i, fd_bile, 3 );
if( g->u.sees( i ) ) {
add_msg( _( "Bile splatters on the %s!" ), g->m.tername( i ) );
}
return true;
}
}
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, 10 );
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 ) ) {
const mtype *mt = i.get_mtype();
if( !( i.is_corpse() && i.can_revive() && i.active && mt->has_flag( MF_REVIVES ) &&
mt->in_species( ZOMBIE ) && !mt->has_flag( MF_NO_NECRO ) ) ) {
continue;
}
found_eligible_corpse = true;
if( raising_level == 0 ) {
// Since we have a target, start charging to raise it.
if( sees_necromancer ) {
add_msg( m_info, _( "The %s throws its arms wide." ), z->name() );
}
while( z->moves >= 0 ) {
z->add_effect( effect_raising, 1_minutes );
z->moves -= 100;
}
return false;
}
int raise_score = ( i.damage_level( 4 ) + 1 ) * mt->hp + i.burnt;
lowest_raise_score = std::min( lowest_raise_score, raise_score );
if( raise_score <= raising_level ) {
corpses.push_back( std::make_pair( p, &i ) );
}
}
}
if( corpses.empty() ) { // No nearby corpses
if( found_eligible_corpse ) {
// There was a corpse, but we haven't charged enough.
if( sees_necromancer && x_in_y( 1, sqrt( lowest_raise_score / 30.0 ) ) ) {
add_msg( m_info, _( "The %s gesticulates wildly." ), z->name() );
}
while( z->moves >= 0 ) {
z->add_effect( effect_raising, 1_minutes );
z->moves -= 100;
return false;
}
} else if( raising_level != 0 ) {
z->remove_effect( effect_raising );
}
// Check to see if there are any nearby living zombies to see if we should get angry
const bool allies = g->get_creature_if( [&]( const Creature & critter ) {
const monster *const zed = dynamic_cast<const monster *>( &critter );
return zed && zed != z && zed->type->has_flag( MF_REVIVES ) && zed->type->in_species( ZOMBIE ) &&
z->attitude_to( *zed ) == Creature::Attitude::A_FRIENDLY &&
within_target_range( z, zed, 10 );
} );
if( !allies ) {
// Nobody around who we could revive, get angry
z->anger = 100;
} else {
// Someone is around who might die and we could revive,
// calm down.
z->anger = 5;
}
return false;
} else {
// We're reviving someone/could revive someone, calm down.
z->anger = 5;
}
if( z->get_speed_base() <= z->type->speed / 2 ) {
// We can only resurrect so many times in a time period
// and we're currently out
return false;
}
std::pair<tripoint, item *> raised = random_entry( corpses );
assert( raised.second ); // To appease static analysis
float corpse_damage = raised.second->damage_level( 4 );
// Did we successfully raise something?
if( g->revive_corpse( raised.first, *raised.second ) ) {
g->m.i_rem( raised.first, raised.second );
if( sees_necromancer ) {
add_msg( m_info, _( "The %s gestures at a nearby corpse." ), z->name() );
}
z->remove_effect( effect_raising );
z->moves -= z->type->speed; // Takes one turn
// Penalize speed by between 10% and 50% based on how damaged the corpse is.
float speed_penalty = 0.1 + ( corpse_damage * 0.1 );
z->set_speed_base( z->get_speed_base() - speed_penalty * z->type->speed );
monster *const zed = g->critter_at<monster>( raised.first );
if( !zed ) {
debugmsg( "Misplaced or failed to revive a zombie corpse" );
return true;
}
zed->make_ally( *z );
if( g->u.sees( *zed ) ) {
add_msg( m_warning, _( "A nearby %s rises from the dead!" ), zed->name() );
} else if( sees_necromancer ) {
// We saw the necromancer but not the revival
add_msg( m_info, _( "But nothing seems to happen." ) );
}
}
return true;
}
void mattack::smash_specific( monster *z, Creature *target )
{
if( target == nullptr || !is_adjacent( z, target, false ) ) {
return;
}
if( z->has_flag( MF_RIDEABLE_MECH ) ) {
z->use_mech_power( -5 );
}
z->set_goal( target->pos() );
smash( z );
}