summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/command.cpp2
-rw-r--r--src/industry_cmd.cpp14
-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
5 files changed, 27 insertions, 16 deletions
diff --git a/src/command.cpp b/src/command.cpp
index bc33c27d5..aa2723e90 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -242,7 +242,7 @@ static const Command _command_proc_table[] = {
DEF_CMD(CmdChangeServiceInt, 0, CMDT_VEHICLE_MANAGEMENT ), // CMD_CHANGE_SERVICE_INT
- DEF_CMD(CmdBuildIndustry, 0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_INDUSTRY
+ DEF_CMD(CmdBuildIndustry, CMD_DEITY, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_INDUSTRY
DEF_CMD(CmdSetCompanyManagerFace, 0, CMDT_OTHER_MANAGEMENT ), // CMD_SET_COMPANY_MANAGER_FACE
DEF_CMD(CmdSetCompanyColour, 0, CMDT_OTHER_MANAGEMENT ), // CMD_SET_COMPANY_COLOUR
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index abb41e6db..ab10c7de8 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -1827,6 +1827,7 @@ static CommandCost CreateNewIndustryHelper(TileIndex tile, IndustryType type, Do
* @param p1 various bitstuffed elements
* - p1 = (bit 0 - 7) - industry type see build_industry.h and see industry.h
* - p1 = (bit 8 - 15) - first layout to try
+ * - p1 = (bit 16 ) - 0 = prospect, 1 = fund (only valid if current company is DEITY)
* @param p2 seed to use for desyncfree randomisations
* @param text unused
* @return the cost of this operation or an error
@@ -1843,11 +1844,11 @@ CommandCost CmdBuildIndustry(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
/* If the setting for raw-material industries is not on, you cannot build raw-material industries.
* Raw material industries are industries that do not accept cargo (at least for now) */
- if (_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 0 && indspec->IsRawIndustry()) {
+ if (_game_mode != GM_EDITOR && _current_company != OWNER_DEITY && _settings_game.construction.raw_industry_construction == 0 && indspec->IsRawIndustry()) {
return CMD_ERROR;
}
- if (_game_mode != GM_EDITOR && GetIndustryProbabilityCallback(it, IACT_USERCREATION, 1) == 0) {
+ if (_game_mode != GM_EDITOR && GetIndustryProbabilityCallback(it, _current_company == OWNER_DEITY ? IACT_RANDOMCREATION : IACT_USERCREATION, 1) == 0) {
return CMD_ERROR;
}
@@ -1857,16 +1858,17 @@ CommandCost CmdBuildIndustry(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
uint32 random_var8f = randomizer.Next();
int num_layouts = indspec->num_table;
CommandCost ret = CommandCost(STR_ERROR_SITE_UNSUITABLE);
+ const bool deity_prospect = _current_company == OWNER_DEITY && !HasBit(p1, 16);
Industry *ind = NULL;
- if (_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && indspec->IsRawIndustry()) {
+ if (deity_prospect || (_game_mode != GM_EDITOR && _current_company != OWNER_DEITY && _settings_game.construction.raw_industry_construction == 2 && indspec->IsRawIndustry())) {
if (flags & DC_EXEC) {
/* Prospected industries are build as OWNER_TOWN to not e.g. be build on owned land of the founder */
Backup<CompanyByte> cur_company(_current_company, OWNER_TOWN, FILE_LINE);
/* Prospecting has a chance to fail, however we cannot guarantee that something can
* be built on the map, so the chance gets lower when the map is fuller, but there
* is nothing we can really do about that. */
- if (Random() <= indspec->prospecting_chance) {
+ if (deity_prospect || Random() <= indspec->prospecting_chance) {
for (int i = 0; i < 5000; i++) {
/* We should not have more than one Random() in a function call
* because parameter evaluation order is not guaranteed in the c++ standard
@@ -1877,7 +1879,7 @@ CommandCost CmdBuildIndustry(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
/* Check now each layout, starting with the random one */
for (int j = 0; j < num_layouts; j++) {
layout = (layout + 1) % num_layouts;
- ret = CreateNewIndustryHelper(tile, it, flags, indspec, layout, random_var8f, random_initial_bits, cur_company.GetOriginalValue(), IACT_PROSPECTCREATION, &ind);
+ ret = CreateNewIndustryHelper(tile, it, flags, indspec, layout, random_var8f, random_initial_bits, cur_company.GetOriginalValue(), _current_company == OWNER_DEITY ? IACT_RANDOMCREATION : IACT_PROSPECTCREATION, &ind);
if (ret.Succeeded()) break;
}
if (ret.Succeeded()) break;
@@ -1892,7 +1894,7 @@ CommandCost CmdBuildIndustry(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
/* Check subsequently each layout, starting with the given layout in p1 */
for (int i = 0; i < num_layouts; i++) {
layout = (layout + 1) % num_layouts;
- ret = CreateNewIndustryHelper(tile, it, flags, indspec, layout, random_var8f, random_initial_bits, _current_company, IACT_USERCREATION, &ind);
+ ret = CreateNewIndustryHelper(tile, it, flags, indspec, layout, random_var8f, random_initial_bits, _current_company, _current_company == OWNER_DEITY ? IACT_RANDOMCREATION : IACT_USERCREATION, &ind);
if (ret.Succeeded()) break;
}
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);