Bazaar developer reference

CvTacticalAI::FindClosestNavalOperationUnit(CvPlot *, bool)

Defined in
CvTacticalAI.cpp, line 9477
Class
CvTacticalAI
Hook name
CivHooks::CvTacticalAI_FindClosestNavalOperationUnit

Hooks

static bool BeforeCvTacticalAI_FindClosestNavalOperationUnit(CvTacticalAI* self, CvPlot* pTarget, bool bEscortedUnits, bool& result);static void AfterCvTacticalAI_FindClosestNavalOperationUnit(CvTacticalAI* self, CvPlot* pTarget, bool bEscortedUnits, bool& result);static bool ReplaceCvTacticalAI_FindClosestNavalOperationUnit(bool (*original)(CvTacticalAI*, CvPlot*, bool), CvTacticalAI* self, CvPlot* pTarget, bool bEscortedUnits);CivRegisterBefore<CivHooks::CvTacticalAI_FindClosestNavalOperationUnit>(host, &BeforeCvTacticalAI_FindClosestNavalOperationUnit);CivRegisterAfter<CivHooks::CvTacticalAI_FindClosestNavalOperationUnit>(host, &AfterCvTacticalAI_FindClosestNavalOperationUnit);CivRegisterReplace<CivHooks::CvTacticalAI_FindClosestNavalOperationUnit>(host, &ReplaceCvTacticalAI_FindClosestNavalOperationUnit);

Code

9476/// Fills m_CurrentMoveUnits with all units in naval operation that can get to target (returns TRUE if 1 or more found)9477bool CvTacticalAI::FindClosestNavalOperationUnit(CvPlot* pTarget, bool bEscortedUnits)9478{9479	FStaticVector<CvOperationUnit, SAFE_ESTIMATE_NUM_MULTIUNITFORMATION_ENTRIES, true, c_eCiv5GameplayDLL, 0>::iterator it;9480	UnitHandle pLoopUnit;94819482	bool rtnValue = false;9483	m_CurrentMoveUnits.clear();94849485	// Loop through all units available to operation9486	for(it = m_OperationUnits.begin(); it != m_OperationUnits.end(); it++)9487	{9488		pLoopUnit = m_pPlayer->getUnit(it->GetUnitID());9489		if(pLoopUnit)9490		{9491			bool bValidUnit = true;94929493			if(bEscortedUnits && (!pLoopUnit->IsGreatAdmiral() && pLoopUnit->getDomainType() != DOMAIN_LAND))9494			{9495				bValidUnit = false;9496			}94979498			if(!bEscortedUnits && (pLoopUnit->getDomainType() != DOMAIN_SEA || pLoopUnit->IsGreatAdmiral()))9499			{9500				bValidUnit = false;9501			}95029503			if(bValidUnit)9504			{9505				int iTurns = TurnsToReachTarget(pLoopUnit, pTarget, false /*bReusePaths*/, true /*bIgnoreUnits*/);95069507				if(iTurns != MAX_INT)9508				{9509					CvTacticalUnit unit;9510					unit.SetID(pLoopUnit->GetID());9511					unit.SetAttackStrength(1000-iTurns);9512					unit.SetHealthPercent(10,10);9513					unit.SetMovesToTarget(plotDistance(pLoopUnit->getX(), pLoopUnit->getY(), pTarget->getX(), pTarget->getY()));9514					m_CurrentMoveUnits.push_back(unit);9515					rtnValue = true;9516				}9517			}9518		}9519	}95209521	// Now sort them by turns to reach9522	std::stable_sort(m_CurrentMoveUnits.begin(), m_CurrentMoveUnits.end());95239524	return rtnValue;9525}

Calls

Called by