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

Function fillholetyp

src/dig.c:605–637  ·  view source on GitHub ↗

Return typ of liquid to fill a hole with, or ROOM, if no liquid nearby */

Source from the content-addressed store, hash-verified

603
604/* Return typ of liquid to fill a hole with, or ROOM, if no liquid nearby */
605schar
606fillholetyp(coordxy x, coordxy y,
607 boolean fill_if_any) /* force filling if it exists at all */
608{
609 coordxy x1, y1;
610 coordxy lo_x = max(1, x - 1), hi_x = min(x + 1, COLNO - 1),
611 lo_y = max(0, y - 1), hi_y = min(y + 1, ROWNO - 1);
612 int pool_cnt = 0, moat_cnt = 0, lava_cnt = 0;
613
614 for (x1 = lo_x; x1 <= hi_x; x1++)
615 for (y1 = lo_y; y1 <= hi_y; y1++)
616 if (is_moat(x1, y1))
617 moat_cnt++;
618 else if (is_pool(x1, y1))
619 /* This must come after is_moat since moats are pools
620 * but not vice-versa. */
621 pool_cnt++;
622 else if (is_lava(x1, y1))
623 lava_cnt++;
624
625 if (!fill_if_any)
626 pool_cnt /= 3; /* not as much liquid as the others */
627
628 if ((lava_cnt > moat_cnt + pool_cnt && rn2(lava_cnt + 1))
629 || (lava_cnt && fill_if_any))
630 return LAVAPOOL;
631 else if ((moat_cnt > 0 && rn2(moat_cnt + 1)) || (moat_cnt && fill_if_any))
632 return MOAT;
633 else if ((pool_cnt > 0 && rn2(pool_cnt + 1)) || (pool_cnt && fill_if_any))
634 return POOL;
635 else
636 return ROOM;
637}
638
639void
640digactualhole(coordxy x, coordxy y, struct monst *madeby, int ttyp)

Callers 5

digholeFunction · 0.85
zap_digFunction · 0.85
do_pitFunction · 0.85
blow_up_landmineFunction · 0.85
do_break_wandFunction · 0.85

Calls 4

is_moatFunction · 0.85
is_poolFunction · 0.85
is_lavaFunction · 0.85
rn2Function · 0.85

Tested by

no test coverage detected