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

Function domove_swap_with_pet

src/hack.c:2097–2225  ·  view source on GitHub ↗

maybe swap places with a pet? returns TRUE if swapped places */

Source from the content-addressed store, hash-verified

2095
2096/* maybe swap places with a pet? returns TRUE if swapped places */
2097staticfn boolean
2098domove_swap_with_pet(
2099 struct monst *mtmp,
2100 coordxy x, coordxy y)
2101{
2102 struct trap *trap;
2103 /* if it turns out we can't actually move */
2104 boolean didnt_move = FALSE;
2105 boolean u_with_boulder = (sobj_at(BOULDER, u.ux, u.uy) != 0);
2106
2107 /* seemimic/newsym should be done before moving hero, otherwise
2108 the display code will draw the hero here before we possibly
2109 cancel the swap below (we can ignore steed mx,my here) */
2110 u.ux = u.ux0, u.uy = u.uy0;
2111 mtmp->mundetected = 0;
2112 if (M_AP_TYPE(mtmp))
2113 seemimic(mtmp);
2114 u.ux = mtmp->mx, u.uy = mtmp->my; /* resume swapping positions */
2115
2116 trap = mtmp->mtrapped ? t_at(mtmp->mx, mtmp->my) : 0;
2117 if (!trap)
2118 mtmp->mtrapped = 0;
2119
2120 if (mtmp->mtrapped && is_pit(trap->ttyp)
2121 && sobj_at(BOULDER, trap->tx, trap->ty)) {
2122 /* can't swap places with pet pinned in a pit by a boulder */
2123 didnt_move = TRUE;
2124 } else if (u.ux0 != x && u.uy0 != y && NODIAG(mtmp->data - mons)) {
2125 /* can't swap places when pet can't move to your spot */
2126 You("stop. %s can't move diagonally.", YMonnam(mtmp));
2127 didnt_move = TRUE;
2128 } else if (u_with_boulder
2129 && !(verysmall(mtmp->data)
2130 && (!mtmp->minvent || curr_mon_load(mtmp) <= 600))) {
2131 /* can't swap places when pet won't fit there with the boulder */
2132 You("stop. %s won't fit into the same spot that you're at.",
2133 YMonnam(mtmp));
2134 didnt_move = TRUE;
2135 } else if (u.ux0 != x && u.uy0 != y && bad_rock(mtmp->data, x, u.uy0)
2136 && bad_rock(mtmp->data, u.ux0, y)
2137 && (bigmonst(mtmp->data) || (curr_mon_load(mtmp) > 600))) {
2138 /* can't swap places when pet won't fit thru the opening */
2139 You("stop. %s won't fit through.", YMonnam(mtmp));
2140 didnt_move = TRUE;
2141 } else if (mtmp->mpeaceful && mtmp->mtrapped) {
2142 /* all mtame are also mpeaceful, so this affects pets too */
2143 assert(trap != NULL); /* implied by mtrapped */
2144 const char *what = trapname(trap->ttyp, FALSE), *which = "that ";
2145 char anbuf[10];
2146
2147 if (!trap->tseen) {
2148 feeltrap(trap); /* show on map once mtmp is out of the way */
2149 which = just_an(anbuf, what); /* "a " or "an " */
2150 }
2151 You("stop. %s can't move out of %s%s.", YMonnam(mtmp), which, what);
2152 (void) handle_tip(TIP_UNTRAP_MON);
2153 didnt_move = TRUE;
2154 } else if (mtmp->mpeaceful

Callers 1

domove_coreFunction · 0.85

Calls 15

sobj_atFunction · 0.85
seemimicFunction · 0.85
t_atFunction · 0.85
YouFunction · 0.85
YMonnamFunction · 0.85
curr_mon_loadFunction · 0.85
bad_rockFunction · 0.85
trapnameFunction · 0.85
feeltrapFunction · 0.85
just_anFunction · 0.85
handle_tipFunction · 0.85
goodposFunction · 0.85

Tested by

no test coverage detected