From 12b7c733932a39b27ac2efe105d4b40b6614cb55 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 13 May 2021 19:06:38 +0200 Subject: [PATCH] - turning some of the player arrays into Player members. For script code we do not want the arrays accessible so all that get accessed need to be moved into the struct first. --- source/games/exhumed/src/cheats.cpp | 1 - source/games/exhumed/src/exhumed.cpp | 7 ------ source/games/exhumed/src/gameloop.cpp | 2 +- source/games/exhumed/src/gun.cpp | 15 ----------- source/games/exhumed/src/init.cpp | 3 --- source/games/exhumed/src/player.cpp | 36 ++++++--------------------- source/games/exhumed/src/player.h | 1 + source/games/exhumed/src/save.cpp | 1 - source/games/exhumed/src/status.cpp | 2 +- 9 files changed, 11 insertions(+), 57 deletions(-) diff --git a/source/games/exhumed/src/cheats.cpp b/source/games/exhumed/src/cheats.cpp index 0dc38b898..17055f960 100644 --- a/source/games/exhumed/src/cheats.cpp +++ b/source/games/exhumed/src/cheats.cpp @@ -209,7 +209,6 @@ static void cmd_Give(int player, uint8_t** stream, bool skip) { PlayerList[player].keys = 0xFFFF; if (player == myconnectindex) StatusMessage(150, GStrings("TXT_EX_KEYS")); - RefreshStatus(); } if (buttons & kButtonCheatItems) // LOBOSWAG cheat { diff --git a/source/games/exhumed/src/exhumed.cpp b/source/games/exhumed/src/exhumed.cpp index 8227fece3..354946b35 100644 --- a/source/games/exhumed/src/exhumed.cpp +++ b/source/games/exhumed/src/exhumed.cpp @@ -482,10 +482,6 @@ static void SetTileNames() void GameInterface::app_init() { - int i; - //int esi = 1; - //int edi = esi; - #if 0 help_disabled = true; #endif @@ -510,9 +506,6 @@ void GameInterface::app_init() seq_LoadSequences(); InitStatus(); - for (i = 0; i < kMaxPlayers; i++) { - nPlayerLives[i] = kDefaultLives; - } resettiming(); GrabPalette(); diff --git a/source/games/exhumed/src/gameloop.cpp b/source/games/exhumed/src/gameloop.cpp index 644e45d1b..04142292e 100644 --- a/source/games/exhumed/src/gameloop.cpp +++ b/source/games/exhumed/src/gameloop.cpp @@ -168,7 +168,7 @@ void GameInterface::LevelCompleted(MapRecord *to_map, int skill) { if (to_map->levelNumber > nBestLevel) nBestLevel = to_map->levelNumber - 1; - if (to_map->gameflags & LEVEL_EX_COUNTDOWN) nPlayerLives[0] = 0; + if (to_map->gameflags & LEVEL_EX_COUNTDOWN) PlayerList[0].nLives = 0; if (to_map->gameflags & LEVEL_EX_TRAINING) { gameaction = ga_nextlevel; diff --git a/source/games/exhumed/src/gun.cpp b/source/games/exhumed/src/gun.cpp index 7adfcf42e..e36e6cb22 100644 --- a/source/games/exhumed/src/gun.cpp +++ b/source/games/exhumed/src/gun.cpp @@ -227,21 +227,6 @@ void FireWeapon(short nPlayer) void SetWeaponStatus(short nPlayer) { - if (nPlayer != nLocalPlayer) - return; - - short nWeapon = PlayerList[nPlayer].nCurrentWeapon; - - if (nWeapon < 0) - { - nCounterBullet = -1; - SetCounterImmediate(0); - } - else - { - nCounterBullet = WeaponInfo[nWeapon].nAmmoType; - SetCounterImmediate(PlayerList[nPlayer].nAmmo[nCounterBullet]); - } } uint8_t WeaponCanFire(short nPlayer) diff --git a/source/games/exhumed/src/init.cpp b/source/games/exhumed/src/init.cpp index d6852fc3c..1bd543b8f 100644 --- a/source/games/exhumed/src/init.cpp +++ b/source/games/exhumed/src/init.cpp @@ -185,7 +185,6 @@ void InitLevel(MapRecord* map) } EndLevel = 0; lastfps = 0; - InitStatus(); ResetView(); ResetEngine(); totalmoves = 0; @@ -195,8 +194,6 @@ void InitLevel(MapRecord* map) lPlayerYVel = 0; movefifopos = movefifoend; - RefreshStatus(); - if (!mus_redbook && map->music.IsNotEmpty()) Mus_Play(map->music, true); // Allow non-CD music if defined for the current level playCDtrack(map->cdSongId, true); setLevelStarted(currentLevel); diff --git a/source/games/exhumed/src/player.cpp b/source/games/exhumed/src/player.cpp index 7feba1a2a..d55573556 100644 --- a/source/games/exhumed/src/player.cpp +++ b/source/games/exhumed/src/player.cpp @@ -103,7 +103,6 @@ short nPlayerPushSound[kMaxPlayers]; short nTauntTimer[kMaxPlayers]; short nPlayerTorch[kMaxPlayers]; uint16_t nPlayerWeapons[kMaxPlayers]; // each set bit represents a weapon the player has -short nPlayerLives[kMaxPlayers]; Player PlayerList[kMaxPlayers]; short nPlayerInvisible[kMaxPlayers]; short nPlayerDouble[kMaxPlayers]; @@ -225,7 +224,7 @@ void InitPlayerInventory(short nPlayer) ResetPlayerWeapons(nPlayer); - nPlayerLives[nPlayer] = kDefaultLives; + PlayerList[nPlayer].nLives = kDefaultLives; PlayerList[nPlayer].nSprite = -1; PlayerList[nPlayer].nRun = -1; @@ -560,19 +559,15 @@ void StartDeathSeq(int nPlayer, int nVal) if (nTotalPlayers == 1) { if (!(currentLevel->gameflags & LEVEL_EX_TRAINING)) { // if not on the training level - nPlayerLives[nPlayer]--; + PlayerList[nPlayer].nLives--; } - if (nPlayerLives[nPlayer] < 0) { - nPlayerLives[nPlayer] = 0; + if (PlayerList[nPlayer].nLives < 0) { + PlayerList[nPlayer].nLives = 0; } } ototalvel[nPlayer] = totalvel[nPlayer] = 0; - - if (nPlayer == nLocalPlayer) { - RefreshStatus(); - } } int AddAmmo(int nPlayer, int nWeapon, int nAmmoAmount) @@ -594,13 +589,6 @@ int AddAmmo(int nPlayer, int nWeapon, int nAmmoAmount) PlayerList[nPlayer].nAmmo[nWeapon] = nAmmoAmount; - if (nPlayer == nLocalPlayer) - { - if (nWeapon == nCounterBullet) { - SetCounter(nAmmoAmount); - } - } - if (nWeapon == 1) { if (!nPistolClip[nPlayer]) { @@ -1812,11 +1800,11 @@ do_default_b: { var_88 = -1; - if (nPlayerLives[nPlayer] >= kMaxPlayerLives) { + if (PlayerList[nPlayer].nLives >= kMaxPlayerLives) { break; } - nPlayerLives[nPlayer]++; + PlayerList[nPlayer].nLives++; var_8C = 32; var_44 = 32; @@ -2533,7 +2521,7 @@ loc_1BD2E: PlayerList[nPlayer].nCurrentWeapon = nPlayerOldWeapon[nPlayer]; - if (nPlayerLives[nPlayer] && nNetTime) + if (PlayerList[nPlayer].nLives && nNetTime) { if (nAction != 20) { @@ -2709,6 +2697,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, Player& w, Player* ("seq", w.nSeq) ("horizon", w.horizon) ("angle", w.angle) + ("lives", w.nLives) .EndObject(); } return arc; @@ -2759,7 +2748,6 @@ void SerializePlayer(FSerializer& arc) .Array("taunttimer", nTauntTimer, PlayerCount) .Array("torch", nPlayerTorch, PlayerCount) .Array("weapons", nPlayerWeapons, PlayerCount) - .Array("lives", nPlayerLives, PlayerCount) .Array("list", PlayerList, PlayerCount) .Array("invisible", nPlayerInvisible, PlayerCount) .Array("double", nPlayerDouble, PlayerCount) @@ -2771,14 +2759,6 @@ void SerializePlayer(FSerializer& arc) .Array("netstartsprite", nNetStartSprite, PlayerCount) .Array("grenade", nPlayerGrenade, PlayerCount) .Array("d282a", word_D282A, PlayerCount); - - if (SaveVersion < 13) // Item was an external array in older versions. - { - int nPlayerItem[8]{}; - arc.Array("item", nPlayerItem, PlayerCount); - for (int i = 0; i < PlayerCount; i++) PlayerList[i].nItem = nPlayerItem[i]; - } - arc.EndObject(); } } diff --git a/source/games/exhumed/src/player.h b/source/games/exhumed/src/player.h index 436df6ec1..ae559bee6 100644 --- a/source/games/exhumed/src/player.h +++ b/source/games/exhumed/src/player.h @@ -50,6 +50,7 @@ extern int lPlayerYVel; struct Player { short nHealth; + short nLives; short field_2; short nAction; short nSprite; diff --git a/source/games/exhumed/src/save.cpp b/source/games/exhumed/src/save.cpp index e51bc81a5..0c2f218d8 100644 --- a/source/games/exhumed/src/save.cpp +++ b/source/games/exhumed/src/save.cpp @@ -133,7 +133,6 @@ void GameInterface::SerializeGameState(FSerializer& arc) } Mus_ResumeSaved(); - RefreshStatus(); } } diff --git a/source/games/exhumed/src/status.cpp b/source/games/exhumed/src/status.cpp index febba7d1c..6fdf09122 100644 --- a/source/games/exhumed/src/status.cpp +++ b/source/games/exhumed/src/status.cpp @@ -488,7 +488,7 @@ private: DrawStatusSequence(nStatusSeqOffset + 156 + 2* count, 0, 0); } - short nLives = nPlayerLives[nLocalPlayer]; + short nLives = PlayerList[nLocalPlayer].nLives; DrawStatusSequence(nStatusSeqOffset + 145 + (2 * nLives), 0, 0); if (nHurt > 0) DrawStatusSequence(nStatusSeqOffset + 4, nHurt - 1, 0);