diff --git a/src/script/api/ai_changelog.hpp b/src/script/api/ai_changelog.hpp index dc4af49213..f728ab18fe 100644 --- a/src/script/api/ai_changelog.hpp +++ b/src/script/api/ai_changelog.hpp @@ -17,6 +17,7 @@ * * This version is not yet released. The following changes are not set in stone yet. * + * \li AIIndustryType::ResolveNewGRFID * \li AIObjectType::ResolveNewGRFID * * \b 12.0 diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp index e99ac2f1f5..159671807d 100644 --- a/src/script/api/game_changelog.hpp +++ b/src/script/api/game_changelog.hpp @@ -17,6 +17,7 @@ * * This version is not yet released. The following changes are not set in stone yet. * + * \li GSIndustryType::ResolveNewGRFID * \li GSObjectType::ResolveNewGRFID * * \b 12.0 diff --git a/src/script/api/script_industrytype.cpp b/src/script/api/script_industrytype.cpp index ce8d63e512..14b9a3f67a 100644 --- a/src/script/api/script_industrytype.cpp +++ b/src/script/api/script_industrytype.cpp @@ -154,3 +154,11 @@ return (::GetIndustrySpec(industry_type)->behaviour & INDUSTRYBEH_AI_AIRSHIP_ROUTES) != 0; } + +/* static */ IndustryType ScriptIndustryType::ResolveNewGRFID(uint32 grfid, uint16 grf_local_id) +{ + EnforcePrecondition(INVALID_INDUSTRYTYPE, IsInsideBS(grf_local_id, 0x00, NUM_INDUSTRYTYPES_PER_GRF)); + + grfid = BSWAP32(grfid); // Match people's expectations. + return _industry_mngr.GetID(grf_local_id, grfid); +} diff --git a/src/script/api/script_industrytype.hpp b/src/script/api/script_industrytype.hpp index 3314cb053f..e68546cced 100644 --- a/src/script/api/script_industrytype.hpp +++ b/src/script/api/script_industrytype.hpp @@ -181,6 +181,15 @@ public: * @return True when this type has a dock. */ static bool HasDock(IndustryType industry_type); + + /** + * Get a specific industry-type from a grf. + * @param grf_id The ID of the NewGRF. + * @param grf_local_id The ID of the industry, local to the NewGRF. + * @pre 0x00 <= grf_local_id < NUM_INDUSTRYTYPES_PER_GRF. + * @return the industry-type ID, local to the current game (this diverges from the grf_local_id). + */ + static IndustryType ResolveNewGRFID(uint32 grfid, uint16 grf_local_id); }; #endif /* SCRIPT_INDUSTRYTYPE_HPP */