diff options
author | glx <glx@openttd.org> | 2019-12-17 03:37:43 +0100 |
---|---|---|
committer | Niels Martin Hansen <nielsm@indvikleren.dk> | 2019-12-21 20:13:03 +0100 |
commit | d8a1be48cd60c690235de175e9a044b95f92ea28 (patch) | |
tree | 2e1481aa11661c28df49f0d62f56fbf730577152 /src/disaster_vehicle.cpp | |
parent | 9892d90b26db4dfe97ec7baeb89e43acb53a178e (diff) | |
download | openttd-d8a1be48cd60c690235de175e9a044b95f92ea28.tar.xz |
Codechange: Replace vehicle related FOR_ALL with range-based for loops
Diffstat (limited to 'src/disaster_vehicle.cpp')
-rw-r--r-- | src/disaster_vehicle.cpp | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/src/disaster_vehicle.cpp b/src/disaster_vehicle.cpp index a76b9a3cf..1244f99ab 100644 --- a/src/disaster_vehicle.cpp +++ b/src/disaster_vehicle.cpp @@ -331,8 +331,7 @@ static bool DisasterTick_Ufo(DisasterVehicle *v) v->current_order.SetDestination(1); uint n = 0; // Total number of targetable road vehicles. - RoadVehicle *u; - FOR_ALL_ROADVEHICLES(u) { + for (const RoadVehicle *u : RoadVehicle::Iterate()) { if (u->IsFrontEngine()) n++; } @@ -343,14 +342,16 @@ static bool DisasterTick_Ufo(DisasterVehicle *v) } n = RandomRange(n); // Choose one of them. - FOR_ALL_ROADVEHICLES(u) { + for (const RoadVehicle *u : RoadVehicle::Iterate()) { /* Find (n+1)-th road vehicle. */ - if (u->IsFrontEngine() && (n-- == 0)) break; + if (u->IsFrontEngine() && (n-- == 0)) { + /* Target it. */ + v->dest_tile = u->index; + v->age = 0; + break; + } } - /* Target it. */ - v->dest_tile = u->index; - v->age = 0; return true; } else { /* Target a vehicle */ @@ -540,8 +541,7 @@ static bool DisasterTick_Big_Ufo(DisasterVehicle *v) v->current_order.SetDestination(2); - Vehicle *target; - FOR_ALL_VEHICLES(target) { + for (Vehicle *target : Vehicle::Iterate()) { if (target->IsGroundVehicle()) { if (Delta(target->x_pos, v->x_pos) + Delta(target->y_pos, v->y_pos) <= 12 * (int)TILE_SIZE) { target->breakdown_ctr = 5; @@ -937,8 +937,7 @@ void StartupDisasters() */ void ReleaseDisastersTargetingIndustry(IndustryID i) { - DisasterVehicle *v; - FOR_ALL_DISASTERVEHICLES(v) { + for (DisasterVehicle *v : DisasterVehicle::Iterate()) { /* primary disaster vehicles that have chosen target */ if (v->subtype == ST_AIRPLANE || v->subtype == ST_HELICOPTER) { /* if it has chosen target, and it is this industry (yes, dest_tile is IndustryID here), set order to "leaving map peacefully" */ @@ -953,8 +952,7 @@ void ReleaseDisastersTargetingIndustry(IndustryID i) */ void ReleaseDisastersTargetingVehicle(VehicleID vehicle) { - DisasterVehicle *v; - FOR_ALL_DISASTERVEHICLES(v) { + for (DisasterVehicle *v : DisasterVehicle::Iterate()) { /* primary disaster vehicles that have chosen target */ if (v->subtype == ST_SMALL_UFO) { if (v->current_order.GetDestination() != 0 && v->dest_tile == vehicle) { |