Bazaar developer reference

CvTacticalAI::PlotWithdrawMoves()

Defined in
CvTacticalAI.cpp, line 3873
Class
CvTacticalAI
Hook name
CivHooks::CvTacticalAI_PlotWithdrawMoves

Hooks

static bool BeforeCvTacticalAI_PlotWithdrawMoves(CvTacticalAI* self);static void AfterCvTacticalAI_PlotWithdrawMoves(CvTacticalAI* self);static void ReplaceCvTacticalAI_PlotWithdrawMoves(void (*original)(CvTacticalAI*), CvTacticalAI* self);CivRegisterBefore<CivHooks::CvTacticalAI_PlotWithdrawMoves>(host, &BeforeCvTacticalAI_PlotWithdrawMoves);CivRegisterAfter<CivHooks::CvTacticalAI_PlotWithdrawMoves>(host, &AfterCvTacticalAI_PlotWithdrawMoves);CivRegisterReplace<CivHooks::CvTacticalAI_PlotWithdrawMoves>(host, &ReplaceCvTacticalAI_PlotWithdrawMoves);

Code

3872/// Withdraw out of current dominance zone3873void CvTacticalAI::PlotWithdrawMoves()3874{3875	list<int>::iterator it;3876	m_CurrentMoveUnits.clear();3877	CvTacticalUnit unit;38783879	CvTacticalDominanceZone* pZone = m_pMap->GetZone(m_iCurrentZoneIndex);38803881	// Loop through all recruited units3882	for(it = m_CurrentTurnUnits.begin(); it != m_CurrentTurnUnits.end(); it++)3883	{3884		UnitHandle pUnit = m_pPlayer->getUnit(*it);3885		if(pUnit)3886		{3887			// Proper domain of unit?3888			if(pZone->IsWater() && pUnit->getDomainType() == DOMAIN_SEA || !pZone->IsWater() && pUnit->getDomainType() == DOMAIN_LAND)3889			{3890				// Am I in the current dominance zone?3891				int iPlotIndex = GC.getMap().plotNum(pUnit->getX(), pUnit->getY());3892				if(m_pMap->GetCell(iPlotIndex)->GetDominanceZone() == m_pMap->GetZone(m_iCurrentZoneIndex)->GetDominanceZoneID())3893				{3894					unit.SetID(pUnit->GetID());3895					m_CurrentMoveUnits.push_back(unit);3896				}38973898				// Or am I within tactical recruit range of center of zone and in danger and not in friendly territory?3899				else if(pZone->GetClosestCity() != NULL)3900				{3901					if(plotDistance(pZone->GetClosestCity()->getX(), pZone->GetClosestCity()->getY(), pUnit->getX(), pUnit->getY()) <= m_iRecruitRange)3902					{3903						CvPlot* pPlot = pUnit->plot();3904						if(m_pPlayer->GetPlotDanger(*pPlot) > 0)3905						{3906							if(pUnit->plot()->getOwner() != pUnit->getOwner())3907							{3908								unit.SetID(pUnit->GetID());3909								m_CurrentMoveUnits.push_back(unit);3910							}3911						}3912					}3913				}39143915				// Or we are withdrawing from unowned lands zone and this is a plot in danger3916				else if(pZone->GetTerritoryType() == TACTICAL_TERRITORY_NO_OWNER)3917				{3918					CvPlot* pPlot = pUnit->plot();3919					if(m_pPlayer->GetPlotDanger(*pPlot) > 0)3920					{3921						if(pUnit->plot()->getOwner() != pUnit->getOwner())3922						{3923							unit.SetID(pUnit->GetID());3924							m_CurrentMoveUnits.push_back(unit);3925						}3926					}3927				}3928			}3929		}3930	}39313932	if(m_CurrentMoveUnits.size() > 0)3933	{3934		ExecuteWithdrawMoves();3935	}3936}

Calls

Called by