Bazaar developer reference

CvGameTrade::DoAutoWarPlundering(TeamTypes, TeamTypes)

Defined in
CvTradeClasses.cpp, line 1118
Class
CvGameTrade
Hook name
CivHooks::CvGameTrade_DoAutoWarPlundering

Hooks

static bool BeforeCvGameTrade_DoAutoWarPlundering(CvGameTrade* self, TeamTypes eTeam1, TeamTypes eTeam2);static void AfterCvGameTrade_DoAutoWarPlundering(CvGameTrade* self, TeamTypes eTeam1, TeamTypes eTeam2);static void ReplaceCvGameTrade_DoAutoWarPlundering(void (*original)(CvGameTrade*, TeamTypes, TeamTypes), CvGameTrade* self, TeamTypes eTeam1, TeamTypes eTeam2);CivRegisterBefore<CivHooks::CvGameTrade_DoAutoWarPlundering>(host, &BeforeCvGameTrade_DoAutoWarPlundering);CivRegisterAfter<CivHooks::CvGameTrade_DoAutoWarPlundering>(host, &AfterCvGameTrade_DoAutoWarPlundering);CivRegisterReplace<CivHooks::CvGameTrade_DoAutoWarPlundering>(host, &ReplaceCvGameTrade_DoAutoWarPlundering);

Code

1117// when war is declared, both sides plunder each others trade routes for cash!1118void CvGameTrade::DoAutoWarPlundering(TeamTypes eTeam1, TeamTypes eTeam2)1119{1120	// walk through each team1121	for (uint uiTeam = 0; uiTeam < 2; uiTeam++)1122	{1123		TeamTypes eTRTeam = NO_TEAM;1124		TeamTypes ePlunderTeam = NO_TEAM;1125		switch (uiTeam)1126		{1127		case 0:1128			eTRTeam = eTeam1;1129			ePlunderTeam = eTeam2;1130			break;1131		case 1:1132			eTRTeam = eTeam2;1133			ePlunderTeam = eTeam1;1134		}11351136		// walk through each player on the team1137		for (uint uiPlayer = 0; uiPlayer < MAX_MAJOR_CIVS; uiPlayer++)1138		{1139			PlayerTypes ePlayer = (PlayerTypes)uiPlayer;1140			if (GET_PLAYER(ePlayer).getTeam() != eTRTeam)1141			{1142				continue;1143			}1144			1145			// walk through each of the trade routes1146			for (uint uiTradeRoute = 0; uiTradeRoute < m_aTradeConnections.size(); uiTradeRoute++)1147			{1148				if (IsTradeRouteIndexEmpty(uiTradeRoute))1149				{1150					continue;1151				}11521153				// if it's not my trade route1154				if (m_aTradeConnections[uiTradeRoute].m_eOriginOwner != ePlayer)1155				{1156					continue;1157				}11581159				// if the destination is not the civ I'm going to war with1160				if (GET_PLAYER(m_aTradeConnections[uiTradeRoute].m_eDestOwner).getTeam() != ePlunderTeam)1161				{1162					continue;1163				}11641165				// get the plot where the trade route is1166				int iLocationIndex = m_aTradeConnections[uiTradeRoute].m_iTradeUnitLocationIndex;1167				int iPlotX = m_aTradeConnections[uiTradeRoute].m_aPlotList[iLocationIndex].m_iX;1168				int iPlotY = m_aTradeConnections[uiTradeRoute].m_aPlotList[iLocationIndex].m_iY;1169				CvPlot* pPlot = GC.getMap().plot(iPlotX, iPlotY);11701171				// see if there is unit from the other team above it1172				IDInfo* pUnitNode = pPlot->headUnitNode();1173				while(pUnitNode != NULL)1174				{1175					CvUnit* pLoopUnit = GetPlayerUnit(*pUnitNode);1176					if(pLoopUnit)1177					{1178						if (GET_PLAYER(pLoopUnit->getOwner()).getTeam() == ePlunderTeam)1179						{1180							if (pLoopUnit->canPlunderTradeRoute(pPlot, true))1181							{1182								// cheating to get around war!1183#if defined(MOD_API_EXTENSIONS)1184								GET_PLAYER(pLoopUnit->getOwner()).GetTrade()->PlunderTradeRoute(m_aTradeConnections[uiTradeRoute].m_iID, pLoopUnit);1185#else1186								GET_PLAYER(pLoopUnit->getOwner()).GetTrade()->PlunderTradeRoute(m_aTradeConnections[uiTradeRoute].m_iID);1187#endif1188								break;1189							}1190						}1191					}11921193					pUnitNode = pPlot->nextUnitNode(pUnitNode);1194				}1195			}1196		}1197	}1198}

Calls

Called by