Bazaar developer reference

CvTacticalAI::PlotPlunderTradePlotMoves(DomainTypes)

Defined in
CvTacticalAI.cpp, line 2811
Class
CvTacticalAI
Hook name
CivHooks::CvTacticalAI_PlotPlunderTradePlotMoves

Hooks

static bool BeforeCvTacticalAI_PlotPlunderTradePlotMoves(CvTacticalAI* self, DomainTypes eDomain);static void AfterCvTacticalAI_PlotPlunderTradePlotMoves(CvTacticalAI* self, DomainTypes eDomain);static void ReplaceCvTacticalAI_PlotPlunderTradePlotMoves(void (*original)(CvTacticalAI*, DomainTypes), CvTacticalAI* self, DomainTypes eDomain);CivRegisterBefore<CivHooks::CvTacticalAI_PlotPlunderTradePlotMoves>(host, &BeforeCvTacticalAI_PlotPlunderTradePlotMoves);CivRegisterAfter<CivHooks::CvTacticalAI_PlotPlunderTradePlotMoves>(host, &AfterCvTacticalAI_PlotPlunderTradePlotMoves);CivRegisterReplace<CivHooks::CvTacticalAI_PlotPlunderTradePlotMoves>(host, &ReplaceCvTacticalAI_PlotPlunderTradePlotMoves);

Code

2810/// Assigns units to sit on trade routes it knows about and wait for enemy trade units2811void CvTacticalAI::PlotPlunderTradePlotMoves (DomainTypes eDomain)2812{2813	AITacticalTargetType eTargetType = AI_TACTICAL_TARGET_NONE;2814	bool bNavalOnly = false;2815	if (eDomain == DOMAIN_LAND)2816	{2817		eTargetType = AI_TACTICAL_TARGET_TRADE_UNIT_LAND_PLOT;2818	}2819	else if (eDomain == DOMAIN_SEA)2820	{2821		eTargetType = AI_TACTICAL_TARGET_TRADE_UNIT_SEA_PLOT;2822		bNavalOnly = true;2823	}28242825	CvAssertMsg(eTargetType != AI_TACTICAL_TARGET_NONE, "Undefined domain type for target");2826	if (eTargetType == AI_TACTICAL_TARGET_NONE)2827	{2828		return;2829	}28302831	for (uint ui = 0; ui < m_CurrentMoveUnits.size(); ui++)2832	{2833		UnitHandle pUnit = m_pPlayer->getUnit(m_CurrentMoveUnits[ui].GetID());2834		if (!pUnit)2835		{2836			continue;2837		}28382839		if (pUnit->getDomainType() != eDomain)2840		{2841			continue;2842		}28432844		int iClosestTarget = MAX_INT;2845		CvPlot* pClosestPlot = NULL;2846		CvTacticalTarget* pChosenTarget = NULL;2847		CvTacticalTarget* pTarget = GetFirstZoneTarget(eTargetType);2848		while(pTarget != NULL)2849		{2850			if (pTarget->GetAuxIntData() == 0)2851			{2852				int iDistance = plotDistance(pUnit->getX(), pUnit->getY(), pTarget->GetTargetX(), pTarget->GetTargetY());2853				if(iDistance < iClosestTarget)2854				{2855					pClosestPlot = GC.getMap().plot(pTarget->GetTargetX(), pTarget->GetTargetY());2856					iClosestTarget = iDistance;2857					pChosenTarget = pTarget;2858				}2859			}28602861			pTarget = GetNextZoneTarget();2862		}28632864		if (pClosestPlot)2865		{2866			pUnit->PushMission(CvTypes::getMISSION_MOVE_TO(), pClosestPlot->getX(), pClosestPlot->getY());2867			pUnit->finishMoves();2868			2869			// Delete this unit from those we have to move2870			UnitProcessed(m_CurrentMoveUnits[ui].GetID());28712872			// flag target as used2873			pChosenTarget->SetAuxIntData(1);2874		}2875	}2876}

Calls

Called by