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

Function create_trap

src/sp_lev.c:1811–1846  ·  view source on GitHub ↗

* Create a trap in a room. */

Source from the content-addressed store, hash-verified

1809 * Create a trap in a room.
1810 */
1811staticfn void
1812create_trap(spltrap *t, struct mkroom *croom)
1813{
1814 coordxy x = -1, y = -1;
1815 coord tm;
1816 unsigned mktrap_flags = MKTRAP_MAZEFLAG;
1817
1818 if (t->type == VIBRATING_SQUARE) {
1819 pick_vibrasquare_location();
1820 maketrap(svi.inv_pos.x, svi.inv_pos.y, VIBRATING_SQUARE);
1821 return;
1822 } else if (croom) {
1823 get_free_room_loc(&x, &y, croom, t->coord);
1824 } else {
1825 int trycnt = 0;
1826
1827 do {
1828 get_location_coord(&x, &y, DRY, croom, t->coord);
1829 } while ((levl[x][y].typ == STAIRS || levl[x][y].typ == LADDER)
1830 && ++trycnt <= 100);
1831 if (trycnt > 100)
1832 return;
1833 }
1834
1835 if (!t->spider_on_web)
1836 mktrap_flags |= MKTRAP_NOSPIDERONWEB;
1837 if (t->seen)
1838 mktrap_flags |= MKTRAP_SEEN;
1839 if (t->novictim)
1840 mktrap_flags |= MKTRAP_NOVICTIM;
1841
1842 tm.x = x;
1843 tm.y = y;
1844
1845 mktrap(t->type, mktrap_flags, (struct mkroom *) 0, &tm);
1846}
1847
1848/*
1849 * Create a monster in a room.

Callers 1

lspo_trapFunction · 0.85

Calls 5

maketrapFunction · 0.85
get_free_room_locFunction · 0.85
get_location_coordFunction · 0.85
mktrapFunction · 0.85

Tested by

no test coverage detected