Thoughts on trade

Mize

Prince
Joined
Jun 17, 2011
Messages
448
Maybe many of you have noticed these, but I don't recall seeing them discussed, so here we go:

- Per turn trade income in cities apparently derives not from the total trade of the two trading cities but from the trade minus the corruption. Sometimes when I push caravans around my empire, I will consistently get lower incomes from cities that I expect to give me more arrows. F. ex. a city with 70 trade will bring 5 arrows per turn in the caravan’s home city while a city with 65 will bring 6. Of course, the 70 trade city had more corruption, and thus less viable arrows for trading. At least I think so. (Edit: this also means that the F1 screen shows base trade sans corruption.)

- Trade routes between player cities can supersede foreign trade routes even if they give you less arrows per turn. When trading with the AI, if a player city already has three trade routes and sends a caravan to a fourth AI city, the lowest paying route will be replaced if that fourth AI city has higher trade. However, if the player sends a caravan to one of their own cities, it will sometimes replace one of the foreign trade routes, even if it was actually more profitable. So don’t caravan push at your own cities if the home city of the caravan has good foreign trade, you might actually lower your overall income by accident. My theory is that the game decides which trade route deserves the spot before it slices the income in half for trading between your own cities. Which leads me to my next point…

- One of the most unrealistic things about civ is that trade with the AI keeps flowing at peacetime rates even when you’re at war. Shouldn’t trade route incomes be at least halved or, possibly, brought down to 1/3 of their worth during war? That would make you think twice before declaring war or refusing tribute. Of course, players already think about this because when you conquer an AI city your existing trade with it is halved. It would also be cool if the AI used this kind of logic to decide whether to wage war on someone, but of course there’s the problem that the AI doesn’t trade with the player… Otherwise it would be quite nice to be able to play the Swiss game -- get so much foreign trade and investment that nobody wants to bomb you.

Let’s say this is a thinly-veiled wish-list for one of those clones or hacks of civ that never seem to get finished.
 
About corruption: it's a strange thing, because game calculate actual, normal corruption at the end, after when per-turn benefits from trade routes were calculated. But before this, game calculates "base trade" value for a city (which is stored in memory for every city), and then this value is used to calculate per turn profit from trade routes. And when game calculate "base trade", it applies corruption to it - but corruption logic here is slightly different. Game do not call same logic twice (as function or something), but instead "corruption" logic is kinda copy-pasted, but with some differencies. I can see in decompiled code, but it's also somewhere in Darkpanda's JCivED source code, in (unfinished) city logic.

Well, from Darkpanda's code (cityprocess.java, line 1087 and below):

First round of corruption, for "base trade":
0) set corruption to 0
1) if govt is communism, set distance to capital to 10
2) set corruption to (total_trade * distance_to_capital * 3) / (20 * government_id + 80);
3) if city has Palace or Courthouse, corruption = corruption/2;
4) if govt is democracy, corruption = 0
5) set "base trade" to total_trade - corruption
after that, we calculate profits from trade routes (using "base trade" values of our city and our partner city) and add them to total trade
and calculate "normal corruption":
1) set corruption to (total_trade * distance_to_capital * 3) / (20 * government_id + 80);
2) if govt is democracy, corruption = 0
3) if city has a Courthouse, corruption = corruption/2;
4) calculate luxuries, coins and bulbs, using this corruption value
5) add luxuries, coins and bulbs from specialists

Well, it not so different as I remember. Actually, only under communism corruption calculates differently for the capital. In all other cases, it works the same in both cases.

Should also look at conditions for trade route to rewrite an old one.

EDIT. So. Logic to replace old trade routes:

1) set "new_value": new_value = base_trade of "new" city
2) if this city is not belongs to our civ, increase "new_value" by 2 times.

new_route = -1; //0,1 or 2, if some city was selected
i = 0; //loop from 0 to 2 (3 trade routes total)
do endless loop:
1) if i > 2, then, if new_route is not -1, replace city of new_route. Return from the function.
2) if trade route number i of caravan home city is the same as the new city, then break the loop (= we already have this trade route)
3) if city of trade route number i is -1, then set "old_value" to -1
else set "old_value" to base_trade of city from trade route number i and, if this city does not belong to our civ, increase "old_value" by 2 times.
If new_value > old_value, then new_value = old_value; new_route = i; (we did find better trade route instead of worst one)
4) i++;

Btw, even though you cannot get NONE caravans normally (because you cannot buy one from AI), but if you somehow still get a NONE caravan, trade route logic will work pretty buggy, because there's no check anywhere that caravan is not from city -1.

Also, type of goods is determined by caravan unit id, 0,8,16 etc. - silk, 1,9,17 etc. - silver, then: wine, copper, gems, dye, salt, spice. 8 total. They have no any gameplay meaning in Civ 1, of course.

EDIT2: I think a reason why you can get less instant bonus coins+bulbs from your new trade route with your own city it's because you get a penalty from RAILROADS and FLIGHT tech. Because your civ knows them but enemy civ doesn't. "Not diffirent continent" penalty works both for your and enemy cities, so it makes no difference and "not enemy city" penalty is actually taken into account with x2 bonus for "value" of other civ cities.

But should look into per-turn bonus still... EDIT3: well, formula (your_city_base_trade+other_city_base_trade+4)/8 is used, this value is divided by 2, if it's your own city... Problem is, that here trade from BOTH your and other city is divided by 2! So of course, it can be lower, even if base_trade of new trade partner (your civ) > base_trade of old trade partner/2 (other civ). The more trade caravan home city produces, the greater the loss will be. If it's close to 0 and main part of equation is from partner city, then such change can be profitable. Or if base_trade of new partner city (from your civ) is so much greater than base_trade of old partner city (from other civ), that even with your_city_base_trade/2 it's still will be more profitable. But problem is, game replace it even if it's only twice as big.
 
Last edited:
Thanks for the thorough reply, tupi. The bit about corruption being calculated twice is a very interesting and quite logical way things should be done.

Your third edit basically nails down the issue I described. But the problem is not only that the game can replace a more profitable trade route with a less profitable one. There's also the fact that it might not replace the route you want it to replace at all. It might delete your most profitable route instead. Let's say your city has one foreign trade route and two domestic ones. The domestic ones bring in 5 arrows per turn, the foreign one brings in 8. If you then move a caravan into one of your own cities, which would give you 6 arrows per turn, the game will not replace one of your 5-APT home routes but the 8-APT foreign one because it deems it less profitable.
 
Game always replaces the worst trade route, defined by lowest value of "base_trade" (x2 if this route with other civ). Maybe it's a good idea to use (caravan city base_trade+destination city base_trade+4)/8 (with /2, if destionation city belongs to our civ) instead of base_trade of destination city (with *2, if not our civ city). But it's hard to implement. One idea is: create function somewhere for this formula and call this function. Then maybe we will have enough bytes to squeeze it into...
 
Last edited:
The solution to the problem of not being able to replace the trade route you want to replace is actually much simpler. I feel really stupid for not immediately coming up with it. If you want to replace the trade route with city A (your city) in favor of city B (AI city), just drop city A's trade output by moving citizens about before you push the caravan into city B. Only don't forget to put the people of city A back to work before you end your turn.
 
Back
Top Bottom