OpenTTD Source: src/highscore.cpp File Reference

OpenTTD Source 15.0-RC2

Functions | Variables
highscore.cpp File Reference

Definition of functions used for highscore handling. More...

`#include "stdafx.h"`
`#include "highscore.h"`
`#include "company_base.h"`
`#include "company_func.h"`
`#include "cheat_func.h"`
`#include "fileio_func.h"`
`#include "string_func.h"`
`#include "strings_func.h"`
`#include "debug.h"`
`#include "table/strings.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Functions
StringID | EndGameGetPerformanceTitleFromValue (uint value)
int8_t | SaveHighScoreValue (const Company *c)
| Save the highscore for the company.
static bool | HighScoreSorter (const Company *const &a, const Company *const &b)
| Sort all companies given their performance.
int8_t | SaveHighScoreValueNetwork ()
| Save the highscores in a network game when it has ended.
void | SaveToHighScore ()
| Save HighScore table to file.
void | LoadFromHighScore ()
| Initialize the highscore table to 0 and if any file exists, load in values.

## Variables
HighScoresTable | _highscore_table
| Table with all the high scores.
std::string | _highscore_file
| The file to store the highscore data in.
static const StringID | _endgame_perf_titles []

## Detailed Description

Definition of functions used for highscore handling.

Definition in file highscore.cpp.

## Function Documentation

## ◆ EndGameGetPerformanceTitleFromValue()

StringID EndGameGetPerformanceTitleFromValue | ( | uint | value | ) |

Definition at line 46 of file highscore.cpp.

## ◆ HighScoreSorter()

static bool HighScoreSorter | ( | const Company *const & | a,
|  | const Company *const & | b
| ) |  |
| static

Sort all companies given their performance.

Definition at line 79 of file highscore.cpp.

References CompanyProperties::old_economy.

Referenced by SaveHighScoreValueNetwork().

## ◆ 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

  c | The 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(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, 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(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Iterate(), CompanyProperties::name, 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, Debug, FileHandle::Open(), and SP_SAVED_HIGHSCORE_END.

## Variable Documentation

## ◆ _endgame_perf_titles

const StringID _endgame_perf_titles[]
| static

Initial value:
= {
STR_HIGHSCORE_PERFORMANCE_TITLE_BUSINESSMAN,
STR_HIGHSCORE_PERFORMANCE_TITLE_BUSINESSMAN,
STR_HIGHSCORE_PERFORMANCE_TITLE_BUSINESSMAN,
STR_HIGHSCORE_PERFORMANCE_TITLE_BUSINESSMAN,
STR_HIGHSCORE_PERFORMANCE_TITLE_BUSINESSMAN,
STR_HIGHSCORE_PERFORMANCE_TITLE_ENTREPRENEUR,
STR_HIGHSCORE_PERFORMANCE_TITLE_ENTREPRENEUR,
STR_HIGHSCORE_PERFORMANCE_TITLE_INDUSTRIALIST,
STR_HIGHSCORE_PERFORMANCE_TITLE_INDUSTRIALIST,
STR_HIGHSCORE_PERFORMANCE_TITLE_CAPITALIST,
STR_HIGHSCORE_PERFORMANCE_TITLE_CAPITALIST,
STR_HIGHSCORE_PERFORMANCE_TITLE_MAGNATE,
STR_HIGHSCORE_PERFORMANCE_TITLE_MAGNATE,
STR_HIGHSCORE_PERFORMANCE_TITLE_MOGUL,
STR_HIGHSCORE_PERFORMANCE_TITLE_MOGUL,
STR_HIGHSCORE_PERFORMANCE_TITLE_TYCOON_OF_THE_CENTURY
}

Definition at line 27 of file highscore.cpp.

## ◆ _highscore_file

std::string _highscore_file

The file to store the highscore data in.

Definition at line 25 of file highscore.cpp.

Referenced by DeterminePaths(), LoadFromHighScore(), and SaveToHighScore().

## ◆ _highscore_table

HighScoresTable _highscore_table

Table with all the high scores.

Definition at line 24 of file highscore.cpp.

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