diff options
author | alberth <alberth@openttd.org> | 2010-02-27 10:21:59 +0000 |
---|---|---|
committer | alberth <alberth@openttd.org> | 2010-02-27 10:21:59 +0000 |
commit | b33264f30f598244f24fae9ed2aca7adc037f831 (patch) | |
tree | c275bc0fa5b83c7c459dd5973adc8d7b4bed8d53 /src | |
parent | 1c66ce9ea3affb6c33389dd0ac3b3c2a832fa335 (diff) | |
download | openttd-b33264f30f598244f24fae9ed2aca7adc037f831.tar.xz |
(svn r19269) -Codechange: PerformIndustryTileSlopeCheck() returns a succeeded or failed command.
Diffstat (limited to 'src')
-rw-r--r-- | src/industry_cmd.cpp | 4 | ||||
-rw-r--r-- | src/newgrf_industrytiles.cpp | 27 | ||||
-rw-r--r-- | src/newgrf_industrytiles.h | 2 |
3 files changed, 23 insertions, 10 deletions
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index ec52c15b0..f4eee73e3 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -1349,7 +1349,9 @@ static CommandCost CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTil if (HasBit(its->callback_mask, CBM_INDT_SHAPE_CHECK)) { custom_shape = true; - if (!PerformIndustryTileSlopeCheck(tile, cur_tile, its, type, gfx, itspec_index)) return_cmd_error(_error_message); + CommandCost ret = PerformIndustryTileSlopeCheck(tile, cur_tile, its, type, gfx, itspec_index); + ret.SetGlobalErrorMessage(); + if (ret.Failed()) return ret; } else { Slope tileh = GetTileSlope(cur_tile, NULL); refused_slope |= IsSlopeRefused(tileh, its->slopes_refused); diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp index 63e8b7524..26905c004 100644 --- a/src/newgrf_industrytiles.cpp +++ b/src/newgrf_industrytiles.cpp @@ -238,7 +238,16 @@ bool DrawNewIndustryTile(TileInfo *ti, Industry *i, IndustryGfx gfx, const Indus extern bool IsSlopeRefused(Slope current, Slope refused); -bool PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind_tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx, uint itspec_index) +/** Check the slope of a tile of a new industry. + * @param ind_base_tile Base tile of the industry. + * @param ind_tile Tile to check. + * @param its Tile specification. + * @param type Industry type. + * @param gfx Gfx of the tile. + * @param itspec_index Layout. + * @return Suceeded or failed command. + */ +CommandCost PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind_tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx, uint itspec_index) { Industry ind; ind.index = INVALID_INDUSTRY; @@ -248,12 +257,14 @@ bool PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind_tile, uint16 callback_res = GetIndustryTileCallback(CBID_INDTILE_SHAPE_CHECK, 0, itspec_index, gfx, &ind, ind_tile); if (callback_res == CALLBACK_FAILED) { - return !IsSlopeRefused(GetTileSlope(ind_tile, NULL), its->slopes_refused); + if (!IsSlopeRefused(GetTileSlope(ind_tile, NULL), its->slopes_refused)) return CommandCost(); + return_cmd_error(STR_ERROR_SITE_UNSUITABLE); } if (its->grf_prop.grffile->grf_version < 7) { - return callback_res != 0; + if (callback_res != 0) return CommandCost(); + return_cmd_error(STR_ERROR_SITE_UNSUITABLE); } - if (callback_res == 0x400) return true; + if (callback_res == 0x400) return CommandCost(); /* Copy some parameters from the registers to the error message text ref. stack */ SwitchToErrorRefStack(); @@ -261,10 +272,10 @@ bool PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind_tile, SwitchToNormalRefStack(); switch (callback_res) { - case 0x401: _error_message = STR_ERROR_SITE_UNSUITABLE; return false; - case 0x402: _error_message = STR_ERROR_CAN_ONLY_BE_BUILT_IN_RAINFOREST; return false; - case 0x403: _error_message = STR_ERROR_CAN_ONLY_BE_BUILT_IN_DESERT; return false; - default: _error_message = GetGRFStringID(its->grf_prop.grffile->grfid, 0xD000 + callback_res); return false; + 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(its->grf_prop.grffile->grfid, 0xD000 + callback_res)); } } diff --git a/src/newgrf_industrytiles.h b/src/newgrf_industrytiles.h index 15751ff81..086e6b120 100644 --- a/src/newgrf_industrytiles.h +++ b/src/newgrf_industrytiles.h @@ -27,7 +27,7 @@ enum IndustryAnimationTrigger { bool DrawNewIndustryTile(TileInfo *ti, Industry *i, IndustryGfx gfx, const IndustryTileSpec *inds); uint16 GetIndustryTileCallback(CallbackID callback, uint32 param1, uint32 param2, IndustryGfx gfx_id, Industry *industry, TileIndex tile); -bool PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind_tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx, uint itspec_index); +CommandCost PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind_tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx, uint itspec_index); void AnimateNewIndustryTile(TileIndex tile); bool StartStopIndustryTileAnimation(TileIndex tile, IndustryAnimationTrigger iat, uint32 random = Random()); |