summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorennewalker <ennewalker@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-19 16:02:35 +0000
committerennewalker <ennewalker@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-19 16:02:35 +0000
commit7cfae909af95fc2a633a0aa25e5d644677fe4a52 (patch)
tree5a513a40d8acc40f90b615e07e964ec2f2d0c994
parente58388c7925c5572450709785f83f8901fbeecef (diff)
downloadcrawl-ref-7cfae909af95fc2a633a0aa25e5d644677fe4a52.tar.gz
crawl-ref-7cfae909af95fc2a633a0aa25e5d644677fe4a52.zip
Applying r6609 to 0.4.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/branches/stone_soup-0.4@6610 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r--crawl-ref/source/acr.cc9
-rw-r--r--crawl-ref/source/monstuff.cc41
-rw-r--r--crawl-ref/source/monstuff.h2
-rw-r--r--crawl-ref/source/player.cc8
-rw-r--r--crawl-ref/source/player.h2
5 files changed, 48 insertions, 14 deletions
diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc
index 3dcb424d40..4ee02b279d 100644
--- a/crawl-ref/source/acr.cc
+++ b/crawl-ref/source/acr.cc
@@ -4257,13 +4257,15 @@ static void _move_player(int move_x, int move_y)
return;
}
+ coord_def mon_swap_dest;
+
if (targ_monst != NON_MONSTER && !mons_is_submerged(&menv[targ_monst]))
{
monsters *mon = &menv[targ_monst];
if (can_swap_places && !beholder)
{
- if (swap_places( mon ))
+ if (swap_check(mon, mon_swap_dest))
swap = true;
else
moving = false;
@@ -4291,9 +4293,12 @@ static void _move_player(int move_x, int move_y)
{
you.time_taken *= player_movement_speed();
you.time_taken /= 10;
- if (!move_player_to_grid(targ_x, targ_y, true, false, swap))
+ if (!move_player_to_grid(targ_x, targ_y, true, false, swap, swap))
return;
+ if (swap)
+ swap_places(&menv[targ_monst], mon_swap_dest);
+
you.prev_move_x = move_x;
you.prev_move_y = move_y;
diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc
index d4c0dd213c..70ce9ea013 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
{
diff --git a/crawl-ref/source/monstuff.h b/crawl-ref/source/monstuff.h
index 8cebd84d8f..b9ac6c99d3 100644
--- a/crawl-ref/source/monstuff.h
+++ b/crawl-ref/source/monstuff.h
@@ -159,6 +159,8 @@ monsters *choose_random_monster_on_level(
* called from: acr
* *********************************************************************** */
bool swap_places(monsters *monster);
+bool swap_places(monsters *monster, const coord_def &loc);
+bool swap_check(monsters *monster, coord_def &loc);
/* ***********************************************************************
diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc
index cfa61aadd7..1611f4330e 100644
--- a/crawl-ref/source/player.cc
+++ b/crawl-ref/source/player.cc
@@ -106,8 +106,9 @@ static void _attribute_increase();
// stepped - normal walking moves
// allow_shift - allowed to scramble in any direction out of lava/water
// force - ignore safety checks, move must happen (traps, lava/water).
+// swapping - player is swapping with a monster at (x,y)
bool move_player_to_grid( int x, int y, bool stepped, bool allow_shift,
- bool force )
+ bool force, bool swapping )
{
ASSERT( in_bounds( x, y ) );
@@ -122,8 +123,9 @@ bool move_player_to_grid( int x, int y, bool stepped, bool allow_shift,
ASSERT( you.can_pass_through_feat( new_grid ) );
// Better not be an unsubmerged monster either.
- ASSERT(mgrd[x][y] == NON_MONSTER
- || mons_is_submerged( &menv[ mgrd[x][y] ] ));
+ ASSERT(swapping && mgrd[x][y] != NON_MONSTER ||
+ !swapping && (mgrd[x][y] == NON_MONSTER
+ || mons_is_submerged( &menv[ mgrd[x][y] ])));
const int cloud = env.cgrid[x][y];
if (cloud != EMPTY_CLOUD)
diff --git a/crawl-ref/source/player.h b/crawl-ref/source/player.h
index a1bd79ac52..b5c3a0bc39 100644
--- a/crawl-ref/source/player.h
+++ b/crawl-ref/source/player.h
@@ -28,7 +28,7 @@ enum genus_type
};
bool move_player_to_grid( int x, int y, bool stepped, bool allow_shift,
- bool force );
+ bool force, bool swapping = false );
bool player_in_mappable_area(void);
bool player_in_branch( int branch );