Bazaar developer reference

CvTradeAI::ScoreFoodTR(const TradeConnection &, CvCity *)

Defined in
CvTradeClasses.cpp, line 4535
Class
CvTradeAI
Hook name
CivHooks::CvTradeAI_ScoreFoodTR

Hooks

static bool BeforeCvTradeAI_ScoreFoodTR(CvTradeAI* self, const TradeConnection& kTradeConnection, CvCity* pSmallestCity, int& result);static void AfterCvTradeAI_ScoreFoodTR(CvTradeAI* self, const TradeConnection& kTradeConnection, CvCity* pSmallestCity, int& result);static int ReplaceCvTradeAI_ScoreFoodTR(int (*original)(CvTradeAI*, const TradeConnection&, CvCity*), CvTradeAI* self, const TradeConnection& kTradeConnection, CvCity* pSmallestCity);CivRegisterBefore<CivHooks::CvTradeAI_ScoreFoodTR>(host, &BeforeCvTradeAI_ScoreFoodTR);CivRegisterAfter<CivHooks::CvTradeAI_ScoreFoodTR>(host, &AfterCvTradeAI_ScoreFoodTR);CivRegisterReplace<CivHooks::CvTradeAI_ScoreFoodTR>(host, &ReplaceCvTradeAI_ScoreFoodTR);

Code

4534/// Score Food TR4535int CvTradeAI::ScoreFoodTR (const TradeConnection& kTradeConnection, CvCity* pSmallestCity)4536{4537	if (kTradeConnection.m_eConnectionType != TRADE_CONNECTION_FOOD)4538	{4539		return 0;4540	}45414542	// if this was recently plundered, 0 the score4543	if (m_pPlayer->GetTrade()->CheckTradeConnectionWasPlundered(kTradeConnection))4544	{4545		return 0;4546	}45474548	// if we're not going to the smallest city, ignore4549	if (kTradeConnection.m_iDestX != pSmallestCity->getX() && kTradeConnection.m_iDestY != pSmallestCity->getY())4550	{4551		return 0;4552	}45534554	int iMaxDistance = 60;4555	int iDistance = kTradeConnection.m_aPlotList.size();4556	int iDistanceScore = iMaxDistance - iDistance;4557	if (kTradeConnection.m_eDomain == DOMAIN_SEA)4558	{4559		iDistanceScore = iDistanceScore * 2;4560	}45614562	//CvPlayerTrade* pPlayerTrade = m_pPlayer->GetTrade();4563	int iDangerSum = 1; // can't be zero because we divide by zero!4564	for (uint uiPlotList = 0; uiPlotList < kTradeConnection.m_aPlotList.size(); uiPlotList++)4565	{4566		CvPlot* pPlot = GC.getMap().plot(kTradeConnection.m_aPlotList[uiPlotList].m_iX, kTradeConnection.m_aPlotList[uiPlotList].m_iY);4567		CvAssertMsg(pPlot, "pPlot is null when trying to evaluate the list");4568		if (pPlot == NULL)4569		{4570			break;4571		}4572		int iDangerValue = m_pPlayer->GetPlotDanger(*pPlot);4573		if (iDangerValue == 0)4574		{4575			if (!pPlot->isVisible(m_pPlayer->getTeam()))4576			{4577				iDangerValue += 1;4578			}45794580			if (pPlot->getTeam() != NO_TEAM && GET_TEAM(m_pPlayer->getTeam()).isAtWar(pPlot->getTeam()))4581			{4582				iDangerValue += 1000;4583			}4584		}4585		iDangerSum += iDangerValue;4586	}45874588	return iDistanceScore - iDangerSum;4589}

Calls

Called by