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

Function create_subroom

src/sp_lev.c:1667–1707  ·  view source on GitHub ↗

* Create a subroom in room proom at pos x,y with width w & height h. * x & y are relative to the parent room. */

Source from the content-addressed store, hash-verified

1665 * x & y are relative to the parent room.
1666 */
1667staticfn boolean
1668create_subroom(
1669 struct mkroom *proom,
1670 coordxy x, coordxy y,
1671 coordxy w, coordxy h,
1672 xint16 rtype, xint16 rlit)
1673{
1674 coordxy width, height;
1675
1676 width = proom->hx - proom->lx + 1;
1677 height = proom->hy - proom->ly + 1;
1678
1679 /* There is a minimum size for the parent room */
1680 if (width < 4 || height < 4)
1681 return FALSE;
1682
1683 /* Check for random position, size, etc... */
1684
1685 if (w == -1)
1686 w = rnd(width - 3);
1687 if (h == -1)
1688 h = rnd(height - 3);
1689 if (x == -1)
1690 x = rnd(width - w);
1691 if (y == -1)
1692 y = rnd(height - h);
1693 if (x == 1)
1694 x = 0;
1695 if (y == 1)
1696 y = 0;
1697 if ((x + w + 1) == width)
1698 x++;
1699 if ((y + h + 1) == height)
1700 y++;
1701 if (rtype == -1)
1702 rtype = OROOM;
1703 rlit = litstate_rnd(rlit);
1704 add_subroom(proom, proom->lx + x, proom->ly + y, proom->lx + x + w - 1,
1705 proom->ly + y + h - 1, rlit, rtype, FALSE);
1706 return TRUE;
1707}
1708
1709/*
1710 * Create a new door in a room.

Callers 1

build_roomFunction · 0.85

Calls 3

rndFunction · 0.85
litstate_rndFunction · 0.85
add_subroomFunction · 0.85

Tested by

no test coverage detected