Merge branch 'master' into jgrpp

# Conflicts:
#	regression/regression/result.txt
#	src/autoreplace_cmd.cpp
#	src/industry_gui.cpp
#	src/landscape.cpp
#	src/network/network_content.cpp
#	src/newgrf_roadstop.cpp
#	src/pathfinder/yapf/yapf_ship.cpp
#	src/road_gui.cpp
#	src/saveload/ai_sl.cpp
#	src/saveload/saveload.h
#	src/saveload/vehicle_sl.cpp
#	src/station.cpp
#	src/station_gui.cpp
#	src/video/cocoa/cocoa_ogl.h
#	src/video/sdl2_opengl_v.h
#	src/video/video_driver.hpp
#	src/video/win32_v.h
#	src/widget_type.h
#	src/widgets/dropdown.cpp
#	src/widgets/dropdown_type.h
#	src/window.cpp
This commit is contained in:
Jonathan G Rennison
2024-02-19 18:50:33 +00:00
119 changed files with 4346 additions and 2129 deletions

View File

@@ -22,6 +22,7 @@
* \li AITown::ROAD_LAYOUT_RANDOM
* \li AIVehicle::IsPrimaryVehicle
* \li AITileList_StationCoverage
* \li AIAirport::GetAirportNumHelipads
*
* API removals:
* \li AIError::ERR_PRECONDITION_TOO_MANY_PARAMETERS, that error is never returned anymore.

View File

@@ -88,6 +88,7 @@
* \li GSStoryPage::IsValidStoryPageButtonFlags
* \li GSStoryPage::IsValidStoryPageButtonCursor
* \li GSTileList_StationCoverage
* \li GSAirport::GetAirportNumHelipads
*
* API removals:
* \li GSError::ERR_PRECONDITION_TOO_MANY_PARAMETERS, that error is never returned anymore.

View File

@@ -173,3 +173,10 @@ extern uint8_t GetAirportNoiseLevelForDistance(const struct AirportSpec *as, uin
return (int64_t)GetMaintenanceCostFactor(type) * _price[PR_INFRASTRUCTURE_AIRPORT] >> 3;
}
/* static */ SQInteger ScriptAirport::GetAirportNumHelipads(AirportType type)
{
if (!IsAirportInformationAvailable(type)) return -1;
return ::AirportSpec::Get(type)->fsm->num_helipads;
}

View File

@@ -207,6 +207,14 @@ public:
* @return Monthly maintenance cost of the airport type.
*/
static Money GetMonthlyMaintenanceCost(AirportType type);
/**
* Get the number of helipads of this airport type.
* @param type The airport type.
* @pre IsAirportInformationAvailable(type)
* @return Number of helipads of this type of airport. When 0 helicopters will go to normal terminals.
*/
static SQInteger GetAirportNumHelipads(AirportType type);
};
#endif /* SCRIPT_AIRPORT_HPP */

View File

@@ -108,7 +108,10 @@
/* static */ SQInteger ScriptGroup::GetNumEngines(GroupID group_id, EngineID engine_id)
{
EnforceCompanyModeValid(-1);
if (!IsValidGroup(group_id) && group_id != GROUP_DEFAULT && group_id != GROUP_ALL) return -1;
if (!ScriptEngine::IsValidEngine(engine_id)) return -1;
bool valid_group = IsValidGroup(group_id);
if (!valid_group && group_id != GROUP_DEFAULT && group_id != GROUP_ALL) return -1;
if (valid_group && ScriptEngine::GetVehicleType(engine_id) != GetVehicleType(group_id)) return -1;
return GetGroupNumEngines(ScriptObject::GetCompany(), group_id, engine_id);
}

View File

@@ -129,7 +129,9 @@ public:
* Get the number of engines in a given group.
* @param group_id The group to get the number of engines in.
* @param engine_id The engine id to count.
* @pre IsValidGroup(group_id) || group_id == GROUP_ALL || group_id == GROUP_DEFAULT.
* @pre ScriptEngine::IsValidEngine(engine_id).
* @pre (IsValidGroup(group_id) && ScriptEngine::GetVehicleType(engine_id) == GetVehicleType(group_id)) ||
group_id == GROUP_ALL || group_id == GROUP_DEFAULT.
* @game @pre ScriptCompanyMode::IsValid().
* @return The number of engines with id engine_id in the group with id group_id.
*/

View File

@@ -19,7 +19,7 @@
#include "../safeguards.h"
void ScriptConfig::Change(std::optional<const std::string> name, int version, bool force_exact_match, bool is_random)
void ScriptConfig::Change(std::optional<const std::string> name, int version, bool force_exact_match)
{
if (name.has_value()) {
this->name = std::move(name.value());
@@ -28,7 +28,6 @@ void ScriptConfig::Change(std::optional<const std::string> name, int version, bo
this->info = nullptr;
}
this->version = (info == nullptr) ? -1 : info->GetVersion();
this->is_random = is_random;
this->config_list.reset();
this->to_load_data.reset();
@@ -40,7 +39,6 @@ ScriptConfig::ScriptConfig(const ScriptConfig *config)
this->name = config->name;
this->info = config->info;
this->version = config->version;
this->is_random = config->is_random;
this->to_load_data.reset();
for (const auto &item : config->settings) {
@@ -126,11 +124,11 @@ void ScriptConfig::ResetEditableSettings(bool yet_to_start)
}
}
void ScriptConfig::AddRandomDeviation()
void ScriptConfig::AddRandomDeviation(CompanyID owner)
{
for (const auto &item : *this->GetConfigList()) {
if (item.random_deviation != 0) {
this->SetSetting(item.name, ScriptObject::GetRandomizer(OWNER_NONE).Next(item.random_deviation * 2 + 1) - item.random_deviation + this->GetSetting(item.name));
this->SetSetting(item.name, ScriptObject::GetRandomizer(owner).Next(item.random_deviation * 2 + 1) - item.random_deviation + this->GetSetting(item.name));
}
}
}
@@ -140,11 +138,6 @@ bool ScriptConfig::HasScript() const
return this->info != nullptr;
}
bool ScriptConfig::IsRandom() const
{
return this->is_random;
}
const std::string &ScriptConfig::GetName() const
{
return this->name;

View File

@@ -59,7 +59,6 @@ public:
ScriptConfig() :
version(-1),
info(nullptr),
is_random(false),
to_load_data(nullptr)
{}
@@ -80,7 +79,7 @@ public:
* as specified. If false any compatible version is ok.
* @param is_random Is the Script chosen randomly?
*/
void Change(std::optional<const std::string> name, int version = -1, bool force_exact_match = false, bool is_random = false);
void Change(std::optional<const std::string> name, int version = -1, bool force_exact_match = false);
/**
* Get the ScriptInfo linked to this ScriptConfig.
@@ -139,7 +138,7 @@ public:
/**
* Randomize all settings the Script requested to be randomized.
*/
void AddRandomDeviation();
void AddRandomDeviation(CompanyID owner);
/**
* Is this config attached to an Script? In other words, is there a Script
@@ -147,11 +146,6 @@ public:
*/
bool HasScript() const;
/**
* Is the current Script a randomly chosen Script?
*/
bool IsRandom() const;
/**
* Get the name of the Script.
*/
@@ -191,7 +185,6 @@ protected:
class ScriptInfo *info; ///< ScriptInfo object for related to this Script version
SettingValueList settings; ///< List with all setting=>value pairs that are configure for this Script
std::unique_ptr<ScriptConfigItemList> config_list; ///< List with all settings defined by this Script
bool is_random; ///< True if the AI in this slot was randomly chosen.
std::unique_ptr<ScriptInstance::ScriptData> to_load_data; ///< Data to load after the Script start.
/**

View File

@@ -317,13 +317,11 @@ struct ScriptSettingsWindow : public Window {
closing_dropdown(false),
timeout(0)
{
this->script_config = GetConfig(slot);
this->CreateNestedTree();
this->vscroll = this->GetScrollbar(WID_SCRS_SCROLLBAR);
this->FinishInitNested(slot); // Initializes 'this->line_height' as side effect.
this->RebuildVisibleSettings();
this->OnInvalidateData();
}
void Close(int data = 0) override
@@ -609,6 +607,8 @@ struct ScriptSettingsWindow : public Window {
*/
void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
{
this->script_config = GetConfig(this->slot);
if (this->script_config->GetConfigList()->empty()) this->Close();
this->RebuildVisibleSettings();
HideDropDownMenu(this);
this->CloseChildWindows(WC_QUERY_STRING);
@@ -1231,7 +1231,8 @@ struct ScriptDebugWindow : public Window {
this->SetWidgetLoweredState(WID_SCRD_BREAK_STR_ON_OFF_BTN, this->filter.break_check_enabled);
this->SetWidgetLoweredState(WID_SCRD_MATCH_CASE_BTN, this->filter.case_sensitive_break_check);
this->SetWidgetDisabledState(WID_SCRD_SETTINGS, this->filter.script_debug_company == INVALID_COMPANY);
this->SetWidgetDisabledState(WID_SCRD_SETTINGS, this->filter.script_debug_company == INVALID_COMPANY ||
GetConfig(this->filter.script_debug_company)->GetConfigList()->empty());
extern CompanyID _local_company;
this->SetWidgetDisabledState(WID_SCRD_RELOAD_TOGGLE,
this->filter.script_debug_company == INVALID_COMPANY ||