mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-12-27 18:24:40 +00:00
P_IsLocalPlayer changes
This is the function that controls whether a bunch of music-related function (and also whether certain error messages get printed). * P_IsLocalPlayer now supports party players (currently untested, but the code is pretty airtight). * P_IsLocalPlayer now always returns false in replays. * P_IsMachineLocalPlayer now exists for the one situation the game determines local players that actually has a net-related function (kicking illegal character changes). * Invincibility/grow sfx now operates based on whether the player is NOT local (it used to be whether it was NOT a displayplayer). * Refactored P_SpectatorJoinGame to make future team support easier, and also reset the relevant camera focus, rather than always the consoleplayer's. * Fix viewpoints on non-local players having overlapping viewpoint text.
This commit is contained in:
parent
4b1cef0f20
commit
7508e0e198
6 changed files with 105 additions and 76 deletions
|
|
@ -1560,7 +1560,7 @@ static void Got_NameAndColor(UINT8 **cp, INT32 playernum)
|
|||
demo_extradata[playernum] |= DXD_COLOR;
|
||||
|
||||
// normal player colors
|
||||
if (server && !P_IsLocalPlayer(p))
|
||||
if (server && !P_IsMachineLocalPlayer(p))
|
||||
{
|
||||
boolean kick = false;
|
||||
|
||||
|
|
|
|||
17
src/k_kart.c
17
src/k_kart.c
|
|
@ -6597,7 +6597,7 @@ static void K_UpdateInvincibilitySounds(player_t *player)
|
|||
{
|
||||
INT32 sfxnum = sfx_None;
|
||||
|
||||
if (player->mo->health > 0 && !P_IsDisplayPlayer(player))
|
||||
if (player->mo->health > 0 && !P_IsLocalPlayer(player)) // used to be !P_IsDisplayPlayer(player)
|
||||
{
|
||||
if (cv_kartinvinsfx.value)
|
||||
{
|
||||
|
|
@ -8989,10 +8989,16 @@ void K_MoveKartPlayer(player_t *player, boolean onground)
|
|||
P_SetScale(overlay, player->mo->scale);
|
||||
}
|
||||
player->invincibilitytimer = itemtime+(2*TICRATE); // 10 seconds
|
||||
if (P_IsLocalPlayer(player))
|
||||
|
||||
if (P_IsLocalPlayer(player) == true)
|
||||
{
|
||||
S_ChangeMusicSpecial("kinvnc");
|
||||
if (! P_IsDisplayPlayer(player))
|
||||
S_StartSound(player->mo, (cv_kartinvinsfx.value ? sfx_alarmg : sfx_kinvnc));
|
||||
}
|
||||
else //used to be "if (P_IsDisplayPlayer(player) == false)"
|
||||
{
|
||||
S_StartSound(player->mo, (cv_kartinvinsfx.value ? sfx_alarmi : sfx_kinvnc));
|
||||
}
|
||||
|
||||
P_RestoreMusic(player);
|
||||
K_PlayPowerGloatSound(player->mo);
|
||||
player->itemamount--;
|
||||
|
|
@ -9220,8 +9226,7 @@ void K_MoveKartPlayer(player_t *player, boolean onground)
|
|||
{
|
||||
S_ChangeMusicSpecial("kgrow");
|
||||
}
|
||||
|
||||
if (P_IsDisplayPlayer(player) == false)
|
||||
else //used to be "if (P_IsDisplayPlayer(player) == false)"
|
||||
{
|
||||
S_StartSound(player->mo, (cv_kartinvinsfx.value ? sfx_alarmg : sfx_kgrow));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -682,6 +682,7 @@ static int lib_pSpawnLockOn(lua_State *L)
|
|||
return LUA_ErrInvalid(L, "player_t");
|
||||
if (state >= NUMSTATES)
|
||||
return luaL_error(L, "state %d out of range (0 - %d)", state, NUMSTATES-1);
|
||||
#if 0
|
||||
if (P_IsLocalPlayer(player)) // Only display it on your own view.
|
||||
{
|
||||
mobj_t *visual = P_SpawnMobj(lockon->x, lockon->y, lockon->z, MT_LOCKON); // positioning, flip handled in P_SceneryThinker
|
||||
|
|
@ -689,6 +690,9 @@ static int lib_pSpawnLockOn(lua_State *L)
|
|||
visual->renderflags |= RF_DONTDRAW;
|
||||
P_SetMobjStateNF(visual, state);
|
||||
}
|
||||
#else
|
||||
CONS_Alert(CONS_WARNING, "TODO: P_SpawnLockOn is deprecated\n");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -155,6 +155,7 @@ void P_ResetPlayer(player_t *player);
|
|||
boolean P_PlayerCanDamage(player_t *player, mobj_t *thing);
|
||||
|
||||
boolean P_IsLocalPlayer(player_t *player);
|
||||
boolean P_IsMachineLocalPlayer(player_t *player);
|
||||
boolean P_IsDisplayPlayer(player_t *player);
|
||||
|
||||
void P_SetPlayerAngle(player_t *player, angle_t angle);
|
||||
|
|
|
|||
142
src/p_user.c
142
src/p_user.c
|
|
@ -1070,19 +1070,16 @@ void P_SetObjectMomZ(mobj_t *mo, fixed_t value, boolean relative)
|
|||
}
|
||||
|
||||
//
|
||||
// P_IsLocalPlayer
|
||||
// P_IsMachineLocalPlayer
|
||||
//
|
||||
// Returns true if player is
|
||||
// on the local machine.
|
||||
// ACTUALLY on the local machine
|
||||
//
|
||||
boolean P_IsLocalPlayer(player_t *player)
|
||||
boolean P_IsMachineLocalPlayer(player_t *player)
|
||||
{
|
||||
UINT8 i;
|
||||
|
||||
if (demo.playback)
|
||||
return P_IsDisplayPlayer(player);
|
||||
|
||||
for (i = 0; i <= r_splitscreen; i++) // DON'T skip P1
|
||||
for (i = 0; i <= r_splitscreen; i++)
|
||||
{
|
||||
if (player == &players[g_localplayers[i]])
|
||||
return true;
|
||||
|
|
@ -1091,6 +1088,35 @@ boolean P_IsLocalPlayer(player_t *player)
|
|||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// P_IsLocalPlayer
|
||||
//
|
||||
// Returns true if player is
|
||||
// on the local machine
|
||||
// (or simulated party)
|
||||
//
|
||||
boolean P_IsLocalPlayer(player_t *player)
|
||||
{
|
||||
UINT8 i;
|
||||
|
||||
// nobody is ever local when watching something back - you're a spectator there, even if your g_localplayers might say otherwise
|
||||
if (demo.playback)
|
||||
return false;
|
||||
|
||||
// parties - treat everyone as if it's couch co-op
|
||||
if (splitscreen_partied[consoleplayer])
|
||||
{
|
||||
for (i = 0; i < splitscreen_party_size[consoleplayer]; i++)
|
||||
{
|
||||
if (splitscreen_party[consoleplayer][i] == (player-players))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return P_IsMachineLocalPlayer(player);
|
||||
}
|
||||
|
||||
//
|
||||
// P_IsDisplayPlayer
|
||||
//
|
||||
|
|
@ -3539,6 +3565,9 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall
|
|||
|
||||
boolean P_SpectatorJoinGame(player_t *player)
|
||||
{
|
||||
INT32 changeto = 0;
|
||||
const char *text = NULL;
|
||||
|
||||
// Team changing isn't allowed.
|
||||
if (!cv_allowteamchange.value)
|
||||
{
|
||||
|
|
@ -3546,12 +3575,13 @@ boolean P_SpectatorJoinGame(player_t *player)
|
|||
CONS_Printf(M_GetText("Server does not allow team change.\n"));
|
||||
//player->flashing = TICRATE + 1; //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.
|
||||
else if (G_GametypeHasTeams())
|
||||
// a surprise tool that will help us later...
|
||||
if (G_GametypeHasTeams())
|
||||
{
|
||||
INT32 changeto = 0;
|
||||
INT32 z, numplayersred = 0, numplayersblue = 0;
|
||||
|
||||
//find a team by num players, score, or random if all else fails.
|
||||
|
|
@ -3578,55 +3608,57 @@ boolean P_SpectatorJoinGame(player_t *player)
|
|||
|
||||
if (!LUAh_TeamSwitch(player, changeto, true, false, false))
|
||||
return false;
|
||||
|
||||
if (player->mo)
|
||||
{
|
||||
P_RemoveMobj(player->mo);
|
||||
player->mo = NULL;
|
||||
}
|
||||
player->spectator = false;
|
||||
player->pflags &= ~PF_WANTSTOJOIN;
|
||||
player->spectatewait = 0;
|
||||
player->ctfteam = changeto;
|
||||
player->playerstate = PST_REBORN;
|
||||
|
||||
//Reset away view
|
||||
if (P_IsLocalPlayer(player) && displayplayers[0] != consoleplayer)
|
||||
{
|
||||
// Call ViewpointSwitch hooks here.
|
||||
// The viewpoint was forcibly changed.
|
||||
LUAh_ViewpointSwitch(player, &players[consoleplayer], true);
|
||||
displayplayers[0] = consoleplayer;
|
||||
}
|
||||
|
||||
if (changeto == 1)
|
||||
CONS_Printf(M_GetText("%s switched to the %c%s%c.\n"), player_names[player-players], '\x85', M_GetText("Red team"), '\x80');
|
||||
else if (changeto == 2)
|
||||
CONS_Printf(M_GetText("%s switched to the %c%s%c.\n"), player_names[player-players], '\x84', M_GetText("Blue team"), '\x80');
|
||||
|
||||
return true; // no more player->mo, cannot continue.
|
||||
}
|
||||
// Joining in game from firing.
|
||||
else
|
||||
|
||||
// no conditions that could cause the gamejoin to fail below this line
|
||||
|
||||
if (player->mo)
|
||||
{
|
||||
if (player->mo)
|
||||
{
|
||||
P_RemoveMobj(player->mo);
|
||||
player->mo = NULL;
|
||||
}
|
||||
player->spectator = false;
|
||||
player->pflags &= ~PF_WANTSTOJOIN;
|
||||
player->spectatewait = 0;
|
||||
player->playerstate = PST_REBORN;
|
||||
|
||||
//Reset away view
|
||||
if (P_IsLocalPlayer(player) && displayplayers[0] != consoleplayer)
|
||||
displayplayers[0] = consoleplayer;
|
||||
|
||||
HU_AddChatText(va(M_GetText("\x82*%s entered the game."), player_names[player-players]), false);
|
||||
return true; // no more player->mo, cannot continue.
|
||||
P_RemoveMobj(player->mo);
|
||||
player->mo = NULL;
|
||||
}
|
||||
return false;
|
||||
player->spectator = false;
|
||||
player->pflags &= ~PF_WANTSTOJOIN;
|
||||
player->spectatewait = 0;
|
||||
player->ctfteam = changeto;
|
||||
player->playerstate = PST_REBORN;
|
||||
|
||||
// Reset away view (some code referenced from P_IsLocalPlayer)
|
||||
{
|
||||
UINT8 i = 0;
|
||||
if (splitscreen_partied[consoleplayer])
|
||||
{
|
||||
for (i = splitscreen_party_size[consoleplayer]; i > 0; i--)
|
||||
{
|
||||
if (splitscreen_party[consoleplayer][i-1] == (player-players))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == 0)
|
||||
for (i = r_splitscreen; i > 0; i--)
|
||||
{
|
||||
if (g_localplayers[i-1] == (player-players))
|
||||
break;
|
||||
}
|
||||
|
||||
if (i && displayplayers[i-1] != (player-players))
|
||||
{
|
||||
LUAh_ViewpointSwitch(player, player, true);
|
||||
displayplayers[i-1] = (player-players);
|
||||
}
|
||||
}
|
||||
|
||||
// a surprise tool that will help us later...
|
||||
if (changeto == 1)
|
||||
text = va("\x82*%s switched to the %c%s%c team.\n", player_names[player-players], '\x85', "RED", '\x82');
|
||||
else if (changeto == 2)
|
||||
text = va("\x82*%s switched to the %c%s%c team.\n", player_names[player-players], '\x85', "BLU", '\x82');
|
||||
else
|
||||
text = va("\x82*%s entered the game.", player_names[player-players]);
|
||||
|
||||
HU_AddChatText(text, false);
|
||||
return true; // no more player->mo, cannot continue.
|
||||
}
|
||||
|
||||
// the below is first person only, if you're curious. check out P_CalcChasePostImg in p_mobj.c for chasecam
|
||||
|
|
|
|||
|
|
@ -1074,20 +1074,7 @@ static void ST_overlayDrawer(void)
|
|||
{
|
||||
if (cv_showviewpointtext.value)
|
||||
{
|
||||
if (!(multiplayer && demo.playback))
|
||||
{
|
||||
if(!P_IsLocalPlayer(stplyr))
|
||||
{
|
||||
/*char name[MAXPLAYERNAME+1];
|
||||
// shorten the name if its more than twelve characters.
|
||||
strlcpy(name, player_names[stplyr-players], 13);*/
|
||||
|
||||
// Show name of player being displayed
|
||||
V_DrawCenteredString((BASEVIDWIDTH/2), BASEVIDHEIGHT-40, 0, M_GetText("VIEWPOINT:"));
|
||||
V_DrawCenteredString((BASEVIDWIDTH/2), BASEVIDHEIGHT-32, V_ALLOWLOWERCASE, player_names[stplyr-players]);
|
||||
}
|
||||
}
|
||||
else if (!demo.title)
|
||||
if (!demo.title && !P_IsLocalPlayer(stplyr))
|
||||
{
|
||||
if (!r_splitscreen)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue