| 453 | } |
| 454 | |
| 455 | struct trap * |
| 456 | maketrap(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); |
no test coverage detected