| 5 | // Contains ScriptExt::Mission_Move and its helper functions. |
| 6 | |
| 7 | void ScriptExt::Mission_Move(TeamClass* pTeam, int calcThreatMode, bool pickAllies, int attackAITargetType, int idxAITargetTypeItem) |
| 8 | { |
| 9 | bool noWaitLoop = false; |
| 10 | bool bAircraftsWithoutAmmo = false; |
| 11 | const auto pTeamData = TeamExt::ExtMap.Find(pTeam); |
| 12 | |
| 13 | // When the new target wasn't found it sleeps some few frames before the new attempt. This can save cycles and cycles of unnecessary executed lines. |
| 14 | if (pTeamData->WaitNoTargetCounter > 0) |
| 15 | { |
| 16 | if (pTeamData->WaitNoTargetTimer.InProgress()) |
| 17 | return; |
| 18 | |
| 19 | pTeamData->WaitNoTargetTimer.Stop(); |
| 20 | noWaitLoop = true; |
| 21 | pTeamData->WaitNoTargetCounter = 0; |
| 22 | |
| 23 | if (pTeamData->WaitNoTargetAttempts > 0) |
| 24 | pTeamData->WaitNoTargetAttempts--; |
| 25 | } |
| 26 | |
| 27 | for (auto pFoot = pTeam->FirstUnit; pFoot; pFoot = pFoot->NextTeamMember) |
| 28 | { |
| 29 | if (pFoot && pFoot->IsAlive && !pFoot->InLimbo) |
| 30 | { |
| 31 | const auto pTechnoType = pFoot->GetTechnoType(); |
| 32 | |
| 33 | if (pFoot->WhatAmI() == AbstractType::Aircraft |
| 34 | && !pFoot->IsInAir() |
| 35 | && static_cast<AircraftTypeClass*>(pTechnoType)->AirportBound |
| 36 | && pFoot->Ammo < pTechnoType->Ammo) |
| 37 | { |
| 38 | bAircraftsWithoutAmmo = true; |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | // Find the Leader |
| 44 | auto pLeaderUnit = pTeamData->TeamLeader; |
| 45 | |
| 46 | if (!ScriptExt::IsUnitAvailable(pLeaderUnit, true)) |
| 47 | { |
| 48 | pLeaderUnit = ScriptExt::FindTheTeamLeader(pTeam); |
| 49 | pTeamData->TeamLeader = pLeaderUnit; |
| 50 | } |
| 51 | |
| 52 | const auto pScript = pTeam->CurrentScript; |
| 53 | const auto pScriptType = pScript->Type; |
| 54 | |
| 55 | if (!pLeaderUnit || bAircraftsWithoutAmmo) |
| 56 | { |
| 57 | pTeamData->IdxSelectedObjectFromAIList = -1; |
| 58 | |
| 59 | if (pTeamData->CloseEnough > 0) |
| 60 | pTeamData->CloseEnough = -1; |
| 61 | |
| 62 | if (pTeamData->WaitNoTargetAttempts != 0) |
| 63 | { |
| 64 | pTeamData->WaitNoTargetTimer.Stop(); |
nothing calls this directly
no test coverage detected