From 6f1723502bba926fdbffe9d5a5d632c285792716 Mon Sep 17 00:00:00 2001 From: ennewalker Date: Sat, 19 Jul 2008 15:56:30 +0000 Subject: [2021920] Fixing issue where swapping into a fire elemental and cancelling due to the cloud still moved the fire elemental but not the player. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@6609 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/monstuff.cc | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) (limited to 'crawl-ref/source/monstuff.cc') diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc index 25f023ac34..3e291c3df1 100644 --- a/crawl-ref/source/monstuff.cc +++ b/crawl-ref/source/monstuff.cc @@ -1795,6 +1795,37 @@ static bool _habitat_okay( const monsters *monster, dungeon_feature_type targ ) // when the player is over lava or water (if the player wants to // swap pets to their death, we can let that go). -- bwr bool swap_places(monsters *monster) +{ + coord_def loc; + if (swap_check(monster, loc)) + { + swap_places(monster, loc); + return true; + } + return false; +} + +// Swap monster to this location. Player is swapped elsewhere. +bool swap_places(monsters *monster, const coord_def &loc) +{ + ASSERT(map_bounds(loc)); + ASSERT(_habitat_okay(monster, grd(loc))); + + mpr("You swap places."); + + mgrd[monster->x][monster->y] = NON_MONSTER; + + monster->x = loc.x; + monster->y = loc.y; + + mgrd[monster->x][monster->y] = monster_index(monster); + + return true; +} + +// Returns true if this is a valid swap for this monster. If true, then +// the valid location is set in loc. +bool swap_check(monsters *monster, coord_def &loc) { int loc_x = you.x_pos; int loc_y = you.y_pos; @@ -1859,14 +1890,8 @@ bool swap_places(monsters *monster) if (swap) { - mpr("You swap places."); - - mgrd[monster->x][monster->y] = NON_MONSTER; - - monster->x = loc_x; - monster->y = loc_y; - - mgrd[monster->x][monster->y] = monster_index(monster); + loc.x = loc_x; + loc.y = loc_y; } else { -- cgit v1.2.3-54-g00ecf