CvTradeAI::ScoreProductionTR(const TradeConnection &, std::vector<CvCity *>)
- Defined in
- CvTradeClasses.cpp, line 4592
- Class
- CvTradeAI
- Hook name
CivHooks::CvTradeAI_ScoreProductionTR
Hooks
static bool BeforeCvTradeAI_ScoreProductionTR(CvTradeAI* self, const TradeConnection& kTradeConnection, std::vector<CvCity*> aTargetCityList, int& result);static void AfterCvTradeAI_ScoreProductionTR(CvTradeAI* self, const TradeConnection& kTradeConnection, std::vector<CvCity*> aTargetCityList, int& result);static int ReplaceCvTradeAI_ScoreProductionTR(int (*original)(CvTradeAI*, const TradeConnection&, std::vector<CvCity*>), CvTradeAI* self, const TradeConnection& kTradeConnection, std::vector<CvCity*> aTargetCityList);CivRegisterBefore<CivHooks::CvTradeAI_ScoreProductionTR>(host, &BeforeCvTradeAI_ScoreProductionTR);CivRegisterAfter<CivHooks::CvTradeAI_ScoreProductionTR>(host, &AfterCvTradeAI_ScoreProductionTR);CivRegisterReplace<CivHooks::CvTradeAI_ScoreProductionTR>(host, &ReplaceCvTradeAI_ScoreProductionTR);
Code
4591/// Score Production TR4592int CvTradeAI::ScoreProductionTR (const TradeConnection& kTradeConnection, std::vector<CvCity*> aTargetCityList)4593{4594 // only consider production trades4595 if (kTradeConnection.m_eConnectionType != TRADE_CONNECTION_PRODUCTION)4596 {4597 return 0;4598 }45994600 // if this was recently plundered, 0 the score4601 if (m_pPlayer->GetTrade()->CheckTradeConnectionWasPlundered(kTradeConnection))4602 {4603 return 0;4604 }46054606 // if we're not going to a target production city, ignore4607 bool bValidTarget = false;4608 for (uint ui = 0; ui < aTargetCityList.size(); ui++)4609 {4610 if (kTradeConnection.m_iDestX == aTargetCityList[ui]->getX() && kTradeConnection.m_iDestY == aTargetCityList[ui]->getY())4611 {4612 bValidTarget = true;4613 break;4614 }4615 }46164617 if (!bValidTarget)4618 {4619 return 0;4620 }46214622 int iMaxDistance = 60;4623 int iDistance = kTradeConnection.m_aPlotList.size();4624 int iDistanceScore = iMaxDistance - iDistance;4625 if (kTradeConnection.m_eDomain == DOMAIN_SEA)4626 {4627 iDistanceScore = iDistanceScore * 2;4628 }46294630 //CvPlayerTrade* pPlayerTrade = m_pPlayer->GetTrade();4631 int iDangerSum = 1; // can't be zero because we divide by zero!4632 for (uint uiPlotList = 0; uiPlotList < kTradeConnection.m_aPlotList.size(); uiPlotList++)4633 {4634 CvPlot* pPlot = GC.getMap().plot(kTradeConnection.m_aPlotList[uiPlotList].m_iX, kTradeConnection.m_aPlotList[uiPlotList].m_iY);4635 CvAssertMsg(pPlot, "pPlot is null when trying to evaluate the list");4636 if (pPlot == NULL)4637 {4638 break;4639 }4640 int iDangerValue = m_pPlayer->GetPlotDanger(*pPlot);4641 if (iDangerValue == 0)4642 {4643 if (!pPlot->isVisible(m_pPlayer->getTeam()))4644 {4645 iDangerValue += 1;4646 }46474648 if (pPlot->getTeam() != NO_TEAM && GET_TEAM(m_pPlayer->getTeam()).isAtWar(pPlot->getTeam()))4649 {4650 iDangerValue += 1000;4651 }4652 }4653 iDangerSum += iDangerValue;4654 }46554656 return iDistanceScore - iDangerSum;4657}
Calls
BaseVector::operator[]BaseVector::size- CvCity::getX() const
- CvCity::getY() const
- CvGlobals::getMap()
- CvMap::plot(int, int) const
- CvPlayer::GetPlotDanger(CvPlot &) const
- CvPlayer::getTeam() const
- CvPlayer::GetTrade() const
- CvPlayerTrade::CheckTradeConnectionWasPlundered(const TradeConnection &)
- CvPlot::getTeam() const
- CvPlot::isVisible(TeamTypes) const
- CvTeam::getTeam(TeamTypes)
- CvTeam::isAtWar(TeamTypes) const
std::vector::operator[]std::vector::size