Merge branch 'master' into jgrpp
# Conflicts: # src/landscape.cpp # src/landscape.h # src/misc_gui.cpp # src/newgrf_commons.cpp # src/order_cmd.cpp # src/pathfinder/yapf/yapf_base.hpp # src/station_cmd.cpp # src/tunnelbridge_cmd.cpp # src/vehicle.cpp # src/water_cmd.cpp # src/window.cpp
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
* API removals:
|
||||
* \li AIError::ERR_PRECONDITION_TOO_MANY_PARAMETERS, that error is never returned anymore.
|
||||
* \li AIInfo::CONFIG_RANDOM, no longer used.
|
||||
* \li AIInfo::AddSettings random_deviation is no longer used.
|
||||
*
|
||||
* Other changes:
|
||||
* \li AIGroupList accepts an optional filter function
|
||||
|
@@ -95,6 +95,7 @@
|
||||
* API removals:
|
||||
* \li GSError::ERR_PRECONDITION_TOO_MANY_PARAMETERS, that error is never returned anymore.
|
||||
* \li GSInfo::CONFIG_RANDOM, no longer used.
|
||||
* \li GSInfo::AddSettings random_deviation is no longer used.
|
||||
*
|
||||
* Other changes:
|
||||
* \li GSGroupList accepts an optional filter function
|
||||
|
@@ -224,12 +224,6 @@ public:
|
||||
* clamped in the range [MIN(int32_t), MAX(int32_t)] (inclusive).
|
||||
* - default_value The default value. 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
|
||||
* actual value of the setting in game will be randomised in the range
|
||||
* [user_configured_value - random_deviation, user_configured_value + random_deviation] (inclusive).
|
||||
* random_deviation sign is ignored and the value is clamped in the range [0, MAX(int32_t)] (inclusive).
|
||||
* The randomisation will happen just before the Script start.
|
||||
* Not allowed if the CONFIG_BOOLEAN flag is set, otherwise optional.
|
||||
* - step_size The increase/decrease of the value every time the user
|
||||
* clicks one of the up/down arrow buttons. Optional, default is 1.
|
||||
* - flags Bitmask of some flags, see ScriptConfigFlags. Required.
|
||||
|
@@ -196,8 +196,7 @@
|
||||
{
|
||||
if (!::IsValidTile(tile) || !::IsValidCorner((::Corner)corner)) return -1;
|
||||
|
||||
int z;
|
||||
::Slope slope = ::GetTileSlope(tile, &z);
|
||||
auto [slope, z] = ::GetTileSlopeZ(tile);
|
||||
return (z + ::GetSlopeZInCorner(slope, (::Corner)corner));
|
||||
}
|
||||
|
||||
|
@@ -28,8 +28,7 @@
|
||||
/* If it's a tunnel already, take the easy way out! */
|
||||
if (IsTunnelTile(tile)) return ::GetOtherTunnelEnd(tile);
|
||||
|
||||
int start_z;
|
||||
Slope start_tileh = ::GetTileSlope(tile, &start_z);
|
||||
auto [start_tileh, start_z] = ::GetTileSlopeZ(tile);
|
||||
DiagDirection direction = ::GetInclinedSlopeDirection(start_tileh);
|
||||
if (direction == INVALID_DIAGDIR) return INVALID_TILE;
|
||||
|
||||
@@ -39,7 +38,7 @@
|
||||
tile += delta;
|
||||
if (!::IsValidTile(tile)) return INVALID_TILE;
|
||||
|
||||
::GetTileSlope(tile, &end_z);
|
||||
std::tie(std::ignore, end_z) = ::GetTileSlopeZ(tile);
|
||||
} while (start_z != end_z);
|
||||
|
||||
return tile;
|
||||
|
@@ -124,15 +124,6 @@ void ScriptConfig::ResetEditableSettings(bool yet_to_start)
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptConfig::AddRandomDeviation(CompanyID owner)
|
||||
{
|
||||
for (const auto &item : *this->GetConfigList()) {
|
||||
if (item.random_deviation != 0) {
|
||||
this->SetSetting(item.name, ScriptObject::GetRandomizer(owner).Next(item.random_deviation * 2 + 1) - item.random_deviation + this->GetSetting(item.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ScriptConfig::HasScript() const
|
||||
{
|
||||
return this->info != nullptr;
|
||||
|
@@ -38,7 +38,6 @@ struct ScriptConfigItem {
|
||||
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 default_value = 0; ///< The default value of this configuration setting.
|
||||
int random_deviation = 0; ///< The maximum random deviation from the default value.
|
||||
int step_size = 1; ///< The step size in the gui.
|
||||
ScriptConfigFlags flags = SCRIPTCONFIG_NONE; ///< Flags for the configuration setting.
|
||||
LabelMapping labels; ///< Text labels for the integer values.
|
||||
@@ -135,11 +134,6 @@ public:
|
||||
*/
|
||||
void ResetEditableSettings(bool yet_to_start);
|
||||
|
||||
/**
|
||||
* Randomize all settings the Script requested to be randomized.
|
||||
*/
|
||||
void AddRandomDeviation(CompanyID owner);
|
||||
|
||||
/**
|
||||
* Is this config attached to an Script? In other words, is there a Script
|
||||
* that is assigned to this slot.
|
||||
|
@@ -393,18 +393,10 @@ struct ScriptSettingsWindow : public Window {
|
||||
TextColour colour;
|
||||
uint idx = 0;
|
||||
if (config_item.description.empty()) {
|
||||
if (this->slot != OWNER_DEITY && !Company::IsValidID(this->slot) && config_item.random_deviation != 0) {
|
||||
str = STR_AI_SETTINGS_JUST_DEVIATION;
|
||||
} else {
|
||||
str = STR_JUST_STRING1;
|
||||
}
|
||||
str = STR_JUST_STRING1;
|
||||
colour = TC_ORANGE;
|
||||
} else {
|
||||
if (this->slot != OWNER_DEITY && !Company::IsValidID(this->slot) && config_item.random_deviation != 0) {
|
||||
str = STR_AI_SETTINGS_SETTING_DEVIATION;
|
||||
} else {
|
||||
str = STR_AI_SETTINGS_SETTING;
|
||||
}
|
||||
str = STR_AI_SETTINGS_SETTING;
|
||||
colour = TC_LIGHT_BLUE;
|
||||
SetDParamStr(idx++, config_item.description);
|
||||
}
|
||||
@@ -419,35 +411,13 @@ struct ScriptSettingsWindow : public Window {
|
||||
DrawArrowButtons(br.left, y + button_y_offset, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, editable && current_value > config_item.min_value, editable && current_value < config_item.max_value);
|
||||
}
|
||||
|
||||
if (this->slot == OWNER_DEITY || Company::IsValidID(this->slot) || config_item.random_deviation == 0) {
|
||||
auto config_iterator = config_item.labels.find(current_value);
|
||||
if (config_iterator != config_item.labels.end()) {
|
||||
SetDParam(idx++, STR_JUST_RAW_STRING);
|
||||
SetDParamStr(idx++, config_iterator->second);
|
||||
} else {
|
||||
SetDParam(idx++, STR_JUST_INT);
|
||||
SetDParam(idx++, current_value);
|
||||
}
|
||||
auto config_iterator = config_item.labels.find(current_value);
|
||||
if (config_iterator != config_item.labels.end()) {
|
||||
SetDParam(idx++, STR_JUST_RAW_STRING);
|
||||
SetDParamStr(idx++, config_iterator->second);
|
||||
} else {
|
||||
int min_deviated = std::max(config_item.min_value, current_value - config_item.random_deviation);
|
||||
auto config_iterator = config_item.labels.find(min_deviated);
|
||||
if (config_iterator != config_item.labels.end()) {
|
||||
SetDParam(idx++, STR_JUST_RAW_STRING);
|
||||
SetDParamStr(idx++, config_iterator->second);
|
||||
} else {
|
||||
SetDParam(idx++, STR_JUST_INT);
|
||||
SetDParam(idx++, min_deviated);
|
||||
}
|
||||
|
||||
int max_deviated = std::min(config_item.max_value, current_value + config_item.random_deviation);
|
||||
config_iterator = config_item.labels.find(max_deviated);
|
||||
if (config_iterator != config_item.labels.end()) {
|
||||
SetDParam(idx++, STR_JUST_RAW_STRING);
|
||||
SetDParamStr(idx++, config_iterator->second);
|
||||
} else {
|
||||
SetDParam(idx++, STR_JUST_INT);
|
||||
SetDParam(idx++, max_deviated);
|
||||
}
|
||||
SetDParam(idx++, STR_JUST_INT);
|
||||
SetDParam(idx++, current_value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -87,9 +87,7 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
|
||||
ScriptConfigItem config;
|
||||
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 */
|
||||
sq_pushnull(vm);
|
||||
@@ -124,9 +122,7 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
|
||||
config.max_value = ClampTo<int32_t>(res);
|
||||
items |= 0x008;
|
||||
} else if (key == "easy_value") {
|
||||
SQInteger res;
|
||||
if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
|
||||
easy_value = ClampTo<int32_t>(res);
|
||||
// No longer parsed.
|
||||
items |= 0x010;
|
||||
} else if (key == "medium_value") {
|
||||
SQInteger res;
|
||||
@@ -134,9 +130,7 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
|
||||
medium_value = ClampTo<int32_t>(res);
|
||||
items |= 0x020;
|
||||
} else if (key == "hard_value") {
|
||||
SQInteger res;
|
||||
if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
|
||||
hard_value = ClampTo<int32_t>(res);
|
||||
// No longer parsed.
|
||||
items |= 0x040;
|
||||
} else if (key == "custom_value") {
|
||||
// No longer parsed.
|
||||
@@ -146,10 +140,7 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
|
||||
config.default_value = ClampTo<int32_t>(res);
|
||||
items |= 0x080;
|
||||
} else if (key == "random_deviation") {
|
||||
SQInteger res;
|
||||
if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
|
||||
config.random_deviation = ClampTo<int32_t>(abs(res));
|
||||
items |= 0x200;
|
||||
// No longer parsed.
|
||||
} else if (key == "step_size") {
|
||||
SQInteger res;
|
||||
if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
|
||||
@@ -179,27 +170,12 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
|
||||
}
|
||||
|
||||
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
|
||||
* be set for the same config item. */
|
||||
if ((items & 0x200) != 0 && (config.flags & SCRIPTCONFIG_BOOLEAN) != 0) {
|
||||
this->engine->ThrowError("setting both random_deviation and CONFIG_BOOLEAN is not allowed");
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
/* Reset the bit for random_deviation as it's optional. */
|
||||
items &= ~0x200;
|
||||
|
||||
/* Make sure all properties are defined */
|
||||
uint mask = (config.flags & SCRIPTCONFIG_BOOLEAN) ? 0x1F3 : 0x1FF;
|
||||
if (items != mask) {
|
||||
|
Reference in New Issue
Block a user