* Create a new door in a room. * It's placed on a wall (north, south, east or west). */
| 1711 | * It's placed on a wall (north, south, east or west). |
| 1712 | */ |
| 1713 | staticfn void |
| 1714 | create_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)) |
no test coverage detected