CvTacticalAI::AssignDeployingUnits(int)
- Defined in
- CvTacticalAI.cpp, line 10596
- Class
- CvTacticalAI
- Hook name
CivHooks::CvTacticalAI_AssignDeployingUnits
Hooks
static bool BeforeCvTacticalAI_AssignDeployingUnits(CvTacticalAI* self, int iNumUnitsRequiredToDeploy, bool& result);static void AfterCvTacticalAI_AssignDeployingUnits(CvTacticalAI* self, int iNumUnitsRequiredToDeploy, bool& result);static bool ReplaceCvTacticalAI_AssignDeployingUnits(bool (*original)(CvTacticalAI*, int), CvTacticalAI* self, int iNumUnitsRequiredToDeploy);CivRegisterBefore<CivHooks::CvTacticalAI_AssignDeployingUnits>(host, &BeforeCvTacticalAI_AssignDeployingUnits);CivRegisterAfter<CivHooks::CvTacticalAI_AssignDeployingUnits>(host, &AfterCvTacticalAI_AssignDeployingUnits);CivRegisterReplace<CivHooks::CvTacticalAI_AssignDeployingUnits>(host, &ReplaceCvTacticalAI_AssignDeployingUnits);
Code
10595/// Uses information from m_PotentialBlocks to make final assignments to put deploying unit on target10596bool CvTacticalAI::AssignDeployingUnits(int iNumUnitsRequiredToDeploy)10597{10598 bool bChoseOne = true;10599 bool bRtnValue = true;1060010601 m_TemporaryBlocks.clear();10602 m_ChosenBlocks.clear();1060310604 // Loop through potential blocks looking for assignments we MUST make (only one possibility)10605 while(bChoseOne)10606 {10607 bChoseOne = false;10608 m_NewlyChosen.clear();1060910610 for(unsigned int iI = 0; iI < m_PotentialBlocks.size(); iI++)10611 {10612 if(m_PotentialBlocks[iI].GetNumChoices() == 1)10613 {10614 m_NewlyChosen.push_back(m_PotentialBlocks[iI]);10615 bChoseOne = true;10616 }10617 }1061810619 if(bChoseOne)10620 {10621 // Do we have the same unit in m_NewlyChosen twice?10622 if(HaveDuplicateUnit())10623 {10624 return false; // Not going to work10625 }10626 else10627 {10628 // Copy to final list10629 for(unsigned int jJ = 0; jJ < m_NewlyChosen.size(); jJ++)10630 {10631 m_ChosenBlocks.push_back(m_NewlyChosen[jJ]);10632 }1063310634 RemoveChosenUnits();1063510636 // Do we have enough units left to cover everything?10637 if(NumUniqueUnitsLeft() < (iNumUnitsRequiredToDeploy - (int)m_ChosenBlocks.size()))10638 {10639 return false;10640 }10641 }10642 }10643 }1064410645 // Pick closest unit for highest priority assignment until all processed10646 while(m_PotentialBlocks.size() > 0)10647 {10648 bChoseOne = false;10649 m_NewlyChosen.clear();1065010651 m_NewlyChosen.push_back(m_PotentialBlocks[0]);10652 m_ChosenBlocks.push_back(m_PotentialBlocks[0]);1065310654 // Don't copy the other entries for this hex so pass in the number of choices here10655 RemoveChosenUnits(m_PotentialBlocks[0].GetNumChoices());1065610657 // Do we have enough units left to cover everything?10658 if(NumUniqueUnitsLeft() < (iNumUnitsRequiredToDeploy - (int)m_ChosenBlocks.size()))10659 {10660 // Used to abort here, but better if we get the moves in we can10661 bRtnValue = false;10662 }10663 }1066410665 return bRtnValue;10666}
Calls
BaseVector::clearBaseVector::operator[]BaseVector::size- CvBlockingUnit::GetNumChoices() const
- CvTacticalAI::HaveDuplicateUnit()
- CvTacticalAI::NumUniqueUnitsLeft()
- CvTacticalAI::RemoveChosenUnits(int)
FStaticVector::push_back