File diff r8029:8fa304783822 → r8030:87f5c8990099
src/industry_cmd.cpp
Show inline comments
 
@@ -1139,104 +1139,104 @@ static CheckNewIndustryProc * const _che
 
	CheckNewIndustry_NULL,
 
	CheckNewIndustry_Forest,
 
	CheckNewIndustry_OilRefinery,
 
	CheckNewIndustry_Farm,
 
	CheckNewIndustry_Plantation,
 
	CheckNewIndustry_Water,
 
	CheckNewIndustry_Lumbermill,
 
	CheckNewIndustry_BubbleGen,
 
	CheckNewIndustry_OilRig
 
};
 

	
 
static bool CheckSuitableIndustryPos(TileIndex tile)
 
{
 
	uint x = TileX(tile);
 
	uint y = TileY(tile);
 

	
 
	if (x < 2 || y < 2 || x > MapMaxX() - 3 || y > MapMaxY() - 3) {
 
		_error_message = STR_0239_SITE_UNSUITABLE;
 
		return false;
 
	}
 

	
 
	return true;
 
}
 

	
 
static const Town *CheckMultipleIndustryInTown(TileIndex tile, int type)
 
{
 
	const Town *t;
 
	const Industry *i;
 

	
 
	t = ClosestTownFromTile(tile, (uint)-1);
 

	
 
	if (_patches.multiple_industry_per_town) return t;
 

	
 
	FOR_ALL_INDUSTRIES(i) {
 
		if (i->type == (byte)type &&
 
				i->town == t) {
 
			_error_message = STR_0287_ONLY_ONE_ALLOWED_PER_TOWN;
 
			return NULL;
 
		}
 
	}
 

	
 
	return t;
 
}
 

	
 
bool IsSlopeRefused(Slope current, Slope refused)
 
{
 
	if (IsSteepSlope(current)) return true;
 
	if (current != SLOPE_FLAT) {
 
		if (refused & SLOPE_STEEP) return true;
 
		if (IsSteepSlope(refused)) 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;
 
		if (refused & SLOPE_W && (t & SLOPE_NW)) return true;
 
		if (refused & SLOPE_S && (t & SLOPE_NE)) return true;
 
		if (refused & SLOPE_E && (t & SLOPE_SW)) return true;
 
		if (refused & SLOPE_N && (t & SLOPE_SE)) return true;
 
	}
 

	
 
	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;
 
	bool refused_slope = false;
 
	bool custom_shape = false;
 

	
 
	do {
 
		IndustryGfx gfx = GetTranslatedIndustryTileID(it->gfx);
 
		TileIndex cur_tile = tile + ToTileIndexDiff(it->ti);
 

	
 
		if (!IsValidTile(cur_tile)) {
 
			if (gfx == GFX_WATERTILE_SPECIALCHECK) continue;
 
			return false;
 
		}
 

	
 
		if (gfx == GFX_WATERTILE_SPECIALCHECK) {
 
			if (!IsTileType(cur_tile, MP_WATER) ||
 
					GetTileSlope(cur_tile, NULL) != SLOPE_FLAT) {
 
				return false;
 
			}
 
		} else {
 
			if (!EnsureNoVehicleOnGround(cur_tile)) return false;
 
			if (MayHaveBridgeAbove(cur_tile) && IsBridgeAbove(cur_tile)) return false;
 

	
 
			const IndustryTileSpec *its = GetIndustryTileSpec(gfx);
 

	
 
			IndustryBehaviour ind_behav = GetIndustrySpec(type)->behaviour;
 

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

	
 
			if (HasBit(its->callback_flags, CBM_INDT_SHAPE_CHECK)) {
 
				custom_shape = true;
 
				if (!PerformIndustryTileSlopeCheck(tile, cur_tile, its, type, gfx, itspec_index)) return false;
 
			} else {
 
				Slope tileh = GetTileSlope(cur_tile, NULL);
 
				refused_slope |= IsSlopeRefused(tileh, its->slopes_refused);
 
			}
 

	
 
			if (ind_behav & (INDUSTRYBEH_ONLY_INTOWN | INDUSTRYBEH_TOWN1200_MORE)) {
 
				if (!IsTileType(cur_tile, MP_HOUSE)) {
 
					_error_message = STR_029D_CAN_ONLY_BE_BUILT_IN_TOWNS;
 
					return false;