Maintain map of targeted road vehicles to small UFO disaster vehicle

This commit is contained in:
Jonathan G Rennison
2024-02-12 00:48:13 +00:00
parent 1e2834a422
commit 903adceab5
6 changed files with 66 additions and 15 deletions

View File

@@ -507,6 +507,8 @@ void AfterLoadVehicles(bool part_of_load)
}
}
ResetDisasterVehicleTargeting();
for (Vehicle *v : Vehicle::Iterate()) {
si_v = v;
switch (v->type) {
@@ -539,6 +541,22 @@ void AfterLoadVehicles(bool part_of_load)
UpdateAircraftCache(Aircraft::From(v), true);
}
break;
case VEH_DISASTER: {
auto *dv = DisasterVehicle::From(v);
if (dv->subtype == ST_SMALL_UFO && dv->state != 0) {
RoadVehicle *u = RoadVehicle::GetIfValid(v->dest_tile);
if (u != nullptr && u->IsFrontEngine()) {
/* Delete UFO targeting a vehicle which is already a target. */
if (!SetDisasterVehicleTargetingVehicle(u->index, dv->index)) {
delete v;
continue;
}
}
}
break;
}
default: break;
}