Changeset - r15256:e22f3389fd3a
[Not reviewed]
master
0 5 0
frosch - 14 years ago 2010-05-29 13:08:50
frosch@openttd.org
(svn r19901) -Add: [NewGRF] Access to industry founder (var A7) during callbacks 28 and 2F. (yexo)
5 files changed with 14 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/industry_cmd.cpp
Show inline comments
 
@@ -1318,16 +1318,17 @@ bool IsSlopeRefused(Slope current, Slope
 
/** Are the tiles of the industry free?
 
 * @param tile                     Position to check.
 
 * @param it                       Industry tiles table.
 
 * @param itspec_index             The index of the itsepc to build/fund
 
 * @param type                     Type of the industry.
 
 * @param initial_random_bits      The random bits the industry is going to have after construction.
 
 * @param founder Industry founder
 
 * @param [out] custom_shape_check Perform custom check for the site.
 
 * @return Failed or succeeded command.
 
 */
 
static CommandCost CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable *it, uint itspec_index, int type, uint16 initial_random_bits, bool *custom_shape_check = NULL)
 
static CommandCost CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable *it, uint itspec_index, int type, uint16 initial_random_bits, Owner founder, bool *custom_shape_check = NULL)
 
{
 
	bool refused_slope = false;
 
	bool custom_shape = false;
 

	
 
	do {
 
		IndustryGfx gfx = GetTranslatedIndustryTileID(it->gfx);
 
@@ -1353,13 +1354,13 @@ static CommandCost CheckIfIndustryTilesA
 

	
 
			/* Perform land/water check if not disabled */
 
			if (!HasBit(its->slopes_refused, 5) && (IsWaterTile(cur_tile) == !(ind_behav & INDUSTRYBEH_BUILT_ONWATER))) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
 

	
 
			if (HasBit(its->callback_mask, CBM_INDT_SHAPE_CHECK)) {
 
				custom_shape = true;
 
				CommandCost ret = PerformIndustryTileSlopeCheck(tile, cur_tile, its, type, gfx, itspec_index, initial_random_bits);
 
				CommandCost ret = PerformIndustryTileSlopeCheck(tile, cur_tile, its, type, gfx, itspec_index, initial_random_bits, founder);
 
				if (ret.Failed()) return ret;
 
			} else {
 
				Slope tileh = GetTileSlope(cur_tile, NULL);
 
				refused_slope |= IsSlopeRefused(tileh, its->slopes_refused);
 
			}
 

	
 
@@ -1705,17 +1706,17 @@ static CommandCost CreateNewIndustryHelp
 
	assert(itspec_index < indspec->num_table);
 
	const IndustryTileTable *it = indspec->table[itspec_index];
 
	bool custom_shape_check = false;
 

	
 
	*ip = NULL;
 

	
 
	CommandCost ret = CheckIfIndustryTilesAreFree(tile, it, itspec_index, type, random_initial_bits, &custom_shape_check);
 
	CommandCost ret = CheckIfIndustryTilesAreFree(tile, it, itspec_index, type, random_initial_bits, founder, &custom_shape_check);
 
	if (ret.Failed()) return ret;
 

	
 
	if (HasBit(GetIndustrySpec(type)->callback_mask, CBM_IND_LOCATION)) {
 
		ret = CheckIfCallBackAllowsCreation(tile, type, itspec_index, random_var8f, random_initial_bits);
 
		ret = CheckIfCallBackAllowsCreation(tile, type, itspec_index, random_var8f, random_initial_bits, founder);
 
	} else {
 
		ret = _check_new_industry_procs[indspec->check_proc](tile);
 
	}
 
	if (ret.Failed()) return ret;
 

	
 
	if (!custom_shape_check && _settings_game.game_creation.land_generator == LG_TERRAGENESIS && _generating_world &&
 
@@ -1808,13 +1809,13 @@ CommandCost CmdBuildIndustry(TileIndex t
 
		if (num >= count) return CMD_ERROR;
 

	
 
		CommandCost ret = CommandCost(STR_ERROR_SITE_UNSUITABLE);
 
		do {
 
			if (--count < 0) return ret;
 
			if (--num < 0) num = indspec->num_table - 1;
 
			ret = CheckIfIndustryTilesAreFree(tile, itt[num], num, it, random_initial_bits);
 
			ret = CheckIfIndustryTilesAreFree(tile, itt[num], num, it, random_initial_bits, _current_company);
 
		} while (ret.Failed());
 

	
 
		ret = CreateNewIndustryHelper(tile, it, flags, indspec, num, random_var8f, random_initial_bits, _current_company, &ind);
 
		if (ret.Failed()) return ret;
 
	}
 

	
src/newgrf_industries.cpp
Show inline comments
 
@@ -450,15 +450,16 @@ uint32 IndustryLocationGetVariable(const
 
/** 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.
 
 * @param initial_random_bits The random bits the industry is going to have after construction.
 
 * @param founder Industry founder
 
 * @return Succeeded or failed command.
 
 */
 
CommandCost CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint layout, uint32 seed, uint16 initial_random_bits)
 
CommandCost CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint layout, uint32 seed, uint16 initial_random_bits, Owner founder)
 
{
 
	const IndustrySpec *indspec = GetIndustrySpec(type);
 

	
 
	ResolverObject object;
 
	const SpriteGroup *group;
 

	
 
@@ -467,12 +468,13 @@ CommandCost CheckIfCallBackAllowsCreatio
 
	ind.location.tile = tile;
 
	ind.location.w = 0; // important to mark the industry invalid
 
	ind.type = type;
 
	ind.selected_layout = layout;
 
	ind.town = ClosestTownFromTile(tile, UINT_MAX);
 
	ind.random = initial_random_bits;
 
	ind.founder = founder;
 

	
 
	NewIndustryResolver(&object, tile, &ind, type);
 
	object.GetVariable = IndustryLocationGetVariable;
 
	object.callback = CBID_INDUSTRY_LOCATION;
 
	_industry_creation_random_bits = seed;
 

	
src/newgrf_industries.h
Show inline comments
 
@@ -34,13 +34,13 @@ enum IndustryAvailabilityCallType {
 

	
 
/* in newgrf_industry.cpp */
 
uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available);
 
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);
 
CommandCost CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint layout, uint32 seed, uint16 initial_random_bits);
 
CommandCost CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint layout, uint32 seed, uint16 initial_random_bits, Owner founder);
 
bool CheckIfCallBackAllowsAvailability(IndustryType type, IndustryAvailabilityCallType creation_type);
 

	
 
IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32 grf_id);
 

	
 
/* in newgrf_industrytiles.cpp*/
 
uint32 GetNearbyIndustryTileInformation(byte parameter, TileIndex tile, IndustryID index);
src/newgrf_industrytiles.cpp
Show inline comments
 
@@ -255,22 +255,24 @@ extern bool IsSlopeRefused(Slope current
 
 * @param ind_tile      Tile to check.
 
 * @param its           Tile specification.
 
 * @param type          Industry type.
 
 * @param gfx           Gfx of the tile.
 
 * @param itspec_index  Layout.
 
 * @param initial_random_bits Random bits of industry after construction
 
 * @param founder       Industry founder
 
 * @return Suceeded or failed command.
 
 */
 
CommandCost PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind_tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx, uint itspec_index, uint16 initial_random_bits)
 
CommandCost PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind_tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx, uint itspec_index, uint16 initial_random_bits, Owner founder)
 
{
 
	Industry ind;
 
	ind.index = INVALID_INDUSTRY;
 
	ind.location.tile = ind_base_tile;
 
	ind.location.w = 0;
 
	ind.type = type;
 
	ind.random = initial_random_bits;
 
	ind.founder = founder;
 

	
 
	uint16 callback_res = GetIndustryTileCallback(CBID_INDTILE_SHAPE_CHECK, 0, itspec_index, gfx, &ind, ind_tile);
 
	if (callback_res == CALLBACK_FAILED) {
 
		if (!IsSlopeRefused(GetTileSlope(ind_tile, NULL), its->slopes_refused)) return CommandCost();
 
		return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
 
	}
src/newgrf_industrytiles.h
Show inline comments
 
@@ -24,13 +24,13 @@ enum IndustryAnimationTrigger {
 
	IAT_INDUSTRY_RECEIVED_CARGO,
 
	IAT_INDUSTRY_DISTRIBUTES_CARGO,
 
};
 

	
 
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);
 
CommandCost PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind_tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx, uint itspec_index, uint16 initial_random_bits);
 
CommandCost PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind_tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx, uint itspec_index, uint16 initial_random_bits, Owner founder);
 

	
 
void AnimateNewIndustryTile(TileIndex tile);
 
bool StartStopIndustryTileAnimation(TileIndex tile, IndustryAnimationTrigger iat, uint32 random = Random());
 
bool StartStopIndustryTileAnimation(const Industry *ind, IndustryAnimationTrigger iat);
 

	
 

	
0 comments (0 inline, 0 general)