Hooks
static bool BeforeCvTradeAI_GetAvailableTR(CvTradeAI* self, TradeConnectionList& aTradeConnectionList);static void AfterCvTradeAI_GetAvailableTR(CvTradeAI* self, TradeConnectionList& aTradeConnectionList);static void ReplaceCvTradeAI_GetAvailableTR(void (*original)(CvTradeAI*, TradeConnectionList&), CvTradeAI* self, TradeConnectionList& aTradeConnectionList);CivRegisterBefore<CivHooks::CvTradeAI_GetAvailableTR>(host, &BeforeCvTradeAI_GetAvailableTR);CivRegisterAfter<CivHooks::CvTradeAI_GetAvailableTR>(host, &AfterCvTradeAI_GetAvailableTR);CivRegisterReplace<CivHooks::CvTradeAI_GetAvailableTR>(host, &ReplaceCvTradeAI_GetAvailableTR);
Code
4310/// Get all available TR4311void CvTradeAI::GetAvailableTR(TradeConnectionList& aTradeConnectionList)4312{4313 aTradeConnectionList.clear();43144315 // build trade route list4316 CvPlayerTrade* pPlayerTrade = m_pPlayer->GetTrade();4317 CvGameTrade* pGameTrade = GC.getGame().GetGameTrade();4318 int iOriginCityLoop;4319 CvCity* pOriginCity = NULL;4320 for (pOriginCity = m_pPlayer->firstCity(&iOriginCityLoop); pOriginCity != NULL; pOriginCity = m_pPlayer->nextCity(&iOriginCityLoop))4321 {4322 PlayerTypes eOtherPlayer = NO_PLAYER;4323 for (uint ui = 0; ui < MAX_CIV_PLAYERS; ui++)4324 {4325 eOtherPlayer = (PlayerTypes)ui;43264327 if (!GET_PLAYER(eOtherPlayer).isAlive())4328 {4329 continue;4330 }43314332 if (GET_PLAYER(eOtherPlayer).isBarbarian())4333 {4334 continue;4335 }43364337 int iDestCityLoop;4338 CvCity* pDestCity = NULL;4339 for (pDestCity = GET_PLAYER(eOtherPlayer).firstCity(&iDestCityLoop); pDestCity != NULL; pDestCity = GET_PLAYER(eOtherPlayer).nextCity(&iDestCityLoop))4340 {4341 // if this is the same city4342 if (pOriginCity == pDestCity)4343 {4344 continue;4345 }43464347 DomainTypes eDomain = NO_DOMAIN;4348 for (eDomain = (DomainTypes)0; eDomain < NUM_DOMAIN_TYPES; eDomain = (DomainTypes)(eDomain + 1))4349 {4350 // if this isn't a valid trade domain, ignore4351 if (eDomain != DOMAIN_LAND && eDomain != DOMAIN_SEA)4352 {4353 continue;4354 }43554356 bool bCheckPath = true;4357 TradeConnectionType eConnection = NUM_TRADE_CONNECTION_TYPES;4358 for (uint uiConnectionTypes = 0; uiConnectionTypes < NUM_TRADE_CONNECTION_TYPES; uiConnectionTypes++)4359 {4360 eConnection = (TradeConnectionType)uiConnectionTypes;43614362 // Check the trade route, ignoring the path for now4363 bool bTradeAvailable = pPlayerTrade->CanCreateTradeRoute(pOriginCity, pDestCity, eDomain, eConnection, true, false);4364 if (!bTradeAvailable)4365 {4366 continue;4367 }43684369 // Now test the path4370 if (bCheckPath)4371 {4372 bTradeAvailable = pGameTrade->IsValidTradeRoutePath(pOriginCity, pDestCity, eDomain);4373 if (!bTradeAvailable)4374 break; // If there is no path for this domain, just skip the rest of the connection tests.43754376 bCheckPath = false; // No need to check the path for this domain again4377 }43784379 TradeConnection kConnection;4380 kConnection.m_iOriginX = pOriginCity->getX();4381 kConnection.m_iOriginY = pOriginCity->getY();4382 kConnection.m_iDestX = pDestCity->getX();4383 kConnection.m_iDestY = pDestCity->getY();4384 kConnection.m_eConnectionType = eConnection;4385 kConnection.m_eDomain = eDomain;4386 kConnection.m_eOriginOwner = pOriginCity->getOwner();4387 kConnection.m_eDestOwner = pDestCity->getOwner();43884389 CvAStarNode* pNode = NULL;4390 if (eDomain == DOMAIN_LAND)4391 {4392 pNode = GC.GetInternationalTradeRouteLandFinder().GetLastNode();4393 }4394 else if (eDomain == DOMAIN_SEA)4395 {4396 pNode = GC.GetInternationalTradeRouteWaterFinder().GetLastNode();4397 }43984399 CvAssertMsg(pNode != NULL, "no path found for unit");4400 if (pNode == NULL)4401 {4402 continue;4403 }44044405 GC.getGame().GetGameTrade()->CopyPathIntoTradeConnection(pNode, &kConnection);4406 aTradeConnectionList.push_back(kConnection);4407 }4408 }4409 }4410 }4411 }4412}