19 #include "table/strings.h" 28 static const StringID _endgame_perf_titles[] = {
29 STR_HIGHSCORE_PERFORMANCE_TITLE_BUSINESSMAN,
30 STR_HIGHSCORE_PERFORMANCE_TITLE_BUSINESSMAN,
31 STR_HIGHSCORE_PERFORMANCE_TITLE_BUSINESSMAN,
32 STR_HIGHSCORE_PERFORMANCE_TITLE_BUSINESSMAN,
33 STR_HIGHSCORE_PERFORMANCE_TITLE_BUSINESSMAN,
34 STR_HIGHSCORE_PERFORMANCE_TITLE_ENTREPRENEUR,
35 STR_HIGHSCORE_PERFORMANCE_TITLE_ENTREPRENEUR,
36 STR_HIGHSCORE_PERFORMANCE_TITLE_INDUSTRIALIST,
37 STR_HIGHSCORE_PERFORMANCE_TITLE_INDUSTRIALIST,
38 STR_HIGHSCORE_PERFORMANCE_TITLE_CAPITALIST,
39 STR_HIGHSCORE_PERFORMANCE_TITLE_CAPITALIST,
40 STR_HIGHSCORE_PERFORMANCE_TITLE_MAGNATE,
41 STR_HIGHSCORE_PERFORMANCE_TITLE_MAGNATE,
42 STR_HIGHSCORE_PERFORMANCE_TITLE_MOGUL,
43 STR_HIGHSCORE_PERFORMANCE_TITLE_MOGUL,
44 STR_HIGHSCORE_PERFORMANCE_TITLE_TYCOON_OF_THE_CENTURY
47 StringID EndGameGetPerformanceTitleFromValue(uint value)
49 value =
minu(value / 64,
lengthof(_endgame_perf_titles) - 1);
51 return _endgame_perf_titles[value];
64 for (i = 0; i <
lengthof(_highscore_table[0]); i++) {
66 if (hs[i].score <= score) {
68 memmove(&hs[i + 1], &hs[i],
sizeof(
HighScore) * (
lengthof(_highscore_table[0]) - i - 1));
71 GetString(hs[i].company, STR_HIGHSCORE_NAME,
lastof(hs[i].company));
73 hs[i].
title = EndGameGetPerformanceTitleFromValue(score);
84 return (*b)->old_economy[0].performance_history - (*a)->old_economy[0].performance_history;
99 FOR_ALL_COMPANIES(c) cl[count++] = c;
106 memset(_highscore_table[
SP_MULTIPLAYER], 0,
sizeof(_highscore_table[SP_MULTIPLAYER]));
109 for (i = 0; i <
lengthof(_highscore_table[SP_MULTIPLAYER]) && i < count; i++) {
116 hs->
title = EndGameGetPerformanceTitleFromValue(hs->
score);
137 for (hs = _highscore_table[i]; hs !=
endof(_highscore_table[i]); hs++) {
141 if (fwrite(&length,
sizeof(length), 1, fp) != 1 ||
142 fwrite(hs->
company, length, 1, fp) > 1 ||
143 fwrite(&hs->
score,
sizeof(hs->
score), 1, fp) != 1 ||
144 fwrite(
" ", 2, 1, fp) != 1) {
145 DEBUG(misc, 1,
"Could not save highscore.");
160 memset(_highscore_table, 0,
sizeof(_highscore_table));
167 for (hs = _highscore_table[i]; hs !=
endof(_highscore_table[i]); hs++) {
169 if (fread(&length,
sizeof(length), 1, fp) != 1 ||
171 fread(&hs->
score,
sizeof(hs->
score), 1, fp) != 1 ||
172 fseek(fp, 2, SEEK_CUR) == -1) {
173 DEBUG(misc, 1,
"Highscore corrupted");
178 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
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.
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
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.
Maximum number of companies.
#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 bool StrEmpty(const char *s)
Check if a string buffer is empty.
End of saved highscore tables.
Functions related to sorting operations.
CompanyEconomyEntry old_economy[MAX_HISTORY_QUARTERS]
Economic data of the company of the last MAX_HISTORY_QUARTERS quarters.
#define endof(x)
Get the end element of an fixed size array.
static int CDECL HighScoreSorter(const Company *const *a, const Company *const *b)
Sort all companies given their performance.
void SaveToHighScore()
Save HighScore table to file.
static void QSortT(T *base, uint num, int(CDECL *comparator)(const T *, const T *), bool desc=false)
Type safe qsort()
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.