Hooks
static bool BeforeCvTradeAI_ScoreInternationalTR(CvTradeAI* self, const TradeConnection& kTradeConnection, int& result);static void AfterCvTradeAI_ScoreInternationalTR(CvTradeAI* self, const TradeConnection& kTradeConnection, int& result);static int ReplaceCvTradeAI_ScoreInternationalTR(int (*original)(CvTradeAI*, const TradeConnection&), CvTradeAI* self, const TradeConnection& kTradeConnection);CivRegisterBefore<CivHooks::CvTradeAI_ScoreInternationalTR>(host, &BeforeCvTradeAI_ScoreInternationalTR);CivRegisterAfter<CivHooks::CvTradeAI_ScoreInternationalTR>(host, &AfterCvTradeAI_ScoreInternationalTR);CivRegisterReplace<CivHooks::CvTradeAI_ScoreInternationalTR>(host, &ReplaceCvTradeAI_ScoreInternationalTR);
Code
4414/// Score TR4415int CvTradeAI::ScoreInternationalTR (const TradeConnection& kTradeConnection)4416{4417 // don't evaluate other trade types4418 if (kTradeConnection.m_eConnectionType != TRADE_CONNECTION_INTERNATIONAL)4419 {4420 return 0;4421 }44224423 // if this was recently plundered, 0 the score4424 if (m_pPlayer->GetTrade()->CheckTradeConnectionWasPlundered(kTradeConnection))4425 {4426 return 0;4427 }44284429 CvPlayerTrade* pPlayerTrade = m_pPlayer->GetTrade();4430 CvPlayerTrade* pOtherPlayerTrade = GET_PLAYER(kTradeConnection.m_eDestOwner).GetTrade();4431 int iDangerSum = 1; // can't be zero because we divide by zero!4432 for (uint uiPlotList = 0; uiPlotList < kTradeConnection.m_aPlotList.size(); uiPlotList++)4433 {4434 CvPlot* pPlot = GC.getMap().plot(kTradeConnection.m_aPlotList[uiPlotList].m_iX, kTradeConnection.m_aPlotList[uiPlotList].m_iY);4435 CvAssertMsg(pPlot, "pPlot is null when trying to evaluate the list");4436 if (pPlot == NULL)4437 {4438 break;4439 }4440 int iDangerValue = m_pPlayer->GetPlotDanger(*pPlot);4441 if (iDangerValue == 0)4442 {4443 if (!pPlot->isVisible(m_pPlayer->getTeam()))4444 {4445 iDangerValue += 1;4446 }44474448 if (pPlot->getTeam() != NO_TEAM && GET_TEAM(m_pPlayer->getTeam()).isAtWar(pPlot->getTeam()))4449 {4450 iDangerValue += 1000;4451 }4452 }4453 iDangerSum += iDangerValue;4454 }44554456 // gold4457 int iGoldAmount = pPlayerTrade->GetTradeConnectionValueTimes100(kTradeConnection, YIELD_GOLD, true);4458 int iOtherGoldAmount = pOtherPlayerTrade->GetTradeConnectionValueTimes100(kTradeConnection, YIELD_GOLD, false);4459 int iGoldDelta = iGoldAmount - iOtherGoldAmount;44604461 // getting out of a logjam at the beginning of the game on an archepeligo map4462 // if the player has made a trade unit but all the trade routes yields will be negative to the player4463 // still try to trade with some of the minor civs4464 if (iGoldDelta <= 0 && GET_PLAYER(kTradeConnection.m_eDestOwner).isMinorCiv())4465 {4466 iGoldDelta = 1;4467 }44684469 // tech4470 int iTechDifferenceP1fromP2 = GC.getGame().GetGameTrade()->GetTechDifference(kTradeConnection.m_eOriginOwner, kTradeConnection.m_eDestOwner);4471 int iTechDifferenceP2fromP1 = GC.getGame().GetGameTrade()->GetTechDifference(kTradeConnection.m_eDestOwner, kTradeConnection.m_eOriginOwner);4472 int iTechDelta = iTechDifferenceP1fromP2 - iTechDifferenceP2fromP1;44734474 // religion4475 ReligionTypes eOwnerFoundedReligion = GC.getGame().GetGameReligions()->GetReligionCreatedByPlayer(m_pPlayer->GetID());4476 int iReligionDelta = 0;4477 if (eOwnerFoundedReligion != NO_RELIGION)4478 {4479 CvCity* pToCity = CvGameTrade::GetDestCity(kTradeConnection);4480 CvCity* pFromCity = CvGameTrade::GetOriginCity(kTradeConnection);4481 CvAssert(pToCity != NULL && pFromCity != NULL);4482 if (pToCity != NULL && pFromCity != NULL)4483 {4484 ReligionTypes eToReligion = NO_RELIGION;4485 int iToPressure = 0;4486 ReligionTypes eFromReligion = NO_RELIGION;4487 int iFromPressure = 0;4488 bool bAnyFromCityPressure = pFromCity->GetCityReligions()->WouldExertTradeRoutePressureToward(pToCity, eToReligion, iToPressure);4489 bool bAnyToCityPressure = pToCity->GetCityReligions()->WouldExertTradeRoutePressureToward(pFromCity, eFromReligion, iFromPressure);44904491 // Internally pressure is now 10 times greater than what is shown to user4492 iToPressure /= GC.getRELIGION_MISSIONARY_PRESSURE_MULTIPLIER();4493 iFromPressure /= GC.getRELIGION_MISSIONARY_PRESSURE_MULTIPLIER();44944495 // if anyone is exerting pressure4496 if (bAnyFromCityPressure || bAnyToCityPressure)4497 {4498 // "to" and "from" religions need to be different for us to care4499 if (eToReligion != eFromReligion)4500 {4501 if (eToReligion == eOwnerFoundedReligion)4502 {4503 iReligionDelta += iToPressure;4504 }45054506 if (eFromReligion != eOwnerFoundedReligion)4507 {4508 iReligionDelta -= iFromPressure;4509 }4510 }4511 }4512 }4513 }45144515 int iScore = 0;4516 iScore += iGoldDelta;4517 iScore += iTechDelta * 3; // 3 science = 1 gold4518 iScore += iReligionDelta * 2; // 2 religion = 1 gold4519 iScore = (iScore * 10) / iDangerSum;4520 4521 // if we have any tourism and the destination owner is not a minor civ4522 if (m_pPlayer->GetCulture()->GetTourism() > 0 && !GET_PLAYER(kTradeConnection.m_eDestOwner).isMinorCiv())4523 {4524 // if we're not connected to a player, double the value to that player4525 if (!GC.getGame().GetGameTrade()->IsPlayerConnectedToPlayer(m_pPlayer->GetID(), kTradeConnection.m_eDestOwner))4526 {4527 iScore *= 2;4528 }4529 }45304531 return iScore;4532}