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

Function hmonas

src/uhitm.c:5423–5860  ·  view source on GitHub ↗

attack monster as a monster; returns True if mon survives */

Source from the content-addressed store, hash-verified

5421
5422/* attack monster as a monster; returns True if mon survives */
5423staticfn boolean
5424hmonas(struct monst *mon)
5425{
5426 struct attack *mattk, alt_attk;
5427 struct obj *weapon, **originalweapon;
5428 boolean altwep = FALSE, weapon_used = FALSE, odd_claw = TRUE;
5429 int i, tmp, dieroll, armorpenalty, sum[NATTK],
5430 dhit = 0, attknum = 0, multi_claw = 0, multi_weap = 0;
5431 boolean monster_survived;
5432
5433 /* not used here but umpteen mhitm_ad_xxxx() need this */
5434 gv.vis = (canseemon(mon) || m_next2u(mon));
5435
5436 /* with just one touch/claw/weapon attack, both rings matter;
5437 with more than one, alternate right and left when checking
5438 whether silver ring causes successful hit */
5439 for (i = 0; i < NATTK; i++) {
5440 sum[i] = M_ATTK_MISS;
5441 mattk = getmattk(&gy.youmonst, mon, i, sum, &alt_attk);
5442 if (mattk->aatyp == AT_WEAP)
5443 ++multi_weap;
5444 if (mattk->aatyp == AT_WEAP
5445 || mattk->aatyp == AT_CLAW || mattk->aatyp == AT_TUCH)
5446 ++multi_claw;
5447 }
5448 multi_claw = (multi_claw > 1); /* switch from count to yes/no */
5449 gt.twohits = 0;
5450
5451 gs.skipdrin = FALSE; /* [see mattackm(mhitm.c)] */
5452
5453 for (i = 0; i < NATTK; i++) {
5454 /* sum[i] = M_ATTK_MISS; -- now done above */
5455
5456 /* target might have been knocked back so no longer in range, or an
5457 engulfing vampshifted fog cloud killed and reverted to vampire
5458 that's placed at another spot (hero occupies mon's first spot) */
5459 if (i > 0 && (m_at(gb.bhitpos.x, gb.bhitpos.y) != mon
5460 || DEADMONSTER(mon)))
5461 continue;
5462
5463 mattk = getmattk(&gy.youmonst, mon, i, sum, &alt_attk);
5464 if (gs.skipdrin && mattk->aatyp == AT_TENT && mattk->adtyp == AD_DRIN)
5465 continue;
5466 weapon = 0;
5467 switch (mattk->aatyp) {
5468 case AT_WEAP:
5469 /* if (!uwep) goto weaponless; */
5470 use_weapon:
5471 odd_claw = !odd_claw; /* see case AT_CLAW,AT_TUCH below */
5472 /* if we've already hit with a two-handed weapon, we don't
5473 get to make another weapon attack (note: monsters who
5474 use weapons do not have this restriction, but they also
5475 never have the opportunity to use two weapons) */
5476 if (weapon_used && (sum[i - 1] > M_ATTK_MISS)
5477 && uwep && bimanual(uwep))
5478 continue;
5479 /* Certain monsters don't use weapons when encountered as enemies,
5480 * but players who polymorph into them have hands or claws and

Callers 1

do_attackFunction · 0.85

Calls 15

canseemonFunction · 0.85
getmattkFunction · 0.85
find_roll_to_hitFunction · 0.85
mon_maybe_unparalyzeFunction · 0.85
rndFunction · 0.85
known_hitumFunction · 0.85
damageumFunction · 0.85
mtrapped_in_pitFunction · 0.85
could_seduceFunction · 0.85
YouFunction · 0.85
mon_namFunction · 0.85
wakeupFunction · 0.85

Tested by

no test coverage detected