diff --git a/game/Maelstrom_Globals.h b/game/Maelstrom_Globals.h index 8e078a94..5a466331 100644 --- a/game/Maelstrom_Globals.h +++ b/game/Maelstrom_Globals.h @@ -111,7 +111,6 @@ extern StarPtr gTheStars[MAX_STARS]; extern Uint32 gStarColors[]; // in game.cpp : -extern int gScore; extern int gDisplayed; extern int gGameOn; extern int gPaused; diff --git a/game/game.cpp b/game/game.cpp index d139db41..7bc3bc51 100644 --- a/game/game.cpp +++ b/game/game.cpp @@ -32,7 +32,6 @@ // Global variables set in this file... GameInfo gGameInfo; Replay gReplay; -int gScore; int gGameOn; int gPaused; int gWave; @@ -1056,10 +1055,9 @@ static void DoGameOver(void) Delay(SOUND_DELAY); /* -- See if they got a high score */ - gScore = TheShip->GetScore(); LoadScores(); for ( i = 0; i<10; ++i ) { - if ( gScore > (int)hScores[i].score ) { + if ( TheShip->GetScore() >= (int)hScores[i].score ) { which = i; break; } diff --git a/game/main.cpp b/game/main.cpp index a355e723..4f41936d 100644 --- a/game/main.cpp +++ b/game/main.cpp @@ -89,7 +89,7 @@ static void RunReplayGame(const char *file) } static void RunLastReplay(void*) { - RunReplayGame("LastScore"); + RunReplayGame(LAST_REPLAY); } static void RunQuitGame(void*) { @@ -515,8 +515,12 @@ MainPanelDelegate::OnTick() label = m_panel->GetElement("last_score"); if (label) { - sprintf(text, "%d", gScore); - label->SetText(text); + if (gReplay.Load(LAST_REPLAY, true)) { + sprintf(text, "%d", gReplay.GetFinalScore()); + label->SetText(text); + } else { + label->SetText("0"); + } } label = m_panel->GetElement("volume"); diff --git a/game/replay.cpp b/game/replay.cpp index f0a88738..51c2c2a0 100644 --- a/game/replay.cpp +++ b/game/replay.cpp @@ -170,21 +170,21 @@ Replay::Load(const char *file, bool headerOnly) } } - if (!headerOnly) { - if (!PHYSFS_readULE32(fp, &size)) { - goto physfs_read_error; - } - data.Reset(); - data.Grow(size); - if (!PHYSFS_readBytes(fp, data.data, size)) { - goto physfs_read_error; - } - data.len = size; - if (!m_game.ReadFromPacket(data)) { - fprintf(stderr, "Couldn't read game information from %s", file); - goto error_return; - } + if (!PHYSFS_readULE32(fp, &size)) { + goto physfs_read_error; + } + data.Reset(); + data.Grow(size); + if (!PHYSFS_readBytes(fp, data.data, size)) { + goto physfs_read_error; + } + data.len = size; + if (!m_game.ReadFromPacket(data)) { + fprintf(stderr, "Couldn't read game information from %s", file); + goto error_return; + } + if (!headerOnly) { if (!PHYSFS_readULE32(fp, &size)) { goto physfs_read_error; } @@ -445,5 +445,5 @@ Replay::HandleGameOver() } // Save this as the last score - Save("LastScore"); + Save(LAST_REPLAY); } diff --git a/game/replay.h b/game/replay.h index 6a2457e1..4e514470 100644 --- a/game/replay.h +++ b/game/replay.h @@ -35,6 +35,7 @@ #define REPLAY_VERSION 1 #define REPLAY_DIRECTORY "Scores" #define REPLAY_FILETYPE "mreplay" +#define LAST_REPLAY "LastScore" enum REPLAY_MODE { REPLAY_IDLE, @@ -50,15 +51,32 @@ class Replay // You should never change this while the game is running void SetMode(REPLAY_MODE mode); - bool IsPlaying() { + bool IsPlaying() const { return m_mode == REPLAY_PLAYBACK; } - bool IsRecording() { + bool IsRecording() const { return m_mode == REPLAY_RECORDING; } - int GetDisplayPlayer() { + + int GetDisplayPlayer() const { return m_finalPlayer; } + const char *GetDisplayName() const { + return m_game.GetPlayer(GetDisplayPlayer())->name; + } + int GetFinalWave() const { + return m_finalWave; + } + int GetFinalScore() const { + return m_finalScore[GetDisplayPlayer()].Score; + } + int GetFinalFrags() const { + return m_finalScore[GetDisplayPlayer()].Frags; + } + float GetReplayTime() const { + // Return the approximage length of the replay, in seconds + return (float)m_frameCount / 30.0f; + } bool Load(const char *file, bool headerOnly = false); bool Save(const char *file);