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 =
minu(value / 64,
lengthof(_endgame_perf_titles) - 1);
48 return _endgame_perf_titles[value];
61 for (i = 0; i <
lengthof(_highscore_table[0]); i++) {
63 if (hs[i].score <= score) {
65 memmove(&hs[i + 1], &hs[i],
sizeof(
HighScore) * (
lengthof(_highscore_table[0]) - i - 1));
68 GetString(hs[i].company, STR_HIGHSCORE_NAME,
lastof(hs[i].company));
70 hs[i].
title = EndGameGetPerformanceTitleFromValue(score);
102 memset(_highscore_table[
SP_MULTIPLAYER], 0,
sizeof(_highscore_table[SP_MULTIPLAYER]));
105 for (i = 0; i <
lengthof(_highscore_table[SP_MULTIPLAYER]) && i < count; i++) {
112 hs->
title = EndGameGetPerformanceTitleFromValue(hs->
score);
133 for (hs = _highscore_table[i]; hs !=
endof(_highscore_table[i]); hs++) {
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.");
156 memset(_highscore_table, 0,
sizeof(_highscore_table));
163 for (hs = _highscore_table[i]; hs !=
endof(_highscore_table[i]); hs++) {
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);
Functions related to OTTD's strings.
int8 SaveHighScoreValueNetwork()
Save the highscores in a network game when it has ended.
Definition of stuff that is very close to a company, like the company struct itself.
static uint minu(const uint a, const uint b)
Returns the minimum of two unsigned integers.
bool CheatHasBeenUsed()
Return true if any cheat has been used, false otherwise.
int32 performance_history
Company score (scale 0-1000)
Functions related to debugging.
StringID title
NOSAVE, has troubles with changing string-numbers.
HighScore _highscore_table[SP_HIGHSCORE_END][5]
various difficulty-settings; top 5
static bool HighScoreSorter(const Company *const &a, const Company *const &b)
Sort all companies given their performance.
No profile, special "custom" highscore.
Tindex index
Index of this pool item.
#define lastof(x)
Get the last element of an fixed size array.
Allow nothing and replace nothing.
Special "multiplayer" highscore. Not saved, always specific to the current game.
Functions related to low-level strings.
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...
char * _highscore_file
The file to store the highscore data in.
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
char company[(MAX_LENGTH_COMPANY_NAME_CHARS+MAX_LENGTH_PRESIDENT_NAME_CHARS+5) *MAX_CHAR_LENGTH]
The name of the company and president.
Functions related to cheating.
#define lengthof(x)
Return the length of an fixed size array.
static T min(const T a, const T b)
Returns the minimum of two values.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
#define DEBUG(name, level,...)
Output a line of debugging information.
uint16 score
The score for this high score. Do NOT change type, will break hs.dat.
Functions related to companies.
int8 SaveHighScoreValue(const Company *c)
Save the highscore for the company.
Declaration of functions and types defined in highscore.h and highscore_gui.h.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
End of saved highscore tables.
CompanyEconomyEntry old_economy[MAX_HISTORY_QUARTERS]
Economic data of the company of the last MAX_HISTORY_QUARTERS quarters.
Maximum number of companies.
#define endof(x)
Get the end element of an fixed size array.
void SaveToHighScore()
Save HighScore table to file.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
void LoadFromHighScore()
Initialize the highscore table to 0 and if any file exists, load in values.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.