From 7508e0e1982e70fa42723dce07344e23a2c8f142 Mon Sep 17 00:00:00 2001 From: toaster Date: Mon, 24 Jan 2022 22:03:40 +0000 Subject: [PATCH 1/5] 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. --- src/d_netcmd.c | 2 +- src/k_kart.c | 17 ++++-- src/lua_baselib.c | 4 ++ src/p_local.h | 1 + src/p_user.c | 142 ++++++++++++++++++++++++++++------------------ src/st_stuff.c | 15 +---- 6 files changed, 105 insertions(+), 76 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 416aeb86a..474306704 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -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; diff --git a/src/k_kart.c b/src/k_kart.c index 99f2b1cac..e2b4aa6c2 100644 --- a/src/k_kart.c +++ b/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)); } diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 596f8b158..95e5146c6 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -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; } diff --git a/src/p_local.h b/src/p_local.h index a3d5ecd74..4940daf81 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -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); diff --git a/src/p_user.c b/src/p_user.c index 1e1269751..f8eb8ad38 100644 --- a/src/p_user.c +++ b/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 diff --git a/src/st_stuff.c b/src/st_stuff.c index 3e0788f4d..f64f5c5e7 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -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) { From 4567d9c57f0032bfa6f5badba1ea65246461ca0d Mon Sep 17 00:00:00 2001 From: toaster Date: Fri, 11 Feb 2022 00:35:11 +0000 Subject: [PATCH 2/5] Fix allowteamchange (although this code wasn't being run, it still SHOULD return early...) --- src/p_user.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/p_user.c b/src/p_user.c index f8eb8ad38..d78cfe84b 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -3570,11 +3570,7 @@ boolean P_SpectatorJoinGame(player_t *player) // 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->flashing = TICRATE + 1; //to prevent message spam. - } + return false; // Team changing in Team Match and CTF // Pressing fire assigns you to a team that needs players if allowed. From 03a47cfb5ae1095dc64e84d542318aaf55b5cf02 Mon Sep 17 00:00:00 2001 From: toaster Date: Fri, 11 Feb 2022 01:13:38 +0000 Subject: [PATCH 3/5] Prevent using a grow while invincible resetting the invincible music timer, when that SHOULDN'T be touched and will be set to grow properly once that's over. --- src/k_kart.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/k_kart.c b/src/k_kart.c index e2b4aa6c2..1f961b15b 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -9222,7 +9222,11 @@ void K_MoveKartPlayer(player_t *player, boolean onground) player->growshrinktimer = itemtime+(4*TICRATE); // 12 seconds - if (P_IsLocalPlayer(player) == true) + if (player->invincibilitytimer > 0) + { + ; // invincibility has priority in P_RestoreMusic, no point in starting here + } + else if (P_IsLocalPlayer(player) == true) { S_ChangeMusicSpecial("kgrow"); } From 913610b1b7bdc425c4079ec9dfe9d35c479f8076 Mon Sep 17 00:00:00 2001 From: toaster Date: Fri, 11 Feb 2022 10:38:16 +0000 Subject: [PATCH 4/5] Fixed P_RestoreMusic using displayplayers instead of local players (did not use any of the functions directly and so was missed). --- src/p_user.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/p_user.c b/src/p_user.c index d78cfe84b..30ad2b8d4 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -813,6 +813,7 @@ void P_RestoreMusic(player_t *player) if (r_splitscreen) { INT32 bestlocaltimer = 1; + INT32 *localplayertable = (splitscreen_partied[consoleplayer] ? splitscreen_party[consoleplayer] : g_localplayers); #define setbests(p) \ if (players[p].playerstate == PST_LIVE) \ @@ -822,12 +823,12 @@ void P_RestoreMusic(player_t *player) else if (players[p].growshrinktimer > bestlocaltimer) \ { wantedmus = 2; bestlocaltimer = players[p].growshrinktimer; } \ } - setbests(displayplayers[0]); - setbests(displayplayers[1]); + setbests(localplayertable[0]); + setbests(localplayertable[1]); if (r_splitscreen > 1) - setbests(displayplayers[2]); + setbests(localplayertable[2]); if (r_splitscreen > 2) - setbests(displayplayers[3]); + setbests(localplayertable[3]); #undef setbests } else From 006b6f00ac57157549c337041c466620f3b94211 Mon Sep 17 00:00:00 2001 From: toaster Date: Fri, 11 Feb 2022 12:09:00 +0000 Subject: [PATCH 5/5] Rewrite the awayview reset for both Got_Teamchange and P_SpectatorJoinGame. --- src/d_netcmd.c | 19 ++++++++++++------- src/p_user.c | 28 +++++++++------------------- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 474306704..2bdc8d66e 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -3459,15 +3459,20 @@ static void Got_Teamchange(UINT8 **cp, INT32 playernum) else if (NetPacket.packet.newteam == 0) HU_AddChatText(va("\x82*%s became a spectator.", player_names[playernum]), false); // "entered the game" text was moved to P_SpectatorJoinGame - //reset view if you are changed, or viewing someone who was changed. - if (playernum == consoleplayer || displayplayers[0] == playernum) + // Reset away view (some code referenced from P_SpectatorJoinGame) { - // Call ViewpointSwitch hooks here. - // The viewpoint was forcibly changed. - if (displayplayers[0] != consoleplayer) // You're already viewing yourself. No big deal. - LUAh_ViewpointSwitch(&players[consoleplayer], &players[consoleplayer], true); + UINT8 i = 0; + INT32 *localplayertable = (splitscreen_partied[consoleplayer] ? splitscreen_party[consoleplayer] : g_localplayers); - displayplayers[0] = consoleplayer; + for (i = 0; i < r_splitscreen; i++) + { + if (localplayertable[i] == playernum) + { + LUAh_ViewpointSwitch(players+playernum, players+playernum, true); + displayplayers[i] = playernum; + break; + } + } } /*if (G_GametypeHasTeams()) diff --git a/src/p_user.c b/src/p_user.c index 30ad2b8d4..7a36121dd 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -3620,29 +3620,19 @@ boolean P_SpectatorJoinGame(player_t *player) player->ctfteam = changeto; player->playerstate = PST_REBORN; - // Reset away view (some code referenced from P_IsLocalPlayer) + // Reset away view (some code referenced from Got_Teamchange) { 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; - } - } + INT32 *localplayertable = (splitscreen_partied[consoleplayer] ? splitscreen_party[consoleplayer] : g_localplayers); - 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)) + for (i = 0; i < r_splitscreen; i++) { - LUAh_ViewpointSwitch(player, player, true); - displayplayers[i-1] = (player-players); + if (localplayertable[i] == (player-players)) + { + LUAh_ViewpointSwitch(player, player, true); + displayplayers[i] = (player-players); + break; + } } }