diff options
author | Shmuale Mark <shm.mark@gmail.com> | 2014-06-19 16:05:04 -0400 |
---|---|---|
committer | Shmuale Mark <shm.mark@gmail.com> | 2014-06-22 10:03:45 -0400 |
commit | 465957cba490a2a9d5444a64523572a90cfb837f (patch) | |
tree | 536c94ce0702e60217120aa2bb27325aff1b8f2d /crawl-ref/source/mon-movetarget.cc | |
parent | 393eda0d444702a7eda580e6c363bbdcaba8d54e (diff) | |
download | crawl-ref-465957cba490a2a9d5444a64523572a90cfb837f.tar.gz crawl-ref-465957cba490a2a9d5444a64523572a90cfb837f.zip |
The great mon-stuff migration.
A good deal of functions move to the two new files, mon-poly and
mon-message. Of the others, some go to where they are used, some to
mon-util, and a few are made member methods of monster.
This probably breaks Xcode compilation, and I'm not able to test
the changes I made to MSVC that will (hopefully) keep it working.
Diffstat (limited to 'crawl-ref/source/mon-movetarget.cc')
-rw-r--r-- | crawl-ref/source/mon-movetarget.cc | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/crawl-ref/source/mon-movetarget.cc b/crawl-ref/source/mon-movetarget.cc index 5dfaf16caa..5e81010317 100644 --- a/crawl-ref/source/mon-movetarget.cc +++ b/crawl-ref/source/mon-movetarget.cc @@ -9,13 +9,13 @@ #include "env.h" #include "fprop.h" #include "items.h" +#include "itemprop.h" #include "libutil.h" #include "los_def.h" #include "losglobal.h" #include "mon-behv.h" #include "mon-pathfind.h" #include "mon-place.h" -#include "mon-stuff.h" #include "random.h" #include "state.h" #include "terrain.h" @@ -1039,7 +1039,6 @@ int mons_find_nearest_level_exit(const monster* mon, vector<level_exit> &e, return retval; } - void set_random_slime_target(monster* mon) { // Strictly neutral slimes will go for the nearest item. @@ -1065,3 +1064,51 @@ end: if (mon->target == mon->pos() || mon->target == you.pos()) set_random_target(mon); } + +static bool _can_safely_go_through(const monster * mon, const coord_def p) +{ + ASSERT(map_bounds(p)); + + if (!monster_habitable_grid(mon, grd(p))) + return false; + + // Stupid monsters don't pathfind around shallow water + // except the clinging ones. + if (mon->floundering_at(p) + && (mons_intel(mon) >= I_NORMAL || mon->can_cling_to_walls())) + { + return false; + } + + return true; +} + +// Checks whether there is a straight path from p1 to p2 that monster can +// safely passes through. +// If it exists, such a path may be missed; on the other hand, it +// is not guaranteed that p2 is visible from p1 according to LOS rules. +// Not symmetric. +// FIXME: This is used for monster movement. It should instead be +// something like exists_ray(p1, p2, opacity_monmove(mons)), +// where opacity_monmove() is fixed to include opacity_immob. +bool can_go_straight(const monster* mon, const coord_def& p1, + const coord_def& p2) +{ + // If no distance, then trivially true + if (p1 == p2) + return true; + + if (distance2(p1, p2) > los_radius2) + return false; + + // XXX: Hack to improve results for now. See FIXME above. + ray_def ray; + if (!find_ray(p1, p2, ray, opc_immob)) + return false; + + while (ray.advance() && ray.pos() != p2) + if (!_can_safely_go_through(mon, ray.pos())) + return false; + + return true; +} |