summaryrefslogtreecommitdiff
path: root/src/script/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/api')
-rw-r--r--src/script/api/game_changelog.hpp1
-rw-r--r--src/script/api/script_industrytype.cpp15
-rw-r--r--src/script/api/script_industrytype.hpp11
3 files changed, 18 insertions, 9 deletions
diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp
index 83a030499..eeb1f05f8 100644
--- a/src/script/api/game_changelog.hpp
+++ b/src/script/api/game_changelog.hpp
@@ -29,6 +29,7 @@
* \li GSStation::IsAirportClosed
* \li GSStation::OpenCloseAirport
* \li GSController::Break
+ * \li GSIndustryType::BuildIndustry, GSIndustryType::CanBuildIndustry, GSIndustryType::ProspectIndustry and GSIndustryType::CanProspectIndustry when outside GSCompanyMode scope
*
* \b 1.2.2
*
diff --git a/src/script/api/script_industrytype.cpp b/src/script/api/script_industrytype.cpp
index 7db905829..bbfca99a4 100644
--- a/src/script/api/script_industrytype.cpp
+++ b/src/script/api/script_industrytype.cpp
@@ -94,7 +94,9 @@
{
if (!IsValidIndustryType(industry_type)) return false;
- if (::GetIndustryProbabilityCallback(industry_type, IACT_USERCREATION, 1) == 0) return false;
+ const bool deity = ScriptObject::GetCompany() == OWNER_DEITY;
+ if (::GetIndustryProbabilityCallback(industry_type, deity ? IACT_RANDOMCREATION : IACT_USERCREATION, 1) == 0) return false;
+ if (deity) return true;
if (!::GetIndustrySpec(industry_type)->IsRawIndustry()) return true;
/* raw_industry_construction == 1 means "Build as other industries" */
@@ -105,26 +107,25 @@
{
if (!IsValidIndustryType(industry_type)) return false;
- if (!::GetIndustrySpec(industry_type)->IsRawIndustry()) return false;
- if (::GetIndustryProbabilityCallback(industry_type, IACT_USERCREATION, 1) == 0) return false;
+ const bool deity = ScriptObject::GetCompany() == OWNER_DEITY;
+ if (!deity && !::GetIndustrySpec(industry_type)->IsRawIndustry()) return false;
+ if (::GetIndustryProbabilityCallback(industry_type, deity ? IACT_RANDOMCREATION : IACT_USERCREATION, 1) == 0) return false;
/* raw_industry_construction == 2 means "prospect" */
- return _settings_game.construction.raw_industry_construction == 2;
+ return deity || _settings_game.construction.raw_industry_construction == 2;
}
/* static */ bool ScriptIndustryType::BuildIndustry(IndustryType industry_type, TileIndex tile)
{
- EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
EnforcePrecondition(false, CanBuildIndustry(industry_type));
EnforcePrecondition(false, ScriptMap::IsValidTile(tile));
uint32 seed = ::InteractiveRandom();
- return ScriptObject::DoCommand(tile, (::InteractiveRandomRange(::GetIndustrySpec(industry_type)->num_table) << 8) | industry_type, seed, CMD_BUILD_INDUSTRY);
+ return ScriptObject::DoCommand(tile, (1 << 16) | (::InteractiveRandomRange(::GetIndustrySpec(industry_type)->num_table) << 8) | industry_type, seed, CMD_BUILD_INDUSTRY);
}
/* static */ bool ScriptIndustryType::ProspectIndustry(IndustryType industry_type)
{
- EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
EnforcePrecondition(false, CanProspectIndustry(industry_type));
uint32 seed = ::InteractiveRandom();
diff --git a/src/script/api/script_industrytype.hpp b/src/script/api/script_industrytype.hpp
index de5180c43..bae0919e9 100644
--- a/src/script/api/script_industrytype.hpp
+++ b/src/script/api/script_industrytype.hpp
@@ -113,6 +113,9 @@ public:
* @pre IsValidIndustryType(industry_type).
* @return True if you can build this type of industry at locations of your choice.
* @note Returns false if you can only prospect this type of industry, or not build it at all.
+ * @game @note If no valid ScriptCompanyMode active in scope, the script can
+ * @game build as long as the industry type can be built. (a NewGRF can for example
+ * @game reject construction based on current year)
*/
static bool CanBuildIndustry(IndustryType industry_type);
@@ -123,6 +126,9 @@ public:
* @return True if you can prospect this type of industry.
* @note If the setting "Manual primary industry construction method" is set
* to either "None" or "as other industries" this function always returns false.
+ * @game @note If no valid ScriptCompanyMode active in scope, the script can
+ * @game prospect as long as the industry type can be built. (a NewGRF can for
+ * @game example reject construction based on current year)
*/
static bool CanProspectIndustry(IndustryType industry_type);
@@ -131,7 +137,6 @@ public:
* @param industry_type The type of the industry to build.
* @param tile The tile to build the industry on.
* @pre CanBuildIndustry(industry_type).
- * @game @pre Valid ScriptCompanyMode active in scope.
* @return True if the industry was successfully build.
*/
static bool BuildIndustry(IndustryType industry_type, TileIndex tile);
@@ -141,10 +146,12 @@ public:
* an industry on a random place on the map.
* @param industry_type The type of the industry.
* @pre CanProspectIndustry(industry_type).
- * @game @pre Valid ScriptCompanyMode active in scope.
* @return True if no error occurred while trying to prospect.
* @note Even if true is returned there is no guarantee a new industry is build.
* @note If true is returned the money is paid, whether a new industry was build or not.
+ * @game @note if no valid ScriptCompanyMode exist in scope, prospection will not fail
+ * @game due to the general chance that prospection may fail. However prospection can still
+ * @game fail if OpenTTD is unable to find a suitable location to place the industry.
*/
static bool ProspectIndustry(IndustryType industry_type);