From 0e34e7f32fb49d4868ebf8c0f0a05a104fbca176 Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Tue, 18 Dec 2018 14:48:04 -0500 Subject: [PATCH 1/2] G_SetCustomExitVars for setting nextmapoverride & skipstats This is desparately needed for KIMOKAWAIII, since there's many instances I need to change nextlevel but still want to use the existing player exit stuff. --- src/lua_baselib.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 96998776..5298c1e3 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -1923,6 +1923,38 @@ static int lib_gExitLevel(lua_State *L) return 0; } +// Another Lua function that doesn't actually exist! +// Sets nextmapoverride & skipstats without instantly ending the level, for instances where other sources should be exiting the level, like normal signposts. +static int lib_gSetCustomExitVars(lua_State *L) +{ + int n = lua_gettop(L); // Num arguments + NOHUD + + // LUA EXTENSION: Custom exit like support + // Supported: + // G_SetCustomExitVars(); [reset to defaults] + // G_SetCustomExitVars(int) [nextmap override only] + // G_SetCustomExitVars(bool) [skipstats only] + // G_SetCustomExitVars(int, bool) [both of the above] + if (n >= 1) + { + if (lua_isnumber(L, 1) || n >= 2) + { + nextmapoverride = (INT16)luaL_checknumber(L, 1); + lua_pop(L, 1); // pop nextmapoverride; skipstats now 1 if available + } + skipstats = lua_optboolean(L, 1); + } + else + { + nextmapoverride = 0; + skipstats = false; + } + // --- + + return 0; +} + static int lib_gIsSpecialStage(lua_State *L) { INT32 mapnum = luaL_optinteger(L, 1, gamemap); @@ -2180,6 +2212,7 @@ static luaL_Reg lib[] = { {"G_BuildMapName",lib_gBuildMapName}, {"G_DoReborn",lib_gDoReborn}, {"G_ExitLevel",lib_gExitLevel}, + {"G_SetCustomExitVars",lib_gSetCustomExitVars}, {"G_IsSpecialStage",lib_gIsSpecialStage}, {"G_GametypeUsesLives",lib_gGametypeUsesLives}, {"G_GametypeHasTeams",lib_gGametypeHasTeams}, From 42a9e66883aa209a3be78bfad0225c0ca1201477 Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Tue, 18 Dec 2018 15:03:54 -0500 Subject: [PATCH 2/2] Let lib_gExitLevel call lib_gSetCustomExitVars, for reduced code duplication. --- src/lua_baselib.c | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 5298c1e3..40ca1963 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -1897,32 +1897,6 @@ static int lib_gDoReborn(lua_State *L) return 0; } -static int lib_gExitLevel(lua_State *L) -{ - int n = lua_gettop(L); // Num arguments - NOHUD - - // LUA EXTENSION: Custom exit like support - // Supported: - // G_ExitLevel(); [no modifications] - // G_ExitLevel(int) [nextmap override only] - // G_ExitLevel(bool) [skipstats only] - // G_ExitLevel(int, bool) [both of the above] - if (n >= 1) - { - if (lua_isnumber(L, 1) || n >= 2) - { - nextmapoverride = (INT16)luaL_checknumber(L, 1); - lua_pop(L, 1); // pop nextmapoverride; skipstats now 1 if available - } - skipstats = lua_optboolean(L, 1); - } - // --- - - G_ExitLevel(); - return 0; -} - // Another Lua function that doesn't actually exist! // Sets nextmapoverride & skipstats without instantly ending the level, for instances where other sources should be exiting the level, like normal signposts. static int lib_gSetCustomExitVars(lua_State *L) @@ -1955,6 +1929,17 @@ static int lib_gSetCustomExitVars(lua_State *L) return 0; } +static int lib_gExitLevel(lua_State *L) +{ + int n = lua_gettop(L); // Num arguments + NOHUD + // Moved this bit to G_SetCustomExitVars + if (n >= 1) // Don't run the reset to defaults option + lib_gSetCustomExitVars(L); + G_ExitLevel(); + return 0; +} + static int lib_gIsSpecialStage(lua_State *L) { INT32 mapnum = luaL_optinteger(L, 1, gamemap); @@ -2211,8 +2196,8 @@ static luaL_Reg lib[] = { // g_game {"G_BuildMapName",lib_gBuildMapName}, {"G_DoReborn",lib_gDoReborn}, - {"G_ExitLevel",lib_gExitLevel}, {"G_SetCustomExitVars",lib_gSetCustomExitVars}, + {"G_ExitLevel",lib_gExitLevel}, {"G_IsSpecialStage",lib_gIsSpecialStage}, {"G_GametypeUsesLives",lib_gGametypeUsesLives}, {"G_GametypeHasTeams",lib_gGametypeHasTeams},