CvTacticalAI::FindNearbyTarget(UnitHandle, int, AITacticalTargetType, CvUnit *)
- Defined in
- CvTacticalAI.cpp, line 10342
- Class
- CvTacticalAI
- Hook name
CivHooks::CvTacticalAI_FindNearbyTarget
Hooks
static bool BeforeCvTacticalAI_FindNearbyTarget(CvTacticalAI* self, UnitHandle pUnit, int iRange, AITacticalTargetType eType, CvUnit* pNoLikeUnit, CvPlot*& result);static void AfterCvTacticalAI_FindNearbyTarget(CvTacticalAI* self, UnitHandle pUnit, int iRange, AITacticalTargetType eType, CvUnit* pNoLikeUnit, CvPlot*& result);static CvPlot* ReplaceCvTacticalAI_FindNearbyTarget(CvPlot* (*original)(CvTacticalAI*, UnitHandle, int, AITacticalTargetType, CvUnit*), CvTacticalAI* self, UnitHandle pUnit, int iRange, AITacticalTargetType eType, CvUnit* pNoLikeUnit);CivRegisterBefore<CivHooks::CvTacticalAI_FindNearbyTarget>(host, &BeforeCvTacticalAI_FindNearbyTarget);CivRegisterAfter<CivHooks::CvTacticalAI_FindNearbyTarget>(host, &AfterCvTacticalAI_FindNearbyTarget);CivRegisterReplace<CivHooks::CvTacticalAI_FindNearbyTarget>(host, &ReplaceCvTacticalAI_FindNearbyTarget);
Code
10341/// Find a multi-turn target for a land unit to wander towards10342CvPlot* CvTacticalAI::FindNearbyTarget(UnitHandle pUnit, int iRange, AITacticalTargetType eType, CvUnit* pNoLikeUnit)10343{10344 CvPlot* pBestMovePlot = NULL;10345 int iBestValue;10346 int iValue;10347 CvPlot* pPlot;1034810349 iBestValue = MAX_INT;10350 pBestMovePlot = NULL;1035110352 // Loop through all appropriate targets to find the closest10353 for(unsigned int iI = 0; iI < m_ZoneTargets.size(); iI++)10354 {10355 // Is the target of an appropriate type?10356 bool bTypeMatch = false;10357 if(eType == AI_TACTICAL_TARGET_NONE)10358 {10359 if(m_ZoneTargets[iI].GetTargetType() == AI_TACTICAL_TARGET_HIGH_PRIORITY_UNIT ||10360 m_ZoneTargets[iI].GetTargetType() == AI_TACTICAL_TARGET_MEDIUM_PRIORITY_UNIT ||10361 m_ZoneTargets[iI].GetTargetType() == AI_TACTICAL_TARGET_LOW_PRIORITY_UNIT ||10362 m_ZoneTargets[iI].GetTargetType() == AI_TACTICAL_TARGET_CITY ||10363 m_ZoneTargets[iI].GetTargetType() == AI_TACTICAL_TARGET_IMPROVEMENT)10364 {10365 bTypeMatch = true;10366 }10367 }10368 else if(m_ZoneTargets[iI].GetTargetType() == eType)10369 {10370 bTypeMatch = true;10371 }1037210373 // Is this unit near enough?10374 if(bTypeMatch)10375 {10376 pPlot = GC.getMap().plot(m_ZoneTargets[iI].GetTargetX(), m_ZoneTargets[iI].GetTargetY());10377 int iDistance = plotDistance(pUnit->getX(), pUnit->getY(), m_ZoneTargets[iI].GetTargetX(), m_ZoneTargets[iI].GetTargetY());10378 if(iDistance == 0)10379 {10380 return pPlot;10381 }10382 else if(iDistance < iRange)10383 {10384 if(pUnit->getArea() == pPlot->getArea())10385 {10386 if(!pNoLikeUnit || pPlot->getNumFriendlyUnitsOfType(pNoLikeUnit) == 0)10387 {10388 iValue = TurnsToReachTarget(pUnit, pPlot, true /*bReusePaths*/);10389 if(iValue < iBestValue)10390 {10391 pBestMovePlot = pPlot;10392 iBestValue = iValue;10393 }10394 }10395 }10396 }10397 }10398 }1039910400 return pBestMovePlot;10401}
Calls
BaseVector::operator[]BaseVector::size- CvGlobals::getMap()
- CvMap::plot(int, int) const
- CvPlot::getArea() const
- CvPlot::getNumFriendlyUnitsOfType(const CvUnit *, bool) const
- CvTacticalTarget::GetTargetType()
- CvTacticalTarget::GetTargetX()
- CvTacticalTarget::GetTargetY()
- CvUnit::getArea() const
- CvUnit::getX() const
- CvUnit::getY() const
FObjectHandle::FObjectHandleFObjectHandle::operator->- plotDistance(int, int, int, int)
- TurnsToReachTarget(UnitHandle, CvPlot *, bool, bool, bool)