diff --git a/src/lua_playerlib.c b/src/lua_playerlib.c index 4fa6fa01e..2a4586f3d 100644 --- a/src/lua_playerlib.c +++ b/src/lua_playerlib.c @@ -99,44 +99,29 @@ static int lib_lenPlayer(lua_State *L) static int lib_iterateDisplayplayers(lua_State *L) { - INT32 i = -1; - INT32 temp = -1; - INT32 iter = 0; + INT32 i = lua_tonumber(L, lua_upvalueindex(1)); if (lua_gettop(L) < 2) - { - //return luaL_error(L, "Don't call displayplayers.iterate() directly, use it as 'for player in displayplayers.iterate do end'."); - lua_pushcfunction(L, lib_iterateDisplayplayers); + { + lua_pushcclosure(L, lib_iterateDisplayplayers, 1); return 1; } - lua_settop(L, 2); - lua_remove(L, 1); // state is unused. - if (!lua_isnil(L, 1)) + + if (i <= r_splitscreen) { - temp = (INT32)(*((player_t **)luaL_checkudata(L, 1, META_PLAYER)) - players); // get the player # of the last iterated player. - - // @FIXME: - // I didn't quite find a better way for this; Here, we go back to which player in displayplayers we last iterated to resume the for loop below for this new function call - // I don't understand enough about how the Lua stacks work to get this to work in possibly a single line. - // So anyone feel free to correct this! - - for (; iter < MAXSPLITSCREENPLAYERS; iter++) - { - if (displayplayers[iter] == temp) - { - i = iter; - break; - } - } - } - - for (i++; i < MAXSPLITSCREENPLAYERS; i++) - { - if (i > r_splitscreen || !playeringame[displayplayers[i]]) - return 0; // Stop! There are no more players for us to go through. There will never be a player gap in displayplayers. - + if (!playeringame[displayplayers[i]]) + return 0; + + // Return player and splitscreen index. LUA_PushUserdata(L, &players[displayplayers[i]], META_PLAYER); - lua_pushinteger(L, i); // push this to recall what number we were on for the next function call. I suppose this also means you can retrieve the splitscreen player number with 'for p, n in displayplayers.iterate'! + lua_pushnumber(L, i); + + // Update splitscreen index value for next iteration. + lua_pushnumber(L, i + 1); + lua_pushvalue(L, -1); + lua_replace(L, lua_upvalueindex(1)); + lua_pop(L, 1); + return 2; } return 0; @@ -162,7 +147,7 @@ static int lib_getDisplayplayers(lua_State *L) field = luaL_checkstring(L, 2); if (fastcmp(field,"iterate")) { - lua_pushcfunction(L, lib_iterateDisplayplayers); + lua_pushcclosure(L, lib_iterateDisplayplayers, 1); return 1; } return 0; diff --git a/src/menus/transient/pause-replay.c b/src/menus/transient/pause-replay.c index ef5d1eb1e..3abee007f 100644 --- a/src/menus/transient/pause-replay.c +++ b/src/menus/transient/pause-replay.c @@ -137,6 +137,10 @@ void M_EndModeAttackRun(void) // Return to the menu. D_ClearState(); M_StartControlPanel(); + // This removes any lingering optionsmenu.profile pointers, + // so that when returning to char select, it will show the normal + // stat grid instead of the profile one (this is also most likely a bad way to fix this) + M_ResetOptions(); } // Replay Playback Menu diff --git a/src/p_mobj.c b/src/p_mobj.c index 43df4deea..d991e45d4 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -2398,6 +2398,14 @@ boolean P_ZMovement(mobj_t *mo) return false; } break; + case MT_MONITOR: + // Prevent battle monitors getting stuck in pits + if (P_CheckDeathPitCollide(mo)) + { + P_RemoveMobj(mo); + return false; + } + break; default: // SRB2kart stuff that should die in pits // Shouldn't stop moving along the Z if there's no speed though!