View Full Version : [XML] Trade Mission


TC01
Jul 15, 2009, 07:48 PM
So I'm looking to add a unit that can conduct a trade mission, like the Great Merchant.

There are two XML values that handle this:

<iBaseTrade>500</iBaseTrade>
<iTradeMultiplier>200</iTradeMultiplier>

What is the difference? Is <iBaseTrade> the minimum? How does <iTradeMultiplier> effect the former value? Is it distance from capital?

I'm not asking for the actual math that I could probably find after digging in the SDK source for an hour- just what it does generally.


Further, is there a way to make it so that conducting a trade mission does not kill the unit that does it without using the SDK? If there isn't, I can get around it, but I'm just wondering.

The_J
Jul 16, 2009, 01:19 PM
Yes, the first value is the base.

The multiplier...i think, you're right, but i'm not sure.

For the killing...you could just create a new unit of the same type after the trade mission is performed.

Yamps
Aug 18, 2009, 08:49 PM
bump...:)

I've been looking into this from a playing perspective. I wanted to compare GS bulbs with great merchant trade missions and one thing led to another...I barely know some C and I haven't studied C++ at all, but here are some things that I've found:

From CvUnit.cpp


int CvUnit::getTradeGold(const CvPlot* pPlot) const
{
CvCity* pCapitalCity;
CvCity* pCity;
int iGold;

pCity = pPlot->getPlotCity();
pCapitalCity = GET_PLAYER(getOwnerINLINE()).getCapitalCity();

if (pCity == NULL)
{
return 0;
}

iGold = (GC.getUnitInfo(getUnitType()).getBaseTrade() + (GC.getUnitInfo(getUnitType()).getTradeMultiplier( ) * ((pCapitalCity != NULL) ? pCity->calculateTradeProfit(pCapitalCity) : 0)));

iGold *= GC.getGameSpeedInfo(GC.getGameINLINE().getGameSpee dType()).getUnitTradePercent();
iGold /= 100;

return max(0, iGold);
}



If I got it right, basically this says

trade_mission_gold = 500 + 200 * trade_profit_between_the_target_city_and_my_capita l

Then it scales for game speed and does some integer division with 100. (actually, that /100 is part of speed scaling most likely)


calculateTradeProfit function is a beyond my abilities. From CvCity.cpp:



int CvCity::calculateTradeProfit(CvCity* pCity)
{
int iProfit;

iProfit = min(((pCity->getPopulation() * GC.getDefineINT("THEIR_POPULATION_TRADE_PERCENT")) / 100), ((plotDistance(getX_INLINE(), getY_INLINE(), pCity->getX_INLINE(), pCity->getY_INLINE()) * GC.getWorldInfo(GC.getMapINLINE().getWorldSize()). getTradeProfitPercent()) / 100));

if (getTeam() != pCity->getTeam())
{
iProfit *= max(0, (GC.getDefineINT("FOREIGN_TRADE_MODIFIER") + 100));
iProfit /= 100;
}

iProfit *= max(0, (totalTradeModifier() + 100));
iProfit /= 100;

iProfit *= GC.getDefineINT("TRADE_PROFIT_PERCENT");
iProfit /= 100;

return max(((getTeam() != pCity->getTeam()) ? 2 : 1), iProfit);
}


This involves city population, distance, world size, trade modifiers and possibly sth else I've missed. Anyway, I think that this function should have something to do with the trade route yield that the other city would get from the capital. In fact, I've got good results with the following final formula:

trade_mission_gold = 500 + 200 * trade_route_gold_that_the_other_guy_would_have_wit h_my_capital

That would be for normal speed, for epic it would get multiplied by 1.5.

(btw, sorry about silly variable naming :crazyeye:)

I've checked with WB and spies for a few values, it seems to be working okay.


Phew...at least the bulbing thing looks simpler:


int CvUnit::getDiscoverResearch(TechTypes eTech) const
{
int iResearch;

iResearch = (GC.getUnitInfo(getUnitType()).getBaseDiscover() + (GC.getUnitInfo(getUnitType()).getDiscoverMultipli er() * GET_TEAM(getTeam()).getTotalPopulation()));

iResearch *= GC.getGameSpeedInfo(GC.getGameINLINE().getGameSpee dType()).getUnitDiscoverPercent();
iResearch /= 100;

iResearch = min(GET_TEAM(getTeam()).getResearchLeft(eTech), iResearch);

return max(0, iResearch);
}


BaseDiscover is 1500 and DiscoverMultiplier is 3 for a GS, 1000 and 2 for other great people. This is simply

bulb_value = 1500 + 3 * total_team_population

for a GS, scaled with game speed.

:crazyeye:If I continue this way, I'll find myself filling up gaps in my education just to play civ better...:p