Bazaar developer reference

CvHomelandAI::ExecuteTradeUnitMoves()

Defined in
CvHomelandAI.cpp, line 5120
Class
CvHomelandAI
Hook name
CivHooks::CvHomelandAI_ExecuteTradeUnitMoves

Hooks

static bool BeforeCvHomelandAI_ExecuteTradeUnitMoves(CvHomelandAI* self);static void AfterCvHomelandAI_ExecuteTradeUnitMoves(CvHomelandAI* self);static void ReplaceCvHomelandAI_ExecuteTradeUnitMoves(void (*original)(CvHomelandAI*), CvHomelandAI* self);CivRegisterBefore<CivHooks::CvHomelandAI_ExecuteTradeUnitMoves>(host, &BeforeCvHomelandAI_ExecuteTradeUnitMoves);CivRegisterAfter<CivHooks::CvHomelandAI_ExecuteTradeUnitMoves>(host, &AfterCvHomelandAI_ExecuteTradeUnitMoves);CivRegisterReplace<CivHooks::CvHomelandAI_ExecuteTradeUnitMoves>(host, &ReplaceCvHomelandAI_ExecuteTradeUnitMoves);

Code

5119// Get a trade unit and send it to a city!5120void CvHomelandAI::ExecuteTradeUnitMoves()5121{5122	CvTradeAI* pkTradeAI = m_pPlayer->GetTradeAI();51235124	static TradeConnectionList aTradeConnections; // slewis - added static to work around the stack limit5125	pkTradeAI->PrioritizeTradeRoutes(aTradeConnections);51265127	FStaticVector< CvHomelandUnit, 64, true, c_eCiv5GameplayDLL >::iterator it;5128	for(it = m_CurrentMoveUnits.begin(); it != m_CurrentMoveUnits.end(); ++it)5129	{5130		CvUnit* pUnit = m_pPlayer->getUnit(it->GetID());5131		if(!pUnit)5132		{5133			continue;5134		}51355136		int iOriginPlotIndex = MAX_INT;5137		int iDestPlotIndex = MAX_INT;5138		TradeConnectionType eTradeConnectionType = NUM_TRADE_CONNECTION_TYPES;5139		bool bDisband = false;5140		bool bSuccess = m_pPlayer->GetTradeAI()->ChooseTradeUnitTargetPlot(pUnit, iOriginPlotIndex, iDestPlotIndex, eTradeConnectionType, bDisband, aTradeConnections);5141		if (bSuccess)5142		{5143			if (bDisband)5144			{5145				pUnit->kill(true);5146				if(GC.getLogging() && GC.getAILogging())5147				{5148					CvString strLogString;5149					strLogString.Format("Disbanding unit because we want different domains for our trade units");5150					LogHomelandMessage(strLogString);5151				}5152			}5153			else5154			{5155				CvPlot* pOriginPlot = GC.getMap().plotByIndex(iOriginPlotIndex);5156				if (pOriginPlot != pUnit->plot())5157				{5158					pUnit->PushMission(CvTypes::getMISSION_CHANGE_TRADE_UNIT_HOME_CITY(), pOriginPlot->getX(), pOriginPlot->getY());5159					if(GC.getLogging() && GC.getAILogging())5160					{5161						CvPlot* pPlot = GC.getMap().plotByIndex(iDestPlotIndex);5162						CvString strLogString;5163						strLogString.Format("Changing trade route home city, X: %d, Y: %d", pPlot->getX(), pPlot->getY());5164						LogHomelandMessage(strLogString);5165					}5166				}5167				else5168				{5169					pUnit->PushMission(CvTypes::getMISSION_ESTABLISH_TRADE_ROUTE(), iDestPlotIndex, eTradeConnectionType);5170					if(GC.getLogging() && GC.getAILogging())5171					{5172						CvPlot* pPlot = GC.getMap().plotByIndex(iDestPlotIndex);5173						CvString strLogString;51745175						switch (eTradeConnectionType)5176						{5177						case TRADE_CONNECTION_FOOD:5178							strLogString.Format("Establishing trade route, X: %d, Y: %d, food", pPlot->getX(), pPlot->getY());5179							break;5180						case TRADE_CONNECTION_INTERNATIONAL:5181							strLogString.Format("Establishing trade route, X: %d, Y: %d, gold", pPlot->getX(), pPlot->getY());5182							break;5183						case TRADE_CONNECTION_PRODUCTION:5184							strLogString.Format("Establishing trade route, X: %d, Y: %d, production", pPlot->getX(), pPlot->getY());5185							break;5186#if defined(MOD_TRADE_WONDER_RESOURCE_ROUTES)5187						case TRADE_CONNECTION_WONDER_RESOURCE:5188							strLogString.Format("Establishing trade route, X: %d, Y: %d, wonder resource", pPlot->getX(), pPlot->getY());5189							break;5190#endif5191						}51925193						LogHomelandMessage(strLogString);5194					}5195				}5196			}5197		}5198		else5199		{5200			pUnit->PushMission(CvTypes::getMISSION_SKIP());5201			pUnit->finishMoves();			5202			if(GC.getLogging() && GC.getAILogging())5203			{5204				CvString strLogString;5205				strLogString.Format("Trade unit idling");5206				LogHomelandMessage(strLogString);5207			}5208		}5209	}5210}

Calls

Called by