Technology propagation

Issue #137 new
joseasoler repo owner created an issue

Currently, the MNAI system for tech diffusion works like this:

A) The game calculates a % increase in research due to the number of teams known by the player. This value follows the following formula:

techDiffusion% = TECH_DIFFUSION_KNOWN_TEAM_MODIFIER - (TECH_DIFFUSION_KNOWN_TEAM_MODIFIER * (0.85 ^ knownTeamsModifier) + 0.5)

The knownTeamsModifier modifier is calculated as follows:

1) knownTeamsModifier set to 0.

2) For each team that the player has met that has the technology being researched:

2a) Increase knownTeamsModifier by 0.5

2b) If the team has an open borders agreement with the player or they are a vassal of the player, increase knownTeamsModifier by 1.5.

2c) If 2b is false and either the team is at war with the player or the team is a vassal of the player, increase knownTeamsModifier by 0.5.

2d) If the team has a right of passage agreement with the player, increase knownTeamsModifier by 0.5.

2e) If the team has an embassy with the player, increase knownTeamsModifier by 0.5.

B) The game calculates a % increase in research due to "welfare", which is a way to grant technology progress to the teams that are losing. The code looks fishy, I need to check it in more detail.

When tech diffusion is enabled, the game counts the number of teams met by the player with the technology (iKnownCount), the total number of alive teams (iPossibleKnownCount) and grants a % bonus equal to:

notTechDiffusion% = (TECH_COST_TOTAL_KNOWN_TEAM_MODIFIER * iKnownCount) / iPossibleKnownCount


To be implemented in 0.6:

  • Display tech diffusion as done in Realism Invictus.

Implemented in 0.5.0:

Technology diffusion gets its own game option.

Technology no longer diffuses if technology diffusion is off.

Technology no longer diffuses just by meeting another team. In order to diffuse technology, some diplomatic agreement must be reached first.

There is no longer a "tech diffusion by welfare".

When technology diffusion is on, it is also possible to get some small research progress by city conquest.

The technology diffusion algorithm will be substituted with the following one.

TECH_DIFFUSION_MAX defines the maximum % increase in research that technology diffusion can provide. This value is a global define in XML files.

team(i)Diffusion%: For each alive team met by the researching player that has researched the technology being researched by the researching player, a % value is initialized as follows. All of the percentage values mentioned below will be global defines in XML files. team(i)Diffusion% can have final values over 100%.

  • If the teams share a right of passage, team(i)Diffusion% is initialized to 15%.
  • If the team i is the player's master, team(i)Diffusion% is initialized to 30%.
  • If the teams share open borders, team(i)Diffusion %is initialized to 45%.
  • If the team i is the player's vassal or puppet state, team(i)Diffusion %is initialized to 60%.

After initialization, if team(i)Diffusion% is greater than 0%, it can be increased if certain conditions are met:

  • If the researching player has an embassy with the team i, 15 is added to team(i)Diffusion%.
  • If the researching player and at least one member of the team i share alignment, 10 is added to team(i)Diffusion%.
  • If the researching player and at least one member of the team i share a religion, 10 is added to team(i)Diffusion%.
  • If the researching player and at least one member of the team i share a membership civic, 10 is added to team(i)Diffusion%.
  • If the teams share a defensive pact, 15 is added to team(i)Diffusion%.

Once that all team(i)Diffusion% values are calculated, all of them are added together and divided by the number of alive teams that have researched the technology (regardless of having met the researching player or not), and then divided again by TECH_DIFFUSION_MAX. If the resulting value is greater than TECH_DIFFUSION_MAX, it is capped to TECH_DIFFUSION_MAX. The calculated value is then used as the final % increase in research caused by technology diffusion.

When deciding to sign certain treaties, the AI will add a positive or negative weight to its decision depending on if it is behind or in front of the other team in technology, and on the % amount in which that specific treaty increases technology diffusion. These treaties are right of passage, open borders, becoming a vassal, asking someone to become a vassal and establishing an embassy.

Defensive pacts also have a weight calculated as indicated in the previous paragraph, but negative weights are ignored.


For the future:

  • Sidar get a new civilization trait which multiplies the team(i)Diffusion% their team grants by 0.75.
  • Malakim get a new civilization trait which multiplies the team(i)Diffusion% they get from each team and the TECH_DIFFUSION_MAX value by 1.25.
  • The Barbarian trait multiplies the team(i)Diffusion% they get from each team and the TECH_DIFFUSION_MAX value by 0.9.
  • Scholarship multiplies the team(i)Diffusion% they get from each team and the TECH_DIFFUSION_MAX value by 1.2.
  • Foreign trade multiplies the team(i)Diffusion% they get from each team and the TECH_DIFFUSION_MAX value by 1.25. It also multiplies the team(i)Diffusion% their team grants by 1.25.
  • Isolationism multiplies the team(i)Diffusion% they get from each team and the TECH_DIFFUSION_MAX value by 0.75. It also multiplies the team(i)Diffusion% their team grants by 0.75.

Comments (25)

  1. joseasoler reporter

    Ideally I would prefer to have the default technology trading disabled and enable technology difussion by default.

  2. joseasoler reporter

    The Sidar could get a new civilization trait that sharply reduces the rate at which their technologies are spread to nearby players.

  3. lfgr

    You linked the wrong file, the CvPlayer.cpp chance is related to TechDiffusion, the other is about religion spreading (he actually changed nothing, just "code cleanup and adding a note for a future task" as mentioned in the commit message).

  4. Tasunke Witka

    Sidar should certainly have a strong decrease in how much tech they give away. -25% outward diffusion

    Isolationism Civic should increase that by -25%, for a total of -50% outward diffustion, and possibly -25% inward diffusion as well.

    If a mechanic is ever created that gives Sidar cities hidden by fog ... any hidden cities, or all cities if border cities are fogged, etc, then that would reduce both inward and outward to a hard zero.

    Malakim with their trade focus should be learning neighbor's techs more quickly +25% inward diffusion

    Foreign Trade sounds like a good civic to increase both Inward and Outward diffusion by 20%

  5. joseasoler reporter
    • edited description

    I have edited the proposal. I have no plans to implement something as complex as the fog mechanic.

  6. Former user Account Deleted

    Technology diffusion is annoying and undermines the seperate-lines approach of FFH research. However, it's better then tech trading, so having TT off by default (or maybe Technology Brookering on instead?), and TD on but with an option to turn off seems to be the optimal situation.

    It definitely should have an option to turn off, however. It is a rather big change in how the game works, and as mentioned earlier cheapens strategic depth of researching into seperate lines. For that reason, it will always be annoying to a portion of the population, and should have an option for off - may I suggest cannibilizing the No Duin Halfnorn option if you don't want to add one?

  7. joseasoler reporter

    I'm aware of the "undermining separate technology lines" problem. I just prefer it to technology trading, as it feels extremely weird to be able to start trading techs around with AIs and become a scientific giant in a few turns. Technology brokering helps with that, but the trade is still quite strange and unnatural.

    Having said that; we agree on it requiring its own game option. I have no problem in including new game options, so I will give it a new one.

  8. lfgr

    Did you consider linking TD to open borders? I think it's done that way in Realism Invictus, and I like the idea.

  9. joseasoler reporter

    My first contact with a feature like this one was in Realism Invictus; I believe they handle it very well. I still have not decided the best way to modify and complete the implementation of technology diffusion (in fact, I have not even checked in detail how it works in MNAI) but I was planning on using the RI implementation as a model by also looking into some complementing features they already have such as technology by conquest, the helpful interface changes to show to the user what is happening and so on.

    The research boosts granted by RI may be too big for the FFH tech system (as Queue Beyond indicated, this system reduces the penalty of researching specific technology lines), but I also believe that tech diffusion should be limited to players that have at least some diplomatic treaties.

    I did a check of how MNAI handles technology diffusion and now I see feasible to partially implement this proposal for 0.5.0. I edited the first post to show what I plan to implement and what would be left behind for future versions. Feedback is welcome.

    I also added a description of how tech diffusion currently works in MNAI. I find the formulas a bit complicated, but the way they increase make sense. The logic behind calculating how the % increases depending on the relationship between teams is quite weird and I'm proposing changes at the first post.

    The code of the welfare system seems as if it is doing the inverse of what it says (giving more progress for each team lagging behind). It can be found at CvPlayer.cpp searching by getTECH_DIFFUSION_WELFARE_THRESHOLD. I wonder if for EMM we should just remove it, anyways.

    I found that there is some tech diffusion-like increase in research even in vanilla FFH, which is also documented at the first post.

  10. joseasoler reporter

    The visualization of research modified by technology propagation has been reverted because of the issue mentioned earlier. All of the things meant to be in 0.5.0 are already included; the rest are marked as FUTURE.

  11. joseasoler reporter

    For 0.5.0, technology propagation is missing a CONCEPT page explaining how it works, and adapting TechDiffusion.py to work with the same premises that the bonuses to research.

  12. Log in to comment