diff options
author | Pavel Stupnikov <dp@dpointer.org> | 2020-12-22 16:29:48 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-22 14:29:48 +0100 |
commit | 9a45a0f535e312cd97db12c3a2ec1068fa381136 (patch) | |
tree | eb4f235933ea178c370c04c9b12cd00b005f4644 /src/script | |
parent | b7751c483e5545aa683baf0b9f09a0add34cfefd (diff) | |
download | openttd-9a45a0f535e312cd97db12c3a2ec1068fa381136.tar.xz |
Feature: Set exclusive access to industry from GS (#8115)
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/api/game_changelog.hpp | 4 | ||||
-rw-r--r-- | src/script/api/script_industry.cpp | 41 | ||||
-rw-r--r-- | src/script/api/script_industry.hpp | 44 |
3 files changed, 88 insertions, 1 deletions
diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp index abc9e9c35..1f43cdea1 100644 --- a/src/script/api/game_changelog.hpp +++ b/src/script/api/game_changelog.hpp @@ -23,8 +23,12 @@ * \li GSEventStoryPageVehicleSelect * \li GSIndustry::GetCargoLastAcceptedDate * \li GSIndustry::GetControlFlags + * \li GSIndustry::GetExclusiveConsumer + * \li GSIndustry::GetExclusiveSupplier * \li GSIndustry::GetLastProductionYear * \li GSIndustry::SetControlFlags + * \li GSIndustry::SetExclusiveConsumer + * \li GSIndustry::SetExclusiveSupplier * \li GSStoryPage::MakePushButtonReference * \li GSStoryPage::MakeTileButtonReference * \li GSStoryPage::MakeVehicleButtonReference diff --git a/src/script/api/script_industry.cpp b/src/script/api/script_industry.cpp index c2b449b0b..14ba8e402 100644 --- a/src/script/api/script_industry.cpp +++ b/src/script/api/script_industry.cpp @@ -10,7 +10,10 @@ #include "../../stdafx.h" #include "script_industry.hpp" #include "script_cargo.hpp" +#include "script_company.hpp" +#include "script_error.hpp" #include "script_map.hpp" +#include "../../company_base.h" #include "../../industry.h" #include "../../strings_func.h" #include "../../station_base.h" @@ -241,3 +244,41 @@ bool ScriptIndustry::SetControlFlags(IndustryID industry_id, uint32 control_flag return ScriptObject::DoCommand(0, industry_id, 0 | ((control_flags & ::INDCTL_MASK) << 8), CMD_INDUSTRY_CTRL); } + +/* static */ ScriptCompany::CompanyID ScriptIndustry::GetExclusiveSupplier(IndustryID industry_id) +{ + if (!IsValidIndustry(industry_id)) return ScriptCompany::COMPANY_INVALID; + + auto company_id = ::Industry::Get(industry_id)->exclusive_supplier; + if (!::Company::IsValidID(company_id)) return ScriptCompany::COMPANY_INVALID; + + return (ScriptCompany::CompanyID)((byte)company_id); +} + +/* static */ bool ScriptIndustry::SetExclusiveSupplier(IndustryID industry_id, ScriptCompany::CompanyID company_id) +{ + EnforcePrecondition(false, IsValidIndustry(industry_id)); + + auto company = ScriptCompany::ResolveCompanyID(company_id); + ::Owner owner = (company == ScriptCompany::COMPANY_INVALID ? ::INVALID_OWNER : (::Owner)company); + return ScriptObject::DoCommand(0, industry_id, 1 | (((uint8)owner) << 16), CMD_INDUSTRY_CTRL); +} + +/* static */ ScriptCompany::CompanyID ScriptIndustry::GetExclusiveConsumer(IndustryID industry_id) +{ + if (!IsValidIndustry(industry_id)) return ScriptCompany::COMPANY_INVALID; + + auto company_id = ::Industry::Get(industry_id)->exclusive_consumer; + if (!::Company::IsValidID(company_id)) return ScriptCompany::COMPANY_INVALID; + + return (ScriptCompany::CompanyID)((byte)company_id); +} + +/* static */ bool ScriptIndustry::SetExclusiveConsumer(IndustryID industry_id, ScriptCompany::CompanyID company_id) +{ + EnforcePrecondition(false, IsValidIndustry(industry_id)); + + auto company = ScriptCompany::ResolveCompanyID(company_id); + ::Owner owner = (company == ScriptCompany::COMPANY_INVALID ? ::INVALID_OWNER : (::Owner)company); + return ScriptObject::DoCommand(0, industry_id, 2 | (((uint8)owner) << 16), CMD_INDUSTRY_CTRL); +} diff --git a/src/script/api/script_industry.hpp b/src/script/api/script_industry.hpp index 2fbd861cc..dac3d32fd 100644 --- a/src/script/api/script_industry.hpp +++ b/src/script/api/script_industry.hpp @@ -10,8 +10,9 @@ #ifndef SCRIPT_INDUSTRY_HPP #define SCRIPT_INDUSTRY_HPP -#include "script_object.hpp" +#include "script_company.hpp" #include "script_date.hpp" +#include "script_object.hpp" #include "../../industry.h" /** @@ -259,6 +260,47 @@ public: * @api -ai */ static bool SetControlFlags(IndustryID industry_id, uint32 control_flags); + + /** + * Find out which company currently has the exclusive rights to deliver cargo to the industry. + * @param industry_id The index of the industry. + * @pre IsValidIndustry(industry_id). + * @return The company that has the exclusive rights. The value + * ScriptCompany::COMPANY_INVALID means that there are currently no + * exclusive rights given out to anyone. + */ + static ScriptCompany::CompanyID GetExclusiveSupplier(IndustryID industry_id); + + /** + * Sets or resets the company that has exclusive right to deliver cargo to the industry. + * @param industry_id The index of the industry. + * @param company_id The company to set (ScriptCompany::COMPANY_INVALID to reset). + * @pre IsValidIndustry(industry_id). + * @return True if the action succeeded. + * @api -ai + */ + static bool SetExclusiveSupplier(IndustryID industry_id, ScriptCompany::CompanyID company_id); + + /** + * Find out which company currently has the exclusive rights to take cargo from the industry. + * @param industry_id The index of the industry. + * @pre IsValidIndustry(industry_id). + * @return The company that has the exclusive rights. The value + * ScriptCompany::COMPANY_SPECTATOR means that there are currently no + * exclusive rights given out to anyone. + */ + static ScriptCompany::CompanyID GetExclusiveConsumer(IndustryID industry_id); + + /** + * Sets or resets the company that has exclusive right to take cargo from the industry. + * @param industry_id The index of the industry. + * @param company_id The company to set (ScriptCompany::COMPANY_INVALID to reset). + * @pre IsValidIndustry(industry_id). + * @return True if the action succeeded. + * @api -ai + */ + static bool SetExclusiveConsumer(IndustryID industry_id, ScriptCompany::CompanyID company_id); + }; #endif /* SCRIPT_INDUSTRY_HPP */ |