summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2010-02-21 17:01:23 +0000
committeralberth <alberth@openttd.org>2010-02-21 17:01:23 +0000
commit82a4d532b6395172537577974f18e4b61aa99bf4 (patch)
tree2c310157d0b313a84e77b82232681d7318818744 /src
parentc4f67de69c84d4bc500d006af25fccdf0e4569af (diff)
downloadopenttd-82a4d532b6395172537577974f18e4b61aa99bf4.tar.xz
(svn r19185) -Codechange: Return succeeded or failed CommandCost from CheckIfCallBackAllowsCreation().
Diffstat (limited to 'src')
-rw-r--r--src/industry_cmd.cpp6
-rw-r--r--src/newgrf_industries.cpp26
-rw-r--r--src/newgrf_industries.h3
3 files changed, 21 insertions, 14 deletions
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index 846f3c9cc..e16d5b261 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -1708,12 +1708,12 @@ static Industry *CreateNewIndustryHelper(TileIndex tile, IndustryType type, DoCo
if (ret.Failed()) return NULL;
if (HasBit(GetIndustrySpec(type)->callback_mask, CBM_IND_LOCATION)) {
- if (!CheckIfCallBackAllowsCreation(tile, type, itspec_index, seed)) return NULL;
+ ret = CheckIfCallBackAllowsCreation(tile, type, itspec_index, seed);
} else {
ret = _check_new_industry_procs[indspec->check_proc](tile);
- ret.SetGlobalErrorMessage();
- if (ret.Failed()) return NULL;
}
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return NULL;
if (!custom_shape_check && _settings_game.game_creation.land_generator == LG_TERRAGENESIS && _generating_world && !_ignore_restrictions && !CheckIfCanLevelIndustryPlatform(tile, DC_NO_WATER, it, type)) return NULL;
ret = CheckIfFarEnoughFromIndustry(tile, type);
diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp
index 7c62a650f..905e66739 100644
--- a/src/newgrf_industries.cpp
+++ b/src/newgrf_industries.cpp
@@ -448,7 +448,14 @@ uint32 IndustryLocationGetVariable(const ResolverObject *object, byte variable,
return IndustryGetVariable(object, variable, parameter, available);
}
-bool CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint itspec_index, uint32 seed)
+/** Check that the industry callback allows creation of the industry.
+ * @param tile %Tile to build the industry.
+ * @param type Type of industry to build.
+ * @param layout Layout number.
+ * @param seed Seed for the random generator.
+ * @return Succeeded or failed command.
+ */
+CommandCost CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint layout, uint32 seed)
{
const IndustrySpec *indspec = GetIndustrySpec(type);
@@ -460,7 +467,7 @@ bool CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint itspe
ind.location.tile = tile;
ind.location.w = 0;
ind.type = type;
- ind.selected_layout = itspec_index;
+ ind.selected_layout = layout;
ind.town = ClosestTownFromTile(tile, UINT_MAX);
NewIndustryResolver(&object, tile, &ind, type);
@@ -472,9 +479,9 @@ bool CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint itspe
/* Unlike the "normal" cases, not having a valid result means we allow
* the building of the industry, as that's how it's done in TTDP. */
- if (group == NULL) return true;
+ if (group == NULL) return CommandCost();
uint16 result = group->GetCallbackResult();
- if (result == 0x400 || result == CALLBACK_FAILED) return true;
+ if (result == 0x400 || result == CALLBACK_FAILED) return CommandCost();
/* Copy some parameters from the registers to the error message text ref. stack */
SwitchToErrorRefStack();
@@ -482,13 +489,12 @@ bool CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint itspe
SwitchToNormalRefStack();
switch (result) {
- case 0x401: _error_message = STR_ERROR_SITE_UNSUITABLE; break;
- case 0x402: _error_message = STR_ERROR_CAN_ONLY_BE_BUILT_IN_RAINFOREST; break;
- case 0x403: _error_message = STR_ERROR_CAN_ONLY_BE_BUILT_IN_DESERT; break;
- default: _error_message = GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + result); break;
+ case 0x401: return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
+ case 0x402: return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_IN_RAINFOREST);
+ case 0x403: return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_IN_DESERT);
+ default: return_cmd_error(GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + result));
}
-
- return false;
+ NOT_REACHED();
}
bool CheckIfCallBackAllowsAvailability(IndustryType type, IndustryAvailabilityCallType creation_type)
diff --git a/src/newgrf_industries.h b/src/newgrf_industries.h
index 3013f9170..2d103f99b 100644
--- a/src/newgrf_industries.h
+++ b/src/newgrf_industries.h
@@ -12,6 +12,7 @@
#ifndef NEWGRF_INDUSTRIES_H
#define NEWGRF_INDUSTRIES_H
+#include "command_type.h"
#include "newgrf_spritegroup.h"
/** When should the industry(tile) be triggered for random bits? */
@@ -36,7 +37,7 @@ uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte par
uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile);
uint32 GetIndustryIDAtOffset(TileIndex new_tile, const Industry *i, uint32 cur_grfid);
void IndustryProductionCallback(Industry *ind, int reason);
-bool CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint itspec_index, uint32 seed);
+CommandCost CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint layout, uint32 seed);
bool CheckIfCallBackAllowsAvailability(IndustryType type, IndustryAvailabilityCallType creation_type);
IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32 grf_id);