OpenTTD Source 20260218-master-g2123fca5ea
highscore.h File Reference

Declaration of functions and types defined in highscore.h and highscore_gui.h. More...

#include "strings_type.h"
#include "company_type.h"
#include "settings_type.h"

Go to the source code of this file.

Data Structures

struct  HighScore

Typedefs

using HighScores = std::array<HighScore, 5>
 Record 5 high scores.
using HighScoresTable = std::array<HighScores, SP_HIGHSCORE_END>
 Record high score for each of the difficulty levels.

Functions

void SaveToHighScore ()
 Save HighScore table to file.
void LoadFromHighScore ()
 Initialize the highscore table to 0 and if any file exists, load in values.
int8_t SaveHighScoreValue (const Company *c)
 Save the highscore for the company.
int8_t SaveHighScoreValueNetwork ()
 Save the highscores in a network game when it has ended.
StringID EndGameGetPerformanceTitleFromValue (uint value)
void ShowHighscoreTable (int difficulty=SP_CUSTOM, int8_t rank=-1)
 Show the highscore table for a given difficulty.

Variables

HighScoresTable _highscore_table
 Table with all the high scores.

Detailed Description

Declaration of functions and types defined in highscore.h and highscore_gui.h.

Definition in file highscore.h.

Typedef Documentation

◆ HighScores

using HighScores = std::array<HighScore, 5>

Record 5 high scores.

Definition at line 23 of file highscore.h.

◆ HighScoresTable

Record high score for each of the difficulty levels.

Definition at line 24 of file highscore.h.

Function Documentation

◆ EndGameGetPerformanceTitleFromValue()

StringID EndGameGetPerformanceTitleFromValue ( uint value)

Definition at line 46 of file highscore.cpp.

◆ LoadFromHighScore()

void LoadFromHighScore ( )

Initialize the highscore table to 0 and if any file exists, load in values.

Definition at line 139 of file highscore.cpp.

References _highscore_file, _highscore_table, Debug, FileHandle::Open(), SP_SAVED_HIGHSCORE_END, and StrMakeValid().

Referenced by AfterNewGRFScan::OnNewGRFsScanned().

◆ SaveHighScoreValue()

int8_t SaveHighScoreValue ( const Company * c)

Save the highscore for the company.

Parameters
cThe company to insert.
Returns
The index the company got in the high score table, or -1 when it did not end up in the table.

Definition at line 58 of file highscore.cpp.

References _highscore_table, GetString(), CompanyProperties::old_economy, and SP_CUSTOM.

◆ SaveHighScoreValueNetwork()

int8_t SaveHighScoreValueNetwork ( )

Save the highscores in a network game when it has ended.

Returns
Position of the local company in the highscore list.

Definition at line 88 of file highscore.cpp.

References _highscore_table, _local_company, GetString(), HighScoreSorter(), CompanyProperties::old_economy, and SP_MULTIPLAYER.

◆ SaveToHighScore()

void SaveToHighScore ( )

Save HighScore table to file.

Definition at line 116 of file highscore.cpp.

References _highscore_file, _highscore_table, ClampTo(), Debug, FileHandle::Open(), and SP_SAVED_HIGHSCORE_END.

◆ ShowHighscoreTable()

void ShowHighscoreTable ( int difficulty,
int8_t ranking )

Show the highscore table for a given difficulty.

When called from endgame ranking is set to the top5 element that was newly added and is thus highlighted

Parameters
difficultyThe difficulty level to show the high score for.
rankingThe ranking to show the local company at.

Definition at line 249 of file highscore_gui.cpp.

References CloseWindowByClass(), and WC_HIGHSCORE.

Referenced by EndGameWindow::Close(), MenuClickGraphsOrLeague(), and SelectGameWindow::OnClick().

Variable Documentation

◆ _highscore_table

HighScoresTable _highscore_table
extern

Table with all the high scores.

Definition at line 24 of file highscore.cpp.

Referenced by LoadFromHighScore(), HighScoreWindow::OnPaint(), SaveHighScoreValue(), SaveHighScoreValueNetwork(), and SaveToHighScore().