summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/coord.cc
diff options
context:
space:
mode:
authorRaphael Langella <raphael.langella@gmail.com>2011-02-22 00:13:22 +0100
committerRaphael Langella <raphael.langella@gmail.com>2011-02-22 00:14:54 +0100
commit2e34eaf687ec21e6b3bb8296e3dac542dfc3e5b2 (patch)
tree400a89f13eb37fbd4cfd815cbae4193ece5c60f5 /crawl-ref/source/coord.cc
parentce229f1793ccd4502790f44384a50a8be44c19e1 (diff)
downloadcrawl-ref-2e34eaf687ec21e6b3bb8296e3dac542dfc3e5b2.tar.gz
crawl-ref-2e34eaf687ec21e6b3bb8296e3dac542dfc3e5b2.zip
Clinging refactor.
Moved several functions to the coord_def class (to use them in pathfinding). Also fix some bugs and simplify some code.
Diffstat (limited to 'crawl-ref/source/coord.cc')
-rw-r--r--crawl-ref/source/coord.cc30
1 files changed, 30 insertions, 0 deletions
diff --git a/crawl-ref/source/coord.cc b/crawl-ref/source/coord.cc
index 0507ab6732..bfb93d811b 100644
--- a/crawl-ref/source/coord.cc
+++ b/crawl-ref/source/coord.cc
@@ -2,8 +2,12 @@
#include "coord.h"
+#include "areas.h"
+#include "coordit.h"
+#include "env.h"
#include "random.h"
#include "state.h"
+#include "terrain.h"
#include "viewgeom.h"
//////////////////////////////////////////////////////////////////////////
@@ -94,3 +98,29 @@ coord_def grid2player(const coord_def &gc)
{
return (gc - you.pos());
}
+
+bool coord_def::can_cling(bool already_clinging) const
+{
+ if (!already_clinging && liquefied(*this))
+ return false;
+
+ for (orth_adjacent_iterator ai(*this); ai; ++ai)
+ if (feat_is_wall(env.grid(*ai)))
+ return true;
+
+ return false;
+}
+
+bool coord_def::can_cling_to(const coord_def& p) const
+{
+ if (!in_bounds(p))
+ return false;
+
+ for (orth_adjacent_iterator ai(*this); ai; ++ai)
+ if (feat_is_wall(env.grid(*ai)))
+ for (orth_adjacent_iterator ai2(p, false); ai2; ++ai2)
+ if (feat_is_wall(env.grid(*ai2)) && distance(*ai, *ai2) <= 1)
+ return true;
+
+ return false;
+}