MCPcopy Create free account
hub / github.com/Phobos-developers/Phobos / PickRandomScript

Method PickRandomScript

src/Ext/Script/Body.cpp:618–666  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

616}
617
618void ScriptExt::PickRandomScript(TeamClass* pTeam, int idxScriptsList)
619{
620 if (idxScriptsList <= 0)
621 idxScriptsList = pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->CurrentMission].Argument;
622
623 bool changeFailed = true;
624
625 if (idxScriptsList >= 0)
626 {
627 if ((size_t)idxScriptsList < RulesExt::Global()->AIScriptsLists.size())
628 {
629 auto& objectsList = RulesExt::Global()->AIScriptsLists[idxScriptsList];
630
631 if (objectsList.size() > 0)
632 {
633 int IdxSelectedObject = ScenarioClass::Instance->Random.RandomRanged(0, objectsList.size() - 1);
634
635 ScriptTypeClass* pNewScript = objectsList[IdxSelectedObject];
636 if (pNewScript->ActionsCount > 0)
637 {
638 changeFailed = false;
639 TeamExt::ExtMap.Find(pTeam)->PreviousScriptList.push_back(pTeam->CurrentScript);
640 pTeam->CurrentScript = nullptr;
641 pTeam->CurrentScript = GameCreate<ScriptClass>(pNewScript);
642
643 // Ready for jumping to the first line of the new script
644 pTeam->CurrentScript->CurrentMission = -1;
645 pTeam->StepCompleted = true;
646
647 return;
648 }
649 else
650 {
651 pTeam->StepCompleted = true;
652 ScriptExt::Log("AI Scripts - PickRandomScript: [%s] Aborting Script change because [%s] has 0 Action scripts!\n", pTeam->Type->ID, pNewScript->ID);
653
654 return;
655 }
656 }
657 }
658 }
659
660 // This action finished
661 if (changeFailed)
662 {
663 pTeam->StepCompleted = true;
664 ScriptExt::Log("AI Scripts - PickRandomScript: [%s] [%s] Failed to change the Team Script with a random one!\n", pTeam->Type->ID, pTeam->CurrentScript->Type->ID);
665 }
666}
667
668void ScriptExt::SetCloseEnoughDistance(TeamClass* pTeam, double distance)
669{

Callers

nothing calls this directly

Calls 2

sizeMethod · 0.45
FindMethod · 0.45

Tested by

no test coverage detected