Codechange: Replace FOR_ALL_ENGINES with range-based for loops

This commit is contained in:
glx 2019-12-15 22:45:18 +01:00 committed by Niels Martin Hansen
parent 1c92ba8ebe
commit 1f6b3a37f9
16 changed files with 50 additions and 81 deletions

View File

@ -124,8 +124,7 @@ class ReplaceVehicleWindow : public Window {
GUIEngineList *list = &this->engines[side]; GUIEngineList *list = &this->engines[side];
list->clear(); list->clear();
const Engine *e; for (const Engine *e : Engine::IterateType(type)) {
FOR_ALL_ENGINES_OF_TYPE(e, type) {
if (!draw_left && !this->show_hidden_engines && e->IsHidden(_local_company)) continue; if (!draw_left && !this->show_hidden_engines && e->IsHidden(_local_company)) continue;
EngineID eid = e->index; EngineID eid = e->index;
switch (type) { switch (type) {

View File

@ -1260,8 +1260,7 @@ struct BuildVehicleWindow : Window {
* Also check to see if the previously selected engine is still available, * Also check to see if the previously selected engine is still available,
* and if not, reset selection to INVALID_ENGINE. This could be the case * and if not, reset selection to INVALID_ENGINE. This could be the case
* when engines become obsolete and are removed */ * when engines become obsolete and are removed */
const Engine *e; for (const Engine *e : Engine::IterateType(VEH_TRAIN)) {
FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) {
if (!this->show_hidden_engines && e->IsHidden(_local_company)) continue; if (!this->show_hidden_engines && e->IsHidden(_local_company)) continue;
EngineID eid = e->index; EngineID eid = e->index;
const RailVehicleInfo *rvi = &e->u.rail; const RailVehicleInfo *rvi = &e->u.rail;
@ -1304,8 +1303,7 @@ struct BuildVehicleWindow : Window {
this->eng_list.clear(); this->eng_list.clear();
const Engine *e; for (const Engine *e : Engine::IterateType(VEH_ROAD)) {
FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) {
if (!this->show_hidden_engines && e->IsHidden(_local_company)) continue; if (!this->show_hidden_engines && e->IsHidden(_local_company)) continue;
EngineID eid = e->index; EngineID eid = e->index;
if (!IsEngineBuildable(eid, VEH_ROAD, _local_company)) continue; if (!IsEngineBuildable(eid, VEH_ROAD, _local_company)) continue;
@ -1324,8 +1322,7 @@ struct BuildVehicleWindow : Window {
EngineID sel_id = INVALID_ENGINE; EngineID sel_id = INVALID_ENGINE;
this->eng_list.clear(); this->eng_list.clear();
const Engine *e; for (const Engine *e : Engine::IterateType(VEH_SHIP)) {
FOR_ALL_ENGINES_OF_TYPE(e, VEH_SHIP) {
if (!this->show_hidden_engines && e->IsHidden(_local_company)) continue; if (!this->show_hidden_engines && e->IsHidden(_local_company)) continue;
EngineID eid = e->index; EngineID eid = e->index;
if (!IsEngineBuildable(eid, VEH_SHIP, _local_company)) continue; if (!IsEngineBuildable(eid, VEH_SHIP, _local_company)) continue;
@ -1349,8 +1346,7 @@ struct BuildVehicleWindow : Window {
* Also check to see if the previously selected plane is still available, * Also check to see if the previously selected plane is still available,
* and if not, reset selection to INVALID_ENGINE. This could be the case * and if not, reset selection to INVALID_ENGINE. This could be the case
* when planes become obsolete and are removed */ * when planes become obsolete and are removed */
const Engine *e; for (const Engine *e : Engine::IterateType(VEH_AIRCRAFT)) {
FOR_ALL_ENGINES_OF_TYPE(e, VEH_AIRCRAFT) {
if (!this->show_hidden_engines && e->IsHidden(_local_company)) continue; if (!this->show_hidden_engines && e->IsHidden(_local_company)) continue;
EngineID eid = e->index; EngineID eid = e->index;
if (!IsEngineBuildable(eid, VEH_AIRCRAFT, _local_company)) continue; if (!IsEngineBuildable(eid, VEH_AIRCRAFT, _local_company)) continue;

View File

@ -1825,8 +1825,7 @@ struct CompanyInfrastructureWindow : Window
this->roadtypes = ROADTYPES_NONE; this->roadtypes = ROADTYPES_NONE;
/* Find the used railtypes. */ /* Find the used railtypes. */
Engine *e; for (const Engine *e : Engine::IterateType(VEH_TRAIN)) {
FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) {
if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue; if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue;
this->railtypes |= GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes; this->railtypes |= GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes;
@ -1836,7 +1835,7 @@ struct CompanyInfrastructureWindow : Window
this->railtypes = AddDateIntroducedRailTypes(this->railtypes, MAX_DAY); this->railtypes = AddDateIntroducedRailTypes(this->railtypes, MAX_DAY);
/* Find the used roadtypes. */ /* Find the used roadtypes. */
FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) { for (const Engine *e : Engine::IterateType(VEH_ROAD)) {
if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue; if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue;
this->roadtypes |= GetRoadTypeInfo(e->u.road.roadtype)->introduces_roadtypes; this->roadtypes |= GetRoadTypeInfo(e->u.road.roadtype)->introduces_roadtypes;

View File

@ -170,8 +170,7 @@ static void InitBlocksizeForVehicles(VehicleType type, EngineImageType image_typ
int max_extend_right = 0; int max_extend_right = 0;
uint max_height = 0; uint max_height = 0;
const Engine *e; for (const Engine *e : Engine::IterateType(type)) {
FOR_ALL_ENGINES_OF_TYPE(e, type) {
if (!e->IsEnabled()) continue; if (!e->IsEnabled()) continue;
EngineID eid = e->index; EngineID eid = e->index;
@ -222,8 +221,7 @@ void InitDepotWindowBlockSizes()
_consistent_train_width = TRAININFO_DEFAULT_VEHICLE_WIDTH; _consistent_train_width = TRAININFO_DEFAULT_VEHICLE_WIDTH;
bool first = true; bool first = true;
const Engine *e; for (const Engine *e : Engine::IterateType(VEH_TRAIN)) {
FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) {
if (!e->IsEnabled()) continue; if (!e->IsEnabled()) continue;
uint w = TRAININFO_DEFAULT_VEHICLE_WIDTH; uint w = TRAININFO_DEFAULT_VEHICLE_WIDTH;

View File

@ -599,8 +599,7 @@ bool SettingsDisableElrail(int32 p1)
const RailType new_railtype = disable ? RAILTYPE_RAIL : RAILTYPE_ELECTRIC; const RailType new_railtype = disable ? RAILTYPE_RAIL : RAILTYPE_ELECTRIC;
/* walk through all train engines */ /* walk through all train engines */
Engine *e; for (Engine *e : Engine::IterateType(VEH_TRAIN)) {
FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) {
RailVehicleInfo *rv_info = &e->u.rail; RailVehicleInfo *rv_info = &e->u.rail;
/* if it is an electric rail engine and its railtype is the wrong one */ /* if it is an electric rail engine and its railtype is the wrong one */
if (rv_info->engclass == 2 && rv_info->railtype == old_railtype) { if (rv_info->engclass == 2 && rv_info->railtype == old_railtype) {

View File

@ -618,8 +618,7 @@ void SetYearEngineAgingStops()
/* Determine last engine aging year, default to 2050 as previously. */ /* Determine last engine aging year, default to 2050 as previously. */
_year_engine_aging_stops = 2050; _year_engine_aging_stops = 2050;
const Engine *e; for (const Engine *e : Engine::Iterate()) {
FOR_ALL_ENGINES(e) {
const EngineInfo *ei = &e->info; const EngineInfo *ei = &e->info;
/* Exclude certain engines */ /* Exclude certain engines */
@ -694,11 +693,10 @@ void StartupOneEngine(Engine *e, Date aging_date)
*/ */
void StartupEngines() void StartupEngines()
{ {
Engine *e;
/* Aging of vehicles stops, so account for that when starting late */ /* Aging of vehicles stops, so account for that when starting late */
const Date aging_date = min(_date, ConvertYMDToDate(_year_engine_aging_stops, 0, 1)); const Date aging_date = min(_date, ConvertYMDToDate(_year_engine_aging_stops, 0, 1));
FOR_ALL_ENGINES(e) { for (Engine *e : Engine::Iterate()) {
StartupOneEngine(e, aging_date); StartupOneEngine(e, aging_date);
} }
@ -811,8 +809,7 @@ void EnginesDailyLoop()
if (_cur_year >= _year_engine_aging_stops) return; if (_cur_year >= _year_engine_aging_stops) return;
Engine *e; for (Engine *e : Engine::Iterate()) {
FOR_ALL_ENGINES(e) {
EngineID i = e->index; EngineID i = e->index;
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) { if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) {
if (e->preview_company != INVALID_COMPANY) { if (e->preview_company != INVALID_COMPANY) {
@ -848,8 +845,7 @@ void EnginesDailyLoop()
*/ */
void ClearEnginesHiddenFlagOfCompany(CompanyID cid) void ClearEnginesHiddenFlagOfCompany(CompanyID cid)
{ {
Engine *e; for (Engine *e : Engine::Iterate()) {
FOR_ALL_ENGINES(e) {
SB(e->company_hidden, cid, 1, 0); SB(e->company_hidden, cid, 1, 0);
} }
} }
@ -973,8 +969,7 @@ static void NewVehicleAvailable(Engine *e)
void EnginesMonthlyLoop() void EnginesMonthlyLoop()
{ {
if (_cur_year < _year_engine_aging_stops) { if (_cur_year < _year_engine_aging_stops) {
Engine *e; for (Engine *e : Engine::Iterate()) {
FOR_ALL_ENGINES(e) {
/* Age the vehicle */ /* Age the vehicle */
if ((e->flags & ENGINE_AVAILABLE) && e->age != MAX_DAY) { if ((e->flags & ENGINE_AVAILABLE) && e->age != MAX_DAY) {
e->age++; e->age++;
@ -1015,9 +1010,7 @@ void EnginesMonthlyLoop()
*/ */
static bool IsUniqueEngineName(const char *name) static bool IsUniqueEngineName(const char *name)
{ {
const Engine *e; for (const Engine *e : Engine::Iterate()) {
FOR_ALL_ENGINES(e) {
if (e->name != nullptr && strcmp(e->name, name) == 0) return false; if (e->name != nullptr && strcmp(e->name, name) == 0) return false;
} }
@ -1138,10 +1131,9 @@ bool IsEngineRefittable(EngineID engine)
*/ */
void CheckEngines() void CheckEngines()
{ {
const Engine *e;
Date min_date = INT32_MAX; Date min_date = INT32_MAX;
FOR_ALL_ENGINES(e) { for (const Engine *e : Engine::Iterate()) {
if (!e->IsEnabled()) continue; if (!e->IsEnabled()) continue;
/* We have an available engine... yay! */ /* We have an available engine... yay! */

View File

@ -141,6 +141,17 @@ struct Engine : EnginePool::PoolItem<&_engine_pool> {
} }
uint32 GetGRFID() const; uint32 GetGRFID() const;
/**
* Returns an iterable ensemble of all valid engines of the given type
* @param vt the VehicleType for engines to be valid
* @param from index of the first engine to consider
* @return an iterable ensemble of all valid engines of the given type
*/
static Pool::IterateWrapper<Engine> IterateType(VehicleType vt, size_t from = 0)
{
return Pool::IterateWrapper<Engine>(from, [vt](size_t index) { return Engine::Get(index)->type == vt; });
}
}; };
struct EngineIDMapping { struct EngineIDMapping {
@ -165,11 +176,6 @@ struct EngineOverrideManager : std::vector<EngineIDMapping> {
extern EngineOverrideManager _engine_mngr; extern EngineOverrideManager _engine_mngr;
#define FOR_ALL_ENGINES_FROM(var, start) FOR_ALL_ITEMS_FROM(Engine, engine_index, var, start)
#define FOR_ALL_ENGINES(var) FOR_ALL_ENGINES_FROM(var, 0)
#define FOR_ALL_ENGINES_OF_TYPE(e, engine_type) FOR_ALL_ENGINES(e) if (e->type == engine_type)
static inline const EngineInfo *EngInfo(EngineID e) static inline const EngineInfo *EngInfo(EngineID e)
{ {
return &Engine::Get(e)->info; return &Engine::Get(e)->info;

View File

@ -8555,8 +8555,7 @@ void ResetNewGRFData()
_gted = CallocT<GRFTempEngineData>(Engine::GetPoolSize()); _gted = CallocT<GRFTempEngineData>(Engine::GetPoolSize());
/* Fill rail type label temporary data for default trains */ /* Fill rail type label temporary data for default trains */
Engine *e; for (const Engine *e : Engine::IterateType(VEH_TRAIN)) {
FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) {
_gted[e->index].railtypelabel = GetRailTypeInfo(e->u.rail.railtype)->label; _gted[e->index].railtypelabel = GetRailTypeInfo(e->u.rail.railtype)->label;
} }
@ -8772,9 +8771,7 @@ static const CargoLabel * const _default_refitmasks[] = {
*/ */
static void CalculateRefitMasks() static void CalculateRefitMasks()
{ {
Engine *e; for (Engine *e : Engine::Iterate()) {
FOR_ALL_ENGINES(e) {
EngineID engine = e->index; EngineID engine = e->index;
EngineInfo *ei = &e->info; EngineInfo *ei = &e->info;
bool only_defaultcargo; ///< Set if the vehicle shall carry only the default cargo bool only_defaultcargo; ///< Set if the vehicle shall carry only the default cargo
@ -8888,9 +8885,7 @@ static void FinaliseCanals()
/** Check for invalid engines */ /** Check for invalid engines */
static void FinaliseEngineArray() static void FinaliseEngineArray()
{ {
Engine *e; for (Engine *e : Engine::Iterate()) {
FOR_ALL_ENGINES(e) {
if (e->GetGRF() == nullptr) { if (e->GetGRF() == nullptr) {
const EngineIDMapping &eid = _engine_mngr[e->index]; const EngineIDMapping &eid = _engine_mngr[e->index];
if (eid.grfid != INVALID_GRFID || eid.internal_id != eid.substitute_id) { if (eid.grfid != INVALID_GRFID || eid.internal_id != eid.substitute_id) {
@ -9684,8 +9679,7 @@ static void AfterLoadGRFs()
InitRailTypes(); InitRailTypes();
InitRoadTypes(); InitRoadTypes();
Engine *e; for (Engine *e : Engine::IterateType(VEH_ROAD)) {
FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) {
if (_gted[e->index].rv_max_speed != 0) { if (_gted[e->index].rv_max_speed != 0) {
/* Set RV maximum speed from the mph/0.8 unit value */ /* Set RV maximum speed from the mph/0.8 unit value */
e->u.road.max_speed = _gted[e->index].rv_max_speed * 4; e->u.road.max_speed = _gted[e->index].rv_max_speed * 4;
@ -9717,7 +9711,7 @@ static void AfterLoadGRFs()
e->info.climates = 0; e->info.climates = 0;
} }
FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) { for (Engine *e : Engine::IterateType(VEH_TRAIN)) {
RailType railtype = GetRailTypeByLabel(_gted[e->index].railtypelabel); RailType railtype = GetRailTypeByLabel(_gted[e->index].railtypelabel);
if (railtype == INVALID_RAILTYPE) { if (railtype == INVALID_RAILTYPE) {
/* Rail type is not available, so disable this engine */ /* Rail type is not available, so disable this engine */

View File

@ -1236,8 +1236,7 @@ void CommitVehicleListOrderChanges()
{ {
/* Pre-sort engines by scope-grfid and local index */ /* Pre-sort engines by scope-grfid and local index */
std::vector<EngineID> ordering; std::vector<EngineID> ordering;
Engine *e; for (const Engine *e : Engine::Iterate()) {
FOR_ALL_ENGINES(e) {
ordering.push_back(e->index); ordering.push_back(e->index);
} }
std::sort(ordering.begin(), ordering.end(), EnginePreSort); std::sort(ordering.begin(), ordering.end(), EnginePreSort);

View File

@ -267,8 +267,7 @@ RailTypes GetCompanyRailtypes(CompanyID company, bool introduces)
{ {
RailTypes rts = RAILTYPES_NONE; RailTypes rts = RAILTYPES_NONE;
const Engine *e; for (const Engine *e : Engine::IterateType(VEH_TRAIN)) {
FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) {
const EngineInfo *ei = &e->info; const EngineInfo *ei = &e->info;
if (HasBit(ei->climates, _settings_game.game_creation.landscape) && if (HasBit(ei->climates, _settings_game.game_creation.landscape) &&
@ -299,8 +298,7 @@ RailTypes GetRailTypes(bool introduces)
{ {
RailTypes rts = RAILTYPES_NONE; RailTypes rts = RAILTYPES_NONE;
const Engine *e; for (const Engine *e : Engine::IterateType(VEH_TRAIN)) {
FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) {
const EngineInfo *ei = &e->info; const EngineInfo *ei = &e->info;
if (!HasBit(ei->climates, _settings_game.game_creation.landscape)) continue; if (!HasBit(ei->climates, _settings_game.game_creation.landscape)) continue;

View File

@ -189,8 +189,7 @@ RoadTypes GetCompanyRoadTypes(CompanyID company, bool introduces)
{ {
RoadTypes rts = ROADTYPES_NONE; RoadTypes rts = ROADTYPES_NONE;
const Engine *e; for (const Engine *e : Engine::IterateType(VEH_ROAD)) {
FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) {
const EngineInfo *ei = &e->info; const EngineInfo *ei = &e->info;
if (HasBit(ei->climates, _settings_game.game_creation.landscape) && if (HasBit(ei->climates, _settings_game.game_creation.landscape) &&
@ -218,8 +217,7 @@ RoadTypes GetRoadTypes(bool introduces)
{ {
RoadTypes rts = ROADTYPES_NONE; RoadTypes rts = ROADTYPES_NONE;
const Engine *e; for (const Engine *e : Engine::IterateType(VEH_ROAD)) {
FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) {
const EngineInfo *ei = &e->info; const EngineInfo *ei = &e->info;
if (!HasBit(ei->climates, _settings_game.game_creation.landscape)) continue; if (!HasBit(ei->climates, _settings_game.game_creation.landscape)) continue;
@ -282,8 +280,7 @@ RoadTypes ExistingRoadTypes(CompanyID c)
RoadTypes known_roadtypes = ROADTYPES_NONE; RoadTypes known_roadtypes = ROADTYPES_NONE;
/* Find used roadtypes */ /* Find used roadtypes */
Engine *e; for (Engine *e : Engine::IterateType(VEH_ROAD)) {
FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) {
/* Check if the roadtype can be used in the current climate */ /* Check if the roadtype can be used in the current climate */
if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue; if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue;
@ -319,8 +316,7 @@ bool CanBuildRoadTypeInfrastructure(RoadType roadtype, CompanyID company)
* and if we can build new ones */ * and if we can build new ones */
if (_settings_game.vehicle.max_roadveh > 0 && HasBit(roadtypes, roadtype)) { if (_settings_game.vehicle.max_roadveh > 0 && HasBit(roadtypes, roadtype)) {
/* Can we actually build the vehicle type? */ /* Can we actually build the vehicle type? */
const Engine *e; for (const Engine *e : Engine::IterateType(VEH_ROAD)) {
FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) {
if (!HasBit(e->company_avail, company)) continue; if (!HasBit(e->company_avail, company)) continue;
if (HasPowerOnRoad(e->u.road.roadtype, roadtype) || HasPowerOnRoad(roadtype, e->u.road.roadtype)) return true; if (HasPowerOnRoad(e->u.road.roadtype, roadtype) || HasPowerOnRoad(roadtype, e->u.road.roadtype)) return true;
} }

View File

@ -1413,7 +1413,6 @@ bool AfterLoadGame()
/* Time starts at 0 instead of 1920. /* Time starts at 0 instead of 1920.
* Account for this in older games by adding an offset */ * Account for this in older games by adding an offset */
if (IsSavegameVersionBefore(SLV_31)) { if (IsSavegameVersionBefore(SLV_31)) {
Engine *e;
Industry *i; Industry *i;
Vehicle *v; Vehicle *v;
@ -1422,7 +1421,7 @@ bool AfterLoadGame()
for (Station *st : Station::Iterate()) st->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR; for (Station *st : Station::Iterate()) st->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
for (Waypoint *wp : Waypoint::Iterate()) wp->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR; for (Waypoint *wp : Waypoint::Iterate()) wp->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
FOR_ALL_ENGINES(e) e->intro_date += DAYS_TILL_ORIGINAL_BASE_YEAR; for (Engine *e : Engine::Iterate()) e->intro_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
for (Company *c : Company::Iterate()) c->inaugurated_year += ORIGINAL_BASE_YEAR; for (Company *c : Company::Iterate()) c->inaugurated_year += ORIGINAL_BASE_YEAR;
FOR_ALL_INDUSTRIES(i) i->last_prod_year += ORIGINAL_BASE_YEAR; FOR_ALL_INDUSTRIES(i) i->last_prod_year += ORIGINAL_BASE_YEAR;
@ -2044,8 +2043,7 @@ bool AfterLoadGame()
if (c->bankrupt_asked == 0xFF) c->bankrupt_asked = 0xFFFF; if (c->bankrupt_asked == 0xFF) c->bankrupt_asked = 0xFFFF;
} }
Engine *e; for (Engine *e : Engine::Iterate()) {
FOR_ALL_ENGINES(e) {
if (e->company_avail == 0xFF) e->company_avail = 0xFFFF; if (e->company_avail == 0xFF) e->company_avail = 0xFFFF;
} }

View File

@ -86,8 +86,7 @@ Engine *GetTempDataEngine(EngineID index)
static void Save_ENGN() static void Save_ENGN()
{ {
Engine *e; for (Engine *e : Engine::Iterate()) {
FOR_ALL_ENGINES(e) {
SlSetArrayIndex(e->index); SlSetArrayIndex(e->index);
SlObject(e, _engine_desc); SlObject(e, _engine_desc);
} }
@ -118,8 +117,7 @@ static void Load_ENGN()
*/ */
void CopyTempEngineData() void CopyTempEngineData()
{ {
Engine *e; for (Engine *e : Engine::Iterate()) {
FOR_ALL_ENGINES(e) {
if (e->index >= _temp_engine.size()) break; if (e->index >= _temp_engine.size()) break;
const Engine *se = GetTempDataEngine(e->index); const Engine *se = GetTempDataEngine(e->index);

View File

@ -215,11 +215,10 @@ static void CheckValidVehicles()
size_t total_engines = Engine::GetPoolSize(); size_t total_engines = Engine::GetPoolSize();
EngineID first_engine[4] = { INVALID_ENGINE, INVALID_ENGINE, INVALID_ENGINE, INVALID_ENGINE }; EngineID first_engine[4] = { INVALID_ENGINE, INVALID_ENGINE, INVALID_ENGINE, INVALID_ENGINE };
Engine *e; for (const Engine *e : Engine::IterateType(VEH_TRAIN)) { first_engine[VEH_TRAIN] = e->index; break; }
FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) { first_engine[VEH_TRAIN] = e->index; break; } for (const Engine *e : Engine::IterateType(VEH_ROAD)) { first_engine[VEH_ROAD] = e->index; break; }
FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) { first_engine[VEH_ROAD] = e->index; break; } for (const Engine *e : Engine::IterateType(VEH_SHIP)) { first_engine[VEH_SHIP] = e->index; break; }
FOR_ALL_ENGINES_OF_TYPE(e, VEH_SHIP) { first_engine[VEH_SHIP] = e->index; break; } for (const Engine *e : Engine::IterateType(VEH_AIRCRAFT)) { first_engine[VEH_AIRCRAFT] = e->index; break; }
FOR_ALL_ENGINES_OF_TYPE(e, VEH_AIRCRAFT) { first_engine[VEH_AIRCRAFT] = e->index; break; }
Vehicle *v; Vehicle *v;
FOR_ALL_VEHICLES(v) { FOR_ALL_VEHICLES(v) {

View File

@ -15,8 +15,7 @@
ScriptEngineList::ScriptEngineList(ScriptVehicle::VehicleType vehicle_type) ScriptEngineList::ScriptEngineList(ScriptVehicle::VehicleType vehicle_type)
{ {
Engine *e; for (const Engine *e : Engine::IterateType((::VehicleType)vehicle_type)) {
FOR_ALL_ENGINES_OF_TYPE(e, (::VehicleType)vehicle_type) {
if (ScriptObject::GetCompany() == OWNER_DEITY || HasBit(e->company_avail, ScriptObject::GetCompany())) this->AddItem(e->index); if (ScriptObject::GetCompany() == OWNER_DEITY || HasBit(e->company_avail, ScriptObject::GetCompany())) this->AddItem(e->index);
} }
} }

View File

@ -1779,8 +1779,7 @@ bool CanBuildVehicleInfrastructure(VehicleType type, byte subtype)
/* We can build vehicle infrastructure when we may build the vehicle type */ /* We can build vehicle infrastructure when we may build the vehicle type */
if (max > 0) { if (max > 0) {
/* Can we actually build the vehicle type? */ /* Can we actually build the vehicle type? */
const Engine *e; for (const Engine *e : Engine::IterateType(type)) {
FOR_ALL_ENGINES_OF_TYPE(e, type) {
if (type == VEH_ROAD && GetRoadTramType(e->u.road.roadtype) != (RoadTramType)subtype) continue; if (type == VEH_ROAD && GetRoadTramType(e->u.road.roadtype) != (RoadTramType)subtype) continue;
if (HasBit(e->company_avail, _local_company)) return true; if (HasBit(e->company_avail, _local_company)) return true;
} }