| 184 | #define REPAIR_FAR 500.0f |
| 185 | |
| 186 | const AITargetInfo* AIGroup::FindRepairPosition(AIUnit::ResourceState state) const |
| 187 | { |
| 188 | if (state == AIUnit::RSNormal) |
| 189 | { |
| 190 | return nullptr; |
| 191 | } |
| 192 | AI_ERROR(Leader()); |
| 193 | |
| 194 | // find repair in close range |
| 195 | const AITargetInfo* depot = nullptr; |
| 196 | float dist2Depot = FLT_MAX; |
| 197 | const AITargetInfo* truck = nullptr; |
| 198 | float dist2Truck = FLT_MAX; |
| 199 | |
| 200 | for (int i = 0; i < GetCenter()->NTargets(); i++) |
| 201 | { |
| 202 | const AITargetInfo& info = GetCenter()->GetTarget(i); |
| 203 | if (!info._type) |
| 204 | { |
| 205 | continue; |
| 206 | } |
| 207 | if (!(info._side == TCivilian) && !(GetCenter()->IsFriendly(info._side))) |
| 208 | { |
| 209 | continue; |
| 210 | } |
| 211 | if (info._type->GetMaxRepairCargo() <= 0) |
| 212 | { |
| 213 | continue; |
| 214 | } |
| 215 | VehicleSupply* veh = dyn_cast<VehicleSupply, Object>(info._idExact); |
| 216 | if (!veh) |
| 217 | { |
| 218 | continue; |
| 219 | } |
| 220 | if (veh->GetRepairCargo() <= 0) |
| 221 | { |
| 222 | continue; |
| 223 | } |
| 224 | if (GetCenter()->GetExposurePessimistic(info._realPos) > 0) |
| 225 | { |
| 226 | continue; |
| 227 | } |
| 228 | float dist2 = (Leader()->Position() - info._realPos).SquareSizeXZ(); |
| 229 | |
| 230 | if (info._type->IsKindOf(GLOB_WORLD->Preloaded(VTypeStatic))) |
| 231 | { |
| 232 | if (dist2 < dist2Depot) |
| 233 | { |
| 234 | dist2Depot = dist2; |
| 235 | depot = &info; |
| 236 | } |
| 237 | } |
| 238 | else |
| 239 | { |
| 240 | if (dist2 < dist2Truck) |
| 241 | { |
| 242 | dist2Truck = dist2; |
| 243 | truck = &info; |
no test coverage detected