Skip to content

Commit

Permalink
Use the REAL last score, now that we have it. :)
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Nov 21, 2011
1 parent b51ae56 commit 63436ab
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 25 deletions.
1 change: 0 additions & 1 deletion game/Maelstrom_Globals.h
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions game/game.cpp
Expand Up @@ -32,7 +32,6 @@
// Global variables set in this file...
GameInfo gGameInfo;
Replay gReplay;
int gScore;
int gGameOn;
int gPaused;
int gWave;
Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 7 additions & 3 deletions game/main.cpp
Expand Up @@ -89,7 +89,7 @@ static void RunReplayGame(const char *file)
}
static void RunLastReplay(void*)
{
RunReplayGame("LastScore");
RunReplayGame(LAST_REPLAY);
}
static void RunQuitGame(void*)
{
Expand Down Expand Up @@ -515,8 +515,12 @@ MainPanelDelegate::OnTick()

label = m_panel->GetElement<UIElement>("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<UIElement>("volume");
Expand Down
30 changes: 15 additions & 15 deletions game/replay.cpp
Expand Up @@ -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;
}
Expand Down Expand Up @@ -445,5 +445,5 @@ Replay::HandleGameOver()
}

// Save this as the last score
Save("LastScore");
Save(LAST_REPLAY);
}
24 changes: 21 additions & 3 deletions game/replay.h
Expand Up @@ -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,
Expand All @@ -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);
Expand Down

0 comments on commit 63436ab

Please sign in to comment.