| 1353 | } |
| 1354 | |
| 1355 | void ScriptExt::Mission_Attack_List1Random(TeamClass* pTeam, int calcThreatMode, bool repeatAction, int attackAITargetType) |
| 1356 | { |
| 1357 | bool selected = false; |
| 1358 | int idxSelectedObject = -1; |
| 1359 | std::vector<int> validIndexes; |
| 1360 | const auto pTeamData = TeamExt::ExtMap.Find(pTeam); |
| 1361 | |
| 1362 | if (pTeamData->IdxSelectedObjectFromAIList >= 0) |
| 1363 | { |
| 1364 | idxSelectedObject = pTeamData->IdxSelectedObjectFromAIList; |
| 1365 | selected = true; |
| 1366 | } |
| 1367 | |
| 1368 | const auto pScript = pTeam->CurrentScript; |
| 1369 | const auto pScriptType = pScript->Type; |
| 1370 | |
| 1371 | if (attackAITargetType < 0) |
| 1372 | attackAITargetType = pScriptType->ScriptActions[pScript->CurrentMission].Argument; |
| 1373 | |
| 1374 | if (attackAITargetType >= 0 |
| 1375 | && (size_t)attackAITargetType < RulesExt::Global()->AITargetTypesLists.size()) |
| 1376 | { |
| 1377 | auto& objectsList = RulesExt::Global()->AITargetTypesLists[attackAITargetType]; |
| 1378 | |
| 1379 | if (idxSelectedObject < 0 && objectsList.size() > 0 && !selected) |
| 1380 | { |
| 1381 | const auto pFirstUnit = pTeam->FirstUnit; |
| 1382 | validIndexes.reserve(TechnoClass::Array.Count * objectsList.size()); |
| 1383 | |
| 1384 | // Finding the objects from the list that actually exists in the map |
| 1385 | for (int i = 0; i < TechnoClass::Array.Count; i++) |
| 1386 | { |
| 1387 | const auto pTechno = TechnoClass::Array.GetItem(i); |
| 1388 | const auto pTechnoType = pTechno->GetTechnoType(); |
| 1389 | bool found = false; |
| 1390 | |
| 1391 | for (auto j = 0u; j < objectsList.size() && !found; j++) |
| 1392 | { |
| 1393 | if (pTechnoType == objectsList[j] |
| 1394 | && ScriptExt::IsUnitAvailable(pTechno, true) |
| 1395 | && (!pFirstUnit->Owner->IsAlliedWith(pTechno->Owner) |
| 1396 | || ScriptExt::IsMindControlledByEnemy(pFirstUnit->Owner, pTechno))) |
| 1397 | { |
| 1398 | validIndexes.push_back(j); |
| 1399 | found = true; |
| 1400 | } |
| 1401 | } |
| 1402 | } |
| 1403 | |
| 1404 | if (validIndexes.size() > 0) |
| 1405 | { |
| 1406 | idxSelectedObject = validIndexes[ScenarioClass::Instance->Random.RandomRanged(0, validIndexes.size() - 1)]; |
| 1407 | selected = true; |
| 1408 | |
| 1409 | const auto& node = pScriptType->ScriptActions[pScript->CurrentMission]; |
| 1410 | ScriptExt::Log("AI Scripts - AttackListRandom: [%s] [%s] (line: %d = %d,%d) Picked a random Techno from the list index [AITargetTypes][%d][%d] = %s\n", |
| 1411 | pTeam->Type->ID, |
| 1412 | pScriptType->ID, |
nothing calls this directly
no test coverage detected