Skip to content

Commit

Permalink
- turning some of the player arrays into Player members.
Browse files Browse the repository at this point in the history
For script code we do not want the arrays accessible so all that get accessed need to be moved into the struct first.
  • Loading branch information
coelckers committed May 15, 2021
1 parent 4e182ea commit 12b7c73
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 57 deletions.
1 change: 0 additions & 1 deletion source/games/exhumed/src/cheats.cpp
Expand Up @@ -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
{
Expand Down
7 changes: 0 additions & 7 deletions source/games/exhumed/src/exhumed.cpp
Expand Up @@ -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
Expand All @@ -510,9 +506,6 @@ void GameInterface::app_init()
seq_LoadSequences();
InitStatus();

for (i = 0; i < kMaxPlayers; i++) {
nPlayerLives[i] = kDefaultLives;
}
resettiming();
GrabPalette();

Expand Down
2 changes: 1 addition & 1 deletion source/games/exhumed/src/gameloop.cpp
Expand Up @@ -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;
Expand Down
15 changes: 0 additions & 15 deletions source/games/exhumed/src/gun.cpp
Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions source/games/exhumed/src/init.cpp
Expand Up @@ -185,7 +185,6 @@ void InitLevel(MapRecord* map)
}
EndLevel = 0;
lastfps = 0;
InitStatus();
ResetView();
ResetEngine();
totalmoves = 0;
Expand All @@ -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);
Expand Down
36 changes: 8 additions & 28 deletions source/games/exhumed/src/player.cpp
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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]) {
Expand Down Expand Up @@ -1812,11 +1800,11 @@ void FuncPlayer(int a, int nDamage, int nRun)
{
var_88 = -1;

if (nPlayerLives[nPlayer] >= kMaxPlayerLives) {
if (PlayerList[nPlayer].nLives >= kMaxPlayerLives) {
break;
}

nPlayerLives[nPlayer]++;
PlayerList[nPlayer].nLives++;

var_8C = 32;
var_44 = 32;
Expand Down Expand Up @@ -2533,7 +2521,7 @@ void FuncPlayer(int a, int nDamage, int nRun)

PlayerList[nPlayer].nCurrentWeapon = nPlayerOldWeapon[nPlayer];

if (nPlayerLives[nPlayer] && nNetTime)
if (PlayerList[nPlayer].nLives && nNetTime)
{
if (nAction != 20)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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();
}
}
Expand Down
1 change: 1 addition & 0 deletions source/games/exhumed/src/player.h
Expand Up @@ -50,6 +50,7 @@ extern int lPlayerYVel;
struct Player
{
short nHealth;
short nLives;
short field_2;
short nAction;
short nSprite;
Expand Down
1 change: 0 additions & 1 deletion source/games/exhumed/src/save.cpp
Expand Up @@ -133,7 +133,6 @@ void GameInterface::SerializeGameState(FSerializer& arc)
}

Mus_ResumeSaved();
RefreshStatus();
}
}

Expand Down
2 changes: 1 addition & 1 deletion source/games/exhumed/src/status.cpp
Expand Up @@ -488,7 +488,7 @@ class DExhumedStatusBar : public DBaseStatusBar
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);
Expand Down

0 comments on commit 12b7c73

Please sign in to comment.