mirror of https://github.com/OpenTTD/OpenTTD.git
Change: [Script] replace easy/medium/hard values with default value (#11959)
This commit is contained in:
parent
27a920c4a8
commit
849fd5ae03
|
@ -1812,13 +1812,6 @@ STR_CONFIG_SETTING_AI_BUILDS_AIRCRAFT_HELPTEXT :Enabling this s
|
||||||
STR_CONFIG_SETTING_AI_BUILDS_SHIPS :Disable ships for computer: {STRING2}
|
STR_CONFIG_SETTING_AI_BUILDS_SHIPS :Disable ships for computer: {STRING2}
|
||||||
STR_CONFIG_SETTING_AI_BUILDS_SHIPS_HELPTEXT :Enabling this setting makes building ships impossible for a computer player
|
STR_CONFIG_SETTING_AI_BUILDS_SHIPS_HELPTEXT :Enabling this setting makes building ships impossible for a computer player
|
||||||
|
|
||||||
STR_CONFIG_SETTING_AI_PROFILE :Default settings profile: {STRING2}
|
|
||||||
STR_CONFIG_SETTING_AI_PROFILE_HELPTEXT :Choose which settings profile to use for random AIs or for initial values when adding a new AI or Game Script
|
|
||||||
###length 3
|
|
||||||
STR_CONFIG_SETTING_AI_PROFILE_EASY :Easy
|
|
||||||
STR_CONFIG_SETTING_AI_PROFILE_MEDIUM :Medium
|
|
||||||
STR_CONFIG_SETTING_AI_PROFILE_HARD :Hard
|
|
||||||
|
|
||||||
STR_CONFIG_SETTING_AI_IN_MULTIPLAYER :Allow AIs in multiplayer: {STRING2}
|
STR_CONFIG_SETTING_AI_IN_MULTIPLAYER :Allow AIs in multiplayer: {STRING2}
|
||||||
STR_CONFIG_SETTING_AI_IN_MULTIPLAYER_HELPTEXT :Allow AI computer players to participate in multiplayer games
|
STR_CONFIG_SETTING_AI_IN_MULTIPLAYER_HELPTEXT :Allow AI computer players to participate in multiplayer games
|
||||||
|
|
||||||
|
|
|
@ -2862,12 +2862,6 @@ bool AfterLoadGame()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsSavegameVersionBefore(SLV_178)) {
|
|
||||||
extern uint8_t _old_diff_level;
|
|
||||||
/* Initialise script settings profile */
|
|
||||||
_settings_game.script.settings_profile = IsInsideMM(_old_diff_level, SP_BEGIN, SP_END) ? _old_diff_level : (uint)SP_MEDIUM;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
/* Station blocked, wires and pylon flags need to be stored in the map. This is effectively cached data, so no
|
/* Station blocked, wires and pylon flags need to be stored in the map. This is effectively cached data, so no
|
||||||
* version check is necessary. This is done here as the SLV_182 check below needs the blocked status. */
|
* version check is necessary. This is done here as the SLV_182 check below needs the blocked status. */
|
||||||
|
|
|
@ -162,7 +162,7 @@ const SaveLoadCompat _settings_sl_compat[] = {
|
||||||
SLC_VAR("economy.initial_city_size"),
|
SLC_VAR("economy.initial_city_size"),
|
||||||
SLC_VAR("economy.mod_road_rebuild"),
|
SLC_VAR("economy.mod_road_rebuild"),
|
||||||
SLC_NULL(1, SL_MIN_VERSION, SLV_107),
|
SLC_NULL(1, SL_MIN_VERSION, SLV_107),
|
||||||
SLC_VAR("script.settings_profile"),
|
SLC_NULL(1, SLV_178, SLV_TABLE_CHUNKS),
|
||||||
SLC_VAR("ai.ai_in_multiplayer"),
|
SLC_VAR("ai.ai_in_multiplayer"),
|
||||||
SLC_VAR("ai.ai_disable_veh_train"),
|
SLC_VAR("ai.ai_disable_veh_train"),
|
||||||
SLC_VAR("ai.ai_disable_veh_roadveh"),
|
SLC_VAR("ai.ai_disable_veh_roadveh"),
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
* \li AISubsidyList accepts an optional filter function
|
* \li AISubsidyList accepts an optional filter function
|
||||||
* \li AITownList accepts an optional filter function
|
* \li AITownList accepts an optional filter function
|
||||||
* \li AIVehicleList accepts an optional filter function
|
* \li AIVehicleList accepts an optional filter function
|
||||||
|
* \li AIInfo::AddSettings easy_value / medium_value / hard_value are replaced with default_value
|
||||||
*
|
*
|
||||||
* \b 13.0
|
* \b 13.0
|
||||||
*
|
*
|
||||||
|
|
|
@ -99,6 +99,7 @@
|
||||||
* \li GSSubsidyList accepts an optional filter function
|
* \li GSSubsidyList accepts an optional filter function
|
||||||
* \li GSTownList accepts an optional filter function
|
* \li GSTownList accepts an optional filter function
|
||||||
* \li GSVehicleList accepts an optional filter function
|
* \li GSVehicleList accepts an optional filter function
|
||||||
|
* \li GSInfo::AddSettings easy_value / medium_value / hard_value are replaced with default_value
|
||||||
*
|
*
|
||||||
* \b 13.0
|
* \b 13.0
|
||||||
*
|
*
|
||||||
|
|
|
@ -222,18 +222,8 @@ public:
|
||||||
* - max_value The maximum value of this setting. Required for integer
|
* - max_value The maximum value of this setting. Required for integer
|
||||||
* settings and not allowed for boolean settings. The value will be
|
* settings and not allowed for boolean settings. The value will be
|
||||||
* clamped in the range [MIN(int32_t), MAX(int32_t)] (inclusive).
|
* clamped in the range [MIN(int32_t), MAX(int32_t)] (inclusive).
|
||||||
* - easy_value The default value if the easy difficulty level
|
* - default_value The default value. Required. The value will be
|
||||||
* is selected. Required. The value will be clamped in the range
|
* clamped in the range [MIN(int32_t), MAX(int32_t)] (inclusive).
|
||||||
* [MIN(int32_t), MAX(int32_t)] (inclusive).
|
|
||||||
* - medium_value The default value if the medium difficulty level
|
|
||||||
* is selected. Required. The value will be clamped in the range
|
|
||||||
* [MIN(int32_t), MAX(int32_t)] (inclusive).
|
|
||||||
* - hard_value The default value if the hard difficulty level
|
|
||||||
* is selected. Required. The value will be clamped in the range
|
|
||||||
* [MIN(int32_t), MAX(int32_t)] (inclusive).
|
|
||||||
* - custom_value The default value if the custom difficulty level
|
|
||||||
* is selected. Required. The value will be clamped in the range
|
|
||||||
* [MIN(int32_t), MAX(int32_t)] (inclusive).
|
|
||||||
* - random_deviation If this property has a nonzero value, then the
|
* - random_deviation If this property has a nonzero value, then the
|
||||||
* actual value of the setting in game will be randomised in the range
|
* actual value of the setting in game will be randomised in the range
|
||||||
* [user_configured_value - random_deviation, user_configured_value + random_deviation] (inclusive).
|
* [user_configured_value - random_deviation, user_configured_value + random_deviation] (inclusive).
|
||||||
|
|
|
@ -34,10 +34,7 @@ struct ScriptConfigItem {
|
||||||
std::string description; ///< The description of the configuration setting.
|
std::string description; ///< The description of the configuration setting.
|
||||||
int min_value = 0; ///< The minimal value this configuration setting can have.
|
int min_value = 0; ///< The minimal value this configuration setting can have.
|
||||||
int max_value = 1; ///< The maximal value this configuration setting can have.
|
int max_value = 1; ///< The maximal value this configuration setting can have.
|
||||||
int custom_value = 0; ///< The default value on custom difficulty setting.
|
int default_value = 0; ///< The default value of this configuration setting.
|
||||||
int easy_value = 0; ///< The default value on easy difficulty setting.
|
|
||||||
int medium_value = 0; ///< The default value on medium difficulty setting.
|
|
||||||
int hard_value = 0; ///< The default value on hard difficulty setting.
|
|
||||||
int random_deviation = 0; ///< The maximum random deviation from the default value.
|
int random_deviation = 0; ///< The maximum random deviation from the default value.
|
||||||
int step_size = 1; ///< The step size in the gui.
|
int step_size = 1; ///< The step size in the gui.
|
||||||
ScriptConfigFlags flags = SCRIPTCONFIG_NONE; ///< Flags for the configuration setting.
|
ScriptConfigFlags flags = SCRIPTCONFIG_NONE; ///< Flags for the configuration setting.
|
||||||
|
|
|
@ -87,6 +87,10 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
|
||||||
ScriptConfigItem config;
|
ScriptConfigItem config;
|
||||||
uint items = 0;
|
uint items = 0;
|
||||||
|
|
||||||
|
int easy_value = INT32_MIN;
|
||||||
|
int medium_value = INT32_MIN;
|
||||||
|
int hard_value = INT32_MIN;
|
||||||
|
|
||||||
/* Read the table, and find all properties we care about */
|
/* Read the table, and find all properties we care about */
|
||||||
sq_pushnull(vm);
|
sq_pushnull(vm);
|
||||||
while (SQ_SUCCEEDED(sq_next(vm, -2))) {
|
while (SQ_SUCCEEDED(sq_next(vm, -2))) {
|
||||||
|
@ -122,28 +126,30 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
|
||||||
} else if (key == "easy_value") {
|
} else if (key == "easy_value") {
|
||||||
SQInteger res;
|
SQInteger res;
|
||||||
if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
|
if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
|
||||||
config.easy_value = ClampTo<int32_t>(res);
|
easy_value = ClampTo<int32_t>(res);
|
||||||
items |= 0x010;
|
items |= 0x010;
|
||||||
} else if (key == "medium_value") {
|
} else if (key == "medium_value") {
|
||||||
SQInteger res;
|
SQInteger res;
|
||||||
if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
|
if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
|
||||||
config.medium_value = ClampTo<int32_t>(res);
|
medium_value = ClampTo<int32_t>(res);
|
||||||
items |= 0x020;
|
items |= 0x020;
|
||||||
} else if (key == "hard_value") {
|
} else if (key == "hard_value") {
|
||||||
SQInteger res;
|
SQInteger res;
|
||||||
if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
|
if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
|
||||||
config.hard_value = ClampTo<int32_t>(res);
|
hard_value = ClampTo<int32_t>(res);
|
||||||
items |= 0x040;
|
items |= 0x040;
|
||||||
|
} else if (key == "custom_value") {
|
||||||
|
// No longer parsed.
|
||||||
|
} else if (key == "default_value") {
|
||||||
|
SQInteger res;
|
||||||
|
if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
|
||||||
|
config.default_value = ClampTo<int32_t>(res);
|
||||||
|
items |= 0x080;
|
||||||
} else if (key == "random_deviation") {
|
} else if (key == "random_deviation") {
|
||||||
SQInteger res;
|
SQInteger res;
|
||||||
if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
|
if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
|
||||||
config.random_deviation = ClampTo<int32_t>(abs(res));
|
config.random_deviation = ClampTo<int32_t>(abs(res));
|
||||||
items |= 0x200;
|
items |= 0x200;
|
||||||
} else if (key == "custom_value") {
|
|
||||||
SQInteger res;
|
|
||||||
if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
|
|
||||||
config.custom_value = ClampTo<int32_t>(res);
|
|
||||||
items |= 0x080;
|
|
||||||
} else if (key == "step_size") {
|
} else if (key == "step_size") {
|
||||||
SQInteger res;
|
SQInteger res;
|
||||||
if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
|
if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
|
||||||
|
@ -162,6 +168,28 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
|
||||||
}
|
}
|
||||||
sq_pop(vm, 1);
|
sq_pop(vm, 1);
|
||||||
|
|
||||||
|
/* Check if default_value is set. Although required, this was changed with
|
||||||
|
* 14.0, and as such, older AIs don't use it yet. So we convert the older
|
||||||
|
* values into a default_value. */
|
||||||
|
if ((items & 0x080) == 0) {
|
||||||
|
/* Easy/medium/hard should all three be defined. */
|
||||||
|
if ((items & 0x010) == 0 || (items & 0x020) == 0 || (items & 0x040) == 0) {
|
||||||
|
this->engine->ThrowError("please define all properties of a setting (min/max not allowed for booleans)");
|
||||||
|
return SQ_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
config.default_value = medium_value;
|
||||||
|
/* If not boolean and no random deviation set, calculate it based on easy/hard difference. */
|
||||||
|
if ((config.flags & SCRIPTCONFIG_BOOLEAN) == 0 && (items & 0x200) == 0) {
|
||||||
|
config.random_deviation = abs(hard_value - easy_value) / 2;
|
||||||
|
items |= 0x200;
|
||||||
|
}
|
||||||
|
items |= 0x080;
|
||||||
|
} else {
|
||||||
|
/* For compatibility, also act like the default sets the easy/medium/hard. */
|
||||||
|
items |= 0x010 | 0x020 | 0x040;
|
||||||
|
}
|
||||||
|
|
||||||
/* Don't allow both random_deviation and SCRIPTCONFIG_BOOLEAN to
|
/* Don't allow both random_deviation and SCRIPTCONFIG_BOOLEAN to
|
||||||
* be set for the same config item. */
|
* be set for the same config item. */
|
||||||
if ((items & 0x200) != 0 && (config.flags & SCRIPTCONFIG_BOOLEAN) != 0) {
|
if ((items & 0x200) != 0 && (config.flags & SCRIPTCONFIG_BOOLEAN) != 0) {
|
||||||
|
@ -252,14 +280,7 @@ int ScriptInfo::GetSettingDefaultValue(const std::string &name) const
|
||||||
{
|
{
|
||||||
for (const auto &item : this->config_list) {
|
for (const auto &item : this->config_list) {
|
||||||
if (item.name != name) continue;
|
if (item.name != name) continue;
|
||||||
/* The default value depends on the difficulty level */
|
return item.default_value;
|
||||||
switch (GetGameSettings().script.settings_profile) {
|
|
||||||
case SP_EASY: return item.easy_value;
|
|
||||||
case SP_MEDIUM: return item.medium_value;
|
|
||||||
case SP_HARD: return item.hard_value;
|
|
||||||
case SP_CUSTOM: return item.custom_value;
|
|
||||||
default: NOT_REACHED();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* There is no such setting */
|
/* There is no such setting */
|
||||||
|
|
|
@ -2249,7 +2249,6 @@ static SettingsContainer &GetSettingsTree()
|
||||||
{
|
{
|
||||||
SettingsPage *npc = ai->Add(new SettingsPage(STR_CONFIG_SETTING_AI_NPC));
|
SettingsPage *npc = ai->Add(new SettingsPage(STR_CONFIG_SETTING_AI_NPC));
|
||||||
{
|
{
|
||||||
npc->Add(new SettingEntry("script.settings_profile"));
|
|
||||||
npc->Add(new SettingEntry("script.script_max_opcode_till_suspend"));
|
npc->Add(new SettingEntry("script.script_max_opcode_till_suspend"));
|
||||||
npc->Add(new SettingEntry("script.script_max_memory_megabytes"));
|
npc->Add(new SettingEntry("script.script_max_memory_megabytes"));
|
||||||
npc->Add(new SettingEntry("difficulty.competitor_speed"));
|
npc->Add(new SettingEntry("difficulty.competitor_speed"));
|
||||||
|
|
|
@ -405,7 +405,6 @@ struct AISettings {
|
||||||
|
|
||||||
/** Settings related to scripts. */
|
/** Settings related to scripts. */
|
||||||
struct ScriptSettings {
|
struct ScriptSettings {
|
||||||
uint8_t settings_profile; ///< difficulty profile to set initial settings of scripts, esp. random AIs
|
|
||||||
uint32_t script_max_opcode_till_suspend; ///< max opcode calls till scripts will suspend
|
uint32_t script_max_opcode_till_suspend; ///< max opcode calls till scripts will suspend
|
||||||
uint32_t script_max_memory_megabytes; ///< limit on memory a single script instance may have allocated
|
uint32_t script_max_memory_megabytes; ///< limit on memory a single script instance may have allocated
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
; and in the savegame PATS chunk.
|
; and in the savegame PATS chunk.
|
||||||
|
|
||||||
[pre-amble]
|
[pre-amble]
|
||||||
static constexpr std::initializer_list<const char*> _settings_profiles{"easy", "medium", "hard"};
|
|
||||||
|
|
||||||
static const SettingVariant _script_settings_table[] = {
|
static const SettingVariant _script_settings_table[] = {
|
||||||
[post-amble]
|
[post-amble]
|
||||||
|
@ -41,20 +40,6 @@ extra = 0
|
||||||
startup = false
|
startup = false
|
||||||
|
|
||||||
|
|
||||||
[SDT_OMANY]
|
|
||||||
var = script.settings_profile
|
|
||||||
type = SLE_UINT8
|
|
||||||
from = SLV_178
|
|
||||||
flags = SF_GUI_DROPDOWN
|
|
||||||
def = SP_EASY
|
|
||||||
min = SP_EASY
|
|
||||||
max = SP_HARD
|
|
||||||
full = _settings_profiles
|
|
||||||
str = STR_CONFIG_SETTING_AI_PROFILE
|
|
||||||
strhelp = STR_CONFIG_SETTING_AI_PROFILE_HELPTEXT
|
|
||||||
strval = STR_CONFIG_SETTING_AI_PROFILE_EASY
|
|
||||||
cat = SC_BASIC
|
|
||||||
|
|
||||||
[SDT_VAR]
|
[SDT_VAR]
|
||||||
var = script.script_max_opcode_till_suspend
|
var = script.script_max_opcode_till_suspend
|
||||||
type = SLE_UINT32
|
type = SLE_UINT32
|
||||||
|
|
Loading…
Reference in New Issue