Refactor view changes a bit

This commit is contained in:
fickleheart 2019-02-01 19:46:58 -06:00
parent 0ab690bc60
commit 4de79f13af
3 changed files with 103 additions and 61 deletions

View file

@ -2561,8 +2561,10 @@ void CL_RemovePlayer(INT32 playernum, INT32 reason)
RemoveAdminPlayer(playernum); // don't stay admin after you're gone
}
if (playernum == displayplayer)
if (playernum == displayplayer && !demoplayback)
displayplayer = consoleplayer; // don't look through someone's view who isn't there
else
G_ResetViews();
#ifdef HAVE_BLUA
LUA_InvalidatePlayer(&players[playernum]);

View file

@ -1807,67 +1807,9 @@ boolean G_Responder(event_t *ev)
if (!demoplayback && (splitscreen || !netgame))
displayplayer = consoleplayer;
else
{
UINT8 i = 0; // spy mode
for (i = 0; i < MAXPLAYERS; i++)
{
displayplayer++;
if (displayplayer == MAXPLAYERS)
displayplayer = 0;
if (!demoplayback && displayplayer == consoleplayer)
break; // End loop
if (displayplayer == secondarydisplayplayer || displayplayer == thirddisplayplayer || displayplayer == fourthdisplayplayer)
continue;
if (!playeringame[displayplayer])
continue;
if (players[displayplayer].spectator)
continue;
// SRB2Kart: Only go through players who are actually playing
if (players[displayplayer].exiting)
continue;
if (players[displayplayer].pflags & PF_TIMEOVER)
continue;
// I don't know if we want this actually, but I'll humor the suggestion anyway
if (G_BattleGametype())
{
if (players[displayplayer].kartstuff[k_bumper] <= 0)
continue;
}
// SRB2Kart: we have no team-based modes, YET...
/*if (G_GametypeHasTeams())
{
if (players[consoleplayer].ctfteam
&& players[displayplayer].ctfteam != players[consoleplayer].ctfteam)
continue;
}
else if (gametype == GT_HIDEANDSEEK)
{
if (players[consoleplayer].pflags & PF_TAGIT)
continue;
}
// Other Tag-based gametypes?
else if (G_TagGametype())
{
if (!players[consoleplayer].spectator
&& (players[consoleplayer].pflags & PF_TAGIT) != (players[displayplayer].pflags & PF_TAGIT))
continue;
}
else if (G_GametypeHasSpectators() && G_BattleGametype())
{
if (!players[consoleplayer].spectator)
continue;
}*/
break;
}
G_ResetViews();
// change statusbar also if playing back demo
if (singledemo)
@ -2076,6 +2018,102 @@ boolean G_Responder(event_t *ev)
return false;
}
static INT32 G_FindView(INT32 startview)
{
UINT8 i = 0; // spy mode
startview--; // Ensures view doesn't move if the current view is valid
for (i = 0; i < MAXPLAYERS; i++)
{
startview++;
if (startview == MAXPLAYERS)
startview = 0;
if (!demoplayback && startview == consoleplayer)
break; // End loop
if (startview == displayplayer || startview == secondarydisplayplayer || startview == thirddisplayplayer || startview == fourthdisplayplayer)
continue;
if (!playeringame[startview])
continue;
if (players[startview].spectator)
continue;
// SRB2Kart: Only go through players who are actually playing
if (players[startview].exiting)
continue;
if (players[startview].pflags & PF_TIMEOVER)
continue;
// I don't know if we want this actually, but I'll humor the suggestion anyway
if (G_BattleGametype())
{
if (players[startview].kartstuff[k_bumper] <= 0)
continue;
}
// SRB2Kart: we have no team-based modes, YET...
/*if (G_GametypeHasTeams())
{
if (players[consoleplayer].ctfteam
&& players[startview].ctfteam != players[consoleplayer].ctfteam)
continue;
}
else if (gametype == GT_HIDEANDSEEK)
{
if (players[consoleplayer].pflags & PF_TAGIT)
continue;
}
// Other Tag-based gametypes?
else if (G_TagGametype())
{
if (!players[consoleplayer].spectator
&& (players[consoleplayer].pflags & PF_TAGIT) != (players[startview].pflags & PF_TAGIT))
continue;
}
else if (G_GametypeHasSpectators() && G_BattleGametype())
{
if (!players[consoleplayer].spectator)
continue;
}*/
break;
}
return startview;
}
//
// G_ResetViews
// Ensures all viewpoints are valid
//
void G_ResetViews(void)
{
INT32 tempplayer;
tempplayer = displayplayer;
displayplayer = INT32_MAX;
displayplayer = G_FindView(tempplayer);
tempplayer = secondarydisplayplayer;
secondarydisplayplayer = INT32_MAX;
secondarydisplayplayer = G_FindView(tempplayer);
tempplayer = thirddisplayplayer;
thirddisplayplayer = INT32_MAX;
thirddisplayplayer = G_FindView(tempplayer);
tempplayer = fourthdisplayplayer;
fourthdisplayplayer = INT32_MAX;
fourthdisplayplayer = G_FindView(tempplayer);
if (demoplayback)
consoleplayer = displayplayer;
}
//
// G_Ticker
// Make ticcmd_ts for the players.

View file

@ -226,6 +226,8 @@ void G_EndGame(void); // moved from y_inter.c/h and renamed
void G_Ticker(boolean run);
boolean G_Responder(event_t *ev);
void G_ResetViews(void);
void G_AddPlayer(INT32 playernum);
void G_SetExitGameFlag(void);