| 2512 | float AIUnit::GetTimeToLive() const |
| 2513 | { |
| 2514 | const float MinTimeToLive = 5.0; |
| 2515 | // assume we can live max. 24 hours |
| 2516 | float maxTimeToLive = 3600 * 24.0; |
| 2517 | // when in combat, assume we can live max. 1 hour |
| 2518 | if (GetCombatMode() >= CMCombat) |
| 2519 | { |
| 2520 | maxTimeToLive = 3600; |
| 2521 | } |
| 2522 | |
| 2523 | if (!GetGroup()) |
| 2524 | { |
| 2525 | Fail("No group in GetTimeToLive"); |
| 2526 | return MinTimeToLive; |
| 2527 | } |
| 2528 | |
| 2529 | // exposure is updated quite slowly |
| 2530 | // when we calculate timeToLive from current target, |
| 2531 | // we will almost certainly not underestimate |
| 2532 | |
| 2533 | /* |
| 2534 | Target *tgt = GetTargetAssigned(); |
| 2535 | if (tgt) |
| 2536 | { |
| 2537 | EntityAI *veh = GetVehicle(); |
| 2538 | float dist2 = veh->Position().Distance2(tgt->AimingPosition()); |
| 2539 | float visibility = 1; |
| 2540 | Threat threat = tgt->type->GetDammagePerMinute(dist2,visibility); |
| 2541 | VehicleKind kind = veh->GetType()->GetKind(); |
| 2542 | float dpm = threat[kind]; |
| 2543 | |
| 2544 | if (dpm>0) |
| 2545 | { |
| 2546 | float ttl = 60 * GetVehicle()->GetArmor() / dpm; |
| 2547 | saturateMin(maxTimeToLive,ttl); |
| 2548 | } |
| 2549 | } |
| 2550 | */ |
| 2551 | |
| 2552 | int x = toIntFloor(GetVehicle()->Position().X() * InvLandGrid); |
| 2553 | int z = toIntFloor(GetVehicle()->Position().Z() * InvLandGrid); |
| 2554 | float exposure; |
| 2555 | if (IsHoldingFire()) |
| 2556 | { |
| 2557 | exposure = GetGroup()->GetCenter()->GetExposurePessimistic(x, z); |
| 2558 | } |
| 2559 | else |
| 2560 | { |
| 2561 | exposure = GetGroup()->GetCenter()->GetExposureOptimistic(x, z); |
| 2562 | } |
| 2563 | if (exposure <= 0) |
| 2564 | { |
| 2565 | return maxTimeToLive; |
| 2566 | } |
| 2567 | |
| 2568 | float timeToLive = 60 * GetVehicle()->GetArmor() / exposure; |
| 2569 | saturate(timeToLive, MinTimeToLive, maxTimeToLive); |
| 2570 | return timeToLive; |
| 2571 | } |
no test coverage detected