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

Function mv_bubble

src/mkmaze.c:1951–2107  ·  view source on GitHub ↗

* The player, the portal and all other objects and monsters * float along with their associated bubbles. Bubbles may overlap * freely, and the contents may get associated with other bubbles in * the process. Bubbles are "sticky", meaning that if the player is * in the immediate neighborhood of one, he/she may get sucked inside. * This property also makes leaving a bubble slightly difficult.

Source from the content-addressed store, hash-verified

1949 * This property also makes leaving a bubble slightly difficult.
1950 */
1951staticfn void
1952mv_bubble(struct bubble *b, coordxy dx, coordxy dy, boolean ini)
1953{
1954 int i, j, colli = 0;
1955 coordxy x, y;
1956 struct container *cons, *ctemp;
1957
1958 /* clouds move slowly */
1959 if (!Is_airlevel(&u.uz) || !rn2(6)) {
1960 /* move bubble */
1961 if (dx < -1 || dx > 1 || dy < -1 || dy > 1) {
1962 /* pline("mv_bubble: dx = %d, dy = %d", dx, dy); */
1963 dx = sgn(dx);
1964 dy = sgn(dy);
1965 }
1966
1967 /*
1968 * collision with level borders?
1969 * 1 = horizontal border, 2 = vertical, 3 = corner
1970 */
1971 if (b->x <= gbxmin)
1972 colli |= 2;
1973 if (b->y <= gbymin)
1974 colli |= 1;
1975 if ((int) (b->x + b->bm[0] - 1) >= gbxmax)
1976 colli |= 2;
1977 if ((int) (b->y + b->bm[1] - 1) >= gbymax)
1978 colli |= 1;
1979
1980 if (b->x < gbxmin) {
1981 pline("bubble xmin: x = %d, xmin = %d", b->x, gbxmin);
1982 b->x = gbxmin;
1983 }
1984 if (b->y < gbymin) {
1985 pline("bubble ymin: y = %d, ymin = %d", b->y, gbymin);
1986 b->y = gbymin;
1987 }
1988 if ((int) (b->x + b->bm[0] - 1) > gbxmax) {
1989 pline("bubble xmax: x = %d, xmax = %d", b->x + b->bm[0] - 1,
1990 gbxmax);
1991 b->x = gbxmax - b->bm[0] + 1;
1992 }
1993 if ((int) (b->y + b->bm[1] - 1) > gbymax) {
1994 pline("bubble ymax: y = %d, ymax = %d", b->y + b->bm[1] - 1,
1995 gbymax);
1996 b->y = gbymax - b->bm[1] + 1;
1997 }
1998
1999 /* bounce if we're trying to move off the border */
2000 if (b->x == gbxmin && dx < 0)
2001 dx = -dx;
2002 if (b->x + b->bm[0] - 1 == gbxmax && dx > 0)
2003 dx = -dx;
2004 if (b->y == gbymin && dy < 0)
2005 dy = -dy;
2006 if (b->y + b->bm[1] - 1 == gbymax && dy > 0)
2007 dy = -dy;
2008

Callers 3

movebubblesFunction · 0.85
restore_waterlevelFunction · 0.85
mk_bubbleFunction · 0.85

Calls 13

rn2Function · 0.85
sgnFunction · 0.85
unblock_pointFunction · 0.85
block_pointFunction · 0.85
place_objectFunction · 0.85
stackobjFunction · 0.85
mneartoFunction · 0.85
elemental_clogFunction · 0.85
u_on_newposFunction · 0.85
newsymFunction · 0.85
mnextoFunction · 0.85
plineFunction · 0.70

Tested by

no test coverage detected