Changeset - r28398:8d247466e28d
[Not reviewed]
master
0 1 0
Peter Nelson - 4 months ago 2024-01-05 13:13:55
peter1138@openttd.org
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.
1 file changed with 2 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/disaster_vehicle.cpp
Show inline comments
 
@@ -334,8 +334,8 @@ static bool DisasterTick_Ufo(DisasterVeh
 
		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) {
0 comments (0 inline, 0 general)