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

Function use_trap

src/apply.c:2820–2912  ·  view source on GitHub ↗

Place a landmine/bear trap. Helge Hafting */

Source from the content-addressed store, hash-verified

2818
2819/* Place a landmine/bear trap. Helge Hafting */
2820staticfn void
2821use_trap(struct obj *otmp)
2822{
2823 int ttyp, tmp;
2824 const char *what = (char *) 0;
2825 char buf[BUFSZ];
2826 int levtyp = levl[u.ux][u.uy].typ;
2827 const char *occutext = "setting the trap";
2828
2829 if (nohands(gy.youmonst.data))
2830 what = "without hands";
2831 else if (Stunned)
2832 what = "while stunned";
2833 else if (u.uswallow)
2834 what = digests(u.ustuck->data) ? "while swallowed" : "while engulfed";
2835 else if (Underwater)
2836 what = "underwater";
2837 else if (Levitation)
2838 what = "while levitating";
2839 else if (is_pool(u.ux, u.uy))
2840 what = "in water";
2841 else if (is_lava(u.ux, u.uy))
2842 what = "in lava";
2843 else if (On_stairs(u.ux, u.uy)) {
2844 stairway *stway = stairway_at(u.ux, u.uy);
2845 what = stway->isladder ? "on the ladder" : "on the stairs";
2846 } else if (IS_FURNITURE(levtyp) || IS_OBSTRUCTED(levtyp)
2847 || closed_door(u.ux, u.uy) || t_at(u.ux, u.uy))
2848 what = "here";
2849 else if (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz))
2850 what = (levtyp == AIR)
2851 ? "in midair"
2852 : (levtyp == CLOUD)
2853 ? "in a cloud"
2854 : "in this place"; /* Air/Water Plane catch-all */
2855 if (what) {
2856 You_cant("set a trap %s!", what);
2857 reset_trapset();
2858 return;
2859 }
2860 ttyp = (otmp->otyp == LAND_MINE) ? LANDMINE : BEAR_TRAP;
2861 if (otmp == gt.trapinfo.tobj && u_at(gt.trapinfo.tx, gt.trapinfo.ty)) {
2862 You("resume setting %s%s.", shk_your(buf, otmp),
2863 trapname(ttyp, FALSE));
2864 set_occupation(set_trap, occutext, 0);
2865 return;
2866 }
2867 gt.trapinfo.tobj = otmp;
2868 gt.trapinfo.tx = u.ux, gt.trapinfo.ty = u.uy;
2869 tmp = ACURR(A_DEX);
2870 gt.trapinfo.time_needed =
2871 (tmp > 17) ? 2 : (tmp > 12) ? 3 : (tmp > 7) ? 4 : 5;
2872 if (Blind)
2873 gt.trapinfo.time_needed *= 2;
2874 tmp = ACURR(A_STR);
2875 if (ttyp == BEAR_TRAP && tmp < 18)
2876 gt.trapinfo.time_needed += (tmp > 12) ? 1 : (tmp > 7) ? 2 : 4;
2877 /*[fumbling and/or confusion and/or cursed object check(s)

Callers 1

doapplyFunction · 0.85

Calls 15

is_poolFunction · 0.85
is_lavaFunction · 0.85
On_stairsFunction · 0.85
stairway_atFunction · 0.85
closed_doorFunction · 0.85
t_atFunction · 0.85
You_cantFunction · 0.85
reset_trapsetFunction · 0.85
YouFunction · 0.85
shk_yourFunction · 0.85
trapnameFunction · 0.85
set_occupationFunction · 0.85

Tested by

no test coverage detected