From c4246fc216beca0282bf281274a3756a10086f87 Mon Sep 17 00:00:00 2001 From: Jude Brown Date: Sun, 17 Jan 2010 15:29:52 +1000 Subject: Code to alter/check feature properties in Lua. This commit moves str_to_fprop from initfile.cc to fprop.cc. It also introduces two new dungeon Lua wrappers: fprop_changed(x, y, fprop), and fprop_at(x, y, fprop). fprop_at(x, y, fprop) will return testbits(coord_def(x, y), fprop). fprop_changed will either add the fprop to that location, or if it already exists there, it will remove it from that location. It will returrn a boolean value of true if it altered the location, and false if it did nothing. --- crawl-ref/source/fprop.cc | 18 ++++++++++++++ crawl-ref/source/fprop.h | 1 + crawl-ref/source/initfile.cc | 16 ------------- crawl-ref/source/initfile.h | 1 - crawl-ref/source/l_dgn.cc | 57 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 17 deletions(-) diff --git a/crawl-ref/source/fprop.cc b/crawl-ref/source/fprop.cc index 50023409d0..5ab09c5279 100644 --- a/crawl-ref/source/fprop.cc +++ b/crawl-ref/source/fprop.cc @@ -23,3 +23,21 @@ bool is_bloodcovered(const coord_def& p) { return (testbits(env.pgrid(p), FPROP_BLOODY)); } + +int str_to_fprop ( const std::string &str) +{ + if (str == "bloody") + return (FPROP_BLOODY); + if (str == "no_cloud_gen") + return (FPROP_NO_CLOUD_GEN); + if (str == "no_rtele_into") + return (FPROP_NO_RTELE_INTO); + if (str == "no_ctele_into") + return (FPROP_NO_CTELE_INTO); + if (str == "no_tele_into") + return (FPROP_NO_TELE_INTO); + + return (FPROP_NONE); +} + + diff --git a/crawl-ref/source/fprop.h b/crawl-ref/source/fprop.h index 04898519f3..54be5a597e 100644 --- a/crawl-ref/source/fprop.h +++ b/crawl-ref/source/fprop.h @@ -5,6 +5,7 @@ struct coord_def; bool is_sanctuary( const coord_def& p ); bool is_bloodcovered( const coord_def& p ); +int str_to_fprop (const std::string &str); enum feature_property_type { diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc index 1bbebfdb56..a6d1ad826f 100644 --- a/crawl-ref/source/initfile.cc +++ b/crawl-ref/source/initfile.cc @@ -218,22 +218,6 @@ static int _str_to_wand( const std::string& str ) return (SWT_NO_SELECTION); } -int str_to_fprop ( const std::string &str) -{ - if (str == "bloody") - return (FPROP_BLOODY); - if (str == "no_cloud_gen") - return (FPROP_NO_CLOUD_GEN); - if (str == "no_rtele_into") - return (FPROP_NO_RTELE_INTO); - if (str == "no_ctele_into") - return (FPROP_NO_CTELE_INTO); - if (str == "no_tele_into") - return (FPROP_NO_TELE_INTO); - - return (FPROP_NONE); -} - // Summon types can be any of mon_summon_type (enum.h), or a relevant summoning // spell. int str_to_summon_type (const std::string &str) diff --git a/crawl-ref/source/initfile.h b/crawl-ref/source/initfile.h index d2779e25b7..0a39e9db41 100644 --- a/crawl-ref/source/initfile.h +++ b/crawl-ref/source/initfile.h @@ -20,7 +20,6 @@ enum drop_mode_type }; god_type str_to_god(std::string god); -int str_to_fprop (const std::string &str); int str_to_summon_type (const std::string &str); std::string read_init_file(bool runscript = false); diff --git a/crawl-ref/source/l_dgn.cc b/crawl-ref/source/l_dgn.cc index 0f57196add..ff439d5d64 100644 --- a/crawl-ref/source/l_dgn.cc +++ b/crawl-ref/source/l_dgn.cc @@ -909,6 +909,61 @@ static int dgn_terrain_changed(lua_State *ls) return (0); } +static int dgn_fprop_changed(lua_State *ls) +{ + feature_property_type prop = FPROP_NONE; + + if (lua_isnumber(ls, 3)) + prop = static_cast(luaL_checkint(ls, 3)); + else if (lua_isstring(ls, 3)) + prop = static_cast(str_to_fprop(lua_tostring(ls, 3))); + + coord_def pos = coord_def(luaL_checkint(ls, 1), luaL_checkint(ls, 2)); + + if (in_bounds(pos) && prop != FPROP_NONE) + { + if (testbits(env.pgrid(pos), prop)) + { + env.pgrid(pos) &= ~prop; + lua_pushboolean(ls, true); + } + else if (!testbits(env.pgrid(pos), prop)) + { + env.pgrid(pos) |= prop; + lua_pushboolean(ls, true); + } + else + lua_pushboolean(ls, false); + } + else + lua_pushboolean(ls, false); + + return (1); +} + +static int dgn_fprop_at (lua_State *ls) +{ + feature_property_type prop = FPROP_NONE; + + if (lua_isnumber(ls, 3)) + prop = static_cast(luaL_checkint(ls, 3)); + else if (lua_isstring(ls, 3)) + prop = static_cast(str_to_fprop(lua_tostring(ls, 3))); + + coord_def pos = coord_def(luaL_checkint(ls, 1), luaL_checkint(ls, 2)); + + if (in_bounds(pos) && prop != FPROP_NONE) + { + lua_pushboolean(ls, testbits(env.pgrid(pos), prop)); + } + else + { + lua_pushboolean(ls, false); + } + + return (1); +} + static int lua_dgn_set_lt_callback(lua_State *ls) { const char *level_type = luaL_checkstring(ls, 1); @@ -1769,8 +1824,10 @@ const struct luaL_reg dgn_dlib[] = { "subvault", dgn_subvault }, { "colour_at", dgn_colour_at }, +{ "fprop_at", dgn_fprop_at }, { "terrain_changed", dgn_terrain_changed }, +{ "fprop_changed", dgn_fprop_changed }, { "points_connected", dgn_points_connected }, { "any_point_connected", dgn_any_point_connected }, { "has_exit_from", dgn_has_exit_from }, -- cgit v1.2.3