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

Function create_door

src/sp_lev.c:1713–1806  ·  view source on GitHub ↗

* Create a new door in a room. * It's placed on a wall (north, south, east or west). */

Source from the content-addressed store, hash-verified

1711 * It's placed on a wall (north, south, east or west).
1712 */
1713staticfn void
1714create_door(room_door *dd, struct mkroom *broom)
1715{
1716 int x = 0, y = 0;
1717 int trycnt;
1718
1719 if (dd->secret == -1)
1720 dd->secret = rn2(2);
1721
1722 if (dd->wall == W_RANDOM)
1723 dd->wall = W_ANY; /* speeds things up in the below loop */
1724
1725 if (dd->mask == -1) {
1726 /* is it a locked door, closed, or a doorway? */
1727 if (!dd->secret) {
1728 if (!rn2(3)) {
1729 if (!rn2(5))
1730 dd->mask = D_ISOPEN;
1731 else if (!rn2(6))
1732 dd->mask = D_LOCKED;
1733 else
1734 dd->mask = D_CLOSED;
1735 if (dd->mask != D_ISOPEN && !rn2(25))
1736 dd->mask |= D_TRAPPED;
1737 } else
1738 dd->mask = D_NODOOR;
1739 } else {
1740 if (!rn2(5))
1741 dd->mask = D_LOCKED;
1742 else
1743 dd->mask = D_CLOSED;
1744
1745 if (!rn2(20))
1746 dd->mask |= D_TRAPPED;
1747 }
1748 }
1749
1750 for (trycnt = 0; trycnt < 100; ++trycnt) {
1751 int dwall = dd->wall, dpos = dd->pos;
1752
1753 /* Convert wall and pos into an absolute coordinate! */
1754 switch (rn2(4)) {
1755 case 0:
1756 if (!(dwall & W_NORTH))
1757 continue;
1758 y = broom->ly - 1;
1759 x = broom->lx + ((dpos == -1) ? rn2(1 + broom->hx - broom->lx)
1760 : dpos);
1761 if (!isok(x, y - 1) || IS_OBSTRUCTED(levl[x][y - 1].typ))
1762 continue;
1763 break;
1764 case 1:
1765 if (!(dwall & W_SOUTH))
1766 continue;
1767 y = broom->hy + 1;
1768 x = broom->lx + ((dpos == -1) ? rn2(1 + broom->hx - broom->lx)
1769 : dpos);
1770 if (!isok(x, y + 1) || IS_OBSTRUCTED(levl[x][y + 1].typ))

Callers 1

lspo_doorFunction · 0.85

Calls 5

rn2Function · 0.85
isokFunction · 0.85
okdoorFunction · 0.85
set_levltypFunction · 0.85
impossibleFunction · 0.70

Tested by

no test coverage detected