summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/monplace.cc
diff options
context:
space:
mode:
authorj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2008-06-06 19:09:12 +0000
committerj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2008-06-06 19:09:12 +0000
commit9d9efc7fd96b37de17094f6f7cff8abb43a1e8a2 (patch)
treea12c56aab56fb877e73b9b6e9e290ec543be56b6 /crawl-ref/source/monplace.cc
parentf442b6f700fe5e6a588c802fbcab1b5bd0097627 (diff)
downloadcrawl-ref-9d9efc7fd96b37de17094f6f7cff8abb43a1e8a2.tar.gz
crawl-ref-9d9efc7fd96b37de17094f6f7cff8abb43a1e8a2.zip
Add a line on good gods disapproving of certain items to their
description (evil_item). Same for evil_eating. In another step on the way to monster pathfinding, take the shortest path and extract a vector of waypoints out of it. When experimenting with ways to do this I noticed that grid_see_grid is not symmetrical (A may see B but not vice versa); I'm not sure what effects that could have. It won't directly affect the player as the checks for monster sees player and player sees monster both use the player LoS, but it could have an effect on friendly monsters fighting enemy ones, I guess. Also, I don't think num_feats_between needs the shortest beam available (called with false now). In fact, that seemed to hurt visibility a bit, probably because of attempting to take vision obstructing shortcuts. If this reasoning is wrong, please speak up and/or correct it. (I sure hope not because the shortest beam calculation has some more overhead that can be avoided this way.) git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@5501 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/monplace.cc')
-rw-r--r--crawl-ref/source/monplace.cc52
1 files changed, 43 insertions, 9 deletions
diff --git a/crawl-ref/source/monplace.cc b/crawl-ref/source/monplace.cc
index 141920fb15..5780548926 100644
--- a/crawl-ref/source/monplace.cc
+++ b/crawl-ref/source/monplace.cc
@@ -2329,8 +2329,8 @@ bool monster_pathfind::calc_path_to_neighbours()
total = distance + estimated_cost(npos);
if (old_dist == INFINITE_DISTANCE)
{
- mprf("Adding (%d,%d) to hash (total dist = %d)",
- npos.x, npos.y, total);
+// mprf("Adding (%d,%d) to hash (total dist = %d)",
+// npos.x, npos.y, total);
add_new_pos(npos, total);
if (total > max_length)
@@ -2338,8 +2338,8 @@ bool monster_pathfind::calc_path_to_neighbours()
}
else
{
- mprf("Improving (%d,%d) to total dist %d",
- npos.x, npos.y, total);
+// mprf("Improving (%d,%d) to total dist %d",
+// npos.x, npos.y, total);
update_pos(npos, total);
}
@@ -2368,7 +2368,6 @@ bool monster_pathfind::calc_path_to_neighbours()
bool monster_pathfind::get_best_position()
{
-// mprf("minlength: %d, maxlength: %d", min_length, max_length);
for (int i = min_length; i <= max_length; i++)
{
if (!hash[i].empty())
@@ -2378,8 +2377,8 @@ bool monster_pathfind::get_best_position()
std::vector<coord_def> &vec = hash[i];
pos = vec[vec.size()-1];
vec.pop_back();
- mprf("Returning (%d, %d) as best pos with total dist %d.",
- pos.x, pos.y, min_length);
+// mprf("Returning (%d, %d) as best pos with total dist %d.",
+// pos.x, pos.y, min_length);
return (true);
}
@@ -2406,8 +2405,8 @@ std::vector<coord_def> monster_pathfind::backtrack()
dir = prev[pos.x][pos.y];
pos = pos + Compass[dir];
ASSERT(in_bounds(pos));
- mprf("prev: (%d, %d), pos: (%d, %d)", Compass[dir].x, Compass[dir].y,
- pos.x, pos.y);
+// mprf("prev: (%d, %d), pos: (%d, %d)", Compass[dir].x, Compass[dir].y,
+// pos.x, pos.y);
path.push_back(pos);
if (pos.x == 0 && pos.y == 0)
@@ -2419,6 +2418,41 @@ std::vector<coord_def> monster_pathfind::backtrack()
return path;
}
+// Reduces the path coordinates to only a couple of key waypoints needed
+// to reach the target.
+std::vector<coord_def> monster_pathfind::calc_waypoints()
+{
+ std::vector<coord_def> path = backtrack();
+ // If no path found, nothing to be done.
+ if (path.empty())
+ return path;
+
+ dungeon_feature_type can_move;
+ if (mons_amphibious(mons_is_zombified(mons) ? mons->base_monster
+ : mons->type))
+ {
+ can_move = DNGN_DEEP_WATER;
+ }
+ else
+ can_move = DNGN_SHALLOW_WATER;
+
+ std::vector<coord_def> waypoints;
+ pos = path[0];
+
+ for (unsigned int i = 1; i < path.size(); i++)
+ {
+ if (grid_see_grid(pos.x, pos.y, path[i].x, path[i].y, can_move))
+ continue;
+ else
+ {
+ pos = path[i-1];
+ waypoints.push_back(pos);
+ }
+ }
+
+ return waypoints;
+}
+
bool monster_pathfind::traversable(coord_def p)
{
const int montype = mons_is_zombified(mons) ? mons_zombie_base(mons)