src/industry_cmd.cpp
changeset 7640 8cf1b20cc69f
parent 7637 43e2956af72e
child 7645 efa25fcf7917
equal deleted inserted replaced
7639:e17bd2a46caf 7640:8cf1b20cc69f
  1334 	size_y = max_y + 4;
  1334 	size_y = max_y + 4;
  1335 
  1335 
  1336 	/* Check if we don't leave the map */
  1336 	/* Check if we don't leave the map */
  1337 	if (TileX(cur_tile) == 0 || TileY(cur_tile) == 0 || TileX(cur_tile) + size_x >= MapMaxX() || TileY(cur_tile) + size_y >= MapMaxY()) return false;
  1337 	if (TileX(cur_tile) == 0 || TileY(cur_tile) == 0 || TileX(cur_tile) + size_x >= MapMaxX() || TileY(cur_tile) + size_y >= MapMaxY()) return false;
  1338 
  1338 
       
  1339 	/* _current_player is OWNER_NONE for randomly generated industries and in editor, or the player who funded or prospected the industry.
       
  1340 	 * Perform terraforming as OWNER_TOWN to disable autoslope. */
       
  1341 	PlayerID old_player = _current_player;
       
  1342 	_current_player = OWNER_TOWN;
       
  1343 
  1339 	BEGIN_TILE_LOOP(tile_walk, size_x, size_y, cur_tile) {
  1344 	BEGIN_TILE_LOOP(tile_walk, size_x, size_y, cur_tile) {
  1340 		curh = TileHeight(tile_walk);
  1345 		curh = TileHeight(tile_walk);
  1341 		if (curh != h) {
  1346 		if (curh != h) {
  1342 			/* This tile needs terraforming. Check if we can do that without
  1347 			/* This tile needs terraforming. Check if we can do that without
  1343 			 *  damaging the surroundings too much. */
  1348 			 *  damaging the surroundings too much. */
  1344 			if (!CheckCanTerraformSurroundingTiles(tile_walk, h, 0)) return false;
  1349 			if (!CheckCanTerraformSurroundingTiles(tile_walk, h, 0)) {
       
  1350 				_current_player = old_player;
       
  1351 				return false;
       
  1352 			}
  1345 			/* This is not 100% correct check, but the best we can do without modifying the map.
  1353 			/* This is not 100% correct check, but the best we can do without modifying the map.
  1346 			 *  What is missing, is if the difference in height is more than 1.. */
  1354 			 *  What is missing, is if the difference in height is more than 1.. */
  1347 			if (CmdFailed(DoCommand(tile_walk, SLOPE_N, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND))) return false;
  1355 			if (CmdFailed(DoCommand(tile_walk, SLOPE_N, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND))) {
       
  1356 				_current_player = old_player;
       
  1357 				return false;
       
  1358 			}
  1348 		}
  1359 		}
  1349 	} END_TILE_LOOP(tile_walk, size_x, size_y, cur_tile)
  1360 	} END_TILE_LOOP(tile_walk, size_x, size_y, cur_tile)
  1350 
  1361 
  1351 	if (flags & DC_EXEC) {
  1362 	if (flags & DC_EXEC) {
  1352 		/* Terraform the land under the industry */
  1363 		/* Terraform the land under the industry */
  1360 				curh += (curh > h) ? -1 : 1;
  1371 				curh += (curh > h) ? -1 : 1;
  1361 			}
  1372 			}
  1362 		} END_TILE_LOOP(tile_walk, size_x, size_y, cur_tile)
  1373 		} END_TILE_LOOP(tile_walk, size_x, size_y, cur_tile)
  1363 	}
  1374 	}
  1364 
  1375 
       
  1376 	_current_player = old_player;
  1365 	return true;
  1377 	return true;
  1366 }
  1378 }
  1367 
  1379 
  1368 
  1380 
  1369 static bool CheckIfTooCloseToIndustry(TileIndex tile, int type)
  1381 static bool CheckIfTooCloseToIndustry(TileIndex tile, int type)