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

Function maketrap

src/trap.c:455–588  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

453}
454
455struct trap *
456maketrap(coordxy x, coordxy y, int typ)
457{
458 static union vlaunchinfo zero_vl;
459 boolean oldplace, was_ice, clear_flags;
460 struct trap *ttmp;
461 struct rm *lev = &levl[x][y];
462
463 if (typ == TRAPPED_DOOR || typ == TRAPPED_CHEST)
464 return (struct trap *) 0;
465
466 if ((ttmp = t_at(x, y)) != 0) {
467 if (undestroyable_trap(ttmp->ttyp))
468 return (struct trap *) 0;
469 oldplace = TRUE;
470 if (u.utrap && u_at(x, y)
471 && ((u.utraptype == TT_BEARTRAP && typ != BEAR_TRAP)
472 || (u.utraptype == TT_WEB && typ != WEB)
473 || (u.utraptype == TT_PIT && !is_pit(typ))
474 || (u.utraptype == TT_LAVA && !is_lava(x, y))))
475 reset_utrap(FALSE);
476 /* old <tx,ty> remain valid */
477 } else if (!CAN_OVERWRITE_TERRAIN(lev->typ) /* stairs */
478 || is_pool_or_lava(x, y)
479 || (IS_FURNITURE(lev->typ) && (typ != PIT && typ != HOLE))
480 || (lev->typ == DRAWBRIDGE_UP && typ == MAGIC_PORTAL)
481 || (IS_AIR(lev->typ) && typ != MAGIC_PORTAL)
482 || (typ == LEVEL_TELEP && single_level_branch(&u.uz))) {
483 /* no trap on top of furniture (caller usually screens the
484 location to inhibit this, but wizard mode wishing doesn't)
485 and no level teleporter in branch with only one level */
486 return (struct trap *) 0;
487 } else {
488 oldplace = FALSE;
489 ttmp = newtrap();
490 (void) memset((genericptr_t) ttmp, 0, sizeof(struct trap));
491 ttmp->ntrap = 0;
492 ttmp->tx = x;
493 ttmp->ty = y;
494 }
495 /* [re-]initialize all fields except ntrap (handled below) and <tx,ty> */
496 ttmp->vl = zero_vl;
497 ttmp->launch.x = ttmp->launch.y = -1; /* force error if used before set */
498 ttmp->dst.dnum = ttmp->dst.dlevel = -1;
499 ttmp->madeby_u = 0;
500 ttmp->once = 0;
501 ttmp->tseen = unhideable_trap(typ);
502 ttmp->ttyp = typ;
503
504 switch (typ) {
505 case SQKY_BOARD:
506 ttmp->tnote = choose_trapnote(ttmp);
507 break;
508 case STATUE_TRAP: /* create a "living" statue */
509 mk_trap_statue(x, y);
510 break;
511 case ROLLING_BOULDER_TRAP: /* boulder will roll towards trigger */
512 (void) mkroll_launch(ttmp, x, y, BOULDER, 1L);

Callers 15

revive_corpseFunction · 0.85
wizterrainwishFunction · 0.85
digactualholeFunction · 0.85
do_pitFunction · 0.85
dospinwebFunction · 0.85
try_disarmFunction · 0.85
zap_over_floorFunction · 0.85
maybe_spin_webFunction · 0.85
use_defensiveFunction · 0.85
makenicheFunction · 0.85
fill_ordinary_roomFunction · 0.85
mktrapFunction · 0.85

Calls 15

t_atFunction · 0.85
is_lavaFunction · 0.85
reset_utrapFunction · 0.85
is_pool_or_lavaFunction · 0.85
single_level_branchFunction · 0.85
choose_trapnoteFunction · 0.85
mk_trap_statueFunction · 0.85
mkroll_launchFunction · 0.85
hole_destinationFunction · 0.85
in_roomsFunction · 0.85
add_damageFunction · 0.85
obj_ice_effectsFunction · 0.85

Tested by

no test coverage detected