summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/l_dgnevt.cc
diff options
context:
space:
mode:
authorMatthew Cline <zelgadis@sourceforge.net>2009-10-22 03:53:05 -0700
committerMatthew Cline <zelgadis@sourceforge.net>2009-10-22 03:53:05 -0700
commit49870f2bc48989467ea4f8c847fd1274cec73944 (patch)
tree050245a946eb520236d028cec8c661743c76d501 /crawl-ref/source/l_dgnevt.cc
parenta724290e7ae62bc20013919bc14c16e91d842083 (diff)
downloadcrawl-ref-49870f2bc48989467ea4f8c847fd1274cec73944.tar.gz
crawl-ref-49870f2bc48989467ea4f8c847fd1274cec73944.zip
Observerable/observer-ish pattern for Lua markers
A new framework for Lua markers, similar to the observable/observer design pattern, which decouples the thing being activated from the thing watching for the activating condition. This makes it easier to create new types of Lua markers which are triggered by dungeon events, and easier to add new triggering conditions to already existing marker types. Currently only ChangeFlags (clua/lm_flags.lua) and MonsterOnTrigger (clua/lm_monst.lua) use it.
Diffstat (limited to 'crawl-ref/source/l_dgnevt.cc')
-rw-r--r--crawl-ref/source/l_dgnevt.cc26
1 files changed, 25 insertions, 1 deletions
diff --git a/crawl-ref/source/l_dgnevt.cc b/crawl-ref/source/l_dgnevt.cc
index c379bad317..f6d1b56aeb 100644
--- a/crawl-ref/source/l_dgnevt.cc
+++ b/crawl-ref/source/l_dgnevt.cc
@@ -119,9 +119,33 @@ static int dgn_dgn_event(lua_State *ls)
return (retvals);
}
+static dgn_event_type dgn_param_to_event_type(lua_State *ls, int n)
+{
+ if (lua_isnumber(ls, n))
+ return (static_cast<dgn_event_type>(luaL_checkint(ls, n)));
+ else if (lua_isstring(ls, n))
+ return dgn_event_type_by_name(lua_tostring(ls, n));
+ else
+ return (DET_NONE);
+}
+
+static int dgn_dgn_event_is_global(lua_State *ls)
+{
+ lua_pushboolean(ls, dgn_param_to_event_type(ls, 1) & DET_GLOBAL_MASK);
+ return (1);
+}
+
+static int dgn_dgn_event_is_position(lua_State *ls)
+{
+ lua_pushboolean(ls, dgn_param_to_event_type(ls, 1) & DET_POSITION_MASK);
+ return (1);
+}
+
const struct luaL_reg dgn_event_dlib[] =
{
-{ "dgn_event_type", dgn_dgn_event },
+{ "dgn_event_type", dgn_dgn_event },
+{ "dgn_event_is_global", dgn_dgn_event_is_global },
+{ "dgn_event_is_position", dgn_dgn_event_is_position},
{ NULL, NULL }
};