From 623df6b94f2d602aa60481c1298893776cc120be Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Fri, 5 Jan 2024 13:13:55 +0000 Subject: [PATCH] Codechange: Get count of road vehicles by summing company group statistics data in small UFO handler. (#11690) This avoids needing to iterate the complete vehicle pool. Company group statistics are maintained elsewhere already. The vehicle pool is still iterated later to find the nth random road vehicle. --- src/disaster_vehicle.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/disaster_vehicle.cpp b/src/disaster_vehicle.cpp index 6d3ffc9e75..bfc4c58ebd 100644 --- a/src/disaster_vehicle.cpp +++ b/src/disaster_vehicle.cpp @@ -334,8 +334,8 @@ static bool DisasterTick_Ufo(DisasterVehicle *v) v->state = 1; uint n = 0; // Total number of targetable road vehicles. - for (const RoadVehicle *u : RoadVehicle::Iterate()) { - if (u->IsFrontEngine()) n++; + for (const Company *c : Company::Iterate()) { + n += c->group_all[VEH_ROAD].num_vehicle; } if (n == 0) {