diff --git a/src/hack.c b/src/hack.c index d314e2c2f..1f18b41fe 100644 --- a/src/hack.c +++ b/src/hack.c @@ -2557,6 +2557,8 @@ domove_core(void) return; mtmp = m_at(x, y); + /* mtmp can be null at this point */ + /* tentatively move the hero plus steed; leave CLIPPING til later */ u.ux += u.dx; u.uy += u.dy; @@ -2567,47 +2569,50 @@ domove_core(void) exercise_steed(); /* train riding skill */ } - if (displaceu && mtmp) { - boolean noticed_it = (canspotmon(mtmp) || glyph_is_invisible(glyph) - || glyph_is_warning(glyph)); + if (mtmp) { + if (displaceu) { + boolean noticed_it = (canspotmon(mtmp) || glyph_is_invisible(glyph) + || glyph_is_warning(glyph)); - remove_monster(u.ux, u.uy); - place_monster(mtmp, u.ux0, u.uy0); - newsym(u.ux, u.uy); - newsym(u.ux0, u.uy0); - /* monst still knows where hero is */ - mtmp->mux = u.ux, mtmp->muy = u.uy; + remove_monster(u.ux, u.uy); + place_monster(mtmp, u.ux0, u.uy0); + newsym(u.ux, u.uy); + newsym(u.ux0, u.uy0); + /* monst still knows where hero is */ + mtmp->mux = u.ux, mtmp->muy = u.uy; - pline("%s swaps places with you...", - !noticed_it ? Something : Monnam(mtmp)); - if (!canspotmon(mtmp)) - map_invisible(u.ux0, u.uy0); - /* monster chose to swap places; hero doesn't get any credit - or blame if something bad happens to it */ - gc.context.mon_moving = 1; - if (!minliquid(mtmp)) - (void) mintrap(mtmp, NO_TRAP_FLAGS); - gc.context.mon_moving = 0; + pline("%s swaps places with you...", + !noticed_it ? Something : Monnam(mtmp)); + if (!canspotmon(mtmp)) + map_invisible(u.ux0, u.uy0); + /* monster chose to swap places; hero doesn't get any credit + or blame if something bad happens to it */ + gc.context.mon_moving = 1; + if (!minliquid(mtmp)) + (void) mintrap(mtmp, NO_TRAP_FLAGS); + gc.context.mon_moving = 0; - /* - * If safepet at destination then move the pet to the hero's - * previous location using the same conditions as in do_attack(). - * there are special extenuating circumstances: - * (1) if the pet dies then your god angers, - * (2) if the pet gets trapped then your god may disapprove. - * - * Ceiling-hiding pets are skipped by this section of code, to - * be caught by the normal falling-monster code. - */ - } else if (is_safemon(mtmp) - && !(is_hider(mtmp->data) && mtmp->mundetected)) { - if (!domove_swap_with_pet(mtmp, x, y)) { - u.ux = u.ux0, u.uy = u.uy0; /* didn't move after all */ - /* could skip this bit since we're about to call u_on_newpos() */ - if (u.usteed) - u.usteed->mx = u.ux, u.usteed->my = u.uy; + /* + * If safepet at destination then move the pet to the hero's + * previous location using the same conditions as in do_attack(). + * there are special extenuating circumstances: + * (1) if the pet dies then your god angers, + * (2) if the pet gets trapped then your god may disapprove. + * + * Ceiling-hiding pets are skipped by this section of code, to + * be caught by the normal falling-monster code. + */ + } else if (is_safemon(mtmp) + && !(is_hider(mtmp->data) && mtmp->mundetected)) { + if (!domove_swap_with_pet(mtmp, x, y)) { + u.ux = u.ux0, u.uy = u.uy0; /* didn't move after all */ + /* could skip this bit since we're about to call u_on_newpos() */ + if (u.usteed) + u.usteed->mx = u.ux, u.usteed->my = u.uy; + } } - } + } /* mtmp != NULL */ + /* tentative move above didn't handle CLIPPING, in case there was a monster in the way and the move attempt ended up being blocked; do a full re-position now, possibly back to where hero started */