diff options
author | dolorous <dolorous@c06c8d41-db1a-0410-9941-cceddc491573> | 2009-01-26 20:19:40 +0000 |
---|---|---|
committer | dolorous <dolorous@c06c8d41-db1a-0410-9941-cceddc491573> | 2009-01-26 20:19:40 +0000 |
commit | 7b6bfa7d8c9922a6a690fe31db02d678bb60298b (patch) | |
tree | c88a4b788f7e156a53d74a131c75a5ade27bab60 | |
parent | 105d4e75d3ada5b2dfbcd08ab44fff124472a8cf (diff) | |
download | crawl-ref-7b6bfa7d8c9922a6a690fe31db02d678bb60298b.tar.gz crawl-ref-7b6bfa7d8c9922a6a690fe31db02d678bb60298b.zip |
Fix bounds checks for monsters' moving off the map to use map_bounds().
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@8793 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r-- | crawl-ref/source/monstuff.cc | 8 | ||||
-rw-r--r-- | crawl-ref/source/stuff.cc | 26 | ||||
-rw-r--r-- | crawl-ref/source/stuff.h | 4 |
3 files changed, 30 insertions, 8 deletions
diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc index 007f5dfb3f..b64cf0de77 100644 --- a/crawl-ref/source/monstuff.cc +++ b/crawl-ref/source/monstuff.cc @@ -4602,9 +4602,9 @@ static void _handle_movement(monsters *monster) // Bounds check: don't let fleeing monsters try to run off the map. const coord_def s = monster->target + mmov; - if (s.x < 0 || s.x >= GXM) + if (!map_bounds_x(s.x)) mmov.x = 0; - if (s.y < 0 || s.y >= GYM) + if (!map_bounds_y(s.y)) mmov.y = 0; // Now quit if we can't move. @@ -7147,9 +7147,9 @@ static void _handle_monster_move(int i, monsters *monster) // Bounds check: don't let confused monsters try to run // off the map. const coord_def s = monster->pos() + mmov; - if (s.x < 0 || s.x >= GXM) + if (!map_bounds_x(s.x)) mmov.x = 0; - if (s.y < 0 || s.y >= GYM) + if (!map_bounds_y(s.y)) mmov.y = 0; if (!monster->can_pass_through(monster->pos() + mmov)) diff --git a/crawl-ref/source/stuff.cc b/crawl-ref/source/stuff.cc index 0d6368fb83..d724ca5730 100644 --- a/crawl-ref/source/stuff.cc +++ b/crawl-ref/source/stuff.cc @@ -1243,11 +1243,30 @@ bool player_can_hear(const coord_def& p) return (!silenced(p) && !silenced(you.pos())); } +bool in_bounds_x(int x) +{ + return (x > X_BOUND_1 && x < X_BOUND_2); +} + +bool in_bounds_y(int y) +{ + return (y > Y_BOUND_1 && y < Y_BOUND_2); +} + // Returns true if inside the area the player can move and dig (ie exclusive). bool in_bounds(int x, int y) { - return (x > X_BOUND_1 && x < X_BOUND_2 - && y > Y_BOUND_1 && y < Y_BOUND_2); + return (in_bounds_x(x) && in_bounds_y(y)); +} + +bool map_bounds_x(int x) +{ + return (x >= X_BOUND_1 && x <= X_BOUND_2); +} + +bool map_bounds_y(int y) +{ + return (y >= Y_BOUND_1 && y <= Y_BOUND_2); } // Returns true if inside the area the player can map (ie inclusive). @@ -1255,8 +1274,7 @@ bool in_bounds(int x, int y) // ring of rock to frame the level. bool map_bounds(int x, int y) { - return (x >= X_BOUND_1 && x <= X_BOUND_2 - && y >= Y_BOUND_1 && y <= Y_BOUND_2); + return (map_bounds_x(x) && map_bounds_y(y)); } coord_def random_in_bounds() diff --git a/crawl-ref/source/stuff.h b/crawl-ref/source/stuff.h index 415feeaa2b..3e65492b17 100644 --- a/crawl-ref/source/stuff.h +++ b/crawl-ref/source/stuff.h @@ -152,7 +152,11 @@ int yesnoquit( const char* str, bool safe = true, int safeanswer = 0, bool allow_all = false, bool clear_after = true, char alt_yes = 'Y', char alt_yes2 = 'Y' ); +bool in_bounds_x(int x); +bool in_bounds_y(int y); bool in_bounds(int x, int y); +bool map_bounds_x(int x); +bool map_bounds_y(int y); bool map_bounds(int x, int y); coord_def random_in_bounds(); |