(svn r19269) -Codechange: PerformIndustryTileSlopeCheck() returns a succeeded or failed command.

This commit is contained in:
alberth 2010-02-27 10:21:59 +00:00
parent 1c66ce9ea3
commit b33264f30f
3 changed files with 23 additions and 10 deletions

View File

@ -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);

View File

@ -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));
}
}

View File

@ -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());