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

Function trapeffect_arrow_trap

src/trap.c:1189–1248  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1187}
1188
1189staticfn int
1190trapeffect_arrow_trap(
1191 struct monst *mtmp,
1192 struct trap *trap,
1193 unsigned trflags UNUSED)
1194{
1195 struct obj *otmp;
1196 int dam;
1197
1198 if (mtmp == &gy.youmonst) {
1199 if (trap->once && trap->tseen && !rn2(15)) {
1200 Soundeffect(se_loud_click, 100);
1201 You_hear("a loud click!");
1202 deltrap(trap);
1203 newsym(u.ux, u.uy);
1204 return Trap_Is_Gone;
1205 }
1206 trap->once = 1;
1207 seetrap(trap);
1208 pline("An arrow shoots out at you!");
1209 otmp = t_missile(ARROW, trap);
1210 dam = dmgval(otmp, &gy.youmonst);
1211 if (u.usteed && !rn2(2) && steedintrap(trap, otmp)) {
1212 ; /* nothing */
1213 } else if (thitu(8, Maybe_Half_Phys(dam), &otmp, "arrow")) {
1214 if (otmp)
1215 obfree(otmp, (struct obj *) 0);
1216 } else {
1217 place_object(otmp, u.ux, u.uy);
1218 if (!Blind)
1219 observe_object(otmp);
1220 stackobj(otmp);
1221 newsym(u.ux, u.uy);
1222 }
1223 } else {
1224 boolean in_sight = canseemon(mtmp) || (mtmp == u.usteed);
1225 boolean see_it = cansee(mtmp->mx, mtmp->my);
1226 boolean trapkilled = FALSE;
1227
1228 if (trap->once && trap->tseen && !rn2(15)) {
1229 if (in_sight && see_it)
1230 pline_mon(mtmp,
1231 "%s triggers a trap but nothing happens.",
1232 Monnam(mtmp));
1233 deltrap(trap);
1234 newsym(mtmp->mx, mtmp->my);
1235 return Trap_Is_Gone;
1236 }
1237 trap->once = 1;
1238 otmp = t_missile(ARROW, trap);
1239 if (in_sight)
1240 seetrap(trap);
1241 if (thitm(8, mtmp, otmp, 0, FALSE))
1242 trapkilled = TRUE;
1243
1244 return trapkilled ? Trap_Killed_Mon : mtmp->mtrapped
1245 ? Trap_Caught_Mon : Trap_Effect_Finished;
1246 }

Callers 1

trapeffect_selectorFunction · 0.85

Calls 15

rn2Function · 0.85
You_hearFunction · 0.85
deltrapFunction · 0.85
newsymFunction · 0.85
seetrapFunction · 0.85
t_missileFunction · 0.85
dmgvalFunction · 0.85
steedintrapFunction · 0.85
thituFunction · 0.85
obfreeFunction · 0.85
place_objectFunction · 0.85
observe_objectFunction · 0.85

Tested by

no test coverage detected