File diff r25450:7e9533370994 → r25451:917146b539af
src/industry_cmd.cpp
Show inline comments
 
@@ -146,13 +146,13 @@ Industry::~Industry()
 
	 * This means that we do not have to clear tiles either.
 
	 * Also we must not decrement industry counts in that case. */
 
	if (this->location.w == 0) return;
 

	
 
	const bool has_neutral_station = this->neutral_station != nullptr;
 

	
 
	TILE_AREA_LOOP(tile_cur, this->location) {
 
	for (TileIndex tile_cur : this->location) {
 
		if (IsTileType(tile_cur, MP_INDUSTRY)) {
 
			if (GetIndustryIndex(tile_cur) == this->index) {
 
				DeleteNewGRFInspectWindow(GSF_INDUSTRYTILES, tile_cur);
 

	
 
				/* MakeWaterKeepingClass() can also handle 'land' */
 
				MakeWaterKeepingClass(tile_cur, OWNER_NONE);
 
@@ -161,22 +161,22 @@ Industry::~Industry()
 
			DeleteOilRig(tile_cur);
 
		}
 
	}
 

	
 
	if (has_neutral_station) {
 
		/* Remove possible docking tiles */
 
		TILE_AREA_LOOP(tile_cur, this->location) {
 
		for (TileIndex tile_cur : this->location) {
 
			ClearDockingTilesCheckingNeighbours(tile_cur);
 
		}
 
	}
 

	
 
	if (GetIndustrySpec(this->type)->behaviour & INDUSTRYBEH_PLANT_FIELDS) {
 
		TileArea ta = TileArea(this->location.tile, 0, 0).Expand(21);
 

	
 
		/* Remove the farmland and convert it to regular tiles over time. */
 
		TILE_AREA_LOOP(tile_cur, ta) {
 
		for (TileIndex tile_cur : ta) {
 
			if (IsTileType(tile_cur, MP_CLEAR) && IsClearGround(tile_cur, CLEAR_FIELDS) &&
 
					GetIndustryIndexOfField(tile_cur) == this->index) {
 
				SetIndustryIndexOfField(tile_cur, INVALID_INDUSTRY);
 
			}
 
		}
 
	}
 
@@ -1038,25 +1038,25 @@ static void PlantFarmField(TileIndex til
 
	ta.ClampToMap();
 

	
 
	if (ta.w == 0 || ta.h == 0) return;
 

	
 
	/* check the amount of bad tiles */
 
	int count = 0;
 
	TILE_AREA_LOOP(cur_tile, ta) {
 
	for (TileIndex cur_tile : ta) {
 
		assert(cur_tile < MapSize());
 
		count += IsSuitableForFarmField(cur_tile, false);
 
	}
 
	if (count * 2 < ta.w * ta.h) return;
 

	
 
	/* determine type of field */
 
	r = Random();
 
	uint counter = GB(r, 5, 3);
 
	uint field_type = GB(r, 8, 8) * 9 >> 8;
 

	
 
	/* make field */
 
	TILE_AREA_LOOP(cur_tile, ta) {
 
	for (TileIndex cur_tile : ta) {
 
		assert(cur_tile < MapSize());
 
		if (IsSuitableForFarmField(cur_tile, true)) {
 
			MakeField(cur_tile, field_type, industry);
 
			SetClearCounter(cur_tile, counter);
 
			MarkTileDirtyByTile(cur_tile);
 
		}
 
@@ -1112,13 +1112,13 @@ static bool SearchLumberMillTrees(TileIn
 
 * Perform a circular search around the Lumber Mill in order to find trees to cut
 
 * @param i industry
 
 */
 
static void ChopLumberMillTrees(Industry *i)
 
{
 
	/* We only want to cut trees if all tiles are completed. */
 
	TILE_AREA_LOOP(tile_cur, i->location) {
 
	for (TileIndex tile_cur : i->location) {
 
		if (i->TileBelongsToIndustry(tile_cur)) {
 
			if (!IsIndustryCompleted(tile_cur)) return;
 
		}
 
	}
 

	
 
	TileIndex tile = i->location.tile;
 
@@ -1529,13 +1529,13 @@ static CommandCost CheckIfIndustryIsAllo
 
static bool CheckCanTerraformSurroundingTiles(TileIndex tile, uint height, int internal)
 
{
 
	/* Check if we don't leave the map */
 
	if (TileX(tile) == 0 || TileY(tile) == 0 || GetTileType(tile) == MP_VOID) return false;
 

	
 
	TileArea ta(tile - TileDiffXY(1, 1), 2, 2);
 
	TILE_AREA_LOOP(tile_walk, ta) {
 
	for (TileIndex tile_walk : ta) {
 
		uint curh = TileHeight(tile_walk);
 
		/* Is the tile clear? */
 
		if ((GetTileType(tile_walk) != MP_CLEAR) && (GetTileType(tile_walk) != MP_TREES)) return false;
 

	
 
		/* Don't allow too big of a change if this is the sub-tile check */
 
		if (internal != 0 && Delta(curh, height) > 1) return false;
 
@@ -1584,13 +1584,13 @@ static bool CheckIfCanLevelIndustryPlatf
 
	if (TileX(ta.tile) + ta.w >= MapMaxX() || TileY(ta.tile) + ta.h >= MapMaxY()) return false;
 

	
 
	/* _current_company is OWNER_NONE for randomly generated industries and in editor, or the company who funded or prospected the industry.
 
	 * Perform terraforming as OWNER_TOWN to disable autoslope and town ratings. */
 
	Backup<CompanyID> cur_company(_current_company, OWNER_TOWN, FILE_LINE);
 

	
 
	TILE_AREA_LOOP(tile_walk, ta) {
 
	for (TileIndex tile_walk : ta) {
 
		uint curh = TileHeight(tile_walk);
 
		if (curh != h) {
 
			/* This tile needs terraforming. Check if we can do that without
 
			 *  damaging the surroundings too much. */
 
			if (!CheckCanTerraformSurroundingTiles(tile_walk, h, 0)) {
 
				cur_company.Restore();
 
@@ -1604,13 +1604,13 @@ static bool CheckIfCanLevelIndustryPlatf
 
			}
 
		}
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		/* Terraform the land under the industry */
 
		TILE_AREA_LOOP(tile_walk, ta) {
 
		for (TileIndex tile_walk : ta) {
 
			uint curh = TileHeight(tile_walk);
 
			while (curh != h) {
 
				/* We give the terraforming for free here, because we can't calculate
 
				 *  exact cost in the test-round, and as we all know, that will cause
 
				 *  a nice assert if they don't match ;) */
 
				DoCommand(tile_walk, SLOPE_N, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND);
 
@@ -1636,13 +1636,13 @@ static CommandCost CheckIfFarEnoughFromC
 

	
 
	/* On a large map with many industries, it may be faster to check an area. */
 
	static const int dmax = 14;
 
	if (Industry::GetNumItems() > (size_t) (dmax * dmax * 2)) {
 
		const Industry* i = nullptr;
 
		TileArea tile_area = TileArea(tile, 1, 1).Expand(dmax);
 
		TILE_AREA_LOOP(atile, tile_area) {
 
		for (TileIndex atile : tile_area) {
 
			if (GetTileType(atile) == MP_INDUSTRY) {
 
				const Industry *i2 = Industry::GetByTile(atile);
 
				if (i == i2) continue;
 
				i = i2;
 
				if (DistanceMax(tile, i->location.tile) > (uint)dmax) continue;
 
				if (i->type == indspec->conflicting[0] ||