OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
17 #include "table/strings.h"
25 static const StringID _endgame_perf_titles[] = {
26 STR_HIGHSCORE_PERFORMANCE_TITLE_BUSINESSMAN,
27 STR_HIGHSCORE_PERFORMANCE_TITLE_BUSINESSMAN,
28 STR_HIGHSCORE_PERFORMANCE_TITLE_BUSINESSMAN,
29 STR_HIGHSCORE_PERFORMANCE_TITLE_BUSINESSMAN,
30 STR_HIGHSCORE_PERFORMANCE_TITLE_BUSINESSMAN,
31 STR_HIGHSCORE_PERFORMANCE_TITLE_ENTREPRENEUR,
32 STR_HIGHSCORE_PERFORMANCE_TITLE_ENTREPRENEUR,
33 STR_HIGHSCORE_PERFORMANCE_TITLE_INDUSTRIALIST,
34 STR_HIGHSCORE_PERFORMANCE_TITLE_INDUSTRIALIST,
35 STR_HIGHSCORE_PERFORMANCE_TITLE_CAPITALIST,
36 STR_HIGHSCORE_PERFORMANCE_TITLE_CAPITALIST,
37 STR_HIGHSCORE_PERFORMANCE_TITLE_MAGNATE,
38 STR_HIGHSCORE_PERFORMANCE_TITLE_MAGNATE,
39 STR_HIGHSCORE_PERFORMANCE_TITLE_MOGUL,
40 STR_HIGHSCORE_PERFORMANCE_TITLE_MOGUL,
41 STR_HIGHSCORE_PERFORMANCE_TITLE_TYCOON_OF_THE_CENTURY
44 StringID EndGameGetPerformanceTitleFromValue(uint value)
46 value = std::min<uint>(value / 64,
lengthof(_endgame_perf_titles) - 1);
48 return _endgame_perf_titles[value];
63 if (hs[i].score <= score) {
68 GetString(hs[i].company, STR_HIGHSCORE_NAME,
lastof(hs[i].company));
70 hs[i].
title = EndGameGetPerformanceTitleFromValue(score);
112 hs->
title = EndGameGetPerformanceTitleFromValue(hs->
score);
137 if (fwrite(&length,
sizeof(length), 1, fp) != 1 ||
138 fwrite(hs->
company, length, 1, fp) > 1 ||
139 fwrite(&hs->
score,
sizeof(hs->
score), 1, fp) != 1 ||
140 fwrite(
" ", 2, 1, fp) != 1) {
141 DEBUG(misc, 1,
"Could not save highscore.");
165 if (fread(&length,
sizeof(length), 1, fp) != 1 ||
167 fread(&hs->
score,
sizeof(hs->
score), 1, fp) != 1 ||
168 fseek(fp, 2, SEEK_CUR) == -1) {
169 DEBUG(misc, 1,
"Highscore corrupted");
174 hs->
title = EndGameGetPerformanceTitleFromValue(hs->
score);
void str_validate(char *str, const char *last, StringValidationSettings settings)
Scans the string for valid characters and if it finds invalid ones, replaces them with a question mar...
int8 SaveHighScoreValue(const Company *c)
Save the highscore for the company.
Tindex index
Index of this pool item.
@ SP_MULTIPLAYER
Special "multiplayer" highscore. Not saved, always specific to the current game.
void LoadFromHighScore()
Initialize the highscore table to 0 and if any file exists, load in values.
char company[(MAX_LENGTH_COMPANY_NAME_CHARS+MAX_LENGTH_PRESIDENT_NAME_CHARS+5) *MAX_CHAR_LENGTH]
The name of the company and president.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
StringID title
NOSAVE, has troubles with changing string-numbers.
HighScore _highscore_table[SP_HIGHSCORE_END][5]
various difficulty-settings; top 5
int32 performance_history
Company score (scale 0-1000)
#define DEBUG(name, level,...)
Output a line of debugging information.
@ SP_CUSTOM
No profile, special "custom" highscore.
@ SP_HIGHSCORE_END
End of highscore tables.
@ MAX_COMPANIES
Maximum number of companies.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
uint16 score
The score for this high score. Do NOT change type, will break hs.dat.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
void SaveToHighScore()
Save HighScore table to file.
#define endof(x)
Get the end element of an fixed size array.
bool CheatHasBeenUsed()
Return true if any cheat has been used, false otherwise.
@ SP_SAVED_HIGHSCORE_END
End of saved highscore tables.
@ SVS_NONE
Allow nothing and replace nothing.
#define lengthof(x)
Return the length of an fixed size array.
int8 SaveHighScoreValueNetwork()
Save the highscores in a network game when it has ended.
static bool HighScoreSorter(const Company *const &a, const Company *const &b)
Sort all companies given their performance.
std::string _highscore_file
The file to store the highscore data in.
CompanyEconomyEntry old_economy[MAX_HISTORY_QUARTERS]
Economic data of the company of the last MAX_HISTORY_QUARTERS quarters.
#define lastof(x)
Get the last element of an fixed size array.