MCPcopy Create free account
hub / github.com/NetHack/NetHack / hitum

Function hitum

src/uhitm.c:757–815  ·  view source on GitHub ↗

hit target monster; returns TRUE if it still lives */

Source from the content-addressed store, hash-verified

755
756/* hit target monster; returns TRUE if it still lives */
757staticfn boolean
758hitum(struct monst *mon, struct attack *uattk)
759{
760 boolean malive, wep_was_destroyed = FALSE;
761 struct obj *wepbefore = uwep,
762 *secondwep = u.twoweap ? uswapwep : (struct obj *) 0;
763 int tmp, dieroll, mhit, armorpenalty, attknum = 0,
764 x = u.ux + u.dx, y = u.uy + u.dy, oldumort = u.umortality;
765
766 /* Cleaver attacks three spots, 'mon' and one on either side of 'mon';
767 it can't be part of dual-wielding but we guard against that anyway;
768 cleave return value reflects status of primary target ('mon') */
769 if (u_wield_art(ART_CLEAVER) && !u.twoweap
770 && !u.uswallow && !u.ustuck && !NODIAG(u.umonnum))
771 return hitum_cleave(mon, uattk);
772
773 /* 0: single hit, 1: first of two hits; affects strength bonus and
774 silver rings; known_hitum() -> hmon() -> hmon_hitmon() will copy
775 gt.twohits into struct _hitmon_data hmd.twohits */
776 gt.twohits = (uwep ? u.twoweap : double_punch()) ? 1 : 0;
777
778 tmp = find_roll_to_hit(mon, uattk->aatyp, uwep, &attknum, &armorpenalty);
779 mon_maybe_unparalyze(mon);
780 dieroll = rnd(20);
781 mhit = (tmp > dieroll || u.uswallow);
782 if (tmp > dieroll)
783 exercise(A_DEX, TRUE);
784
785 /* gb.bhitpos is set up by caller */
786 malive = known_hitum(mon, uwep, &mhit, tmp, armorpenalty, uattk, dieroll);
787 if (wepbefore && !uwep)
788 wep_was_destroyed = TRUE;
789 (void) passive(mon, uwep, mhit, malive, AT_WEAP, wep_was_destroyed);
790
791 /* second attack for two-weapon combat or skilled unarmed combat;
792 won't occur if Stormbringer overrode confirmation (assumes
793 Stormbringer is primary weapon), or if hero became paralyzed by
794 passive counter-attack, or if hero was killed by passive
795 counter-attack and got life-saved, or if monster was killed or
796 knocked to different location */
797 if (gt.twohits && !(go.override_confirmation
798 || gm.multi < 0 || u.umortality > oldumort
799 || !malive || m_at(x, y) != mon)) {
800 gt.twohits = 2; /* second of 2 hits */
801 tmp = find_roll_to_hit(mon, uattk->aatyp, uswapwep, &attknum,
802 &armorpenalty);
803 mon_maybe_unparalyze(mon);
804 dieroll = rnd(20);
805 mhit = (tmp > dieroll || u.uswallow);
806 malive = known_hitum(mon, secondwep, &mhit, tmp, armorpenalty, uattk,
807 dieroll);
808 /* second passive counter-attack only occurs if second attack hits */
809 if (mhit)
810 (void) passive(mon, secondwep, mhit, malive, AT_WEAP,
811 secondwep && !uswapwep);
812 }
813 gt.twohits = 0;
814 return malive;

Callers 1

do_attackFunction · 0.85

Calls 8

hitum_cleaveFunction · 0.85
double_punchFunction · 0.85
find_roll_to_hitFunction · 0.85
mon_maybe_unparalyzeFunction · 0.85
rndFunction · 0.85
exerciseFunction · 0.85
known_hitumFunction · 0.85
passiveFunction · 0.85

Tested by

no test coverage detected