mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r24786) -Codechange: Add SettingsProfile enum for difficulty profiles and highscore tables.
This commit is contained in:
parent
5b2da98ca3
commit
a499435351
|
@ -80,13 +80,13 @@ int AIConfig::GetSetting(const char *name) const
|
|||
{
|
||||
if (this->info == NULL) {
|
||||
SettingValueList::const_iterator it = this->settings.find(name);
|
||||
if (it == this->settings.end() || GetGameSettings().difficulty.diff_level != 3) {
|
||||
if (it == this->settings.end() || GetGameSettings().difficulty.diff_level != SP_CUSTOM) {
|
||||
assert(strcmp("start_date", name) == 0);
|
||||
switch (GetGameSettings().difficulty.diff_level) {
|
||||
case 0: return AI::START_NEXT_EASY;
|
||||
case 1: return AI::START_NEXT_MEDIUM;
|
||||
case 2: return AI::START_NEXT_HARD;
|
||||
case 3: return AI::START_NEXT_MEDIUM;
|
||||
case SP_EASY: return AI::START_NEXT_EASY;
|
||||
case SP_MEDIUM: return AI::START_NEXT_MEDIUM;
|
||||
case SP_HARD: return AI::START_NEXT_HARD;
|
||||
case SP_CUSTOM: return AI::START_NEXT_MEDIUM;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -422,12 +422,12 @@ struct AISettingsWindow : public Window {
|
|||
void CheckDifficultyLevel()
|
||||
{
|
||||
if (_game_mode == GM_MENU) {
|
||||
if (_settings_newgame.difficulty.diff_level != 3) {
|
||||
_settings_newgame.difficulty.diff_level = 3;
|
||||
if (_settings_newgame.difficulty.diff_level != SP_CUSTOM) {
|
||||
_settings_newgame.difficulty.diff_level = SP_CUSTOM;
|
||||
ShowErrorMessage(STR_WARNING_DIFFICULTY_TO_CUSTOM, INVALID_STRING_ID, WL_WARNING);
|
||||
}
|
||||
} else if (_settings_game.difficulty.diff_level != 3) {
|
||||
IConsoleSetSetting("difficulty.diff_level", 3);
|
||||
} else if (_settings_game.difficulty.diff_level != SP_CUSTOM) {
|
||||
IConsoleSetSetting("difficulty.diff_level", SP_CUSTOM);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "core/sort_func.hpp"
|
||||
#include "debug.h"
|
||||
|
||||
HighScore _highscore_table[5][5]; // 4 difficulty-settings (+ network); top 5
|
||||
HighScore _highscore_table[SP_HIGHSCORE_END][5]; ///< various difficulty-settings; top 5
|
||||
char *_highscore_file; ///< The file to store the highscore data in.
|
||||
|
||||
static const StringID _endgame_perf_titles[] = {
|
||||
|
@ -82,8 +82,10 @@ static int CDECL HighScoreSorter(const Company * const *a, const Company * const
|
|||
return (*b)->old_economy[0].performance_history - (*a)->old_economy[0].performance_history;
|
||||
}
|
||||
|
||||
/* Save the highscores in a network game when it has ended */
|
||||
#define LAST_HS_ITEM lengthof(_highscore_table) - 1
|
||||
/**
|
||||
* Save the highscores in a network game when it has ended
|
||||
* @return Position of the local company in the highscore list.
|
||||
*/
|
||||
int8 SaveHighScoreValueNetwork()
|
||||
{
|
||||
const Company *c;
|
||||
|
@ -99,11 +101,11 @@ int8 SaveHighScoreValueNetwork()
|
|||
{
|
||||
uint i;
|
||||
|
||||
memset(_highscore_table[LAST_HS_ITEM], 0, sizeof(_highscore_table[0]));
|
||||
memset(_highscore_table[SP_MULTIPLAYER], 0, sizeof(_highscore_table[SP_MULTIPLAYER]));
|
||||
|
||||
/* Copy over Top5 companies */
|
||||
for (i = 0; i < lengthof(_highscore_table[LAST_HS_ITEM]) && i < count; i++) {
|
||||
HighScore *hs = &_highscore_table[LAST_HS_ITEM][i];
|
||||
for (i = 0; i < lengthof(_highscore_table[SP_MULTIPLAYER]) && i < count; i++) {
|
||||
HighScore *hs = &_highscore_table[SP_MULTIPLAYER][i];
|
||||
|
||||
SetDParam(0, cl[i]->index);
|
||||
SetDParam(1, cl[i]->index);
|
||||
|
@ -129,7 +131,7 @@ void SaveToHighScore()
|
|||
uint i;
|
||||
HighScore *hs;
|
||||
|
||||
for (i = 0; i < LAST_HS_ITEM; i++) { // don't save network highscores
|
||||
for (i = 0; i < SP_SAVED_HIGHSCORE_END; i++) {
|
||||
for (hs = _highscore_table[i]; hs != endof(_highscore_table[i]); hs++) {
|
||||
/* First character is a command character, so strlen will fail on that */
|
||||
byte length = min(sizeof(hs->company), StrEmpty(hs->company) ? 0 : (int)strlen(&hs->company[1]) + 1);
|
||||
|
@ -139,7 +141,7 @@ void SaveToHighScore()
|
|||
fwrite(&hs->score, sizeof(hs->score), 1, fp) != 1 ||
|
||||
fwrite(" ", 2, 1, fp) != 1) { // XXX - placeholder for hs->title, not saved anymore; compatibility
|
||||
DEBUG(misc, 1, "Could not save highscore.");
|
||||
i = LAST_HS_ITEM;
|
||||
i = SP_SAVED_HIGHSCORE_END;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -159,7 +161,7 @@ void LoadFromHighScore()
|
|||
uint i;
|
||||
HighScore *hs;
|
||||
|
||||
for (i = 0; i < LAST_HS_ITEM; i++) { // don't load network highscores
|
||||
for (i = 0; i < SP_SAVED_HIGHSCORE_END; i++) {
|
||||
for (hs = _highscore_table[i]; hs != endof(_highscore_table[i]); hs++) {
|
||||
byte length;
|
||||
if (fread(&length, sizeof(length), 1, fp) != 1 ||
|
||||
|
@ -167,7 +169,7 @@ void LoadFromHighScore()
|
|||
fread(&hs->score, sizeof(hs->score), 1, fp) != 1 ||
|
||||
fseek(fp, 2, SEEK_CUR) == -1) { // XXX - placeholder for hs->title, not saved anymore; compatibility
|
||||
DEBUG(misc, 1, "Highscore corrupted");
|
||||
i = LAST_HS_ITEM;
|
||||
i = SP_SAVED_HIGHSCORE_END;
|
||||
break;
|
||||
}
|
||||
*lastof(hs->company) = '\0';
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include "strings_type.h"
|
||||
#include "company_type.h"
|
||||
#include "settings_type.h"
|
||||
|
||||
struct HighScore {
|
||||
char company[100];
|
||||
|
@ -21,7 +22,7 @@ struct HighScore {
|
|||
uint16 score; ///< do NOT change type, will break hs.dat
|
||||
};
|
||||
|
||||
extern HighScore _highscore_table[5][5]; // 4 difficulty-settings (+ network); top 5
|
||||
extern HighScore _highscore_table[SP_HIGHSCORE_END][5];
|
||||
|
||||
void SaveToHighScore();
|
||||
void LoadFromHighScore();
|
||||
|
|
|
@ -103,10 +103,10 @@ struct EndGameWindow : EndGameHighScoreBaseWindow {
|
|||
}
|
||||
}
|
||||
|
||||
/* In a network game show the endscores of the custom difficulty 'network' which is the last one
|
||||
* as well as generate a TOP5 of that game, and not an all-time top5. */
|
||||
/* In a network game show the endscores of the custom difficulty 'network' which is
|
||||
* a TOP5 of that game, and not an all-time TOP5. */
|
||||
if (_networking) {
|
||||
this->window_number = lengthof(_highscore_table) - 1;
|
||||
this->window_number = SP_MULTIPLAYER;
|
||||
this->rank = SaveHighScoreValueNetwork();
|
||||
} else {
|
||||
/* in single player _local company is always valid */
|
||||
|
|
|
@ -87,7 +87,7 @@ void ScriptConfig::ClearConfigList()
|
|||
int ScriptConfig::GetSetting(const char *name) const
|
||||
{
|
||||
/* Return default values if the difficulty is not set to Custom */
|
||||
if (GetGameSettings().difficulty.diff_level != 3) {
|
||||
if (GetGameSettings().difficulty.diff_level != SP_CUSTOM) {
|
||||
return this->info->GetSettingDefaultValue(name);
|
||||
}
|
||||
|
||||
|
|
|
@ -294,10 +294,10 @@ int ScriptInfo::GetSettingDefaultValue(const char *name) const
|
|||
if (strcmp((*it).name, name) != 0) continue;
|
||||
/* The default value depends on the difficulty level */
|
||||
switch (GetGameSettings().difficulty.diff_level) {
|
||||
case 0: return (*it).easy_value;
|
||||
case 1: return (*it).medium_value;
|
||||
case 2: return (*it).hard_value;
|
||||
case 3: return (*it).custom_value;
|
||||
case SP_EASY: return (*it).easy_value;
|
||||
case SP_MEDIUM: return (*it).medium_value;
|
||||
case SP_HARD: return (*it).hard_value;
|
||||
case SP_CUSTOM: return (*it).custom_value;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1032,7 +1032,7 @@ static bool InvalidateCompanyInfrastructureWindow(int32 p1)
|
|||
* R: area restructuring (0 = permissive, 2 = hostile)
|
||||
* S: the difficulty level
|
||||
*/
|
||||
static const DifficultySettings _default_game_diff[3] = { /*
|
||||
static const DifficultySettings _default_game_diff[SP_END] = { /*
|
||||
A, C, D, E, F, G, H, J, K, L, M, N, O, P, Q, R, S*/
|
||||
{2, 2, 4, 300000, 2, 0, 2, 1, 2, 0, 1, 0, 0, 0, 0, 0, 0}, ///< easy
|
||||
{4, 2, 3, 150000, 3, 1, 3, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1}, ///< medium
|
||||
|
@ -1041,12 +1041,11 @@ static const DifficultySettings _default_game_diff[3] = { /*
|
|||
|
||||
void SetDifficultyLevel(int mode, DifficultySettings *gm_opt)
|
||||
{
|
||||
assert(mode <= 3);
|
||||
|
||||
if (mode != 3) {
|
||||
if (mode != SP_CUSTOM) {
|
||||
assert(mode >= SP_BEGIN && mode < SP_END);
|
||||
*gm_opt = _default_game_diff[mode];
|
||||
} else {
|
||||
gm_opt->diff_level = 3;
|
||||
gm_opt->diff_level = SP_CUSTOM;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1054,7 +1053,7 @@ void SetDifficultyLevel(int mode, DifficultySettings *gm_opt)
|
|||
static void ValidateSettings()
|
||||
{
|
||||
/* Force the difficulty levels to correct values if they are invalid. */
|
||||
if (_settings_newgame.difficulty.diff_level != 3) {
|
||||
if (_settings_newgame.difficulty.diff_level != SP_CUSTOM) {
|
||||
SetDifficultyLevel(_settings_newgame.difficulty.diff_level, &_settings_newgame.difficulty);
|
||||
}
|
||||
|
||||
|
@ -1077,13 +1076,13 @@ static bool DifficultyReset(int32 level)
|
|||
static bool DifficultyChange(int32)
|
||||
{
|
||||
if (_game_mode == GM_MENU) {
|
||||
if (_settings_newgame.difficulty.diff_level != 3) {
|
||||
if (_settings_newgame.difficulty.diff_level != SP_CUSTOM) {
|
||||
ShowErrorMessage(STR_WARNING_DIFFICULTY_TO_CUSTOM, INVALID_STRING_ID, WL_WARNING);
|
||||
_settings_newgame.difficulty.diff_level = 3;
|
||||
_settings_newgame.difficulty.diff_level = SP_CUSTOM;
|
||||
}
|
||||
SetWindowClassesDirty(WC_SELECT_GAME);
|
||||
} else {
|
||||
_settings_game.difficulty.diff_level = 3;
|
||||
_settings_game.difficulty.diff_level = SP_CUSTOM;
|
||||
}
|
||||
|
||||
/* If we are a network-client, update the difficult setting (if it is open).
|
||||
|
|
|
@ -20,6 +20,23 @@
|
|||
#include "zoom_type.h"
|
||||
#include "openttd.h"
|
||||
|
||||
|
||||
/** Settings profiles and highscore tables. */
|
||||
enum SettingsProfile {
|
||||
SP_BEGIN = 0,
|
||||
SP_EASY = SP_BEGIN, ///< Easy difficulty.
|
||||
SP_MEDIUM, ///< Medium difficulty.
|
||||
SP_HARD, ///< Hard difficulty.
|
||||
|
||||
SP_END, ///< End of setting profiles.
|
||||
|
||||
SP_CUSTOM = SP_END, ///< No profile, special "custom" highscore.
|
||||
SP_SAVED_HIGHSCORE_END, ///< End of saved highscore tables.
|
||||
|
||||
SP_MULTIPLAYER = SP_SAVED_HIGHSCORE_END, ///< Special "multiplayer" highscore. Not saved, always specific to the current game.
|
||||
SP_HIGHSCORE_END, ///< End of highscore tables.
|
||||
};
|
||||
|
||||
/** Available industry map generation densities. */
|
||||
enum IndustryDensity {
|
||||
ID_FUND_ONLY, ///< The game does not build industries.
|
||||
|
@ -50,7 +67,7 @@ struct DifficultySettings {
|
|||
byte line_reverse_mode; ///< reversing at stations or not
|
||||
byte disasters; ///< are disasters enabled
|
||||
byte town_council_tolerance; ///< minimum required town ratings to be allowed to demolish stuff
|
||||
byte diff_level; ///< the difficulty level
|
||||
byte diff_level; ///< the difficulty level. @see SettingsProfile
|
||||
};
|
||||
|
||||
/** Settings related to the GUI and other stuff that is not saved in the savegame. */
|
||||
|
|
|
@ -92,9 +92,9 @@ from = 4
|
|||
base = GameSettings
|
||||
var = difficulty.diff_level
|
||||
type = SLE_UINT8
|
||||
def = 3
|
||||
min = 0
|
||||
max = 3
|
||||
def = SP_CUSTOM
|
||||
min = SP_EASY
|
||||
max = SP_CUSTOM
|
||||
cat = SC_BASIC
|
||||
|
||||
[SDT_OMANY]
|
||||
|
|
Loading…
Reference in New Issue