/
melee-attack.cc
3786 lines (3257 loc) · 112 KB
/
melee-attack.cc
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
/**
* @file
* @brief melee_attack class and associated melee_attack methods
*/
#include "AppHdr.h"
#include "melee-attack.h"
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include "areas.h"
#include "art-enum.h"
#include "attitude-change.h"
#include "bloodspatter.h"
#include "chardump.h"
#include "cloud.h"
#include "delay.h"
#include "english.h"
#include "env.h"
#include "exercise.h"
#include "fineff.h"
#include "god-conduct.h"
#include "god-item.h"
#include "god-passive.h" // passive_t::convert_orcs
#include "hints.h"
#include "item-prop.h"
#include "mapdef.h"
#include "message.h"
#include "mon-behv.h"
#include "mon-poly.h"
#include "mon-tentacle.h"
#include "religion.h"
#include "shout.h"
#include "spl-damage.h"
#include "spl-summoning.h" //AF_SPIDER
#include "state.h"
#include "stepdown.h"
#include "stringutil.h"
#include "tag-version.h"
#include "target.h"
#include "terrain.h"
#include "transform.h"
#include "traps.h"
#include "unwind.h"
#include "view.h"
#include "xom.h"
#ifdef NOTE_DEBUG_CHAOS_BRAND
#define NOTE_DEBUG_CHAOS_EFFECTS
#endif
#ifdef NOTE_DEBUG_CHAOS_EFFECTS
#include "notes.h"
#endif
/*
**************************************************
* BEGIN PUBLIC FUNCTIONS *
**************************************************
*/
melee_attack::melee_attack(actor *attk, actor *defn,
int attack_num, int effective_attack_num,
bool is_cleaving)
: // Call attack's constructor
::attack(attk, defn),
attack_number(attack_num), effective_attack_number(effective_attack_num),
cleaving(is_cleaving), is_riposte(false), is_projected(false), charge_pow(0),
wu_jian_attack(WU_JIAN_ATTACK_NONE),
wu_jian_number_of_targets(1)
{
attack_occurred = false;
damage_brand = attacker->damage_brand(attack_number);
weapon = attacker->weapon(attack_number);
init_attack(SK_UNARMED_COMBAT, attack_number);
if (weapon && !using_weapon())
wpn_skill = SK_FIGHTING;
attack_position = attacker->pos();
}
bool melee_attack::can_reach()
{
return attk_type == AT_HIT && weapon && weapon_reach(*weapon) > REACH_NONE
|| flavour_has_reach(attk_flavour)
|| is_projected;
}
bool melee_attack::bad_attempt()
{
if (!attacker->is_player() || !defender || !defender->is_monster())
return false;
if (player_unrand_bad_attempt())
return true;
if (!cleave_targets.empty())
{
const int range = you.reach_range();
targeter_cleave hitfunc(attacker, defender->pos(), range);
return stop_attack_prompt(hitfunc, "attack");
}
return stop_attack_prompt(defender->as_monster(), false, attack_position);
}
bool melee_attack::player_unrand_bad_attempt()
{
// Unrands with secondary effects that can harm nearby friendlies.
// Don't prompt for confirmation (and leak information about the
// monster's position) if the player can't see the monster.
if (!weapon || !you.can_see(*defender))
return false;
if (is_unrandom_artefact(*weapon, UNRAND_DEVASTATOR))
{
targeter_smite hitfunc(attacker, 1, 1, 1, false);
hitfunc.set_aim(defender->pos());
return stop_attack_prompt(hitfunc, "attack",
[](const actor *act)
{
return !god_protects(act->as_monster());
}, nullptr, defender->as_monster());
}
else if (is_unrandom_artefact(*weapon, UNRAND_VARIABILITY)
|| is_unrandom_artefact(*weapon, UNRAND_SINGING_SWORD)
&& !silenced(you.pos()))
{
targeter_radius hitfunc(&you, LOS_NO_TRANS);
return stop_attack_prompt(hitfunc, "attack",
[](const actor *act)
{
return !god_protects(act->as_monster());
}, nullptr, defender->as_monster());
}
if (is_unrandom_artefact(*weapon, UNRAND_TORMENT))
{
targeter_radius hitfunc(&you, LOS_NO_TRANS);
return stop_attack_prompt(hitfunc, "attack",
[] (const actor *m)
{
return !m->res_torment()
&& !god_protects(m->as_monster());
},
nullptr, defender->as_monster());
}
if (is_unrandom_artefact(*weapon, UNRAND_ARC_BLADE))
{
vector<const actor *> exclude;
return !safe_discharge(defender->pos(), exclude);
}
if (is_unrandom_artefact(*weapon, UNRAND_POWER))
{
targeter_beam hitfunc(&you, 4, ZAP_SWORD_BEAM, 100, 0, 0);
hitfunc.beam.aimed_at_spot = false;
hitfunc.set_aim(defender->pos());
return stop_attack_prompt(hitfunc, "attack",
[](const actor *act)
{
return !god_protects(act->as_monster());
}, nullptr, defender->as_monster());
}
return false;
}
bool melee_attack::handle_phase_attempted()
{
// Skip invalid and dummy attacks.
if (defender && (!adjacent(attack_position, defender->pos())
&& !can_reach())
|| attk_flavour == AF_CRUSH
&& (!attacker->can_constrict(*defender, CONSTRICT_MELEE)
|| attacker->is_monster() && attacker->mid == MID_PLAYER))
{
--effective_attack_number;
return false;
}
if (bad_attempt())
{
cancel_attack = true;
return false;
}
if (attacker->is_player())
{
// Set delay now that we know the attack won't be cancelled.
if (!is_riposte
&& (wu_jian_attack == WU_JIAN_ATTACK_NONE))
{
you.time_taken = you.attack_delay().roll();
}
const caction_type cact_typ = is_riposte ? CACT_RIPOSTE : CACT_MELEE;
if (weapon)
{
if (weapon->base_type == OBJ_WEAPONS)
if (is_unrandom_artefact(*weapon)
&& get_unrand_entry(weapon->unrand_idx)->type_name)
{
count_action(cact_typ, weapon->unrand_idx);
}
else
count_action(cact_typ, weapon->sub_type);
else if (weapon->base_type == OBJ_STAVES)
count_action(cact_typ, WPN_STAFF);
}
else
count_action(cact_typ, -1, -1); // unarmed subtype/auxtype
}
else
{
// Only the first attack costs any energy.
if (!effective_attack_number)
{
int energy = attacker->as_monster()->action_energy(EUT_ATTACK);
int delay = attacker->attack_delay().roll();
dprf(DIAG_COMBAT, "Attack delay %d, multiplier %1.1f", delay, energy * 0.1);
ASSERT(energy > 0);
ASSERT(delay > 0);
attacker->as_monster()->speed_increment
-= div_rand_round(energy * delay, 10);
}
// Statues and other special monsters which have AT_NONE need to lose
// energy, but otherwise should exit the melee attack now.
if (attk_type == AT_NONE)
return false;
}
if (attacker != defender && !is_riposte)
{
// Allow setting of your allies' target, etc.
attacker->attacking(defender);
check_autoberserk();
}
// Xom thinks fumbles are funny...
if (attacker->fumbles_attack())
{
// ... and thinks fumbling when trying to hit yourself is just
// hilarious.
xom_is_stimulated(attacker == defender ? 200 : 10);
return false;
}
// Non-fumbled self-attacks due to confusion are still pretty funny, though.
else if (attacker == defender && attacker->confused())
xom_is_stimulated(100);
// Any attack against a monster we're afraid of has a chance to fail
if (attacker->is_player() && defender &&
you.afraid_of(defender->as_monster()) && one_chance_in(3))
{
mprf("You attempt to attack %s, but flinch away in fear!",
defender->name(DESC_THE).c_str());
return false;
}
if (attk_flavour == AF_SHADOWSTAB
&& defender && !defender->can_see(*attacker))
{
if (you.see_cell(attack_position))
{
mprf("%s strikes at %s from the darkness!",
attacker->name(DESC_THE, true).c_str(),
defender->name(DESC_THE).c_str());
}
to_hit = AUTOMATIC_HIT;
needs_message = false;
}
else if (attacker->is_monster()
&& attacker->type == MONS_DROWNED_SOUL)
{
to_hit = AUTOMATIC_HIT;
}
attack_occurred = true;
// Check for player practicing dodging
if (defender && defender->is_player())
practise_being_attacked();
return true;
}
bool melee_attack::handle_phase_dodged()
{
did_hit = false;
if (needs_message)
{
// TODO: Unify these, placed player_warn_miss here so I can remove
// player_attack
if (attacker->is_player())
player_warn_miss();
else
{
mprf("%s%s misses %s%s",
atk_name(DESC_THE).c_str(),
evasion_margin_adverb().c_str(),
defender_name(true).c_str(),
attack_strength_punctuation(damage_done).c_str());
}
}
if (attacker->is_player())
{
// Upset only non-sleeping non-fleeing monsters if we missed.
if (!defender->asleep() && !mons_is_fleeing(*defender->as_monster()))
behaviour_event(defender->as_monster(), ME_WHACK, attacker);
}
if (defender->is_player())
count_action(CACT_DODGE, DODGE_EVASION);
if (attacker != defender
&& attacker->alive() && defender->can_see(*attacker)
&& !defender->cannot_act() && !defender->confused()
&& (!defender->is_player() || !attacker->as_monster()->neutral())
&& !mons_aligned(attacker, defender) // confused friendlies attacking
// Retaliation only works on the first attack in a round.
// FIXME: player's attack is -1, even for auxes
&& effective_attack_number <= 0)
{
if (adjacent(defender->pos(), attack_position))
{
if (defender->is_player()
? you.has_mutation(MUT_REFLEXIVE_HEADBUTT)
: mons_species(mons_base_type(*defender->as_monster()))
== MONS_MINOTAUR)
{
do_minotaur_retaliation();
}
// Retaliations can kill!
if (!attacker->alive())
return false;
if (defender->is_player() && player_equip_unrand(UNRAND_STARLIGHT))
do_starlight();
}
maybe_riposte();
// Retaliations can kill!
if (!attacker->alive())
return false;
}
return true;
}
void melee_attack::maybe_riposte()
{
// only riposte via fencer's gloves, which (I take it from this code)
// monsters can't use
const bool using_fencers =
defender->is_player()
&& player_equip_unrand(UNRAND_FENCERS)
&& (!defender->weapon()
|| is_melee_weapon(*defender->weapon()));
if (using_fencers
&& !is_riposte // no ping-pong!
&& one_chance_in(3)
&& you.reach_range() >= grid_distance(you.pos(), attack_position))
{
riposte();
}
}
void melee_attack::apply_black_mark_effects()
{
enum black_mark_effect
{
ANTIMAGIC,
WEAKNESS,
DRAINING,
};
// Less reliable effects for players.
if (attacker->is_player()
&& you.has_mutation(MUT_BLACK_MARK)
&& one_chance_in(5)
|| attacker->is_monster()
&& attacker->as_monster()->has_ench(ENCH_BLACK_MARK))
{
if (!defender->alive())
return;
vector<black_mark_effect> effects;
if (defender->antimagic_susceptible())
effects.push_back(ANTIMAGIC);
if (defender->is_player()
|| mons_has_attacks(*defender->as_monster()))
{
effects.push_back(WEAKNESS);
}
if (defender->res_negative_energy() < 3)
effects.push_back(DRAINING);
if (effects.empty())
return;
black_mark_effect choice = effects[random2(effects.size())];
switch (choice)
{
case ANTIMAGIC:
antimagic_affects_defender(damage_done * 8);
break;
case WEAKNESS:
defender->weaken(attacker, 6);
break;
case DRAINING:
defender->drain(attacker, false, damage_done);
break;
}
}
}
void melee_attack::do_ooze_engulf()
{
if (attacker->is_player()
&& you.has_mutation(MUT_ENGULF)
&& defender->alive()
&& !defender->as_monster()->has_ench(ENCH_WATER_HOLD)
&& attacker->can_engulf(*defender)
&& coinflip())
{
defender->as_monster()->add_ench(mon_enchant(ENCH_WATER_HOLD, 1,
attacker, 1));
mprf("You engulf %s in ooze!", defender->name(DESC_THE).c_str());
// Smothers sticky flame.
defender->expose_to_element(BEAM_WATER, 0);
}
}
/* An attack has been determined to have hit something
*
* Handles to-hit effects for both attackers and defenders,
* Determines damage and passes off execution to handle_phase_damaged
* Also applies weapon brands
*
* Returns true if combat should continue, false if it should end here.
*/
bool melee_attack::handle_phase_hit()
{
did_hit = true;
perceived_attack = true;
bool hit_woke_orc = false;
if (attacker->is_player())
{
if (crawl_state.game_is_hints())
Hints.hints_melee_counter++;
// TODO: Remove this (placed here so I can get rid of player_attack)
if (have_passive(passive_t::convert_orcs)
&& mons_genus(defender->mons_species()) == MONS_ORC
&& !defender->is_summoned()
&& !defender->as_monster()->is_shapeshifter()
&& you.see_cell(defender->pos()) && defender->asleep())
{
hit_woke_orc = true;
}
}
damage_done = 0;
// Slimify does no damage and serves as an on-hit effect, handle it
if (attacker->is_player() && you.duration[DUR_SLIMIFY]
&& mon_can_be_slimified(defender->as_monster())
&& !cleaving)
{
// Bail out after sliming so we don't get aux unarmed and
// attack a fellow slime.
slimify_monster(defender->as_monster());
you.duration[DUR_SLIMIFY] = 0;
return false;
}
// This does more than just calculate the damage, it also sets up
// messages, etc. It also wakes nearby creatures on a failed stab,
// meaning it could have made the attacked creature vanish. That
// will be checked early in player_monattack_hit_effects
damage_done += calc_damage();
// Calculate and apply infusion costs immediately after we calculate
// damage, so that later events don't result in us skipping the cost.
if (attacker->is_player())
{
const int infusion = you.infusion_amount();
if (infusion)
{
pay_mp(infusion);
finalize_mp_cost();
}
}
bool stop_hit = false;
// Check if some hit-effect killed the monster.
if (attacker->is_player())
stop_hit = !player_monattk_hit_effects();
// check_unrand_effects is safe to call with a dead defender, so always
// call it, even if the hit effects said to stop.
if (stop_hit)
{
check_unrand_effects();
return false;
}
if (damage_done > 0 || flavour_triggers_damageless(attk_flavour))
{
if (!handle_phase_damaged())
return false;
// TODO: Remove this, (placed here to remove player_attack)
if (attacker->is_player() && hit_woke_orc)
{
// Call function of orcs first noticing you, but with
// beaten-up conversion messages (if applicable).
beogh_follower_convert(defender->as_monster(), true);
}
}
else if (needs_message)
{
attack_verb = attacker->is_player()
? attack_verb
: attacker->conj_verb(mons_attack_verb());
// TODO: Clean this up if possible, checking atype for do / does is ugly
mprf("%s %s %s but %s no damage.",
attacker->name(DESC_THE).c_str(),
attack_verb.c_str(),
defender_name(true).c_str(),
attacker->is_player() ? "do" : "does");
}
// Check for weapon brand & inflict that damage too
apply_damage_brand();
// Fireworks when using Serpent's Lash to kill.
if (!defender->alive()
&& defender->as_monster()->can_bleed()
&& wu_jian_has_momentum(wu_jian_attack))
{
blood_spray(defender->pos(), defender->as_monster()->type,
damage_done / 5);
defender->as_monster()->flags |= MF_EXPLODE_KILL;
}
if (check_unrand_effects())
return false;
if (damage_done > 0)
{
apply_black_mark_effects();
do_ooze_engulf();
}
if (attacker->is_player())
{
// Always upset monster regardless of damage.
// However, successful stabs inhibit shouting.
behaviour_event(defender->as_monster(), ME_WHACK, attacker,
coord_def(), !stab_attempt);
// [ds] Monster may disappear after behaviour event.
if (!defender->alive())
return true;
}
else if (defender->is_player())
{
// These effects (mutations right now) are only triggered when
// the player is hit, each of them will verify their own required
// parameters.
do_passive_freeze();
do_fiery_armour_burn();
emit_foul_stench();
}
return true;
}
bool melee_attack::handle_phase_damaged()
{
if (!attack::handle_phase_damaged())
return false;
if (attacker->is_player() && player_equip_unrand(UNRAND_POWER_GLOVES))
inc_mp(div_rand_round(damage_done, 8));
return true;
}
bool melee_attack::handle_phase_aux()
{
if (attacker->is_player()
&& !cleaving
&& wu_jian_attack != WU_JIAN_ATTACK_TRIGGERED_AUX
&& !is_projected)
{
// returns whether an aux attack successfully took place
// additional attacks from cleave don't get aux
if (!defender->as_monster()->friendly()
&& adjacent(defender->pos(), attack_position))
{
player_aux_unarmed();
}
// Don't print wounds after the first attack with Gyre/Gimble.
// DUR_CLEAVE and Gyre/Gimble interact poorly together at the moment,
// so don't try to skip print_wounds in that case.
if (!(weapon && is_unrandom_artefact(*weapon, UNRAND_GYRE)
&& !you.duration[DUR_CLEAVE]))
{
print_wounds(*defender->as_monster());
}
}
return true;
}
/**
* Handle effects that fire when the defender (the target of the attack) is
* killed.
*
* @return Not sure; it seems to never be checked & always be true?
*/
bool melee_attack::handle_phase_killed()
{
// Wyrmbane needs to be notified of deaths, including ones due to aux
// attacks, but other users of melee_effects() don't want to possibly
// be called twice. Adding another entry for a single artefact would
// be overkill, so here we call it by hand. check_unrand_effects()
// avoided triggering Wyrmbane's death effect earlier in the attack.
if (unrand_entry && weapon && weapon->unrand_idx == UNRAND_WYRMBANE)
{
unrand_entry->melee_effects(weapon, attacker, defender,
true, special_damage);
}
return attack::handle_phase_killed();
}
static void _handle_spectral_brand(actor &attacker, const actor &defender)
{
if (attacker.type == MONS_SPECTRAL_WEAPON || !defender.alive())
return;
attacker.triggered_spectral = true;
spectral_weapon_fineff::schedule(attacker, defender);
}
bool melee_attack::handle_phase_end()
{
if (!cleave_targets.empty() && !simu)
{
attack_cleave_targets(*attacker, cleave_targets, attack_number,
effective_attack_number, wu_jian_attack,
is_projected);
}
// Check for passive mutation effects.
if (defender->is_player() && defender->alive() && attacker != defender)
{
mons_do_eyeball_confusion();
mons_do_tendril_disarm();
}
if (attacker->alive()
&& attacker->is_monster()
&& attacker->as_monster()->has_ench(ENCH_ROLLING))
{
attacker->as_monster()->del_ench(ENCH_ROLLING);
}
if (defender)
{
if (damage_brand == SPWPN_SPECTRAL)
_handle_spectral_brand(*attacker, *defender);
// Use the Nessos hack to give the player glaive of the guard spectral too
if (weapon && is_unrandom_artefact(*weapon, UNRAND_GUARD))
_handle_spectral_brand(*attacker, *defender);
}
return attack::handle_phase_end();
}
/* Initiate the processing of the attack
*
* Called from the main code (fight.cc), this method begins the actual combat
* for a particular attack and is responsible for looping through each of the
* appropriate phases (which then can call other related phases within
* themselves).
*
* Returns whether combat was completely successful
* If combat was not successful, it could be any number of reasons, like
* the defender or attacker dying during the attack? or a defender moving
* from its starting position.
*/
bool melee_attack::attack()
{
if (!cleaving)
{
cleave_setup();
if (!handle_phase_attempted())
return false;
}
if (attacker != defender && attacker->is_monster()
&& mons_self_destructs(*attacker->as_monster()))
{
attacker->self_destruct();
return did_hit = perceived_attack = true;
}
string saved_gyre_name;
if (weapon && is_unrandom_artefact(*weapon, UNRAND_GYRE))
{
saved_gyre_name = get_artefact_name(*weapon);
set_artefact_name(*weapon, cleaving ? "quick blade \"Gimble\""
: "quick blade \"Gyre\"");
}
// Restore gyre's name before we return. We cannot use an unwind_var here
// because the precise address of the ARTEFACT_NAME_KEY property might
// change, for example if a summoned item is reset.
ON_UNWIND
{
if (!saved_gyre_name.empty() && weapon
&& is_unrandom_artefact(*weapon, UNRAND_GYRE))
{
set_artefact_name(*weapon, saved_gyre_name);
}
};
// Attacker might have died from effects of cleaving handled prior to this
if (!attacker->alive())
return false;
// We might have killed the kraken target by cleaving a tentacle.
if (!defender->alive())
{
handle_phase_killed();
handle_phase_end();
return attack_occurred;
}
// Apparently I'm insane for believing that we can still stay general past
// this point in the combat code, mebe I am! --Cryptic
// Calculate various ev values and begin to check them to determine the
// correct handle_phase_ handler.
const int ev = defender->evasion(false, attacker);
ev_margin = test_hit(to_hit, ev, !attacker->is_player());
bool shield_blocked = attack_shield_blocked(true);
// Stuff for god conduct, this has to remain here for scope reasons.
god_conduct_trigger conducts[3];
if (attacker->is_player() && attacker != defender)
{
set_attack_conducts(conducts, *defender->as_monster(),
you.can_see(*defender));
if (player_under_penance(GOD_ELYVILON)
&& god_hates_your_god(GOD_ELYVILON)
&& ev_margin >= 0
&& one_chance_in(20))
{
simple_god_message(" blocks your attack.", GOD_ELYVILON);
handle_phase_end();
return false;
}
// Check for stab (and set stab_attempt and stab_bonus)
player_stab_check();
// Make sure we hit if we passed the stab check.
if (stab_attempt && stab_bonus > 0)
{
ev_margin = AUTOMATIC_HIT;
shield_blocked = false;
}
// Serpent's Lash does not miss
if (wu_jian_has_momentum(wu_jian_attack))
ev_margin = AUTOMATIC_HIT;
}
if (shield_blocked)
{
handle_phase_blocked();
maybe_riposte();
if (!attacker->alive())
{
handle_phase_end();
return false;
}
}
else
{
if (attacker != defender
&& (adjacent(defender->pos(), attack_position) || is_projected)
&& !is_riposte)
{
// Check for defender Spines
do_spines();
// Spines can kill! With Usk's pain bond, they can even kill the
// defender.
if (!attacker->alive() || !defender->alive())
return false;
}
if (ev_margin >= 0)
{
bool cont = handle_phase_hit();
attacker_sustain_passive_damage();
if (!cont)
{
if (!defender->alive())
handle_phase_killed();
handle_phase_end();
return false;
}
}
else
handle_phase_dodged();
}
// don't crash on banishment
if (!defender->pos().origin())
handle_noise(defender->pos());
// Noisy weapons.
if (attacker->is_player()
&& weapon
&& is_artefact(*weapon)
&& artefact_property(*weapon, ARTP_NOISE))
{
noisy_equipment();
}
alert_defender();
if (!defender->alive())
handle_phase_killed();
handle_phase_aux();
handle_phase_end();
return attack_occurred;
}
void melee_attack::check_autoberserk()
{
if (defender->is_monster() && mons_is_firewood(*defender->as_monster()))
return;
if (x_chance_in_y(attacker->angry(), 100))
{
attacker->go_berserk(false);
return;
}
}
bool melee_attack::check_unrand_effects()
{
if (unrand_entry && unrand_entry->melee_effects && weapon)
{
const bool died = !defender->alive();
// Don't trigger the Wyrmbane death effect yet; that is done in
// handle_phase_killed().
if (weapon->unrand_idx == UNRAND_WYRMBANE && died)
return true;
// Recent merge added damage_done to this method call
unrand_entry->melee_effects(weapon, attacker, defender,
died, damage_done);
return !defender->alive(); // may have changed
}
return false;
}
class AuxAttackType
{
public:
AuxAttackType(int _damage, int _chance, string _name) :
damage(_damage), chance(_chance), name(_name) { };
public:
virtual int get_damage(bool /*random*/) const { return damage; };
virtual int get_brand() const { return SPWPN_NORMAL; };
virtual string get_name() const { return name; };
virtual string get_verb() const { return get_name(); };
int get_chance() const {
const int base = get_base_chance();
if (xl_based_chance())
return base * (30 + you.experience_level) / 59;
return base;
}
virtual int get_base_chance() const { return chance; }
virtual bool xl_based_chance() const { return true; }
virtual string describe() const;
protected:
const int damage;
// Per-attack trigger percent, before accounting for XL.
const int chance;
const string name;
};
class AuxConstrict: public AuxAttackType
{
public:
AuxConstrict()
: AuxAttackType(0, 100, "grab") { };
bool xl_based_chance() const override { return false; }
};
class AuxKick: public AuxAttackType
{
public:
AuxKick()
: AuxAttackType(5, 100, "kick") { };
int get_damage(bool /*random*/) const override
{
if (you.has_usable_hooves())
{
// Max hoof damage: 10.
return damage + you.get_mutation_level(MUT_HOOVES) * 5 / 3;
}
if (you.has_usable_talons())
{
// Max talon damage: 9.
return damage + 1 + you.get_mutation_level(MUT_TALONS);
}
// Max spike damage: 8.
// ... yes, apparently tentacle spikes are "kicks".
return damage + you.get_mutation_level(MUT_TENTACLE_SPIKE);
}
string get_verb() const override
{
if (you.has_usable_talons())
return "claw";
if (you.get_mutation_level(MUT_TENTACLE_SPIKE))
return "pierce";
return name;
}
string get_name() const override
{
if (you.get_mutation_level(MUT_TENTACLE_SPIKE))
return "tentacle spike";
return name;
}
};
class AuxHeadbutt: public AuxAttackType
{
public:
AuxHeadbutt()
: AuxAttackType(5, 67, "headbutt") { };
int get_damage(bool /*random*/) const override
{
return damage + you.get_mutation_level(MUT_HORNS) * 3;
}
};
class AuxPeck: public AuxAttackType
{
public:
AuxPeck()
: AuxAttackType(6, 67, "peck") { };
};
class AuxTailslap: public AuxAttackType
{
public:
AuxTailslap()