| 409 | } |
| 410 | |
| 411 | void ScriptExt::Mission_Move_List1Random(TeamClass* pTeam, int calcThreatMode, bool pickAllies, int attackAITargetType, int idxAITargetTypeItem) |
| 412 | { |
| 413 | bool selected = false; |
| 414 | int idxSelectedObject = -1; |
| 415 | std::vector<int> validIndexes; |
| 416 | const auto pTeamData = TeamExt::ExtMap.Find(pTeam); |
| 417 | |
| 418 | if (pTeamData->IdxSelectedObjectFromAIList >= 0) |
| 419 | { |
| 420 | idxSelectedObject = pTeamData->IdxSelectedObjectFromAIList; |
| 421 | selected = true; |
| 422 | } |
| 423 | |
| 424 | const auto pScript = pTeam->CurrentScript; |
| 425 | const auto pScriptType = pScript->Type; |
| 426 | |
| 427 | if (attackAITargetType < 0) |
| 428 | attackAITargetType = pScriptType->ScriptActions[pScript->CurrentMission].Argument; |
| 429 | |
| 430 | if (attackAITargetType >= 0 |
| 431 | && (size_t)attackAITargetType < RulesExt::Global()->AITargetTypesLists.size()) |
| 432 | { |
| 433 | const auto& objectsList = RulesExt::Global()->AITargetTypesLists[attackAITargetType]; |
| 434 | |
| 435 | // Still no random target selected |
| 436 | if (idxSelectedObject < 0 && objectsList.size() > 0 && !selected) |
| 437 | { |
| 438 | const auto pFirstUnit = pTeam->FirstUnit; |
| 439 | validIndexes.reserve(TechnoClass::Array.Count * objectsList.size()); |
| 440 | |
| 441 | // Finding the objects from the list that actually exists in the map |
| 442 | for (int i = 0; i < TechnoClass::Array.Count; i++) |
| 443 | { |
| 444 | const auto pTechno = TechnoClass::Array.GetItem(i); |
| 445 | const auto pTechnoType = pTechno->GetTechnoType(); |
| 446 | bool found = false; |
| 447 | |
| 448 | for (auto j = 0u; j < objectsList.size() && !found; j++) |
| 449 | { |
| 450 | if (pTechnoType == objectsList[j] |
| 451 | && ScriptExt::IsUnitAvailable(pTechno, true) |
| 452 | && pickAllies == pFirstUnit->Owner->IsAlliedWith(pTechno->Owner)) |
| 453 | { |
| 454 | validIndexes.push_back(j); |
| 455 | found = true; |
| 456 | } |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | if (validIndexes.size() > 0) |
| 461 | { |
| 462 | idxSelectedObject = validIndexes[ScenarioClass::Instance->Random.RandomRanged(0, validIndexes.size() - 1)]; |
| 463 | selected = true; |
| 464 | |
| 465 | const auto& node = pScriptType->ScriptActions[pScript->CurrentMission]; |
| 466 | ScriptExt::Log("AI Scripts - Move: [%s] [%s] (line: %d = %d,%d) Picked a random Techno from the list index [AITargetTypes][%d][%d] = %s\n", |
| 467 | pTeam->Type->ID, |
| 468 | pScriptType->ID, |
nothing calls this directly
no test coverage detected