From fde640726668cd8cc68773fe6e237c7e32d44fc5 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 22 Nov 2020 13:28:20 +0100 Subject: [PATCH] - removed the local duplication of the player name in Blood. Using the global CVAR instead - once multiplayer support is in this will work for all players. --- source/blood/src/blood.cpp | 1 - source/blood/src/endgame.cpp | 2 +- source/blood/src/loadsave.cpp | 1 - source/blood/src/player.cpp | 22 +++++++++++----------- source/blood/src/player.h | 2 +- source/blood/src/sbar.cpp | 5 +++-- source/blood/src/view.cpp | 6 +++--- source/core/gamecvars.h | 6 ++++++ 8 files changed, 25 insertions(+), 20 deletions(-) diff --git a/source/blood/src/blood.cpp b/source/blood/src/blood.cpp index 70c331c9f..1c9f423e1 100644 --- a/source/blood/src/blood.cpp +++ b/source/blood/src/blood.cpp @@ -531,7 +531,6 @@ static void gameInit() gMe = gView = &gPlayer[myconnectindex]; PROFILE* pProfile = &gProfile[myconnectindex]; - strcpy(pProfile->name, playername); pProfile->skill = gSkill; UpdateNetworkMenus(); diff --git a/source/blood/src/endgame.cpp b/source/blood/src/endgame.cpp index 8395ffa3a..e79c8a7e0 100644 --- a/source/blood/src/endgame.cpp +++ b/source/blood/src/endgame.cpp @@ -126,7 +126,7 @@ class DBloodSummaryScreen : public DScreenJob { mysnprintf(pBuffer, 40, "%-2d", i); viewDrawText(3, pBuffer, 85, 50 + 8 * i, -128, 0, 0, 1); - mysnprintf(pBuffer, 40, "%s", gProfile[i].name); + mysnprintf(pBuffer, 40, "%s", PlayerName(i)); viewDrawText(3, pBuffer, 100, 50 + 8 * i, -128, 0, 0, 1); mysnprintf(pBuffer, 40, "%d", gPlayer[i].fragCount); viewDrawText(3, pBuffer, 210, 50 + 8 * i, -128, 0, 0, 1); diff --git a/source/blood/src/loadsave.cpp b/source/blood/src/loadsave.cpp index 427a794d3..00ce52553 100644 --- a/source/blood/src/loadsave.cpp +++ b/source/blood/src/loadsave.cpp @@ -523,7 +523,6 @@ bool GameInterface::LoadGame() Mus_ResumeSaved(); PROFILE* pProfile = &gProfile[myconnectindex]; - strcpy(pProfile->name, playername); pProfile->skill = gSkill; return true; } diff --git a/source/blood/src/player.cpp b/source/blood/src/player.cpp index 9d2221e50..877615e0d 100644 --- a/source/blood/src/player.cpp +++ b/source/blood/src/player.cpp @@ -942,7 +942,7 @@ char PickupItem(PLAYER *pPlayer, spritetype *pItem) { pPlayer->hasFlag |= 1; pPlayer->used2[0] = pItem->index; trTriggerSprite(pItem->index, pXItem, kCmdOff); - sprintf(buffer, "%s stole Blue Flag", gProfile[pPlayer->nPlayer].name); + sprintf(buffer, "%s stole Blue Flag", PlayerName(pPlayer->nPlayer)); sndStartSample(8007, 255, 2, 0); viewSetMessage(buffer); } @@ -954,7 +954,7 @@ char PickupItem(PLAYER *pPlayer, spritetype *pItem) { pPlayer->hasFlag &= ~1; pPlayer->used2[0] = -1; trTriggerSprite(pItem->index, pXItem, kCmdOn); - sprintf(buffer, "%s returned Blue Flag", gProfile[pPlayer->nPlayer].name); + sprintf(buffer, "%s returned Blue Flag", PlayerName(pPlayer->nPlayer)); sndStartSample(8003, 255, 2, 0); viewSetMessage(buffer); } @@ -965,7 +965,7 @@ char PickupItem(PLAYER *pPlayer, spritetype *pItem) { team_score[pPlayer->teamId] += 10; team_ticker[pPlayer->teamId] += 240; evSend(0, 0, 81, kCmdOn); - sprintf(buffer, "%s captured Red Flag!", gProfile[pPlayer->nPlayer].name); + sprintf(buffer, "%s captured Red Flag!", PlayerName(pPlayer->nPlayer)); sndStartSample(8001, 255, 2, 0); viewSetMessage(buffer); } @@ -979,7 +979,7 @@ char PickupItem(PLAYER *pPlayer, spritetype *pItem) { pPlayer->hasFlag |= 2; pPlayer->used2[1] = pItem->index; trTriggerSprite(pItem->index, pXItem, kCmdOff); - sprintf(buffer, "%s stole Red Flag", gProfile[pPlayer->nPlayer].name); + sprintf(buffer, "%s stole Red Flag", PlayerName(pPlayer->nPlayer)); sndStartSample(8006, 255, 2, 0); viewSetMessage(buffer); } @@ -991,7 +991,7 @@ char PickupItem(PLAYER *pPlayer, spritetype *pItem) { pPlayer->hasFlag &= ~2; pPlayer->used2[1] = -1; trTriggerSprite(pItem->index, pXItem, kCmdOn); - sprintf(buffer, "%s returned Red Flag", gProfile[pPlayer->nPlayer].name); + sprintf(buffer, "%s returned Red Flag", PlayerName(pPlayer->nPlayer)); sndStartSample(8002, 255, 2, 0); viewSetMessage(buffer); } @@ -1002,7 +1002,7 @@ char PickupItem(PLAYER *pPlayer, spritetype *pItem) { team_score[pPlayer->teamId] += 10; team_ticker[pPlayer->teamId] += 240; evSend(0, 0, 80, kCmdOn); - sprintf(buffer, "%s captured Blue Flag!", gProfile[pPlayer->nPlayer].name); + sprintf(buffer, "%s captured Blue Flag!", PlayerName(pPlayer->nPlayer)); sndStartSample(8000, 255, 2, 0); viewSetMessage(buffer); } @@ -1814,7 +1814,7 @@ void playerFrag(PLAYER *pKiller, PLAYER *pVictim) } else { - sprintf(buffer, gSuicide[nMessage].message, gProfile[nVictim].name); + sprintf(buffer, gSuicide[nMessage].message, PlayerName(nVictim)); } } else @@ -1837,7 +1837,7 @@ void playerFrag(PLAYER *pKiller, PLAYER *pVictim) int nMessage = Random(25); int nSound = gVictory[nMessage].Kills; const char* pzMessage = gVictory[nMessage].message; - sprintf(buffer, pzMessage, gProfile[nKiller].name, gProfile[nVictim].name); + sprintf(buffer, pzMessage, PlayerName(nKiller), PlayerName(nVictim)); if (gGameOptions.nGameType > 0 && nSound >= 0 && pKiller == gMe) sndStartSample(nSound, 255, 2, 0); } @@ -1905,7 +1905,7 @@ spritetype *flagDropped(PLAYER *pPlayer, int a2) if (pSprite) pSprite->owner = pPlayer->used2[0]; gBlueFlagDropped = true; - sprintf(buffer, "%s dropped Blue Flag", gProfile[pPlayer->nPlayer].name); + sprintf(buffer, "%s dropped Blue Flag", PlayerName(pPlayer->nPlayer)); sndStartSample(8005, 255, 2, 0); viewSetMessage(buffer); break; @@ -1915,7 +1915,7 @@ spritetype *flagDropped(PLAYER *pPlayer, int a2) if (pSprite) pSprite->owner = pPlayer->used2[1]; gRedFlagDropped = true; - sprintf(buffer, "%s dropped Red Flag", gProfile[pPlayer->nPlayer].name); + sprintf(buffer, "%s dropped Red Flag", PlayerName(pPlayer->nPlayer)); sndStartSample(8004, 255, 2, 0); viewSetMessage(buffer); break; @@ -2141,7 +2141,7 @@ void PlayerSurvive(int, int nXSprite) viewSetMessage(GStrings("TXT_LIVEAGAIM")); else { - sprintf(buffer, "%s lives again!", gProfile[pPlayer->nPlayer].name); + sprintf(buffer, "%s lives again!", PlayerName(pPlayer->nPlayer)); viewSetMessage(buffer); } pPlayer->newWeapon = 1; diff --git a/source/blood/src/player.h b/source/blood/src/player.h index 7579eee34..badfd38b4 100644 --- a/source/blood/src/player.h +++ b/source/blood/src/player.h @@ -188,7 +188,7 @@ struct PLAYER struct PROFILE { int skill; - char name[MAXPLAYERNAME]; + //char name[MAXPLAYERNAME]; }; struct AMMOINFO diff --git a/source/blood/src/sbar.cpp b/source/blood/src/sbar.cpp index 1a5366391..515b5341a 100644 --- a/source/blood/src/sbar.cpp +++ b/source/blood/src/sbar.cpp @@ -48,6 +48,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "statusbar.h" #include "automap.h" #include "v_draw.h" +#include "gamecvars.h" CVARD(Bool, hud_powerupduration, true, CVAR_ARCHIVE/*|CVAR_FRONTEND_BLOOD*/, "enable/disable displaying the remaining seconds for power-ups") @@ -427,7 +428,7 @@ private: int x = -160 + 80 * (i & 3); int y = 9 * (i / 4); int col = gPlayer[p].teamId & 3; - char* name = gProfile[p].name; + const char* name = PlayerName(p); if (gProfile[p].skill == 2) gTempStr.Format("%s", name); else @@ -455,7 +456,7 @@ private: int x = -160 + 80 * (i & 3); int y = 9 * (i / 4); int col = gPlayer[p].teamId & 3; - char* name = gProfile[p].name; + const char* name = PlayerName(p); if (gProfile[p].skill == 2) gTempStr.Format("%s", name); else diff --git a/source/blood/src/view.cpp b/source/blood/src/view.cpp index 3e5375169..c236a8734 100644 --- a/source/blood/src/view.cpp +++ b/source/blood/src/view.cpp @@ -242,8 +242,8 @@ void viewDrawAimedPlayerName(void) spritetype* pSprite = &sprite[gHitInfo.hitsprite]; if (IsPlayerSprite(pSprite)) { - char nPlayer = pSprite->type-kDudePlayer1; - char* szName = gProfile[nPlayer].name; + int nPlayer = pSprite->type-kDudePlayer1; + const char* szName = PlayerName(nPlayer); int nPalette = (gPlayer[nPlayer].teamId&3)+11; viewDrawText(4, szName, 160, 125, -128, nPalette, 1, 1); } @@ -1001,7 +1001,7 @@ void viewDrawScreen(bool sceneonly) } else if (gView != gMe) { - FStringf gTempStr("] %s [", gProfile[gView->nPlayer].name); + FStringf gTempStr("] %s [", PlayerName(gView->nPlayer)); viewDrawText(0, gTempStr, 160, 10, 0, 0, 1, 0); } if (cl_interpolate) diff --git a/source/core/gamecvars.h b/source/core/gamecvars.h index e9cfe3a15..f43a77054 100644 --- a/source/core/gamecvars.h +++ b/source/core/gamecvars.h @@ -101,6 +101,12 @@ EXTERN_CVAR(Int, m_ffire) EXTERN_CVAR(Int, m_noexits) EXTERN_CVAR(Int, playercolor) +inline const char* PlayerName(int pindex) +{ + // Todo: proper implementation of user CVARs. + return playername; +} + extern bool gNoAutoLoad; extern int hud_statusbarrange; // will be set by the game's configuration setup. bool G_CheckAutorun(bool button);