One of my tasks for this beta was getting in basic diplomacy, although it's still pretty primitive because the relations code is still pretty basic.
You can bring up the Diplomacy screen by going to KingdomWnd and clicking on Foreign Relations. If you've encountered another player, you can click on their entry and click the speak to button or double click on the entry. This gives you 3 options, one of which is disabled: Info, Trade (disabled) and Negotiations. Info compares your stats to the other faction (currently doesn't require espionage or anything else). Trade will be for actually trading resources, units, etc. but is not yet implemented. Negotiation has several treaties, which actually do work.
In the Info screen, you can click on one of three categories to display information about: Civilization, Warfare and Magic. Magic currently doesn't show anything since magic is not currently enabled. Civilization shows stats about things like your treasury, food, research, etc. Warfare lists stats about your military. We may also want to show Diplomacy/Foreign Relations info on this screen also.
Apparently the latest version of the Negotiate screen introduced a bug where not all the treaties are listed immediately; scrolling with the scrollbar fixed this for me. The Negotiate screen lists all the possible treaties, with information about what you would get from each treaty. This needs to be tweaked further because they could really use a 1 line description under each treaty. At any rate, there are thre kinds of treaties right now: treaties that give you bonuses, treaties that affect your relations, and treaties that the code checks for to allow certain behaviors.
New in this beta is the ability to build to roads to foreign cities so that you can trade with other players. This gives you a bonus to your income. I believe that trade between your own cities gives you a bonus to your income as well. If you setup a trade treaty with another player, you will get an additional bonus to income based on the trade income of the other player and your diplomacy score. They also get a bonus based on your trade income and their diplomacy score.
The technology treaty gives you a bonus to your research points per turn based on the other player's research points per turn and your diplomacy score, and similarly, the other player gets a bonus from your research points per turn (not including bonuses from treaties).
The other treaties affect your relations. Currently, you can't declare war from this screen unless you have hostile relations with the other player. But you can get peace if you declare war by invading enemy territory. Declaring war cancels all treaties with the other player. This is currently the only way to cancel treaties.
The Non-Agression Pact allows you to pass through the other player's territory. Eventually, we may make a dialog so that you can limit the duration, but for now it's infinite unless you declare war. The Non-Agression Pact doesn't affect relations or give you anything else.
The really cool thing about the treaties is that they're completely data driven. Here's an example from the xml file that defines the treaties:
Code: xml
- <Treaty InternalName = "TradeTreaty" Type = "Trade">
- <DisplayName>Trade Treaty</DisplayName>
- <Description>Both parties get a bonus to their income from trade.</Description>
- <Duration>-1</Duration>
- <MinimumRelations><![CDATA[[RELATIONS_NEUTRAL]]]></MinimumRelations>
- <Calculate InternalName = "TradeTreatyValue" ValueOwner="Player_2">
- <Expression><![CDATA[[TradeIncome]*[TradeTreatyRate]]]></Expression>
- </Calculate>
- <Calculate InternalName ="TradeTreatyRate" ValueOwner="Player_1">
- <Expression><![CDATA[[A_Diplomacy]*0.1]]></Expression>
- <Min>0.01</Min>
- <Max>1.0</Max>
- </Calculate>
- <Calculate InternalName = "TradeIncomeBonus" ValueOwner="Player_1">
- <Expression><![CDATA[[TradeTreatyValue]+[TradeIncomeBonus]]]></Expression>
- </Calculate>
Duration is the number of turns that the treaty lasts. -1 is infinite, 0 is a one time effect, and anything else is a limited treaty.
You can specify Minimum and Maximum relations, or simply RequiredRelations. These were easy to do, but the really cool part was desiging the calculation system.
Each Calculate object has an internal name which can in turn be used as a variable in another Calculate object.
The ValueOwner attribute is a tag that lets the parent class (in this case, the treaty) know what can provide the other variables it needs. When the treaty is created, it calls a function called SetValueOwner which goes down the chain and sets the pointer for the ValueOwner based on the tag. The tags are meaningful for the code that calls it: the treaty code only deals with the two players it has pointers to, so "Player_1" and "Player_2" refer to its pointers rather than the players with IDs 1 and 2, which might be tags used by another class.
Each Expression can be at most a binary operation (one operator, two operands), but you can build more complicated equations by chaining the Calculate objects. Each Expression can specify a max and min value, although they don't have to specify both.
When the calculation is performed, the Calculate object first goes through and asks its ValueOwner to replace tags in a copy of the expression tag with the appropriate values, and also asks its child calculations for their values. When all the tags have been replaced, the expression is evaluated.
Right now, only a few values have been exposed to the interface that gets passed to the Calculate values, but we'll be able to expose more over time so that you can use the interface in scripts and mods. I'd really like to see more of the data types using the Calculate objects because it would mean that even non-coders could make significant mods, and C++ would be doing most of the work (since C++ is faster than python for a lot of tasks).