(svn r19185) -Codechange: Return succeeded or failed CommandCost from CheckIfCallBackAllowsCreation().

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
alberth 15 years ago
parent c4f67de69c
commit 82a4d532b6

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

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

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

Loading…
Cancel
Save