Changeset - r7662:914446395fe3
[Not reviewed]
master
0 3 0
rubidium - 17 years ago 2007-10-02 16:56:45
rubidium@openttd.org
(svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
3 files changed with 31 insertions and 23 deletions:
0 comments (0 inline, 0 general)
src/industry_cmd.cpp
Show inline comments
 
@@ -1179,7 +1179,23 @@ static const Town *CheckMultipleIndustry
 
	return t;
 
}
 

	
 
static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable *it, int type, bool *custom_shape_check = NULL)
 
bool IsSlopeRefused(Slope current, Slope refused)
 
{
 
	if (current != SLOPE_FLAT) {
 
		if (refused & SLOPE_STEEP) return true;
 

	
 
		Slope t = ComplementSlope(current);
 

	
 
		if (refused & 1 && (t & SLOPE_NW)) return false;
 
		if (refused & 2 && (t & SLOPE_NE)) return false;
 
		if (refused & 4 && (t & SLOPE_SW)) return false;
 
		if (refused & 8 && (t & SLOPE_SE)) return false;
 
	}
 

	
 
	return false;
 
}
 

	
 
static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable *it, uint itspec_index, int type, bool *custom_shape_check = NULL)
 
{
 
	_error_message = STR_0239_SITE_UNSUITABLE;
 

	
 
@@ -1207,7 +1223,7 @@ static bool CheckIfIndustryTilesAreFree(
 

	
 
			if (HASBIT(its->callback_flags, CBM_INDT_SHAPE_CHECK)) {
 
				if (custom_shape_check != NULL) *custom_shape_check = true;
 
				if (!PerformIndustryTileSlopeCheck(cur_tile, its, type, gfx)) return false;
 
				if (!PerformIndustryTileSlopeCheck(tile, cur_tile, its, type, gfx, itspec_index)) return false;
 
			} else {
 
				if (ind_behav & INDUSTRYBEH_BUILT_ONWATER) {
 
					/* As soon as the tile is not water, bail out.
 
@@ -1226,19 +1242,7 @@ static bool CheckIfIndustryTilesAreFree(
 
						/* It is almost impossible to have a fully flat land in TG, so what we
 
						*  do is that we check if we can make the land flat later on. See
 
						*  CheckIfCanLevelIndustryPlatform(). */
 
						if (tileh != SLOPE_FLAT) {
 
							Slope t;
 
							byte bits = its->slopes_refused;
 

	
 
							if (bits & 0x10) return false;
 

	
 
							t = ComplementSlope(tileh);
 

	
 
							if (bits & 1 && (t & SLOPE_NW)) return false;
 
							if (bits & 2 && (t & SLOPE_NE)) return false;
 
							if (bits & 4 && (t & SLOPE_SW)) return false;
 
							if (bits & 8 && (t & SLOPE_SE)) return false;
 
						}
 
						if (IsSlopeRefused(tileh, its->slopes_refused)) return false;
 
					}
 
				}
 
			}
 
@@ -1541,7 +1545,7 @@ static Industry *CreateNewIndustryHelper
 
	const IndustryTileTable *it = indspec->table[itspec_index];
 
	bool custom_shape_check = false;
 

	
 
	if (!CheckIfIndustryTilesAreFree(tile, it, type, &custom_shape_check)) return NULL;
 
	if (!CheckIfIndustryTilesAreFree(tile, it, itspec_index, type, &custom_shape_check)) return NULL;
 

	
 
	if (HASBIT(GetIndustrySpec(type)->callback_flags, CBM_IND_LOCATION)) {
 
		if (!CheckIfCallBackAllowsCreation(tile, type, itspec_index)) return NULL;
 
@@ -1582,7 +1586,6 @@ CommandCost CmdBuildIndustry(TileIndex t
 
{
 
	int num;
 
	const IndustryTileTable * const *itt;
 
	const IndustryTileTable *it;
 
	const IndustrySpec *indspec;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_OTHER);
 
@@ -1626,7 +1629,7 @@ CommandCost CmdBuildIndustry(TileIndex t
 

	
 
		do {
 
			if (--num < 0) return_cmd_error(STR_0239_SITE_UNSUITABLE);
 
		} while (!CheckIfIndustryTilesAreFree(tile, it = itt[num], p1));
 
		} while (!CheckIfIndustryTilesAreFree(tile, itt[num], num, p1));
 

	
 
		if (CreateNewIndustryHelper(tile, p1, flags, indspec, num) == NULL) return CMD_ERROR;
 
	}
src/newgrf_industrytiles.cpp
Show inline comments
 
@@ -247,18 +247,23 @@ bool DrawNewIndustryTile(TileInfo *ti, I
 
	}
 
}
 

	
 
bool PerformIndustryTileSlopeCheck(TileIndex tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx)
 
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)
 
{
 
	Industry ind;
 
	ind.xy = 0;
 
	ind.index = INVALID_INDUSTRY;
 
	ind.xy = ind_base_tile;
 
	ind.width = 0;
 
	ind.type = type;
 

	
 
	uint16 callback_res = GetIndustryTileCallback(CBID_INDTILE_SHAPE_CHECK, 0, 0, gfx, &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 (its->grf_prop.grffile->grf_version < 7) {
 
		return callback_res != 0;
 
	}
 
	if (callback_res == CALLBACK_FAILED) return false;
 

	
 
	switch (callback_res) {
 
		case 0x400: return true;
src/newgrf_industrytiles.h
Show inline comments
 
@@ -15,7 +15,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 tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx);
 
bool 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());
0 comments (0 inline, 0 general)