Translate MapLoad/MapChange and implicit gamemap argument

This commit is contained in:
GenericHeroGuy 2025-03-03 18:58:28 +01:00
parent ec913108b9
commit 1025ac59bd
5 changed files with 33 additions and 4 deletions

View file

@ -5003,7 +5003,7 @@ void G_InitNew(UINT8 pencoremode, INT32 map, boolean resetplayer, boolean skippr
F_StartCustomCutscene(mapheaderinfo[gamemap-1]->precutscenenum-1, true, resetplayer);
else
{
LUA_HookInt(gamemap, HOOK(MapChange));
LUA_HookGamemap(HOOK(MapChange));
G_DoLoadLevel(resetplayer);
}

View file

@ -3164,7 +3164,7 @@ static int lib_gAddGametype(lua_State *L)
static int Lcheckmapnumber (lua_State *L, int idx, const char *fun)
{
if (ISINLEVEL)
return luaL_optinteger(L, idx, gamemap);
return luaL_optinteger(L, idx, lua_compatmode ? G_NativeMapToKart(gamemap-1)+1 : gamemap);
else
{
if (lua_isnoneornil(L, idx))
@ -3370,7 +3370,7 @@ static int lib_gExitLevel(lua_State *L)
static int lib_gIsSpecialStage(lua_State *L)
{
INT32 mapnum = luaL_optinteger(L, 1, gamemap);
INT32 mapnum = Lcheckmapnumber(L, 1, "G_IsSpecialStage");
//HUDSAFE
INLEVEL
lua_pushboolean(L, G_IsSpecialStage(lua_compatmode ? G_KartMapToNative(mapnum-1)+1 : mapnum));

View file

@ -132,6 +132,7 @@ void LUA_HookHUD(huddrawlist_h, int hook);
int LUA_HookMobj(mobj_t *, int hook);
int LUA_Hook2Mobj(mobj_t *, mobj_t *, int hook);
void LUA_HookInt(INT32 integer, int hook);
void LUA_HookGamemap(int hook);
void LUA_HookBool(boolean value, int hook);
int LUA_HookPlayer(player_t *, int hook);
int LUA_HookTiccmd(player_t *, ticcmd_t *, int hook);

View file

@ -501,6 +501,20 @@ static int call_mapped_hud(Hook_State *hook, const hook_t *map)
return map->numHooks;
}
static int call_mapped_gamemap(Hook_State *hook, const hook_t *map)
{
int k;
for (k = 0; k < map->numHooks; ++k)
{
get_hook(hook, map->ids, k);
lua_pushvalue(gL, hook->top - !lua_compatmode);
call_single_hook_no_copy(hook);
}
return map->numHooks;
}
static int call_string_hooks(Hook_State *hook)
{
const stringhook_t *map = &stringHooks[hook->hook_type];
@ -627,6 +641,20 @@ void LUA_HookInt(INT32 number, int hook_type)
}
}
void LUA_HookGamemap(int hook_type)
{
Hook_State hook;
if (prepare_hook(&hook, 0, hook_type))
{
lua_pushinteger(gL, gamemap);
lua_pushinteger(gL, G_NativeMapToKart(gamemap-1)+1);
init_hook_call(&hook, 0, res_none);
hook.values = 1;
call_mapped_gamemap(&hook, &hookIds[hook.hook_type]);
lua_settop(gL, 0);
}
}
void LUA_HookBool(boolean value, int hook_type)
{
Hook_State hook;

View file

@ -8879,7 +8879,7 @@ void P_PostLoadLevel(void)
}
ACS_RunLevelStartScripts();
LUA_HookInt(gamemap, HOOK(MapLoad));
LUA_HookGamemap(HOOK(MapLoad));
UINT8 i;
for (i = 0; i < MAXPLAYERS; i++)