1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Trade Routes

Discussion in 'Civ4 Strategy Articles' started by KrikkitTwo, Feb 13, 2006.

  1. LowtherCastle

    LowtherCastle Deity

    May 18, 2005
    Thanks. I've have since encountered many more. I think what was happening was that sometimes what seemed like a better trade route 1) was worse, because closer or 2) was equal but CIV probably grabs the first one on some list. I looked at 2) and sure enough, in cases where it could have been city X, but was city Y instead, both had the same trade route value anyway.
  2. Alexchamp

    Alexchamp Chieftain

    Jul 19, 2008
    Example? we have 10 cities , if we are connected with 50 cities of 5 different civilizations, and all trade routes give the same amount of gold, how chooses a civilization and towns for trade routes?
    What is priority of choice?

    Thank in advance for help.
  3. DanF5771

    DanF5771 Emperor

    Feb 21, 2008
    Well, there are no real priorities here -- the game simply loops over all cities of all the potential trade partners and compares the respective trade profits.

    The order during the looping is determined by the IDs of the players (= the order in which they appear in your F4 foreign advisor screen) and the respective order of their cities (= the order in which they were founded or acquired = how they would appear in their F1 domestic advisor screens).

    Cities checked at a later point need to yield better trade profits to push back cities that were checked in the beginning. Thus, the human player who normally has the ID=0 (may only be different in scenarios) will usually have a high number of "outgoing" trade routes = a lot of AI cities will have trade routes with the human cities in a balanced game situation, since the human cities are checked first. Therefore the human's Exports-Imports statistics in the F9-Demographics screen will often be negative, but this is rather irrelevant economically.

    But it is not completely irrelevant concerning another game concept: Espionage!
    Espionage missions get a discount on their :espionage:-cost if the target city has an outgoing trade route to a city of the spy's owner. So the human is at a slight disadvantage because missions against him will be a bit cheaper than against other players on average.

    Note that the loop order in which your cities "grab" their partner cities is optimized. As a first step, all your cities are sorted according to their inherent total trade modifier (= function of city size, connected to capital, harbor, but not customs house). Then each city determines the best available partner cities and establishes the trade routes.

    --> In a situation where you move your palace to one of your cities that you founded or "acquired" at a later date, make sure that this city has the best total trade modifier to grab the most lucrative trade routes first in order to maximize the benefit from +50% bureaucracy-bonus on :commerce:. Build a harbor and grow it bigger than any other harbor-city preceding it in your F1-screen.
  4. roidesfoux

    roidesfoux Warlord

    Nov 11, 2003
    I'm having trouble figuring out the distance cap for trade routes. In my current game (small map), I have a city that is 8 tiles east of my capitol and 3 tiles south. The base value of the trade route to the capitol is 1.08. If I'm reading the first post right, the base should be 0.35 (for small map) times either 8 (measuring diagonally) or 11 (orthogonally). This would yield a value of 2.8 or 3.85. What am I missing here?

    (I'm playing RevolutionDCM, if that matters.)
  5. DanF5771

    DanF5771 Emperor

    Feb 21, 2008
    I know nothing about that mod, but I don't think it matters here. Krikkitone seems to have made a slight mistake in the first post, as he used an effective division by 2 for the distance-term instead of the correct division by 5.

    Stuff from the code:
    The base profit for a trade route is presented with 2 decimals in the city screen, but stored as an integer, so I call it BaseProfitTimes100 here. It can never be less than 100.

    BaseProfitTimes100 = ( min( PopOfOtherCity * 50 , DistanceToOtherCity * WorldSizeFactor ) * 20 ) / 100

    with the 50 being the parameter THEIR_POPULATION_TRADE_PERCENT from GlobalDefines.xml
    and the 20 being the parameter TRADE_PROFIT_PERCENT also from GlobalDefines.xml.

    The WorldSizeFactors are the parameters iTradeProfitPercent defined in CIV4WorldInfo.xml:
    huge		30
    large		40
    standard	50
    small		60
    tiny		70
    duel		80
    DistanceToOtherCity is measured as a plotDistance (opposed to that, there is also stepDistance which is relevant for the movement of units):
    [COLOR="SeaGreen"]// 4 | 4 | 3 | 3 | 3 | 4 | 4
    // -------------------------
    // 4 | 3 | 2 | 2 | 2 | 3 | 4
    // -------------------------
    // 3 | 2 | 1 | 1 | 1 | 2 | 3
    // -------------------------
    // 3 | 2 | 1 | 0 | 1 | 2 | 3
    // -------------------------
    // 3 | 2 | 1 | 1 | 1 | 2 | 3
    // -------------------------
    // 4 | 3 | 2 | 2 | 2 | 3 | 4
    // -------------------------
    // 4 | 4 | 3 | 3 | 3 | 4 | 4
    // Returns the distance between plots according to the pattern above...[/COLOR]
    inline int plotDistance(int iX1, int iY1, int iX2, int iY2)										
    	iDX = xDistance(iX1, iX2);
    	iDY = yDistance(iY1, iY2);
    	return (std::max(iDX, iDY) + (std::min(iDX, iDY) / 2));
    This is the sum of the "longer delta" plus half of the "shorter delta" rounded down, so in your example with 8E | 3S, plotDistance becomes 8 + floor(3/2) = 9.

    Therefore your BaseProfitTimes100 calculates to: ( 9 * 60 * 20 ) / 100 = 108.
  6. Jack.

    Jack. Chieftain

    Mar 30, 2010
    Hello I play with the Portuguese with Civ BTS and I must say the Economy is a little bit fuzzy ( Mercantilism and Free Market ) plus the open market with the UN. It is easy to get money if u know how to play Civ ( Noble dificulty )but those three things are a little bit hard to get. I mean with Mercantilism u dont have foreign trades but u get a free specialist and I get it, that means u can get more money but wat about Free Market ? wat does it mean with +1 Trade route per city ?

  7. Evalis

    Evalis Prince

    Mar 2, 2009
    First off my apologies for resurrecting this thread.. but it contained the information (in the initial post) that is relevant to this. That is: Where did you find the calculations for trade routes in beyond the sword. The global defines seems to hold the same information as the one in vanilla. I would really like to edit these values.. is such a thing possible?

    Err specifically that values for the other city population and city distance base ammount, including the minimum value.
  8. PieceOfMind

    PieceOfMind Drill IV Defender Retired Moderator

    Jan 15, 2006
    Are there any clues in CvPlayer::updateTradeRoutes() ?
  9. csarmi

    csarmi Chieftain

    Jan 3, 2006
    Okay, so I don't understand the original formula.

    I have an empire of 10 cities on a std map. 2 on an island close to my continent, 8 on the continent. I'm in isolation (till astronomy at least).

    I have harbors, all cities connected to capital and all my cities receive overseas trade (because of two of my cities being on an island).

    Now that means all my cities produce 2*2.75 gold from trade routes, but those 2.75's are rounded down first.

    Currently, my trade route income is 40 (10*2*2). How do I increase it?

    How do I get that 2.75 up to 3.00 at least?

    I hope that getting my cities to size 15 is not the only way.
  10. AdelineJ

    AdelineJ Warlord

    Apr 28, 2012
    I find it hard to understand everything. Are my sentences right?
    1. max 8 trade routes per city
    2. max 34:commerce:(see http://www.civfr.com/index.php?pid=218)
    3. the trade route begin with : open borders and (route between 2 cities, or navigation with contact in two land, or astronmy), and all tiles are discoveries
  11. BuDDaH

    BuDDaH Chieftain

    Aug 23, 2004
    Moscow, Russia
    This is an MP game.

    Their Athens is 10 pop, has Temple of Artemis
    My London is 23 pop

    We have open borders, lasting peace, trade routes, overseas.

    Athens must have the trade route with London of 10 com.

    2.3 as base value (1/10 of London's population)

    +100% for ToA
    +100% for overseas trade
    +25% for connection to capital
    +150% for lasting peace


    But the English Great Merchant in Athens shows the yield of 2100 gold. As if the yield of the London trade route in Athens were 8 instead of 10. Why???

    I hope I'm correct with the formula of the GM's trade mission yield (trade route value with our city*200 =500)
  12. DanF5771

    DanF5771 Emperor

    Feb 21, 2008
    Your big capital London is probably located too close to Athens so that plotDistance is the limiting factor for the base profit here (see also this post above).

    In case your game uses a standard map size, plotDistance(Athens-London) is likely < 19 -> base profit is capped at 1.8.

    floor(1.8 * 4.75) = 8 ; trade mission money = 8*200 + 500 = 2100 :gold:
  13. Spirictum

    Spirictum Immortal

    Oct 19, 2007
    A lot of good info here on this thread, it was really helpful.

    But I have 2 questions I hope someone knows the answer.

    The first one I think it's easier: Does the AI check its profit on trade routes with you when deciding if it should declare war on you? I know there is the option Aggressive AI on BtS, and the mod I play (Legends of Revolution) has the Ruthless AI option as well (I guess maybe these options change the mechanics of the AI on this aspect), but for the standard AI is this true? If someone knows where I may find this info, please give me the path to discover it myself (of course a direct answer would be far better :cool:).

    The second question is related to some questions brought on this topic: Where is the code for deciding which Trade Routes are going to be used?

    I have done an extensive searching on this topic over the internet and I've found the common statement: Trade route calculations is what slows a lot the late game on big maps with lots of players.

    I've tried to search edead's post about his brilliant recoding of TR calculation, in which his sengoku mod is based. A huge map with up to 70 players (56 playable) with minimal wait between turns. As I remember, he changed the mechanics so TRs would not be chosen from the best options every turn, but now I don't remember if he increased the period of recalculation (e.g. every 5 turns) or made the choice random (so the time spent on calculation would drop considerally).

    I'm interested on bigger then huge maps, and knowing that TR calculation is one of the major factors slowing the game, I would like to know where the code is to change it (as of now I would test a random approach, but later, with more knowledge, a mixed approach of calculation and randomness could be achieved)
  14. plako

    plako Emperor

    Aug 8, 2008
    Here is a post from SevenSpirits here that describes also the algorithm how trade routes are chosen:

    Since main point of the post is to highlight a bug present in MP games here is the most relevant part for players playing only against AI:

    No wonder this takes a long time when lots of cities have been planted.

    Since in SP you're always player #0 your cities are looped through 1st and then the others based on the player order assigned in the beginning of the game. In case of equal value of routes it takes the 1st found (this is where the bug affects in case you're not 1st in turn order).

    You'll probably found the code using this post also present in the same thread:
  15. LincolnOfRome

    LincolnOfRome Glutton for Punishment

    Feb 14, 2010
    Richmond, VA
    Wouldn't Cothon make this eight?

    Edit - I found a post on page three that already caught this. This thread is still worth a bump.

Share This Page