Codechange: Replace FOR_ALL_INDUSTRIES with range-based for loops

This commit is contained in:
glx
2019-12-16 18:51:20 +01:00
committed by Niels Martin Hansen
parent 4ae829cb27
commit 00c2a98cf3
11 changed files with 29 additions and 61 deletions

View File

@@ -1203,8 +1203,7 @@ void OnTick_Industry()
if (_game_mode == GM_EDITOR) return;
Industry *i;
FOR_ALL_INDUSTRIES(i) {
for (Industry *i : Industry::Iterate()) {
ProduceIndustryGoods(i);
}
}
@@ -1391,8 +1390,7 @@ static CommandCost FindTownForIndustry(TileIndex tile, int type, Town **t)
if (_settings_game.economy.multiple_industry_per_town) return CommandCost();
const Industry *i;
FOR_ALL_INDUSTRIES(i) {
for (const Industry *i : Industry::Iterate()) {
if (i->type == (byte)type && i->town == *t) {
*t = nullptr;
return_cmd_error(STR_ERROR_ONLY_ONE_ALLOWED_PER_TOWN);
@@ -1629,11 +1627,11 @@ static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, DoCommandFlag flags,
static CommandCost CheckIfFarEnoughFromConflictingIndustry(TileIndex tile, int type)
{
const IndustrySpec *indspec = GetIndustrySpec(type);
const Industry *i = nullptr;
/* 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) {
if (GetTileType(atile) == MP_INDUSTRY) {
@@ -1651,7 +1649,7 @@ static CommandCost CheckIfFarEnoughFromConflictingIndustry(TileIndex tile, int t
return CommandCost();
}
FOR_ALL_INDUSTRIES(i) {
for (const Industry *i : Industry::Iterate()) {
/* Within 14 tiles from another industry is considered close */
if (DistanceMax(tile, i->location.tile) > 14) continue;
@@ -2833,8 +2831,7 @@ void IndustryMonthlyLoop()
_industry_builder.MonthlyLoop();
Industry *i;
FOR_ALL_INDUSTRIES(i) {
for (Industry *i : Industry::Iterate()) {
UpdateIndustryStatistics(i);
if (i->prod_level == PRODLEVEL_CLOSURE) {
delete i;