diff options
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/api/game_changelog.hpp | 4 | ||||
-rw-r--r-- | src/script/api/script_cargo.hpp | 1 | ||||
-rw-r--r-- | src/script/api/script_industry.cpp | 37 | ||||
-rw-r--r-- | src/script/api/script_industry.hpp | 63 |
4 files changed, 105 insertions, 0 deletions
diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp index fc917a012..abc9e9c35 100644 --- a/src/script/api/game_changelog.hpp +++ b/src/script/api/game_changelog.hpp @@ -21,6 +21,10 @@ * \li GSEventStoryPageButtonClick * \li GSEventStoryPageTileSelect * \li GSEventStoryPageVehicleSelect + * \li GSIndustry::GetCargoLastAcceptedDate + * \li GSIndustry::GetControlFlags + * \li GSIndustry::GetLastProductionYear + * \li GSIndustry::SetControlFlags * \li GSStoryPage::MakePushButtonReference * \li GSStoryPage::MakeTileButtonReference * \li GSStoryPage::MakeVehicleButtonReference diff --git a/src/script/api/script_cargo.hpp b/src/script/api/script_cargo.hpp index 4aab97c70..9ecd4cbfb 100644 --- a/src/script/api/script_cargo.hpp +++ b/src/script/api/script_cargo.hpp @@ -57,6 +57,7 @@ public: /* Note: these values represent part of the in-game CargoTypes enum */ CT_AUTO_REFIT = ::CT_AUTO_REFIT, ///< Automatically choose cargo type when doing auto-refitting. CT_NO_REFIT = ::CT_NO_REFIT, ///< Do not refit cargo of a vehicle. + CT_INVALID = ::CT_INVALID, ///< An invalid cargo type. }; /** diff --git a/src/script/api/script_industry.cpp b/src/script/api/script_industry.cpp index 4d1e91a3c..c2b449b0b 100644 --- a/src/script/api/script_industry.cpp +++ b/src/script/api/script_industry.cpp @@ -16,6 +16,7 @@ #include "../../station_base.h" #include "../../newgrf_industries.h" #include "table/strings.h" +#include <numeric> #include "../../safeguards.h" @@ -204,3 +205,39 @@ return ::Industry::Get(industry_id)->type; } + +int32 ScriptIndustry::GetLastProductionYear(IndustryID industry_id) +{ + Industry *i = Industry::GetIfValid(industry_id); + if (i == nullptr) return 0; + return i->last_prod_year; +} + +ScriptDate::Date ScriptIndustry::GetCargoLastAcceptedDate(IndustryID industry_id, CargoID cargo_type) +{ + Industry *i = Industry::GetIfValid(industry_id); + if (i == nullptr) return ScriptDate::DATE_INVALID; + + if (cargo_type == CT_INVALID) { + return (ScriptDate::Date)std::accumulate(std::begin(i->last_cargo_accepted_at), std::end(i->last_cargo_accepted_at), 0, [](Date a, Date b) { return std::max(a, b); }); + } else { + int index = i->GetCargoAcceptedIndex(cargo_type); + if (index < 0) return ScriptDate::DATE_INVALID; + return (ScriptDate::Date)i->last_cargo_accepted_at[index]; + } +} + +uint32 ScriptIndustry::GetControlFlags(IndustryID industry_id) +{ + Industry *i = Industry::GetIfValid(industry_id); + if (i == nullptr) return 0; + return i->ctlflags; +} + +bool ScriptIndustry::SetControlFlags(IndustryID industry_id, uint32 control_flags) +{ + if (ScriptObject::GetCompany() != OWNER_DEITY) return false; + if (!IsValidIndustry(industry_id)) return false; + + return ScriptObject::DoCommand(0, industry_id, 0 | ((control_flags & ::INDCTL_MASK) << 8), CMD_INDUSTRY_CTRL); +} diff --git a/src/script/api/script_industry.hpp b/src/script/api/script_industry.hpp index 98c7d33ac..2fbd861cc 100644 --- a/src/script/api/script_industry.hpp +++ b/src/script/api/script_industry.hpp @@ -11,6 +11,8 @@ #define SCRIPT_INDUSTRY_HPP #include "script_object.hpp" +#include "script_date.hpp" +#include "../../industry.h" /** * Class that handles all industry related functions. @@ -26,6 +28,27 @@ public: }; /** + * Control flags for industry + * @api -ai + */ + enum IndustryControlFlags { + /** + * When industry production change is evaluated, rolls to decrease are ignored. + * This also prevents industry closure due to production dropping to the lowest level. + */ + INDCTL_NO_PRODUCTION_DECREASE = ::INDCTL_NO_PRODUCTION_DECREASE, + /** + * When industry production change is evaluated, rolls to increase are ignored. + */ + INDCTL_NO_PRODUCTION_INCREASE = ::INDCTL_NO_PRODUCTION_INCREASE, + /** + * Industry can not close regardless of production level or time since last delivery. + * This does not prevent a closure already announced. + */ + INDCTL_NO_CLOSURE = ::INDCTL_NO_CLOSURE, + }; + + /** * Gets the number of industries. * @return The number of industries. * @note The maximum valid IndustryID can be higher than the value returned. @@ -196,6 +219,46 @@ public: * @return The IndustryType of the industry. */ static IndustryType GetIndustryType(IndustryID industry_id); + + /** + * Get the last year this industry had any production output. + * @param industry_id The index of the industry. + * @pre IsValidIndustry(industry_id). + * @return Year the industry last had production, 0 if error. + * @api -ai + */ + static int32 GetLastProductionYear(IndustryID industry_id); + + /** + * Get the last date this industry accepted any cargo delivery. + * @param industry_id The index of the industry. + * @param cargo_type The cargo to query, or CT_INVALID to query latest of all accepted cargoes. + * @pre IsValidIndustry(industry_id). + * @pre IsValidCargo(cargo_type) || cargo_type == CT_INVALID. + * @return Date the industry last received cargo from a delivery, or ScriptDate::DATE_INVALID on error. + * @api -ai + */ + static ScriptDate::Date GetCargoLastAcceptedDate(IndustryID industry_id, CargoID cargo_type); + + /** + * Get the current control flags for an industry. + * @param industry_id The index of the industry. + * @pre IsValidIndustry(industry_id). + * @return Bit flags of the IndustryControlFlags enumeration. + * @api -ai + */ + static uint32 GetControlFlags(IndustryID industry_id); + + /** + * Change the control flags for an industry. + * @param industry_id The index of the industry. + * @param control_flags New flags as a combination of IndustryControlFlags values. + * @pre IsValidIndustry(industry_id). + * @pre No ScriptCompanyMode may be in scope. + * @return True if the action succeeded. + * @api -ai + */ + static bool SetControlFlags(IndustryID industry_id, uint32 control_flags); }; #endif /* SCRIPT_INDUSTRY_HPP */ |