MCPcopy Index your code
hub / github.com/NetHack/NetHack / thitm

Function thitm

src/trap.c:6710–6773  ·  view source on GitHub ↗

Monster is hit by trap. */

Source from the content-addressed store, hash-verified

6708
6709/* Monster is hit by trap. */
6710staticfn boolean
6711thitm(
6712 int tlev, /* missile's attack level */
6713 struct monst *mon, /* target */
6714 struct obj *obj, /* missile; might be Null */
6715 int d_override, /* non-zero: force hit for this amount of damage */
6716 boolean nocorpse) /* True: a trap is completely burning up the target */
6717{
6718 int strike;
6719 boolean trapkilled = FALSE;
6720
6721 if (d_override)
6722 strike = 1;
6723 else if (obj)
6724 strike = (find_mac(mon) + tlev + obj->spe <= rnd(20));
6725 else
6726 strike = (find_mac(mon) + tlev <= rnd(20));
6727
6728 /* Actually more accurate than thitu, which doesn't take
6729 * obj->spe into account.
6730 */
6731 if (!strike) {
6732 if (obj && cansee(mon->mx, mon->my))
6733 pline_mon(mon, "%s is almost hit by %s!",
6734 Monnam(mon), doname(obj));
6735 } else {
6736 int dam = 1;
6737 boolean harmless = (obj && stone_missile(obj)
6738 && passes_rocks(mon->data));
6739
6740 if (obj && cansee(mon->mx, mon->my))
6741 pline_mon(mon, "%s is hit by %s%s",
6742 Monnam(mon), doname(obj),
6743 harmless ? " but is not harmed." : "!");
6744 if (d_override) {
6745 dam = d_override;
6746 } else if (obj) {
6747 dam = dmgval(obj, mon);
6748 if (dam < 1)
6749 dam = 1;
6750 }
6751 if (!harmless) {
6752 mon->mhp -= dam;
6753 if (mon->mhp <= 0) {
6754 int xx = mon->mx, yy = mon->my;
6755
6756 monkilled(mon, "", nocorpse ? -AD_RBRE : AD_PHYS);
6757 if (DEADMONSTER(mon)) {
6758 newsym(xx, yy);
6759 trapkilled = TRUE;
6760 }
6761 }
6762 } else {
6763 strike = 0; /* harmless; don't use up the missile */
6764 }
6765 }
6766 if (obj && (!strike || d_override)) {
6767 place_object(obj, mon->mx, mon->my);

Callers 8

trapeffect_arrow_trapFunction · 0.85
trapeffect_dart_trapFunction · 0.85
trapeffect_rocktrapFunction · 0.85
trapeffect_bear_trapFunction · 0.85
trapeffect_fire_trapFunction · 0.85
trapeffect_pitFunction · 0.85
trapeffect_landmineFunction · 0.85
steedintrapFunction · 0.85

Calls 11

find_macFunction · 0.85
rndFunction · 0.85
pline_monFunction · 0.85
MonnamFunction · 0.85
donameFunction · 0.85
dmgvalFunction · 0.85
monkilledFunction · 0.85
newsymFunction · 0.85
place_objectFunction · 0.85
stackobjFunction · 0.85
dealloc_objFunction · 0.85

Tested by

no test coverage detected