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

Function water_friction

src/mkmaze.c:1688–1720  ·  view source on GitHub ↗

when moving in water, possibly (1 in 3) alter the intended destination */

Source from the content-addressed store, hash-verified

1686
1687/* when moving in water, possibly (1 in 3) alter the intended destination */
1688void
1689water_friction(void)
1690{
1691 coordxy x, y, dx, dy;
1692 boolean eff = FALSE;
1693
1694 if (Swimming && rn2(4))
1695 return; /* natural swimmers have advantage */
1696
1697 if (u.dx && !rn2(!u.dy ? 3 : 6)) { /* 1/3 chance or half that */
1698 /* cancel delta x and choose an arbitrary delta y value */
1699 x = u.ux;
1700 do {
1701 dy = rn2(3) - 1; /* -1, 0, 1 */
1702 y = u.uy + dy;
1703 } while (dy && (!isok(x, y) || !is_pool(x, y)));
1704 u.dx = 0;
1705 u.dy = dy;
1706 eff = TRUE;
1707 } else if (u.dy && !rn2(!u.dx ? 3 : 5)) { /* 1/3 or 1/5*(5/6) */
1708 /* cancel delta y and choose an arbitrary delta x value */
1709 y = u.uy;
1710 do {
1711 dx = rn2(3) - 1; /* -1 .. 1 */
1712 x = u.ux + dx;
1713 } while (dx && (!isok(x, y) || !is_pool(x, y)));
1714 u.dy = 0;
1715 u.dx = dx;
1716 eff = TRUE;
1717 }
1718 if (eff)
1719 pline("Water turbulence affects your movements.");
1720}
1721
1722void
1723save_waterlevel(NHFILE *nhfp)

Callers 1

water_turbulenceFunction · 0.85

Calls 4

rn2Function · 0.85
isokFunction · 0.85
is_poolFunction · 0.85
plineFunction · 0.70

Tested by

no test coverage detected