[MOD - SevoMod 3.0 Addon] Trade Route/Tech Leak

AltarisGreyhawk

Chieftain
Joined
Jul 6, 2006
Messages
21
I am pleased to announce a new add-on for SevoMod 3.0 that causes tech leak to occur over trade routes! You can find the file, with included readme, at the link below:

View attachment SevoMod30_TechLeak_Addon.zip

Please note that this mod is only compatible with SevoMod 3.0, so it will not work with any other mods.

The purpose of this mod is to bridge the often glaring gap in tech advancement between the human player and the AI. A small percentage of tech points are "leaked" over trade routes, giving a boost to research to civs which have fallen behind in tech advancement. The included readme has details on how these calculations are done.

The basic premise is that for every trade route with Player B that Player A has, Player B gains 0.3% of points needed for ALL techs Player A has that Player B does not, and that Player B can research. So if Player A has 4 routes with Player B, Player B is gaining 1.2% of the points needed for EACH tech Player A has and Player B is capable of researching. It's more of a boost than anything else, shortening the time it takes Player B to catch up to Player A. Also, since trade routes increase as techs advance, the boost grows greater as time progresses. I felt this made sense, as I could not imagine it taking some barbaric civ the same time to advance through early techs while trading with some advanced civ.

The 0.3% factor is based off of a 1200-turn Marathon speed. The number scales appropriately depending on the actual number of turns in the game.

I've playtested through this mod once already, and found it very enjoyable, as well as being more realistic. It is still possible to enjoy a tech lead, but the larger the gap becomes, the more of a boost other civs receive until they catch up. In my test game, I found that the top 5 civs, all heavy traders, stayed within 4-5 techs of one another all the way into the Modern Era. Other, smaller, civs fell behind, but they also tended to get picked off as time went by.

One thing to note is that the player can take advantage of this as well. That helps in games where the player falls WAY behind before meeting other civs. Before, I never could recover from that without a massive struggle, but with this mod, the boost from trade route tech leak helps bridge the gap to a more reasonable level.

Hope you all enjoy!
 

Attachments

  • README - SevoMod 3_0 Trade Route Tech Leak.txt
    5.7 KB · Views: 247
Actually, that would be pretty simple to do, if you are comfortable with python modding and the EventManager file. In the zip file, if you drill down through all the directories to the "python" directory, you will find a file called "BTM_Addon.py". The .py file only contains one class (BTM_TechSpread) with one method (OnBeginPlayerTurn). This file just needs to be included in your mod EventManager python file, and the class declared with the method called during the OnBeginPlayerTurn event. You can look at the "CvSevoEventManager.py" file in the zip as well to see how I'm calling it for SevoMod.

Should be pretty simple to do, but I didn't want to get into maintaining multiple versions as this time, and this is the first of several components I'm looking at releasing to be SevoMod compatible.

Hope that helps!
 
Feel free to do with the code as you like. It's really not a very complex script at all, and can easily be modified if you want to try other changes along trade routes. I commented the code pretty well, so it should be easy to pick apart what's going on in the script. If you have any questions, though, feel free to ask.
 
AltarisGreyhawk said:
Actually, that would be pretty simple to do, if you are comfortable with python modding and the EventManager file. In the zip file, if you drill down through all the directories to the "python" directory, you will find a file called "BTM_Addon.py". The .py file only contains one class (BTM_TechSpread) with one method (OnBeginPlayerTurn). This file just needs to be included in your mod EventManager python file, and the class declared with the method called during the OnBeginPlayerTurn event. You can look at the "CvSevoEventManager.py" file in the zip as well to see how I'm calling it for SevoMod.

Should be pretty simple to do, but I didn't want to get into maintaining multiple versions as this time, and this is the first of several components I'm looking at releasing to be SevoMod compatible.

Hope that helps!
Oh ok, thanks. I hadn't looked at the files yet to see how difficult it would be. Saying that it required the SevoMod just scared me at first :mischief:
 
That's great!

Probably, I immediately include it in my Megapolises Add-on.

Thanks
 
The basic premise is that for every trade route with Player B that Player A has, Player B gains 0.3% of points needed for ALL techs Player A has that Player B does not, and that Player B can research.

Per turn or once for each tech?
 
The leak occurs every turn, so a civ that has fallen behind can rack up a fair number of points through trade to help bridge the gap.

From testing, this doesn't unbalance the gameplay, but it does keep the tech gap from getting ridiculously large, and makes it more imperative to strike quick when military advances occur.
 
AltarisGreyhawk,

I tested your Tech Leak Mod and thought it was very interesting. Here is just two points I fixed.

1) I noticed that I always get points divisible by the number of cities (if I have 5 cities, I get 5, 10, 15... points). This is because integering occurs in the loop. In the attachement you can see fixed version. I put int function after the loop (line 78) and added 0.5 to make it round instead of truncation.

2) In my opinion, 0.003 is TOO much. Just imagine, while I was researching Mathematics (30 turns) and Currency (35 turns), I get for free Sailing, Iron Working, Meditation and a couple of other techs. Every turn you get ~40-50 points in total that is roughly equivalent to 30-40 gold you get per turn. I think the tech leak should not be so drastic. I recomend 0.001.
 

Attachments

  • BTMAddon.py.txt
    4.5 KB · Views: 151
Interesting idea, Altaris. I fell waaay behind in my last Large map game and the only reason I have any chance at all was a beeline for the Internet that my entire civilization was bent to. I still think I'm going to lose because I can't stop Gilgamesh from getting a spaceship victory unless my spies get a lot luckier!

Anyway, the issue is that tech leads provide more money and more buildings that in turn increase the lead, so once you're behind catching up is near impossible, and this is a novel way to address the issue.

Interestingly, a result of all this is that one way to decrease foreign tech rates would be to enforce an embargo against them and not trade, something that I think is under-rated in the game.

Nice work!
 
Agreed. I've played through roughly 2/3 of 3 games now, and this really does help balance out the game and keep it interesting. One of the above posters felt like the points were too much, but I've found them to be just right for keeping nearby civs within a reasonable range of techs, while still allowing for quickly advancing civs to enjoy an advantage for a period of time.

The trade embargo's do factor into it as well, and I found myself having to employ them in a recent game against my archrival Egypt, who was my superior in every aspect except techs.

In that same game, India was my closest ally and neighbor, and we shared a great deal of tech with one another. Unfortunately, India was friends with everyone else on the map, while I had made my rise to greatness by crushing others under my bootheel. It felt almost like India was secretly working against me, as my techs were filtering through India, then to the rest of the world. On top of that, India kept letting aggressive Civs through their borders to my lands! It was great fun, though, and I found it to be rather challenging in spots, while still feeling authentic and balanced. And, I still got to land on the small "New World" continents after getting Astronomy, and take out spearmen and archers with my newfound Redcoats.

For me, though, the real advantage of this mod is to keep civs from running rampantly ahead of others. I just never found it fun to leap way ahead around 500 AD, and stay there the rest of the game, slaughtering poor pikemen or musketmen with tanks and marines. The opposite is also true, where if the player falls too far behind, it's practically impossible to catch up. I've found this mod really helps to alleviate this issue at both ends, and so far, I've been pretty happy with the way it's turned out.
 
If it's okay with you, I'm going to include this in my next release (with credit due, of course!)

I think the balancing factor and the increased importance of having and/or limiting foreign trade routes is a great addition to the game. :goodjob:
 
This is a pretty cool idea, and makes some realistic sense. And unlike a lot of suggestions, it looks like it might actually HELP game balance, rather than adding all kinds of snowball effects.
 
Sevo, please feel free to use/modify this mod as you like. I'd be happy to see it included with your impressive compilation of mods.
 
I've been working on another mod too to make religions more balanced and fun, though that's been a much bigger challenge that the tech leak. Here's a link for anyone interested in giving suggestions/ideas:

Improving Religions

It's a nice, balanced system for distributing religions more evenly throughout the game without changing the game mechanics much. That one's getting very close to completion, and I will probably have a release ready in the next week or so.
 
I included Tech Leak in Megapolises Mod (although with decreased effect).

Thanks for this nice idea!
 
I made some minor tweaks to the code for inclusion in Sevomod and I wanted to share.

I change the colors and icons for the leak notifications (the icon now shows the button for the tech being leaked). Just little things but they're nice in game.

I also added a sub-layer of balancing; the problem seemed to be that the more tech routes you have the more tech you gain; therefore bigger civs can gain a missing tech pretty fast, whereas a civ beaten down to just two cities has only a few trade routes and gets less bang. The whole concept of this balancer is to keep the tech race in alignment, so I added another quick layer between the initial calculation and the granting that compares the Leaking and the Gaining civs' relative total Tech score discrepancy, and then adjusts the points gained appropriately (based on the squares of the points). It seems to work nicely in game with the numbers scaled down a bit.

Thanks again for a great idea!

Spoiler :

class BTM_TechSpread:
def onBeginPlayerTurn(self, argsList):
iGameTurn, iPlayer = argsList

# iTechPercentModifier indicates what percent of tech knowledge may be passed to trading partners
iTechPercentModifier = 0.001

# Modify iTechPercentModifier to match game speed (originally tested for marathon, thus the reason for 1200 factor
iTechPercentModifier = iTechPercentModifier * 1200 / CyGame().getMaxTurns()

# bFlagTechLeakShowReceiverMessages - if TRUE, show receiving player message that tech points were received
bFlagTechLeakShowReceiverMessages = true

# bFlagTechLeakShowSenderMessages - if TRUE, show sending player message that tech points were sent
bFlagTechLeakShowSenderMessages = true

pPlayer = gc.getPlayer(iPlayer)

# Loop through all techs
for iTechCursor in range(gc.getNumTechInfos()):
# If pPlayer has tech iTechCursor
if (not pPlayer.isNone() and not pPlayer.isBarbarian() and gc.getTeam(pPlayer.getTeam()).isHasTech(iTechCursor)):
# Loop through all players
for iTargetPlayer in range(gc.getMAX_PLAYERS()):
pTargetPlayer = gc.getPlayer(iTargetPlayer)
# If pTargetPlayer is a valid target to pass techs and does not yet have iTechCursor
if (not pTargetPlayer.isNone() and pTargetPlayer.isAlive() and not pTargetPlayer.isBarbarian() and not gc.getTeam(pTargetPlayer.getTeam()).isHasTech(iTechCursor) and pTargetPlayer.canResearch(iTechCursor, false)):
pTeam = gc.getTeam(pPlayer.getTeam())

# Initialize amount to add variable, this will keep track of total points to add to this tech
iAmtToAdd = 0
# Cycle through all of pPlayer's cities
for iCityCursor in range(pPlayer.getNumCities()):
pPlayerCity = pPlayer.getCity(iCityCursor)
# If pPlayerCity is valid
if (not pPlayerCity.isNone()):
pTargetTeam = gc.getTeam(pTargetPlayer.getTeam())
# Loop through all of pPlayerCity's trade routes
for iTargetCityCursor in range(pPlayerCity.getTradeRoutes()):
pTargetCity = pPlayerCity.getTradeCity(iTargetCityCursor)

# If pTargetCity is valid, and pTargetCity is owned by pTargetPlayer
if (not pTargetCity.isNone() and pTargetCity.getOwner() == pTargetPlayer.getID()):
# Add percentage into amount to add
iAmtToAdd = iAmtToAdd + int(pTargetTeam.getResearchCost(iTechCursor) * iTechPercentModifier)

# Can never auto-grant, so set to 1 less if meets or exceeds amount needed
if (pTargetTeam.getResearchProgress(iTechCursor) + iAmtToAdd >= pTargetTeam.getResearchCost(iTechCursor)):
iAmtToAdd = pTargetTeam.getResearchCost(iTechCursor) - pTargetTeam.getResearchProgress(iTechCursor) - 1

# Sevo: Another balancer; the bigger the gap between the leaking civ and the receiving civ, the more the gain, and vice-versa.
# THIS LINE IS REPEATED ON PURPOSE! It's the same end result as taking the divisor of the squares.
iAmtToAdd = iAmtToAdd * (pPlayer.getTechScore() / (pTargetPlayer.getTechScore()) )
iAmtToAdd = iAmtToAdd * (pPlayer.getTechScore() / (pTargetPlayer.getTechScore()) )
iAmtToAdd = int(iAmtToAdd/2)

# If there are points to be added, do so
if (iAmtToAdd > 0):
pTargetTeam.changeResearchProgress(iTechCursor, iAmtToAdd, pTargetPlayer.getID())

# If message to tech receiving player is turned on, send message
if (bFlagTechLeakShowReceiverMessages):
CyInterface().addMessage(pTargetPlayer.getID(), false, 3, "You have gained %d points towards tech %s from %s!" %(iAmtToAdd, gc.getTechInfo(iTechCursor).getDescription(), pPlayer.getName()), "", 0, gc.getTechInfo(iTechCursor).getButton(), ColorTypes(56), pTargetPlayer.getCapitalCity().getX(), pTargetPlayer.getCapitalCity().getY(), True, True)

# If message to tech sending player is turned on, send message
if (bFlagTechLeakShowSenderMessages):
CyInterface().addMessage(iPlayer, false, 3, "%s has gained %d points towards tech %s from trade with you!" %(pTargetPlayer.getName(), iAmtToAdd, gc.getTechInfo(iTechCursor).getDescription()), "", 0, gc.getTechInfo(iTechCursor).getButton(), ColorTypes(58), pPlayer.getCapitalCity().getX(), pPlayer.getCapitalCity().getY(), True, True)

 
Sevo said:
I also added a sub-layer of balancing; the problem seemed to be that the more tech routes you have the more tech you gain...

Sevo,

it is not correct. The more routes you have the more tech YOUR RIVALS gain from you! Just see to these lines:

check if the Player has tech
if (... gc.getTeam(pPlayer.getTeam()).isHasTech(iTechCurso r)):

check if the Opponent Player does not yet have the tech
if (... not gc.getTeam(pTargetPlayer.getTeam()).isHasTech(iTec hCursor) and pTargetPlayer.canResearch(iTechCursor, false))

therefore Player gives points to Opponent.

and then Cycle through all of Player's (not Opponent's) cities and loop through all of Player City's trade routes.

So it is already balanced - bigger and advanced civs give more techs to smaller civs. Moreover, as I already posted in your thread, trade routes are not bidirectional, so even if a civ has a very few trade routes, it can get a lot of tech points if others are trading with it.

I attached a small picture to illustrate how it is possible (of course, the situation in the picture is idealized).

A very small civ A has the only city with one trade route with a city of civ B.
Civs B, C, and D have not trade routes with each others but all have trade routes with civ A. In this situation civ A gets points from civs B, C, D; civ B gets a small number of points from civ A; civs C and D get NOTHING. Was I clear?

--------------

And another note.

It is better to remove int function from the line
iAmtToAdd = iAmtToAdd + int(pTargetTeam.getResearchCost(iTechCursor) * iTechPercentModifier)

because if you have 0.9 points from one route, you'll get NOTHING even if there are hundreds of trade routes.

Just put int AFTER LOOP like this
iAmtToAdd = int(iAmtToAdd)

Best wishes.
 

Attachments

  • trade-routes-explained.gif
    trade-routes-explained.gif
    2.6 KB · Views: 322
Yes, Fuji is correct. Trade leak occurs to the receiving city of the trade route, not the other way around. So, the more foreign trade routes a civ has, the more points it is leaking out to other civs. So, larger civs are more likely to leak out more points.

What I've found from using this mod is that while this does help out all civs that are lagging, it is really more beneficial to keeping the top ranking civs close to one another. So, as the game progresses, typically the top 1/3 civs all manage to stay fairly close together, as these are the ones trading the most with one another. Smaller civs have a chance to catch up a bit from their trade routes, but the more advanced civs are the ones with most of the trade routes. I actually like this better, as it makes the AI more competent by keeping a few strong civs (whereas typically, the AI will have all civs bumping into each other and stagnating over a period of time).

In my latest game, I'm playing as England, and I only have a small lead in the year 1568 AD. My points are 1468, while Egypt is in 2nd with 1132. The other top 6 players are all above 1000, and we are all within 1-2 techs of one another. The other remaining 7 civs are all in the 500-850 range, as they have slowly become out ranked by the growing dominant civs.

Usually by this point, I have 2x as many points as the 2nd place civ, so this is a much more balanced game than in the past. I have to really consider and pick my targets, or else I find I'm in over my head.

If things continue along the path they appear to be on, I foresee the top 6 civs becoming dominant superpowers by the time the modern era comes around. I'm playing this one through with my new religion mod too, and the big contenders are really divided over religious beliefs right now. I'm hoping that by the time we enter the 1900's, a world war will be on the horizon. May very well be possible too, as Catherine has yet to get Cossacks (which typically indicate a Russian expansion), and Bismark will get his Panzers shortly into the modern era (which often means quick German expansion, especially considering he is on the outs with everyone due to being the only Islamic civ right now).
 
Top Bottom