Bazaar developer reference

CvTacticalAI::FindClosestOperationUnit(CvPlot *, bool, bool)

Defined in
CvTacticalAI.cpp, line 9421
Class
CvTacticalAI
Hook name
CivHooks::CvTacticalAI_FindClosestOperationUnit

Hooks

static bool BeforeCvTacticalAI_FindClosestOperationUnit(CvTacticalAI* self, CvPlot* pTarget, bool bSafeForRanged, bool bMustBeRangedUnit, bool& result);static void AfterCvTacticalAI_FindClosestOperationUnit(CvTacticalAI* self, CvPlot* pTarget, bool bSafeForRanged, bool bMustBeRangedUnit, bool& result);static bool ReplaceCvTacticalAI_FindClosestOperationUnit(bool (*original)(CvTacticalAI*, CvPlot*, bool, bool), CvTacticalAI* self, CvPlot* pTarget, bool bSafeForRanged, bool bMustBeRangedUnit);CivRegisterBefore<CivHooks::CvTacticalAI_FindClosestOperationUnit>(host, &BeforeCvTacticalAI_FindClosestOperationUnit);CivRegisterAfter<CivHooks::CvTacticalAI_FindClosestOperationUnit>(host, &AfterCvTacticalAI_FindClosestOperationUnit);CivRegisterReplace<CivHooks::CvTacticalAI_FindClosestOperationUnit>(host, &ReplaceCvTacticalAI_FindClosestOperationUnit);

Code

9420/// Fills m_CurrentMoveUnits with all units in operation that can get to target (returns TRUE if 1 or more found)9421bool CvTacticalAI::FindClosestOperationUnit(CvPlot* pTarget, bool bSafeForRanged, bool bMustBeRangedUnit)9422{9423	FStaticVector<CvOperationUnit, SAFE_ESTIMATE_NUM_MULTIUNITFORMATION_ENTRIES, true, c_eCiv5GameplayDLL, 0>::iterator it;9424	UnitHandle pLoopUnit;94259426	bool rtnValue = false;9427	m_CurrentMoveUnits.clear();94289429	// Loop through all units available to operation9430	for(it = m_OperationUnits.begin(); it != m_OperationUnits.end(); it++)9431	{9432		pLoopUnit = m_pPlayer->getUnit(it->GetUnitID());9433		if(pLoopUnit)9434		{9435			bool bValidUnit = true;94369437			if (pLoopUnit->hasMoved())9438			{9439				bValidUnit = false;9440			}94419442			else if(!bSafeForRanged && pLoopUnit->IsCanAttackRanged())9443			{9444				bValidUnit = false;9445			}94469447			else if (bMustBeRangedUnit && !pLoopUnit->IsCanAttackRanged())9448			{9449				bValidUnit = false;9450			}94519452			if(bValidUnit)9453			{9454				int iTurns = TurnsToReachTarget(pLoopUnit, pTarget, false /*bReusePaths*/, false /*bIgnoreUnits*/);94559456				if(iTurns != MAX_INT)9457				{9458					CvTacticalUnit unit;9459					unit.SetID(pLoopUnit->GetID());9460					unit.SetAttackStrength(1000-iTurns);9461					unit.SetHealthPercent(10,10);9462					unit.SetMovesToTarget(plotDistance(pLoopUnit->getX(), pLoopUnit->getY(), pTarget->getX(), pTarget->getY()));9463					m_CurrentMoveUnits.push_back(unit);9464					rtnValue = true;9465				}9466			}9467		}9468	}94699470	// Now sort them by turns to reach9471	std::stable_sort(m_CurrentMoveUnits.begin(), m_CurrentMoveUnits.end());94729473	return rtnValue;9474}

Calls

Called by