From 4b15085bb19847c70ae53770dd3442c2454d5feb Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Thu, 5 Dec 2024 16:12:59 +0200 Subject: [PATCH] Avoid naming Vlad's entourage if vampires are genocided --- dat/tower1.lua | 11 ++++++++--- doc/lua.adoc | 9 +++++++++ src/nhlua.c | 23 +++++++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/dat/tower1.lua b/dat/tower1.lua index c968b707c..8aab0a7ad 100644 --- a/dat/tower1.lua +++ b/dat/tower1.lua @@ -37,9 +37,14 @@ des.monster("V",niches[3]) -- gave them titles rather than (or perhaps in addition to) specific names -- and we use those titles here. Marking them as 'waiting' forces them to -- start in vampire form instead of vampshifted into bat/fog/wolf form. -des.monster({ id="Vampire Lady", niches[4], name="Madame", waiting=1 }) -des.monster({ id="Vampire Lady", niches[5], name="Marquise", waiting=1 }) -des.monster({ id="Vampire Lady", niches[6], name="Countess", waiting=1 }) +local Vgenod = nh.is_genocided("vampire"); +local Vnames = { nil, nil, nil }; +if (not Vgenod) then + Vnames = { "Madame", "Marquise", "Countess" }; +end +des.monster({ id="Vampire Lady", niches[4], name=Vnames[1], waiting=1 }) +des.monster({ id="Vampire Lady", niches[5], name=Vnames[2], waiting=1 }) +des.monster({ id="Vampire Lady", niches[6], name=Vnames[3], waiting=1 }) -- The doors des.door("closed",08,03) des.door("closed",10,03) diff --git a/doc/lua.adoc b/doc/lua.adoc index 66983807d..eea32e7d7 100644 --- a/doc/lua.adoc +++ b/doc/lua.adoc @@ -249,6 +249,15 @@ Example: local str = nh.ing_suffix("foo"); +=== is_genocided + +Is specific monster type genocided? Returns a boolean value. + +Example: + + local x = nh.is_genocided("vampire"); + + === level_difficulty Returns an integer value describing the level difficulty. diff --git a/src/nhlua.c b/src/nhlua.c index becef1302..dc2c64911 100644 --- a/src/nhlua.c +++ b/src/nhlua.c @@ -64,6 +64,7 @@ staticfn int nhl_an(lua_State *); staticfn int nhl_rn2(lua_State *); staticfn int nhl_random(lua_State *); staticfn int nhl_level_difficulty(lua_State *); +staticfn int nhl_is_genocided(lua_State *); staticfn void init_nhc_data(lua_State *); staticfn int nhl_push_anything(lua_State *, int, void *); staticfn int nhl_meta_u_index(lua_State *); @@ -954,6 +955,27 @@ nhl_level_difficulty(lua_State *L) return 1; } +/* local x = nh.is_genocided("vampire") */ +staticfn int +nhl_is_genocided(lua_State *L) +{ + int argc = lua_gettop(L); + + if (argc == 1) { + const char *paramstr = luaL_checkstring(L, 1); + int mgend; + int i = name_to_mon(paramstr, &mgend); + + lua_pushboolean(L, (i != NON_PM) + && (svm.mvitals[i].mvflags & G_GENOD) + ? TRUE : FALSE); + } else { + nhl_error(L, "Wrong args"); + } + return 1; +} + + RESTORE_WARNING_UNREACHABLE_CODE /* get mandatory integer value from table */ @@ -1722,6 +1744,7 @@ static const struct luaL_Reg nhl_functions[] = { { "rn2", nhl_rn2 }, { "random", nhl_random }, { "level_difficulty", nhl_level_difficulty }, + { "is_genocided", nhl_is_genocided }, { "parse_config", nhl_parse_config }, { "get_config", nhl_get_config }, { "get_config_errors", l_get_config_errors },