Bazaar developer reference

CvTacticalAI::ExecuteWithdrawMoves()

Defined in
CvTacticalAI.cpp, line 8739
Class
CvTacticalAI
Hook name
CivHooks::CvTacticalAI_ExecuteWithdrawMoves

Hooks

static bool BeforeCvTacticalAI_ExecuteWithdrawMoves(CvTacticalAI* self);static void AfterCvTacticalAI_ExecuteWithdrawMoves(CvTacticalAI* self);static void ReplaceCvTacticalAI_ExecuteWithdrawMoves(void (*original)(CvTacticalAI*), CvTacticalAI* self);CivRegisterBefore<CivHooks::CvTacticalAI_ExecuteWithdrawMoves>(host, &BeforeCvTacticalAI_ExecuteWithdrawMoves);CivRegisterAfter<CivHooks::CvTacticalAI_ExecuteWithdrawMoves>(host, &AfterCvTacticalAI_ExecuteWithdrawMoves);CivRegisterReplace<CivHooks::CvTacticalAI_ExecuteWithdrawMoves>(host, &ReplaceCvTacticalAI_ExecuteWithdrawMoves);

Code

8738/// Move units out of current dominance zone8739void CvTacticalAI::ExecuteWithdrawMoves()8740{8741	CvCity* pNearestCity;8742	int iTurnsToReachTarget;87438744	for(unsigned int iI = 0; iI < m_CurrentMoveUnits.size(); iI++)8745	{8746		UnitHandle pUnit = m_pPlayer->getUnit(m_CurrentMoveUnits[iI].GetID());8747		if(pUnit)8748		{8749			// Compute moves to nearest city and use as sort criteria8750			pNearestCity = GC.getMap().findCity(pUnit->getX(), pUnit->getY(), m_pPlayer->GetID(), NO_TEAM, true /* bSameArea */);8751			if(pNearestCity != NULL)8752			{8753				iTurnsToReachTarget = TurnsToReachTarget(pUnit, pNearestCity->plot());8754				m_CurrentMoveUnits[iI].SetMovesToTarget(iTurnsToReachTarget);8755				m_CurrentMoveUnits[iI].SetAttackStrength(1000-iTurnsToReachTarget);8756				m_CurrentMoveUnits[iI].SetHealthPercent(10,10);8757			}8758		}8759	}87608761	// Sort units by distance to city so closest ones move first8762	std::stable_sort(m_CurrentMoveUnits.begin(), m_CurrentMoveUnits.end());87638764	// Execute the moves8765	for(unsigned int iI = 0; iI < m_CurrentMoveUnits.size(); iI++)8766	{8767		UnitHandle pUnit = m_pPlayer->getUnit(m_CurrentMoveUnits[iI].GetID());8768		if(pUnit)8769		{8770			// Compute moves to nearest city and use as sort criteria8771			pNearestCity = GC.getMap().findCity(pUnit->getX(), pUnit->getY(), m_pPlayer->GetID(), NO_TEAM, true /* bSameArea */);8772			if(pNearestCity != NULL)8773			{8774				MoveToEmptySpaceNearTarget(pUnit, pNearestCity->plot(), (pUnit->getDomainType()==DOMAIN_LAND));87758776				pUnit->finishMoves();8777				UnitProcessed(m_CurrentMoveUnits[iI].GetID(), pUnit->IsCombatUnit());87788779				if(GC.getLogging() && GC.getAILogging())8780				{8781					CvString strLogString;8782					strLogString.Format("%s withdrew toward %s, Current X: %d, Current Y: %d", pUnit->getName().GetCString(), pNearestCity->getName().GetCString(),8783					                    pUnit->getX(), pUnit->getY());8784					LogTacticalMessage(strLogString, false);8785				}8786			}8787		}8788	}8789}

Calls

Called by