Merge tag '14.0-beta1' into jgrpp
# Conflicts: # src/3rdparty/squirrel/squirrel/sqcompiler.cpp # src/aircraft.h # src/animated_tile.h # src/base_consist.h # src/cargotype.h # src/company_gui.cpp # src/console_cmds.cpp # src/core/overflowsafe_type.hpp # src/engine_gui.cpp # src/industry_gui.cpp # src/lang/english.txt # src/music/extmidi.cpp # src/network/core/network_game_info.cpp # src/network/network_server.cpp # src/newgrf.cpp # src/newgrf_industries.cpp # src/order_base.h # src/order_cmd.cpp # src/order_gui.cpp # src/order_type.h # src/os/macosx/misc_osx.cpp # src/os/windows/crashlog_win.cpp # src/rail_gui.cpp # src/rail_gui.h # src/roadveh.h # src/roadveh_cmd.cpp # src/saveload/afterload.cpp # src/saveload/company_sl.cpp # src/saveload/saveload.cpp # src/saveload/saveload.h # src/saveload/saveload_error.hpp # src/script/api/script_town.cpp # src/settingsgen/settingsgen.cpp # src/ship.h # src/ship_cmd.cpp # src/smallmap_gui.cpp # src/spritecache.cpp # src/stdafx.h # src/strgen/strgen.cpp # src/strgen/strgen.h # src/table/settings/script_settings.ini # src/timetable_cmd.cpp # src/timetable_gui.cpp # src/town.h # src/town_cmd.cpp # src/town_cmd.h # src/town_gui.cpp # src/train.h # src/train_cmd.cpp # src/tree_cmd.cpp # src/vehicle.cpp # src/vehicle_base.h # src/vehicle_cmd.cpp # src/vehicle_gui.cpp # src/vehiclelist.cpp # src/waypoint_base.h # src/widget.cpp
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
* \li AISubsidyList accepts an optional filter function
|
||||
* \li AITownList 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
|
||||
*
|
||||
|
@@ -99,6 +99,7 @@
|
||||
* \li GSSubsidyList accepts an optional filter function
|
||||
* \li GSTownList 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
|
||||
*
|
||||
|
@@ -24,7 +24,7 @@
|
||||
|
||||
/* static */ bool ScriptCargo::IsValidTownEffect(TownEffect towneffect_type)
|
||||
{
|
||||
return (towneffect_type >= (TownEffect)TE_BEGIN && towneffect_type < (TownEffect)TE_END);
|
||||
return (towneffect_type >= (TownEffect)TAE_BEGIN && towneffect_type < (TownEffect)TAE_END);
|
||||
}
|
||||
|
||||
/* static */ std::optional<std::string> ScriptCargo::GetName(CargoID cargo_type)
|
||||
@@ -66,7 +66,7 @@
|
||||
{
|
||||
if (!IsValidCargo(cargo_type)) return TE_NONE;
|
||||
|
||||
return (ScriptCargo::TownEffect)::CargoSpec::Get(cargo_type)->town_effect;
|
||||
return (ScriptCargo::TownEffect)::CargoSpec::Get(cargo_type)->town_acceptance_effect;
|
||||
}
|
||||
|
||||
/* static */ Money ScriptCargo::GetCargoIncome(CargoID cargo_type, SQInteger distance, SQInteger days_in_transit)
|
||||
|
@@ -43,12 +43,12 @@ public:
|
||||
*/
|
||||
enum TownEffect {
|
||||
/* Note: these values represent part of the in-game TownEffect enum */
|
||||
TE_NONE = ::TE_NONE, ///< This cargo has no effect on a town
|
||||
TE_PASSENGERS = ::TE_PASSENGERS, ///< This cargo supplies passengers to a town
|
||||
TE_MAIL = ::TE_MAIL, ///< This cargo supplies mail to a town
|
||||
TE_GOODS = ::TE_GOODS, ///< This cargo supplies goods to a town
|
||||
TE_WATER = ::TE_WATER, ///< This cargo supplies water to a town
|
||||
TE_FOOD = ::TE_FOOD, ///< This cargo supplies food to a town
|
||||
TE_NONE = ::TAE_NONE, ///< This cargo has no effect on a town
|
||||
TE_PASSENGERS = ::TAE_PASSENGERS, ///< This cargo supplies passengers to a town
|
||||
TE_MAIL = ::TAE_MAIL, ///< This cargo supplies mail to a town
|
||||
TE_GOODS = ::TAE_GOODS, ///< This cargo supplies goods to a town
|
||||
TE_WATER = ::TAE_WATER, ///< This cargo supplies water to a town
|
||||
TE_FOOD = ::TAE_FOOD, ///< This cargo supplies food to a town
|
||||
};
|
||||
|
||||
/**
|
||||
|
@@ -38,7 +38,7 @@ ScriptError::ScriptErrorMapString ScriptError::error_map_string = ScriptError::S
|
||||
|
||||
case TEXT_TAB_SPECIAL:
|
||||
if (index < 0xE4) break; // Player name
|
||||
FALLTHROUGH;
|
||||
[[fallthrough]];
|
||||
|
||||
case TEXT_TAB_TOWN:
|
||||
if (index < 0xC0) break; // Town name
|
||||
|
@@ -222,18 +222,8 @@ public:
|
||||
* - max_value The maximum value of this setting. Required for integer
|
||||
* settings and not allowed for boolean settings. The value will be
|
||||
* clamped in the range [MIN(int32_t), MAX(int32_t)] (inclusive).
|
||||
* - easy_value The default value if the easy difficulty level
|
||||
* is selected. Required. The value will be clamped in the range
|
||||
* [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).
|
||||
* - 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).
|
||||
|
@@ -148,13 +148,13 @@ void CargoCollector::Update(StationID from, StationID via, uint amount)
|
||||
switch (Tselector) {
|
||||
case ScriptStationList_Cargo::CS_VIA_BY_FROM:
|
||||
if (via != this->other_station) return;
|
||||
FALLTHROUGH;
|
||||
[[fallthrough]];
|
||||
case ScriptStationList_Cargo::CS_BY_FROM:
|
||||
key = from;
|
||||
break;
|
||||
case ScriptStationList_Cargo::CS_FROM_BY_VIA:
|
||||
if (from != this->other_station) return;
|
||||
FALLTHROUGH;
|
||||
[[fallthrough]];
|
||||
case ScriptStationList_Cargo::CS_BY_VIA:
|
||||
key = via;
|
||||
break;
|
||||
|
@@ -20,7 +20,7 @@ ScriptTownList::ScriptTownList(HSQUIRRELVM vm)
|
||||
|
||||
ScriptTownEffectList::ScriptTownEffectList()
|
||||
{
|
||||
for (int i = TE_BEGIN; i < TE_END; i++) {
|
||||
for (int i = TAE_BEGIN; i < TAE_END; i++) {
|
||||
this->AddItem(i);
|
||||
}
|
||||
}
|
||||
|
@@ -37,10 +37,7 @@ struct ScriptConfigItem {
|
||||
std::string description; ///< The description of the configuration setting.
|
||||
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 custom_value = 0; ///< The default value on custom difficulty 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 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.
|
||||
|
@@ -87,6 +87,10 @@ 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);
|
||||
while (SQ_SUCCEEDED(sq_next(vm, -2))) {
|
||||
@@ -122,28 +126,30 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
|
||||
} else if (key == "easy_value") {
|
||||
SQInteger res;
|
||||
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;
|
||||
} else if (key == "medium_value") {
|
||||
SQInteger res;
|
||||
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;
|
||||
} else if (key == "hard_value") {
|
||||
SQInteger res;
|
||||
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;
|
||||
} 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") {
|
||||
SQInteger res;
|
||||
if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
|
||||
config.random_deviation = ClampTo<int32_t>(abs(res));
|
||||
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") {
|
||||
SQInteger res;
|
||||
if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
|
||||
@@ -162,6 +168,28 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
|
||||
}
|
||||
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
|
||||
* be set for the same config item. */
|
||||
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) {
|
||||
if (item.name != name) continue;
|
||||
/* The default value depends on the difficulty level */
|
||||
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();
|
||||
}
|
||||
return item.default_value;
|
||||
}
|
||||
|
||||
/* There is no such setting */
|
||||
|
Reference in New Issue
Block a user