summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/l_view.cc
diff options
context:
space:
mode:
authorelliptic <hyperelliptical@gmail.com>2011-12-03 16:52:53 -0500
committerelliptic <hyperelliptical@gmail.com>2011-12-03 18:47:58 -0500
commit6578c790d3051254aa607c646607fb0ca2c8ed9c (patch)
tree72840a351f36c7951936046ababe7952bb6be448 /crawl-ref/source/l_view.cc
parent4cd1acae612f8796e200ea5a4bdf37cae06aa0dd (diff)
downloadcrawl-ref-6578c790d3051254aa607c646607fb0ca2c8ed9c.tar.gz
crawl-ref-6578c790d3051254aa607c646607fb0ca2c8ed9c.zip
Lua function view.is_safe_square().
It might be preferable to call something like _is_travelsafe_square(), but that function does some things that we might not want here. For now, the function just combines simple checks for cloud/trap/feature safety.
Diffstat (limited to 'crawl-ref/source/l_view.cc')
-rw-r--r--crawl-ref/source/l_view.cc35
1 files changed, 35 insertions, 0 deletions
diff --git a/crawl-ref/source/l_view.cc b/crawl-ref/source/l_view.cc
index d072b9b103..8a9a50d194 100644
--- a/crawl-ref/source/l_view.cc
+++ b/crawl-ref/source/l_view.cc
@@ -14,6 +14,9 @@
#include "libutil.h"
#include "player.h"
#include "terrain.h"
+#include "cloud.h"
+#include "travel.h"
+
coord_def player2show(const coord_def &s)
{
@@ -32,9 +35,41 @@ LUAFN(view_feature_at)
return (1);
}
+LUAFN(view_is_safe_square)
+{
+ COORDSHOW(s, 1, 2)
+ const coord_def p = player2grid(s);
+ if (!map_bounds(p))
+ return (1);
+ cloud_type c = env.map_knowledge(p).cloud();
+ if (c != CLOUD_NONE && is_damaging_cloud(c, true))
+ {
+ PLUARET(boolean, false);
+ return (1);
+ }
+ trap_type t = env.map_knowledge(p).trap();
+ if (t != TRAP_UNASSIGNED)
+ {
+ trap_def trap;
+ trap.type = t;
+ trap.ammo_qty = 1;
+ PLUARET(boolean, trap.is_safe());
+ return (1);
+ }
+ dungeon_feature_type f = env.map_knowledge(p).feat();
+ if (f != DNGN_UNSEEN && !feat_is_traversable(f))
+ {
+ PLUARET(boolean, false);
+ return (1);
+ }
+ PLUARET(boolean, true);
+ return (1);
+}
+
static const struct luaL_reg view_lib[] =
{
{ "feature_at", view_feature_at },
+ { "is_safe_square", view_is_safe_square },
{ NULL, NULL }
};