CvHomelandAI::MoveToEmptySpaceNearTarget(CvUnit *, CvPlot *, bool)
- Defined in
- CvHomelandAI.cpp, line 5808
- Class
- CvHomelandAI
- Hook name
CivHooks::CvHomelandAI_MoveToEmptySpaceNearTarget
Hooks
static bool BeforeCvHomelandAI_MoveToEmptySpaceNearTarget(CvHomelandAI* self, CvUnit* pUnit, CvPlot* pTarget, bool bLand, bool& result);static void AfterCvHomelandAI_MoveToEmptySpaceNearTarget(CvHomelandAI* self, CvUnit* pUnit, CvPlot* pTarget, bool bLand, bool& result);static bool ReplaceCvHomelandAI_MoveToEmptySpaceNearTarget(bool (*original)(CvHomelandAI*, CvUnit*, CvPlot*, bool), CvHomelandAI* self, CvUnit* pUnit, CvPlot* pTarget, bool bLand);CivRegisterBefore<CivHooks::CvHomelandAI_MoveToEmptySpaceNearTarget>(host, &BeforeCvHomelandAI_MoveToEmptySpaceNearTarget);CivRegisterAfter<CivHooks::CvHomelandAI_MoveToEmptySpaceNearTarget>(host, &AfterCvHomelandAI_MoveToEmptySpaceNearTarget);CivRegisterReplace<CivHooks::CvHomelandAI_MoveToEmptySpaceNearTarget>(host, &ReplaceCvHomelandAI_MoveToEmptySpaceNearTarget);
Code
5807/// Move up to our target avoiding our own units if possible5808bool CvHomelandAI::MoveToEmptySpaceNearTarget(CvUnit* pUnit, CvPlot* pTarget, bool bLand)5809{5810 CvPlot* pLoopPlot;58115812 // Look at spaces adjacent to target5813 for(int iI = 0; iI < NUM_DIRECTION_TYPES; iI++)5814 {5815 pLoopPlot = plotDirection(pTarget->getX(), pTarget->getY(), ((DirectionTypes)iI));5816 if(pLoopPlot != NULL && pLoopPlot->isWater() != bLand)5817 {5818 // Must be currently empty of friendly combat units5819 if(!pLoopPlot->getBestDefender(m_pPlayer->GetID()))5820 {5821 // Enemies too5822 if(!pLoopPlot->getBestDefender(NO_PLAYER, m_pPlayer->GetID()))5823 {5824 // Find a path to this space5825 if(pUnit->GeneratePath(pLoopPlot))5826 {5827 // Go ahead with mission5828 pUnit->PushMission(CvTypes::getMISSION_MOVE_TO(), pLoopPlot->getX(), pLoopPlot->getY());5829 return true;5830 }5831 }5832 }5833 }5834 }5835 return false;5836}
Calls
- CvPlayer::GetID() const
- CvPlot::getBestDefender(PlayerTypes, PlayerTypes, const CvUnit *, bool, bool, bool, bool)
- CvPlot::getX() const
- CvPlot::getY() const
- CvPlot::isWater() const
- CvTypes::getMISSION_MOVE_TO()
- CvUnit::GeneratePath(const CvPlot *, int, bool, int *) const
- CvUnit::PushMission(MissionTypes, int, int, int, bool, bool, MissionAITypes, CvPlot *, CvUnit *)
FObjectHandle::operator!- plotDirection(int, int, DirectionTypes)