From 2cc1fcd4c22999a035ce33eada216055a63b3cc7 Mon Sep 17 00:00:00 2001 From: zelgadis Date: Mon, 29 Dec 2008 10:32:57 +0000 Subject: Some more attempts to prevent/catch/diagnose floating monster problems. Among other things: * If level generation leaves some monsters detached then this will be specifically noted. * If applying _handle_monster_move() to a monster causes that monster to become detached it will be noted (those it won't catch *other* monster being detached by that monster moving). git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@8009 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/monstuff.cc | 46 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'crawl-ref/source/monstuff.cc') diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc index da64131419..83da543cf5 100644 --- a/crawl-ref/source/monstuff.cc +++ b/crawl-ref/source/monstuff.cc @@ -1972,11 +1972,9 @@ bool monster_blink(monsters *monster) mons_clear_trapping_net(monster); - mgrd(monster->pos()) = NON_MONSTER; const coord_def oldplace = monster->pos(); - - monster->moveto(near); - mgrd(near) = monster_index(monster); + if (!monster->move_to_pos(near)) + return (false); if (player_monster_visible(monster) && mons_near(monster)) seen_monster(monster); @@ -2124,6 +2122,12 @@ bool swap_places(monsters *monster, const coord_def &loc) ASSERT(map_bounds(loc)); ASSERT(_habitat_okay(monster, grd(loc))); + if (mgrd(loc) != NON_MONSTER) + { + mpr("Something prevents you from swapping places."); + return (false); + } + mpr("You swap places."); mgrd(monster->pos()) = NON_MONSTER; @@ -4681,6 +4685,14 @@ static bool _siren_movement_effect(const monsters *monster) if (swapping) { + if (mgrd(oldpos) != NON_MONSTER) + { + mprf("Something prevents you from swapping places " + "with %s.", + mon->name(DESC_NOCAP_THE).c_str()); + return (do_resist); + } + int swap_mon = mgrd(newpos); // Pick the monster up. mgrd(newpos) = NON_MONSTER; @@ -6386,12 +6398,38 @@ static void _handle_monster_move(int i, monsters *monster) int non_move_energy = std::min(entry->energy_usage.move, entry->energy_usage.swim); +#if DEBUG_MONS_SCAN + bool monster_was_floating = mgrd(monster->pos()) != monster->mindex(); +#endif + while (monster->has_action_energy()) { // The continues & breaks are WRT this. if (!monster->alive()) break; +#if DEBUG_MONS_SCAN + if (!monster_was_floating + && mgrd(monster->pos()) != monster->mindex()) + { + mprf(MSGCH_ERROR, "Monster %s became detached from mgrd " + "in _handle_monster_move() loop", + monster->name(DESC_PLAIN, true).c_str()); + mpr("[[[[[[[[[[[[[[[[[[", MSGCH_WARN); + debug_mons_scan(); + mpr("]]]]]]]]]]]]]]]]]]", MSGCH_WARN); + monster_was_floating = true; + } + else if (monster_was_floating + && mgrd(monster->pos()) == monster->mindex()) + { + mprf(MSGCH_DIAGNOSTICS, "Monster %s re-attached itself to mgrd " + "in _handle_monster_move() loop", + monster->name(DESC_PLAIN, true).c_str()); + monster_was_floating = false; + } +#endif + if (monster->speed_increment >= old_energy) { #if DEBUG -- cgit v1.2.3-54-g00ecf