diff options
author | j-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-05-29 21:53:19 +0000 |
---|---|---|
committer | j-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-05-29 21:53:19 +0000 |
commit | c7d7127e04437181a909dc4c7bbbc5e408e7f798 (patch) | |
tree | a2c99f92832734172185bd78d359ebad2875a036 /crawl-ref/source/view.cc | |
parent | bfed89c67c7d64c104481af653aa8082470a5151 (diff) | |
download | crawl-ref-c7d7127e04437181a909dc4c7bbbc5e408e7f798.tar.gz crawl-ref-c7d7127e04437181a909dc4c7bbbc5e408e7f798.zip |
Diversify patrol behaviour for monsters of different intelligence.
* I_NORMAL, I_HIGH: as before
* I_ANIMAL: try to only move within LOS of the patrol point
* I_INSECT: as animal, but patrol radius is 5
* I_PLANT : patrol radius is also 5, but there are some other
differences:
If the patrol point gets out of sight, zombies don't even attempt to
get back. Instead they become confused (not literally, though) and
reset their patrol point to 0 (if hostile, thus stop patrolling) or
to their current position (to continue "waiting" if friendly).
Also, while patrolling, if they reach their target there's a 50%
chance of not moving this turn, and 50% the next turn, etc.
Especially the latter needs testing. If it looks *too* stupid even
for zombies I'll take it out again.
These changes should also help to make patrolling a bit more
efficient because for stupid monsters we have:
- one los calculation instead of two (patrol point, monster)
- smaller radius
- no calculation at all if success is unlikely (distance check)
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@5335 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/view.cc')
-rw-r--r-- | crawl-ref/source/view.cc | 97 |
1 files changed, 52 insertions, 45 deletions
diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc index 1ad9934809..801be16f2a 100644 --- a/crawl-ref/source/view.cc +++ b/crawl-ref/source/view.cc @@ -5300,7 +5300,7 @@ void handle_terminal_resize(bool redraw) // monster_los monster_los::monster_los() - : gridx(0), gridy(0), mons(), los_field() + : gridx(0), gridy(0), mons(), range(LOS_RADIUS), los_field() { } @@ -5308,6 +5308,30 @@ monster_los::~monster_los() { } +void monster_los::set_monster(monsters *mon) +{ + mons = mon; + if (gridx != mons->x) + gridx = mons->x; + if (gridy != mons->y) + gridy = mons->y; +} + +void monster_los::set_los_centre(int x, int y) +{ + if (!in_bounds(x, y)) + return; + + gridx = x; + gridy = y; +} + +void monster_los::set_los_range(int r) +{ + ASSERT (r >= 1 && r <= LOS_RADIUS); + range = r; +} + coord_def monster_los::pos_to_index(coord_def &p) { int ix = LOS_RADIUS + p.x - gridx; @@ -5384,28 +5408,10 @@ static bool _blocks_movement_sight(monsters *mon, dungeon_feature_type feat) return (false); } -void monster_los::set_monster(monsters *mon) -{ - mons = mon; - if (gridx != mons->x) - gridx = mons->x; - if (gridy != mons->y) - gridy = mons->y; -} - -void monster_los::set_los_centre(int x, int y) -{ - if (!in_bounds(x, y)) - return; - - gridx = x; - gridy = y; -} - void monster_los::fill_los_field() { int pos_x, pos_y; - for (int k = 1; k <= LOS_RADIUS; k++) + for (int k = 1; k <= range; k++) for (int i = -1; i <= 1; i++) for (int j = -1; j <= 1; j++) { @@ -5434,7 +5440,8 @@ void monster_los::fill_los_field() // target1 and target2 are targets we'll be aiming *at* to fire through (dx,dy) static bool _set_beam_target(int cx, int cy, int dx, int dy, int &target1_x, int &target1_y, - int &target2_x, int &target2_y) + int &target2_x, int &target2_y, + int range) { const int xdist = dx - cx; const int ydist = dy - cy; @@ -5442,8 +5449,8 @@ static bool _set_beam_target(int cx, int cy, int dx, int dy, if (xdist == 0 && ydist == 0) return (false); // Nothing to be done. - if (xdist <= -LOS_RADIUS || xdist >= LOS_RADIUS - || ydist <= -LOS_RADIUS || ydist >= LOS_RADIUS) + if (xdist <= -range || xdist >= range + || ydist <= -range || ydist >= range) { // Grids on the edge of a monster's LOS don't block sight any further. return (false); @@ -5475,16 +5482,16 @@ static bool _set_beam_target(int cx, int cy, int dx, int dy, if (xdist == 0) { target1_x = cx; - target1_y = (ydist > 0 ? cy + LOS_RADIUS - : cy - LOS_RADIUS); + target1_y = (ydist > 0 ? cy + range + : cy - range); target2_x = target1_x; target2_y = target1_y; } else if (ydist == 0) { - target1_x = (xdist > 0 ? cx + LOS_RADIUS - : cx - LOS_RADIUS); + target1_x = (xdist > 0 ? cx + range + : cx - range); target1_y = cy; target2_x = target1_x; @@ -5494,13 +5501,13 @@ static bool _set_beam_target(int cx, int cy, int dx, int dy, { if (xdist < 0) { - target1_x = cx - LOS_RADIUS; - target1_y = cy - LOS_RADIUS; + target1_x = cx - range; + target1_y = cy - range; } else { - target1_x = cx + LOS_RADIUS; - target1_y = cy + LOS_RADIUS; + target1_x = cx + range; + target1_y = cy + range; } if (xdist == ydist) @@ -5515,11 +5522,11 @@ static bool _set_beam_target(int cx, int cy, int dx, int dy, if (dx > dy) { target2_x = dx; - target2_y = cy - LOS_RADIUS; + target2_y = cy - range; } else { - target2_x = cx - LOS_RADIUS; + target2_x = cx - range; target2_y = dy; } } @@ -5527,13 +5534,13 @@ static bool _set_beam_target(int cx, int cy, int dx, int dy, { if (dx > dy) { - target2_x = cx + LOS_RADIUS; + target2_x = cx + range; target2_y = dy; } else { target2_x = dx; - target2_y = cy + LOS_RADIUS; + target2_y = cy + range; } } } @@ -5542,13 +5549,13 @@ static bool _set_beam_target(int cx, int cy, int dx, int dy, { if (xdist < 0) // lower left corner { - target1_x = cx - LOS_RADIUS; - target1_y = cy + LOS_RADIUS; + target1_x = cx - range; + target1_y = cy + range; } else // upper right corner { - target1_x = cx + LOS_RADIUS; - target1_y = cy - LOS_RADIUS; + target1_x = cx + range; + target1_y = cy - range; } if (xdist == -ydist) @@ -5562,13 +5569,13 @@ static bool _set_beam_target(int cx, int cy, int dx, int dy, { if (-xdist > ydist) { - target2_x = cx - LOS_RADIUS; + target2_x = cx - range; target2_y = dy; } else { target2_x = dx; - target2_y = cy + LOS_RADIUS; + target2_y = cy + range; } } else // xdist > 0, ydist < 0 @@ -5576,11 +5583,11 @@ static bool _set_beam_target(int cx, int cy, int dx, int dy, if (-xdist > ydist) { target2_x = dx; - target2_y = cy - LOS_RADIUS; + target2_y = cy - range; } else { - target2_x = cx + LOS_RADIUS; + target2_x = cx + range; target2_y = dy; } } @@ -5601,7 +5608,7 @@ void monster_los::check_los_beam(int dx, int dy) int target1_x = 0, target1_y = 0, target2_x = 0, target2_y = 0; if (!_set_beam_target(gridx, gridy, dx, dy, target1_x, target1_y, - target2_x, target2_y)) + target2_x, target2_y, range)) { // Nothing to be done. return; @@ -5619,7 +5626,7 @@ void monster_los::check_los_beam(int dx, int dy) target2_y = help; } - const int max_dist = LOS_RADIUS; + const int max_dist = range; int dist; bool blocked = false; for (int tx = target1_x; tx <= target2_x; tx++) |