Lua tests: monster creation coverage
Expose constants NUMMONS, LOW_PM, and HIGH_PM to lua. Allow converting an int to monster type name. Create one of each type of monster in the lua tests.
This commit is contained in:
12
doc/lua.adoc
12
doc/lua.adoc
@@ -259,6 +259,15 @@ Example:
|
||||
local str = nh.ing_suffix("foo");
|
||||
|
||||
|
||||
=== int_to_pmname
|
||||
|
||||
Convert integer value to monster type name.
|
||||
|
||||
Example:
|
||||
|
||||
local pmname = nh.int_to_pmname(12);
|
||||
|
||||
|
||||
=== is_genocided
|
||||
|
||||
Is specific monster type genocided? Returns a boolean value.
|
||||
@@ -1564,6 +1573,9 @@ These constants are in the `nhc` table.
|
||||
|===
|
||||
| COLNO | Number of map columns
|
||||
| ROWNO | Number of map rows
|
||||
| NUMMONS | Number of different monster types
|
||||
| LOW_PM | First monster type id. See <<_int_to_pmname>>.
|
||||
| HIGH_PM | Last monster type id. See <<_int_to_pmname>>.
|
||||
| DLB | 1 or 0, depending if NetHack is compiled with DLB
|
||||
|===
|
||||
|
||||
|
||||
25
src/nhlua.c
25
src/nhlua.c
@@ -31,6 +31,7 @@ struct e;
|
||||
staticfn int nhl_dump_fmtstr(lua_State *);
|
||||
#endif /* DUMPLOG */
|
||||
staticfn int nhl_dnum_name(lua_State *);
|
||||
staticfn int nhl_int_to_pm_name(lua_State *);
|
||||
staticfn int nhl_stairways(lua_State *);
|
||||
staticfn int nhl_pushkey(lua_State *);
|
||||
staticfn int nhl_doturn(lua_State *);
|
||||
@@ -1164,6 +1165,26 @@ nhl_dnum_name(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* return gender-neutral monster type name by integer value,
|
||||
or empty string if outside LOW_PM - HIGH_PM range */
|
||||
/* local montypename = int_to_pmname(12); */
|
||||
staticfn int
|
||||
nhl_int_to_pm_name(lua_State *L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
|
||||
if (argc == 1) {
|
||||
lua_Integer i = luaL_checkinteger(L, 1);
|
||||
|
||||
if (i >= LOW_PM && i <= HIGH_PM)
|
||||
lua_pushstring(L, mons[i].pmnames[NEUTRAL]);
|
||||
else
|
||||
lua_pushstring(L, "");
|
||||
} else
|
||||
nhl_error(L, "Expected an integer parameter");
|
||||
return 1;
|
||||
}
|
||||
|
||||
DISABLE_WARNING_UNREACHABLE_CODE
|
||||
/* because nhl_error() does not return */
|
||||
|
||||
@@ -1836,6 +1857,7 @@ static const struct luaL_Reg nhl_functions[] = {
|
||||
{ "dump_fmtstr", nhl_dump_fmtstr },
|
||||
#endif /* DUMPLOG */
|
||||
{ "dnum_name", nhl_dnum_name },
|
||||
{ "int_to_pmname", nhl_int_to_pm_name },
|
||||
{ "variable", nhl_variable },
|
||||
{ "stairways", nhl_stairways },
|
||||
{ "pushkey", nhl_pushkey },
|
||||
@@ -1851,6 +1873,9 @@ static const struct {
|
||||
} nhl_consts[] = {
|
||||
{ "COLNO", COLNO },
|
||||
{ "ROWNO", ROWNO },
|
||||
{ "NUMMONS", NUMMONS },
|
||||
{ "LOW_PM", LOW_PM },
|
||||
{ "HIGH_PM", HIGH_PM },
|
||||
#ifdef DLB
|
||||
{ "DLB", 1 },
|
||||
#else
|
||||
|
||||
@@ -124,6 +124,11 @@ function test_monster()
|
||||
des.monster({ id = "Angel", align = "law" });
|
||||
des.monster({ id = "archeologist" });
|
||||
des.monster({ id = "wizard", name = "Rincewind", peaceful = true });
|
||||
|
||||
for i = nhc.LOW_PM, nhc.HIGH_PM do
|
||||
des.monster({ id = nh.int_to_pmname(i) });
|
||||
end
|
||||
|
||||
des.reset_level();
|
||||
des.level_init();
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user