Bazaar developer reference

CvGameTrade::ClearAllCityTradeRoutes(CvPlot *, bool)

Defined in
CvTradeClasses.cpp, line 949
Class
CvGameTrade
Hook name
CivHooks::CvGameTrade_ClearAllCityTradeRoutes

Hooks

static bool BeforeCvGameTrade_ClearAllCityTradeRoutes(CvGameTrade* self, CvPlot* pPlot, bool bIncludeTransits);static void AfterCvGameTrade_ClearAllCityTradeRoutes(CvGameTrade* self, CvPlot* pPlot, bool bIncludeTransits);static void ReplaceCvGameTrade_ClearAllCityTradeRoutes(void (*original)(CvGameTrade*, CvPlot*, bool), CvGameTrade* self, CvPlot* pPlot, bool bIncludeTransits);CivRegisterBefore<CivHooks::CvGameTrade_ClearAllCityTradeRoutes>(host, &BeforeCvGameTrade_ClearAllCityTradeRoutes);CivRegisterAfter<CivHooks::CvGameTrade_ClearAllCityTradeRoutes>(host, &AfterCvGameTrade_ClearAllCityTradeRoutes);CivRegisterReplace<CivHooks::CvGameTrade_ClearAllCityTradeRoutes>(host, &ReplaceCvGameTrade_ClearAllCityTradeRoutes);

Code

947/// Called when a city changes hands948#if defined(MOD_BUGFIX_MINOR)949void CvGameTrade::ClearAllCityTradeRoutes (CvPlot* pPlot, bool bIncludeTransits)950#else951void CvGameTrade::ClearAllCityTradeRoutes (CvPlot* pPlot)952#endif953{954	CvAssert(pPlot != NULL);955956	if (pPlot)957	{958		int iX = pPlot->getX();959		int iY = pPlot->getY();960		for (uint ui = 0; ui < m_aTradeConnections.size(); ui++)961		{962			if (IsTradeRouteIndexEmpty(ui))963			{964				continue;965			}966967			bool bMatchesOrigin = (m_aTradeConnections[ui].m_iOriginX == iX && m_aTradeConnections[ui].m_iOriginY == iY);968			bool bMatchesDest = (m_aTradeConnections[ui].m_iDestX == iX && m_aTradeConnections[ui].m_iDestY == iY);969970			if (bMatchesOrigin || bMatchesDest)971			{972				// if the destination was wiped, the origin gets a trade unit back973				if (bMatchesDest && GET_PLAYER(m_aTradeConnections[ui].m_eOriginOwner).isAlive())974				{975#if defined(MOD_BUGFIX_UNITCLASS_NOT_UNIT)976					CvPlayer& kPlayer = GET_PLAYER(m_aTradeConnections[ui].m_eOriginOwner);977					UnitTypes eUnitType = kPlayer.GetTrade()->GetTradeUnit(m_aTradeConnections[ui].m_eDomain, &kPlayer);978#else979					UnitTypes eUnitType = GET_PLAYER(m_aTradeConnections[ui].m_eOriginOwner).GetTrade()->GetTradeUnit(m_aTradeConnections[ui].m_eDomain);980#endif981					CvAssertMsg(eUnitType != NO_UNIT, "No trade unit found");982					if (eUnitType != NO_UNIT)983					{984						GET_PLAYER(m_aTradeConnections[ui].m_eOriginOwner).initUnit(eUnitType, m_aTradeConnections[ui].m_iOriginX, m_aTradeConnections[ui].m_iOriginY, UNITAI_TRADE_UNIT);985					}986				}987988				EmptyTradeRoute(ui);989			}		990			991#if defined(MOD_BUGFIX_MINOR)992			// If we have any water routes transiting via this city, we need to cancel them993			if (bIncludeTransits && m_aTradeConnections[ui].m_eDomain == DOMAIN_SEA) {994				TradeConnectionPlotList aPlotList = m_aTradeConnections[ui].m_aPlotList;995996				for (uint uiPlotIndex = 0; uiPlotIndex < aPlotList.size(); uiPlotIndex++) {997					if (aPlotList[uiPlotIndex].m_iX == iX && aPlotList[uiPlotIndex].m_iY == iY) {998						CUSTOMLOG("Cancelling water trade route in plot (%i, %i) as city destroyed", iX, iY);999						m_aTradeConnections[ui].m_iCircuitsCompleted = m_aTradeConnections[ui].m_iCircuitsToComplete;1000						break;1001					}1002				}1003			}1004#endif1005		}1006	}1007}

Calls

Called by