Spectator overhaul

- New player flag, PF_WANTSTOJOIN, added for setting up a spectator queue. You are allowed to join as long as no one has started lap 2.
- Map resets when two people have entered the game, so matches can start naturally without the need of an admin.
This commit is contained in:
TehRealSalt 2018-07-20 19:11:36 -04:00
parent a69eef9d82
commit 6eaed1ac7b
10 changed files with 92 additions and 75 deletions

View File

@ -3117,12 +3117,12 @@ static void Got_Teamchange(UINT8 **cp, INT32 playernum)
{
if (!players[playernum].spectator)
P_DamageMobj(players[playernum].mo, NULL, NULL, 10000);
else
/*else
{
P_RemoveMobj(players[playernum].mo);
players[playernum].mo = NULL;
players[playernum].playerstate = PST_REBORN;
}
}*/
}
else
players[playernum].playerstate = PST_REBORN;
@ -3139,7 +3139,7 @@ static void Got_Teamchange(UINT8 **cp, INT32 playernum)
}
else if (NetPacket.packet.newteam != 3) // .newteam == 1 or 2.
{
players[playernum].spectator = false;
players[playernum].pflags |= PF_WANTSTOJOIN; //players[playernum].spectator = false;
players[playernum].pflags &= ~PF_TAGGED;//Just in case.
if (NetPacket.packet.newteam == 1) //Make the player IT.
@ -3149,7 +3149,7 @@ static void Got_Teamchange(UINT8 **cp, INT32 playernum)
}
else // Just join the game.
{
players[playernum].spectator = false;
players[playernum].pflags |= PF_WANTSTOJOIN; //players[playernum].spectator = false;
//If joining after hidetime in normal tag, default to being IT.
if (gametype == GT_TAG && (leveltime > (hidetime * TICRATE)))
@ -3169,7 +3169,7 @@ static void Got_Teamchange(UINT8 **cp, INT32 playernum)
else
{
players[playernum].ctfteam = NetPacket.packet.newteam;
players[playernum].spectator = false;
players[playernum].pflags |= PF_WANTSTOJOIN; //players[playernum].spectator = false;
}
}
else if (G_GametypeHasSpectators())
@ -3177,7 +3177,7 @@ static void Got_Teamchange(UINT8 **cp, INT32 playernum)
if (!NetPacket.packet.newteam)
players[playernum].spectator = true;
else
players[playernum].spectator = false;
players[playernum].pflags |= PF_WANTSTOJOIN; //players[playernum].spectator = false;
}
if (NetPacket.packet.autobalance)
@ -3209,7 +3209,7 @@ static void Got_Teamchange(UINT8 **cp, INT32 playernum)
CONS_Printf(M_GetText("%s switched to the %c%s%c.\n"), player_names[playernum], '\x84', M_GetText("Blue Team"), '\x80');
}
else if (NetPacket.packet.newteam == 3)
CONS_Printf(M_GetText("%s entered the game.\n"), player_names[playernum]);
/*CONS_Printf(M_GetText("%s entered the game.\n"), player_names[playernum])*/;
else
CONS_Printf(M_GetText("%s became a spectator.\n"), player_names[playernum]);

View File

@ -108,8 +108,8 @@ typedef enum
// Did you get a time-over?
PF_TIMEOVER = 1<<10,
// Ready for Super?
PF_SUPERREADY = 1<<11,
// SRB2Kart: Spectator that wants to join
PF_WANTSTOJOIN = 1<<11,
// Character action status
PF_JUMPED = 1<<12,

View File

@ -7383,8 +7383,8 @@ static const char *const PLAYERFLAG_LIST[] = {
// Did you get a time-over?
"TIMEOVER",
// Ready for Super?
"SUPERREADY",
// SRB2Kart: spectator that wants to join
"WANTSTOJOIN",
// Character action status
"JUMPED",

View File

@ -2174,6 +2174,9 @@ void G_Ticker(boolean run)
if (run)
{
if (G_GametypeHasSpectators() && (gamestate == GS_LEVEL || gamestate == GS_INTERMISSION || gamestate == GS_VOTING))
K_CheckSpectateStatus();
if (pausedelay)
pausedelay--;

View File

@ -3355,10 +3355,6 @@ void K_MoveKartPlayer(player_t *player, boolean onground)
if (player->kartstuff[k_positiondelay])
player->kartstuff[k_positiondelay]--;
// Race force spectate
if (player->spectator && netgame && G_RaceGametype() && P_FindHighestLap() > 0)
player->powers[pw_flashing] = 5;
if ((player->pflags & PF_ATTACKDOWN) && !(cmd->buttons & BT_ATTACK))
player->pflags &= ~PF_ATTACKDOWN;
else if (cmd->buttons & BT_ATTACK)
@ -4058,6 +4054,49 @@ void K_CheckBumpers(void)
P_DoPlayerExit(&players[i]);
}
void K_CheckSpectateStatus(void)
{
UINT8 respawnlist[MAXPLAYERS];
UINT8 i, no = 0;
UINT8 numingame = 0, numjoiners = 0;
for (i = 0; i < MAXPLAYERS; i++)
{
if (!playeringame[i])
continue;
if (!players[i].spectator)
{
numingame++;
if (gamestate != GS_LEVEL)
continue;
if (G_RaceGametype() && players[i].laps > 0)
return;
}
if (cv_allowteamchange.value && !(players[i].pflags & PF_WANTSTOJOIN))
continue;
respawnlist[no++] = i;
}
numjoiners = no; // Move the map change stuff up here when it gets a delay, and remove this redundant numjoiners var
while (no)
P_SpectatorJoinGame(&players[respawnlist[--no]]);
if (!server)
return;
// Reset the match if you're in an empty server, TODO: put it on a short 5-10 second timer, so you have a chance to roam.
if (gamestate == GS_LEVEL && (numingame < 2 && numingame+numjoiners >= 2))
{
CONS_Printf("Here comes a new challenger! Resetting map...\n");
D_MapChange(gamemap, gametype, ultimatemode, true, 0, false, false);
return;
}
}
//}
//{ SRB2kart HUD Code

View File

@ -50,6 +50,7 @@ fixed_t K_3dKartMovement(player_t *player, boolean onground, fixed_t forwardmove
void K_MoveKartPlayer(player_t *player, boolean onground);
void K_CalculateBattleWanted(void);
void K_CheckBumpers(void);
void K_CheckSpectateStatus(void);
INT32 K_calcSplitFlags(INT32 snapflags);
void K_LoadKartHUDGraphics(void);

View File

@ -897,7 +897,7 @@ static int lib_pHomingAttack(lua_State *L)
return 0;
}
static int lib_pSuperReady(lua_State *L)
/*static int lib_pSuperReady(lua_State *L)
{
player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
//HUDSAFE
@ -905,7 +905,7 @@ static int lib_pSuperReady(lua_State *L)
return LUA_ErrInvalid(L, "player_t");
lua_pushboolean(L, P_SuperReady(player));
return 1;
}
}*/
static int lib_pDoJump(lua_State *L)
{
@ -2313,7 +2313,7 @@ static luaL_Reg lib[] = {
{"P_LookForEnemies",lib_pLookForEnemies},
{"P_NukeEnemies",lib_pNukeEnemies},
{"P_HomingAttack",lib_pHomingAttack},
{"P_SuperReady",lib_pSuperReady},
//{"P_SuperReady",lib_pSuperReady},
{"P_DoJump",lib_pDoJump},
{"P_SpawnThokMobj",lib_pSpawnThokMobj},
{"P_SpawnSpinMobj",lib_pSpawnSpinMobj},

View File

@ -179,7 +179,7 @@ void P_InstaThrustEvenIn2D(mobj_t *mo, angle_t angle, fixed_t move);
boolean P_LookForEnemies(player_t *player);
void P_NukeEnemies(mobj_t *inflictor, mobj_t *source, fixed_t radius);
void P_HomingAttack(mobj_t *source, mobj_t *enemy); /// \todo doesn't belong in p_user
boolean P_SuperReady(player_t *player);
//boolean P_SuperReady(player_t *player);
void P_DoJump(player_t *player, boolean soundandstate);
boolean P_AnalogMove(player_t *player);
boolean P_TransferToNextMare(player_t *player);

View File

@ -3557,10 +3557,10 @@ static void P_DoSuperStuff(player_t *player)
return; // NiGHTS Super doesn't mix with normal super
// Does player have all emeralds? If so, flag the "Ready For Super!"
if ((ALL7EMERALDS(emeralds) || ALL7EMERALDS(player->powers[pw_emeralds])) && player->health > 50)
/*if ((ALL7EMERALDS(emeralds) || ALL7EMERALDS(player->powers[pw_emeralds])) && player->health > 50)
player->pflags |= PF_SUPERREADY;
else
player->pflags &= ~PF_SUPERREADY;
player->pflags &= ~PF_SUPERREADY;*/
if (player->powers[pw_super])
{
@ -3686,7 +3686,7 @@ static void P_DoSuperStuff(player_t *player)
//
// Returns true if player is ready to turn super, duh
//
boolean P_SuperReady(player_t *player)
/*boolean P_SuperReady(player_t *player)
{
if ((player->pflags & PF_SUPERREADY) && !player->powers[pw_super] && !player->powers[pw_tailsfly]
&& !(player->powers[pw_shield] & SH_NOSTACK)
@ -3697,7 +3697,7 @@ boolean P_SuperReady(player_t *player)
return true;
return false;
}
}*/
//
// P_DoJump
@ -8807,20 +8807,13 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall
boolean P_SpectatorJoinGame(player_t *player)
{
if (!G_GametypeHasSpectators() && G_IsSpecialStage(gamemap) && useNightsSS) // Special Stage spectators should NEVER be allowed to rejoin the game
{
if (P_IsLocalPlayer(player))
CONS_Printf(M_GetText("You cannot enter the game while a special stage is in progress.\n"));
player->powers[pw_flashing] += 2*TICRATE; //to prevent message spam.
}
else if (!cv_allowteamchange.value)
// Team changing isn't allowed.
if (!cv_allowteamchange.value)
{
if (P_IsLocalPlayer(player))
CONS_Printf(M_GetText("Server does not allow team change.\n"));
player->powers[pw_flashing] += 2*TICRATE; //to prevent message spam.
}
// Team changing in Team Match and CTF
// Pressing fire assigns you to a team that needs players if allowed.
// Partial code reproduction from p_tick.c autobalance code.
@ -8857,6 +8850,7 @@ boolean P_SpectatorJoinGame(player_t *player)
player->mo = NULL;
}
player->spectator = false;
player->pflags &= ~PF_WANTSTOJOIN;
player->ctfteam = changeto;
player->playerstate = PST_REBORN;
@ -8874,43 +8868,21 @@ boolean P_SpectatorJoinGame(player_t *player)
// Joining in game from firing.
else
{
// Exception for hide and seek. Don't join a game when you simply
// respawn in place and sit there for the rest of the round.
if (!(gametype == GT_HIDEANDSEEK && leveltime > (hidetime * TICRATE)))
if (player->mo)
{
if (player->mo)
{
P_RemoveMobj(player->mo);
player->mo = NULL;
}
player->spectator = false;
player->playerstate = PST_REBORN;
if (gametype == GT_TAG)
{
//Make joining players "it" after hidetime.
if (leveltime > (hidetime * TICRATE))
{
CONS_Printf(M_GetText("%s is now IT!\n"), player_names[player-players]); // Tell everyone who is it!
player->pflags |= PF_TAGIT;
}
P_CheckSurvivors();
}
//Reset away view
if (P_IsLocalPlayer(player) && displayplayer != consoleplayer)
displayplayer = consoleplayer;
CONS_Printf(M_GetText("%s entered the game.\n"), player_names[player-players]);
return true; // no more player->mo, cannot continue.
}
else
{
if (P_IsLocalPlayer(player))
CONS_Printf(M_GetText("You must wait until next round to enter the game.\n"));
player->powers[pw_flashing] += 2*TICRATE; //to prevent message spam.
P_RemoveMobj(player->mo);
player->mo = NULL;
}
player->spectator = false;
player->pflags &= ~PF_WANTSTOJOIN;
player->playerstate = PST_REBORN;
//Reset away view
if (P_IsLocalPlayer(player) && displayplayer != consoleplayer)
displayplayer = consoleplayer;
CONS_Printf(M_GetText("%s entered the game.\n"), player_names[player-players]);
return true; // no more player->mo, cannot continue.
}
return false;
}
@ -9328,8 +9300,10 @@ void P_PlayerThink(player_t *player)
if ((netgame || splitscreen) && player->spectator && cmd->buttons & BT_ATTACK && !player->powers[pw_flashing])
{
if (P_SpectatorJoinGame(player))
return; // player->mo was removed.
player->pflags ^= PF_WANTSTOJOIN;
player->powers[pw_flashing] += 2*TICRATE;
/*if (P_SpectatorJoinGame(player))
return; // player->mo was removed.*/
}
// Even if not NiGHTS, pull in nearby objects when walking around as John Q. Elliot.

View File

@ -1952,12 +1952,12 @@ static void ST_overlayDrawer(void)
{
// SRB2kart: changed positions & text
V_DrawString(2, BASEVIDHEIGHT-50, V_HUDTRANSHALF|V_YELLOWMAP, M_GetText("- SPECTATING -"));
/*if (G_GametypeHasTeams())
V_DrawString(2, BASEVIDHEIGHT-40, V_HUDTRANSHALF, M_GetText("Item - Join Team"));
else if (G_IsSpecialStage(gamemap) && useNightsSS)
V_DrawString(2, BASEVIDHEIGHT-40, V_HUDTRANSHALF|V_REDMAP, M_GetText("- CANNOT JOIN -"));
else*/
V_DrawString(2, BASEVIDHEIGHT-40, V_HUDTRANSHALF, M_GetText("Item - Enter Game"));
if (stplyr->pflags & PF_WANTSTOJOIN)
V_DrawString(2, BASEVIDHEIGHT-40, V_HUDTRANSHALF, M_GetText("Item - Cancel Join"));
/*else if (G_GametypeHasTeams())
V_DrawString(2, BASEVIDHEIGHT-40, V_HUDTRANSHALF, M_GetText("Item - Join Team"));*/
else
V_DrawString(2, BASEVIDHEIGHT-40, V_HUDTRANSHALF, M_GetText("Item - Join Game"));
V_DrawString(2, BASEVIDHEIGHT-30, V_HUDTRANSHALF, M_GetText("F12 - Change View"));
V_DrawString(2, BASEVIDHEIGHT-20, V_HUDTRANSHALF, M_GetText("Accelerate - Float"));
V_DrawString(2, BASEVIDHEIGHT-10, V_HUDTRANSHALF, M_GetText("Brake - Sink"));