P_DoPlayerExit changes

- Add flag application in function signature
    - Consistent gating of extra PF_NOCONTEST application behind not already exiting
        - This should fix dying after winning in K_Cooperative gametypes breaking things
- P_DoAllPlayersExit
    - Consistent condition of playeringame, spectator, exiting, etc checks
    - Also could force-give a life (for Battle Prisons)
This commit is contained in:
toaster 2023-05-02 18:08:59 +01:00
parent 6935bf4754
commit 12ecb1f7a4
9 changed files with 73 additions and 120 deletions

View file

@ -122,22 +122,17 @@ void K_CheckBumpers(void)
}
}
if (K_Cooperative()
? nobumpers > 0 && nobumpers >= numingame
: eliminated >= numingame - 1)
{
for (i = 0; i < MAXPLAYERS; i++)
{
if (!playeringame[i])
continue;
if (players[i].spectator)
continue;
if (K_Cooperative())
players[i].pflags |= PF_NOCONTEST;
P_DoPlayerExit(&players[i]);
{
if (nobumpers > 0 && nobumpers >= numingame)
{
P_DoAllPlayersExit(PF_NOCONTEST, false);
return;
}
}
else if (eliminated >= numingame - 1)
{
P_DoAllPlayersExit(0, false);
return;
}
@ -156,8 +151,6 @@ void K_CheckBumpers(void)
void K_CheckEmeralds(player_t *player)
{
UINT8 i;
if (!(gametyperules & GTR_POWERSTONES))
{
return;
@ -170,15 +163,7 @@ void K_CheckEmeralds(player_t *player)
player->roundscore = 100; // lmao
for (i = 0; i < MAXPLAYERS; i++)
{
if (!playeringame[i] || players[i].spectator)
{
continue;
}
P_DoPlayerExit(&players[i]);
}
P_DoAllPlayersExit(0, false);
}
UINT16 K_GetChaosEmeraldColor(UINT32 emeraldType)

View file

@ -102,8 +102,7 @@ static void K_MoveExitBeam(void)
if (player->distancetofinish > specialstageinfo.beamDist)
{
player->pflags |= PF_NOCONTEST;
P_DoPlayerExit(player);
P_DoPlayerExit(player, PF_NOCONTEST);
}
}
}

View file

@ -1338,11 +1338,12 @@ static int lib_pMovePlayer(lua_State *L)
static int lib_pDoPlayerExit(lua_State *L)
{
player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
pflags_t flags = luaL_checkinteger(L, 2);
NOHUD
INLEVEL
if (!player)
return LUA_ErrInvalid(L, "player_t");
P_DoPlayerExit(player);
P_DoPlayerExit(player, flags);
return 0;
}

View file

@ -428,23 +428,12 @@ static void UFOMove(mobj_t *ufo)
if (reachedEnd == true)
{
UINT8 i;
// Invalidate UFO/emerald
ufo_waypoint(ufo) = -1;
ufo->flags &= ~(MF_SPECIAL|MF_PICKUPFROMBELOW);
// Disable player
for (i = 0; i < MAXPLAYERS; i++)
{
if (!playeringame[i])
continue;
if (players[i].spectator)
continue;
players[i].pflags |= PF_NOCONTEST;
P_DoPlayerExit(&players[i]);
}
P_DoAllPlayersExit(PF_NOCONTEST, false);
}
if (pathfindsuccess == true)

View file

@ -3418,7 +3418,6 @@ static void P_DoBossVictory(mobj_t *mo)
{
thinker_t *th;
mobj_t *mo2;
INT32 i;
// scan the remaining thinkers to see if all bosses are dead
for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next)
@ -3444,12 +3443,7 @@ static void P_DoBossVictory(mobj_t *mo)
if (mo->flags2 & MF2_BOSSNOTRAP)
{
for (i = 0; i < MAXPLAYERS; i++)
{
if (!playeringame[i])
continue;
P_DoPlayerExit(&players[i]);
}
P_DoAllPlayersExit(0, false);
}
else
{
@ -9236,12 +9230,7 @@ void A_ForceWin(mobj_t *actor)
if (i == MAXPLAYERS)
return;
for (i = 0; i < MAXPLAYERS; i++)
{
if (!playeringame[i])
continue;
P_DoPlayerExit(&players[i]);
}
P_DoAllPlayersExit(0, false);
}
// Function: A_SpikeRetract

View file

@ -656,22 +656,7 @@ static void P_AddBrokenPrison(mobj_t *target, mobj_t *source)
if (++numtargets >= maptargets)
{
UINT8 i;
boolean givelife = false;
for (i = 0; i < MAXPLAYERS; i++)
{
if (!playeringame[i] || players[i].spectator)
continue;
P_DoPlayerExit(&players[i]);
if (!G_GametypeUsesLives())
continue;
P_GivePlayerLives(&players[i], 1);
givelife = true;
}
if (givelife)
S_StartSound(NULL, sfx_cdfm73);
P_DoAllPlayersExit(0, (grandprixinfo.gp == true));
}
else
{
@ -692,8 +677,6 @@ static void P_AddBrokenPrison(mobj_t *target, mobj_t *source)
*/
void P_CheckTimeLimit(void)
{
INT32 i;
if (exitcountdown)
return;
@ -751,6 +734,7 @@ void P_CheckTimeLimit(void)
if ((grandprixinfo.gp == false) && (cv_overtime.value) && (gametyperules & GTR_OVERTIME))
{
#ifndef TESTOVERTIMEINFREEPLAY
UINT8 i;
boolean foundone = false; // Overtime is used for closing off down to a specific item.
for (i = 0; i < MAXPLAYERS; i++)
{
@ -812,14 +796,7 @@ void P_CheckTimeLimit(void)
#endif
}
for (i = 0; i < MAXPLAYERS; i++)
{
if (!playeringame[i] || players[i].spectator)
continue;
if (players[i].exiting)
return;
P_DoPlayerExit(&players[i]);
}
P_DoAllPlayersExit(0, false);
}
/** Checks if a player's score is over the pointlimit and the round should end.
@ -864,14 +841,7 @@ void P_CheckPointLimit(void)
if (g_pointlimit <= players[i].roundscore)
{
for (i = 0; i < MAXPLAYERS; i++) // AAAAA nested loop using the same iteration variable ;;
{
if (!playeringame[i] || players[i].spectator)
continue;
if (players[i].exiting)
return;
P_DoPlayerExit(&players[i]);
}
P_DoAllPlayersExit(0, false);
/*if (server)
SendNetXCmd(XD_EXITLEVEL, NULL, 0);*/
@ -1917,8 +1887,7 @@ static boolean P_KillPlayer(player_t *player, mobj_t *inflictor, mobj_t *source,
if (!player->exiting && (specialstageinfo.valid == true || modeattacking & ATTACKING_SPB))
{
player->pflags |= PF_NOCONTEST;
P_DoPlayerExit(player);
P_DoPlayerExit(player, PF_NOCONTEST);
}
if (player->exiting)

View file

@ -206,7 +206,8 @@ void P_TickAltView(altview_t *view);
void P_MovePlayer(player_t *player);
void P_PlayerThink(player_t *player);
void P_PlayerAfterThink(player_t *player);
void P_DoPlayerExit(player_t *player);
void P_DoPlayerExit(player_t *player, pflags_t flags);
void P_DoAllPlayersExit(pflags_t flags, boolean givelife);
void P_DoTimeOver(player_t *player);
void P_CheckRaceGriefing(player_t *player, boolean dopunishment);

View file

@ -2047,16 +2047,17 @@ static void K_HandleLapIncrement(player_t *player)
// finished race exit setup
if (player->laps > numlaps)
{
pflags_t applyflags = 0;
if (specialstageinfo.valid == true)
{
// Don't permit a win just by sneaking ahead of the UFO/emerald.
if (!(specialstageinfo.ufo == NULL || P_MobjWasRemoved(specialstageinfo.ufo)))
{
player->pflags |= PF_NOCONTEST;
applyflags |= PF_NOCONTEST;
}
}
P_DoPlayerExit(player);
P_DoPlayerExit(player, applyflags);
}
else
{
@ -4220,13 +4221,7 @@ boolean P_ProcessSpecial(activator_t *activator, INT16 special, INT32 *args, cha
CONS_Debug(DBG_GAMELOGIC, "Clock stopped!\n");
if (modeattacking)
{
UINT8 i;
for (i = 0; i < MAXPLAYERS; i++)
{
if (!playeringame[i])
continue;
P_DoPlayerExit(&players[i]);
}
P_DoAllPlayersExit(0, false);
}
break;
@ -4271,15 +4266,7 @@ boolean P_ProcessSpecial(activator_t *activator, INT16 special, INT32 *args, cha
if (!(args[1]))
{
INT32 i;
// Mark all players with the time to exit thingy!
for (i = 0; i < MAXPLAYERS; i++)
{
if (!playeringame[i])
continue;
P_DoPlayerExit(&players[i]);
}
P_DoAllPlayersExit(0, false);
}
}
break;
@ -5145,7 +5132,6 @@ static void P_ProcessEggCapsule(player_t *player, sector_t *sector)
{
thinker_t *th;
mobj_t *mo2;
INT32 i;
if (sector->ceilingdata || sector->floordata)
return;
@ -5173,13 +5159,7 @@ static void P_ProcessEggCapsule(player_t *player, sector_t *sector)
// Open the bottom FOF
EV_DoCeiling(LE_CAPSULE2, NULL, lowerToLowestFast);
// Mark all players with the time to exit thingy!
for (i = 0; i < MAXPLAYERS; i++)
{
if (!playeringame[i])
continue;
P_DoPlayerExit(&players[i]);
}
P_DoAllPlayersExit(0, false);
}
static void P_ProcessExitSector(player_t *player, mtag_t sectag)
@ -5192,7 +5172,7 @@ static void P_ProcessExitSector(player_t *player, mtag_t sectag)
#endif
// Exit (for FOF exits; others are handled in P_PlayerThink in p_user.c)
P_DoPlayerExit(player);
P_DoPlayerExit(player, 0);
P_SetupSignExit(player, false);

View file

@ -1257,16 +1257,18 @@ mobj_t *P_SpawnGhostMobj(mobj_t *mobj)
// P_DoPlayerExit
//
// Player exits the map via sector trigger
void P_DoPlayerExit(player_t *player)
void P_DoPlayerExit(player_t *player, pflags_t flags)
{
const boolean losing = K_IsPlayerLosing(player);
const boolean specialout = (specialstageinfo.valid == true && losing == true);
if (player->exiting || mapreset)
{
return;
}
player->pflags |= flags;
const boolean losing = K_IsPlayerLosing(player);
const boolean specialout = (specialstageinfo.valid == true && losing == true);
if (P_IsLocalPlayer(player) && (!player->spectator && !demo.playback))
{
legitimateexit = true;
@ -1366,6 +1368,44 @@ void P_DoPlayerExit(player_t *player)
demo.savebutton = leveltime;
}
//
// P_DoAllPlayersExit
//
// All players exit the map via event
void P_DoAllPlayersExit(pflags_t flags, boolean trygivelife)
{
UINT8 i;
boolean givenlife = false;
for (i = 0; i < MAXPLAYERS; i++)
{
if (!playeringame[i] || players[i].spectator)
{
continue;
}
if (players[i].exiting)
{
continue;
}
P_DoPlayerExit(&players[i], flags);
if (trygivelife == false)
{
continue;
}
P_GivePlayerLives(&players[i], 1);
givenlife = true;
}
if (givenlife)
{
// Life sound
S_StartSound(NULL, sfx_cdfm73);
}
}
//
// P_PlayerHitFloor
//