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

Function chest_trap

src/trap.c:6293–6499  ·  view source on GitHub ↗

only called when the player is doing something to the chest directly; returns True if chest is destroyed, False if it remains in play */

Source from the content-addressed store, hash-verified

6291/* only called when the player is doing something to the chest directly;
6292 returns True if chest is destroyed, False if it remains in play */
6293boolean
6294chest_trap(
6295 struct obj *obj,
6296 int bodypart,
6297 boolean disarm)
6298{
6299 struct obj *otmp = obj, *otmp2;
6300 char buf[80];
6301 const char *msg;
6302 coord cc;
6303
6304 if (get_obj_location(obj, &cc.x, &cc.y, 0)) /* might be carried */
6305 obj->ox = cc.x, obj->oy = cc.y;
6306
6307 otmp->tknown = 0; /* for xname(); will be set to 1 below */
6308 otmp->otrapped = 0; /* trap is one-shot; clear flag first in case
6309 * chest kills you and ends up in bones file */
6310 You(disarm ? "set it off!" : "trigger a trap!");
6311 display_nhwindow(WIN_MESSAGE, FALSE);
6312 if (Luck > -13 && rn2(13 + Luck) > 7) { /* saved by luck */
6313 /* trap went off, but good luck prevents damage */
6314 switch (rn2(13)) {
6315 case 12:
6316 case 11:
6317 msg = "explosive charge is a dud";
6318 break;
6319 case 10:
6320 case 9:
6321 msg = "electric charge is grounded";
6322 break;
6323 case 8:
6324 case 7:
6325 msg = "flame fizzles out";
6326 break;
6327 case 6:
6328 case 5:
6329 case 4:
6330 msg = "poisoned needle misses";
6331 break;
6332 case 3:
6333 case 2:
6334 case 1:
6335 case 0:
6336 msg = "gas cloud blows away";
6337 break;
6338 default:
6339 impossible("chest disarm bug");
6340 msg = (char *) 0;
6341 break;
6342 }
6343 if (msg)
6344 pline("But luckily the %s!", msg);
6345 } else {
6346 switch (rn2(20) ? ((Luck >= 13) ? 0 : rn2(13 - Luck)) : rn2(26)) {
6347 case 25:
6348 case 24:
6349 case 23:
6350 case 22:

Callers 5

picklockFunction · 0.85
use_containerFunction · 0.85
tipcontainer_checksFunction · 0.85
disarm_boxFunction · 0.85
really_kick_objectFunction · 0.85

Calls 15

get_obj_locationFunction · 0.85
YouFunction · 0.85
rn2Function · 0.85
costly_spotFunction · 0.85
shop_keeperFunction · 0.85
in_roomsFunction · 0.85
inside_shopFunction · 0.85
TobjnamFunction · 0.85
xnameFunction · 0.85
stolen_valueFunction · 0.85
delete_contentsFunction · 0.85
unpunishFunction · 0.85

Tested by

no test coverage detected