From f26b0447e7dea6029ba9d125ce1d3d536f95e67a Mon Sep 17 00:00:00 2001 From: Jude Brown Date: Fri, 4 Dec 2009 19:38:59 +1000 Subject: dLua "mark_summoned" wrapper for monsters. --- crawl-ref/source/initfile.cc | 23 ++++++++++++++++++++++ crawl-ref/source/initfile.h | 1 + crawl-ref/source/l_mons.cc | 45 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 68 insertions(+), 1 deletion(-) (limited to 'crawl-ref') diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc index be738cfb0c..158112a087 100644 --- a/crawl-ref/source/initfile.cc +++ b/crawl-ref/source/initfile.cc @@ -39,6 +39,7 @@ #include "player.h" #include "religion.h" #include "species.h" +#include "spl-util.h" #include "stash.h" #include "state.h" #include "stuff.h" @@ -234,6 +235,28 @@ int str_to_fprop ( const std::string &str) 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) +{ + if (str == "clone") + return (MON_SUMM_CLONE); + if (str == "animate") + return (MON_SUMM_ANIMATE); + if (str == "chaos") + return (MON_SUMM_CHAOS); + if (str == "miscast") + return (MON_SUMM_MISCAST); + if (str == "zot") + return (MON_SUMM_ZOT); + if (str == "wrath") + return (MON_SUMM_WRATH); + if (str == "aid") + return (MON_SUMM_AID); + + return (spell_by_name(str)); +} + static std::string _wand_to_str( int weapon ) { switch (weapon) diff --git a/crawl-ref/source/initfile.h b/crawl-ref/source/initfile.h index 4a1339daf9..d2779e25b7 100644 --- a/crawl-ref/source/initfile.h +++ b/crawl-ref/source/initfile.h @@ -21,6 +21,7 @@ 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_mons.cc b/crawl-ref/source/l_mons.cc index 692369e4f2..c5c59dae5e 100644 --- a/crawl-ref/source/l_mons.cc +++ b/crawl-ref/source/l_mons.cc @@ -5,6 +5,7 @@ #include "delay.h" #include "dlua.h" +#include "initfile.h" #include "mon-util.h" #include "mon-stuff.h" @@ -152,6 +153,47 @@ static int l_mons_do_random_teleport(lua_State *ls) MDEFN(random_teleport, do_random_teleport) +static int l_mons_do_mark_summoned(lua_State *ls) +{ + // And this should only be in dlua as well. + ASSERT_DLUA; + + monsters *mons = + util_get_userdata(ls, lua_upvalueindex(1)); + if (mons->alive()) + { + int longevity = luaL_checkint(ls, 1); + if (longevity < 1 || longevity > 6) + { + std::string err + = make_stringf("Invalid abjuration duration: '%d'.", longevity); + luaL_argerror(ls, 1, err.c_str()); + } + else + { + bool mark_items = true; + int summon_type; + + if (lua_gettop(ls) == 2) + { + if (!luaL_checkstring(ls, 2)) + mark_items = lua_toboolean(ls, 2); + else + summon_type = str_to_summon_type(luaL_checkstring(ls, 2)); + } + else if (lua_gettop(ls) == 3) + summon_type = str_to_summon_type(luaL_checkstring(ls, 3)); + else + summon_type = static_cast(SPELL_SHADOW_CREATURES); + + mons->mark_summoned(longevity, mark_items, summon_type); + } + } + return (0); +} + +MDEFN(mark_summoned, do_mark_summoned) + MDEF(experience) { ASSERT_DLUA; @@ -226,7 +268,8 @@ static MonsAccessor mons_attrs[] = { "experience", l_mons_experience }, { "random_teleport", l_mons_random_teleport }, { "set_prop", l_mons_set_prop }, - { "you_can_see", l_mons_you_can_see } + { "you_can_see", l_mons_you_can_see }, + { "mark_summoned", l_mons_mark_summoned } }; static int monster_get(lua_State *ls) -- cgit v1.2.3-54-g00ecf