diff options
author | ennewalker <ennewalker@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-07-19 15:56:30 +0000 |
---|---|---|
committer | ennewalker <ennewalker@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-07-19 15:56:30 +0000 |
commit | 6f1723502bba926fdbffe9d5a5d632c285792716 (patch) | |
tree | 8ff903f4de28ee91de0cb692e67789cd24a44a82 /crawl-ref/source/monstuff.cc | |
parent | bd188fd76ce16ab6ba0c3be8d8e29976f1ee4d3d (diff) | |
download | crawl-ref-6f1723502bba926fdbffe9d5a5d632c285792716.tar.gz crawl-ref-6f1723502bba926fdbffe9d5a5d632c285792716.zip |
[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
Diffstat (limited to 'crawl-ref/source/monstuff.cc')
-rw-r--r-- | crawl-ref/source/monstuff.cc | 41 |
1 files changed, 33 insertions, 8 deletions
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 @@ -1796,6 +1796,37 @@ static bool _habitat_okay( const monsters *monster, dungeon_feature_type targ ) // 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 { |