Start of movement tests

Adds the following lua functions:

- nh.pushkey("x")
    Pushes a key into the command queue. Support is spotty,
    currently only the keys handled in rhack.
- nh.doturn()
    Runs one turn of main loop, or if optional boolean param
    is true, until g.multi == 0
- nh.monster_generation(false)
    Disable monster generation, and kill off all monsters.

Adds a testmove.lua script to test hero movement. Currently
covers only hjklyubn and HJKLYUBN.
This commit is contained in:
Pasi Kallinen
2021-07-28 19:11:30 +03:00
parent fa8c3f82be
commit 65b320de39
6 changed files with 171 additions and 31 deletions

View File

@@ -19,6 +19,9 @@ static int nhl_dump_fmtstr(lua_State *);
#endif /* DUMPLOG */
static int nhl_dnum_name(lua_State *);
static int nhl_stairways(lua_State *);
static int nhl_pushkey(lua_State *);
static int nhl_doturn(lua_State *);
static int nhl_monster_generation(lua_State *);
static int nhl_test(lua_State *);
static int nhl_getmap(lua_State *);
static void nhl_add_table_entry_bool(lua_State *, const char *, boolean);
@@ -936,6 +939,68 @@ nhl_test(lua_State *L)
return 1;
}
/* push a key into command queue */
/* nh.pushkey("i"); */
static int
nhl_pushkey(lua_State *L)
{
int argc = lua_gettop(L);
if (argc == 1) {
const char *key = luaL_checkstring(L, 1);
cmdq_add_key(key[0]);
}
return 0;
}
/* do a turn of moveloop, or until g.multi is done if param is true. */
/* nh.doturn(); nh.doturn(true); */
static int
nhl_doturn(lua_State *L)
{
int argc = lua_gettop(L);
boolean domulti = FALSE;
if (argc == 1)
domulti = lua_toboolean(L, 1);
do {
moveloop_core();
} while (domulti && g.multi);
return 0;
}
/* disable or enable monster generation. debugging use only. */
/* disabling also kills all monsters on current level. */
/* local prevvalue = nh.monster_generation(false); */
static int
nhl_monster_generation(lua_State *L)
{
int argc = lua_gettop(L);
boolean val = !iflags.debug_mongen; /* value in lua is negated */
if (argc == 1) {
iflags.debug_mongen = !lua_toboolean(L, 1);
if (iflags.debug_mongen) {
register struct monst *mtmp, *mtmp2;
for (mtmp = fmon; mtmp; mtmp = mtmp2) {
mtmp2 = mtmp->nmon;
if (DEADMONSTER(mtmp))
continue;
mongone(mtmp);
}
}
}
lua_pushboolean(L, val);
return 1;
}
static const struct luaL_Reg nhl_functions[] = {
{"test", nhl_test},
@@ -967,6 +1032,9 @@ static const struct luaL_Reg nhl_functions[] = {
#endif /* DUMPLOG */
{"dnum_name", nhl_dnum_name},
{"stairways", nhl_stairways},
{"pushkey", nhl_pushkey},
{"doturn", nhl_doturn},
{"monster_generation", nhl_monster_generation},
{NULL, NULL}
};