Wednesday, October 2, 2013

XML and Scrolling

Cultura has a lot of different resources. And it might be overwhelming to a player who isn't all the rage into Dwarf Fortress or Anno 1404. So, in Cultura, the concept is simplified a bit. There are "items". You can see below in the list those are things like "grain", "fruit", "meat". Within an item category are "materials". So there are different types of grain such as "wheat" or "oats".

What this means is that all goods will require "items" (not materials). So when you want to make "flour", you use "grain". It doesn't matter what kind of grain. But using more types of materials creates higher quality items. Higher quality items last longer or give better bonuses.

The current list of items and materials are:

  • Grain: wheat, oats, rye, barley, stone grass, green brome, silk rye, bluestem
  • Fruit/Vegetable: juniper berries, crab apple, blackberry, strawberry, glowing mushroom, crab plum, yellow berry, tiger nut
  • Dairy: none for now
  • Meat: gazelle, seal, mammoth, sabertooth cat, unicorn, ice crab, dragon, direwolf
  • Stone: granite, limestone, flint, chert, stonewood, rune rock, aquaferra, dark granite
  • Wood: pine, oak, cypress, sycamore, silverleaf, ironwood, amberbark, goldwood
  • Earth: clay, sand, kaolin, silt, bright clay, dark shale, fire sand, frost silt
  • Metal: tin, iron, nickel, zinc, viper stone, cold iron, frost ore, amber nickel
  • Bone: gazelle, seal, mammoth, sabertooth cat, unicorn, ice crab, dragon, direwolf
  • Fur/Skin: gazelle, seal, mammoth, sabertooth cat, unicorn, ice crab, dragon, direwolf
  • Fibre: silk, cotton, ramie, hemp, giant spider silk, thread mushroom, rock string, yarn bush
  • Filler: papyrus, ryegrass, leadtree, burclover, hollow weed, elf blade, grey shrub, goldclover
  • Herb: tea, ginger, basil, cinnamon, glowing nettle, ember flowers, comfrey root, mandrake
  • Precious Metal: gold, silver, copper, platinum, mithril, adamantium, snow silver, null iron
  • Precious Stone: turquoise, diamond, jade, sapphire, mana crystal, moonstone, sky pearl, power stone

In terms of code the only trickiness surrounds meat, bone and skin. For those items they are refined from animal (or sentient) carcasses. Your hunters will go out, kill a gazelle and then harvest "carcass" type goods. These are then turned into meat, bone and skin. This means for the game purposes, meat/bone/skin count as non-raw goods! Instead "animal parts" is what you collect and then based on the material of the animal part you get different meat, bone and skin. You can then use those to craft further items. The xml that has been written looks something like:


<good>
 <name>Meat</name>
 <id>10000</id>
 <prereq>
  <req>
   <id>100</id>
   <amount>1</amount>
  </req>
 </prereq> 
 <category>
  <id>100001</id>
 </category>
 <graphic>
  <meshname>meat</meshname>
  <texture>meat.png</texture>
 </graphic>  
</good>

This gives a quick way to add in new stuff into the game. How do we parse it? Using rapidxml :) I'm not going to write a poopy xml parser when there's a million out there. Those aren't particularly interesting or hard problems to solve versus making Cultura. The intent is, afterall, to make an awesome game.

Using xml, the units, structures, goods and materials are all loaded at initialization. Then they are saved in the "gameEntityCreator". This class holds all the definitions. Whenever some components needs to make a new unit or structure or resource node etc, they call the gameEntityCreator to do so.

Next for the xml loading is to change the UI to make use of the gameEntityCreator and its list of definitions. The goal is modularity and moddability. While I don't have an intent in making the game mod-able, I do intend to have as little "one-shot" code in the game as possible through better design.

Some additional awesome fixes by a friend:

  • Game starts with the camera properly centered on your cave
  • No more scrolling unto infinity, it stops at the edge of the map

Sunday, September 15, 2013

Work Orders and Terrain

Graphics in Cultura is designed around the idea that what an artist draws is what they get to see in the game. That way, there's no strange distortions (other than effects) and so on, allowing artists to simply draw. As part of that, the terrain on the ground used to be rotated quads but no longer! They are now the same as everything else. In addition, the terrain drawing has been randomised using a single hard-coded seed. What this means is that if I have three different grass textures I could rotate through to draw a particular square, it will choose one at random but because the seed is hardcoded, it always chooses the same one so it looks consistent as you scroll around or reload the game.

Using some test tiles, you can see that they are pesudo-randomly chosen and it is always the same every time you load up the game or scroll here.

Work orders have also been finished off, minus UI styling. They list out the existing work orders and allow you to modify them.

If you create one, it will then list it out. This allows you to select it and change it.

The rest is taken care of automatically in the game. Workers will shift what they need to do. By design, if they are already working on an item, they will complete that before adjusting to the new marching orders. That's fine to me so that I don't have to deal with partially finished goods.

Sunday, September 1, 2013

Item Crafting and More!

Features Completed

It's been a while since I posted the last feature complete type of post mainly because the item crafting feature involved a lot of moving pieces. But it's done! The goal after this is expanding it out (I wanted to be able to select a unit and then have an item crafting button at the bottom in a limited action panel) and also to build more infrastructure to support it (I've decided that I'll just go with xml data loading during initialization).

So what was done?

  • Industry Management Screen
  • Work Orders
  • Automated Animal Hunting
  • Automated Node Harvesting
  • Automated Item Crafting

The industry management screen loads up a test-version of the goods tree. On the left hand side are the raw resources and they lead to ANY secondary item that can be produced from them. Later I'll sort the goods alphabetically in their subcategories so everything can be found easily. The point of having each resource lead to any secondary item that can be produced from it is to be able to easily find secondary items (for instance, if an item requires both metal and wood then it will occur twice in the tree extending off from wood and also from metal).

Once you click on one of the goods in the tree, you can then select the options below to change the industry management. Only work orders are fully implemented. So if you select work orders you go to the work order screen.

Here you select how many you want, what materials to use (the options are: must use, use if available, don't use). This screen will also show existing work orders to allow you to change their settings. On next update, the labourers completing the work order will update their settings accordingly. So, there's a delay of building the current item for any labourer completing the work order (for instance, if you cancel the work order, the labourers will still finish what they are working on at the moment).

About item crafting, these are the following game decisions surrounding it:

  • Item crafting must occur in a building
  • The AI will select a building which the person owns or the government has assigned a government building to him (will choose the best building)
  • Material selection occurs each time the unit starts building the next item, in case material settings and availability has changed
  • Each building can only have ONE type of industry improvement (forcing you to build additional houses to improve the industry rate for more labourers)
  • After crafting an item, the carry limit is not checked, the unit will simply be carrying it and queues a drop-off

What doesn't get good screenshots but took a lot of work was the actual implementation of the work orders. There are three different situations: you gave a work order for hunting animals up to a limit, you gave a work order for collecting raw resources or you gave a work order to craft some materials. In the case of hunting animals, the AI finds an animal in the land region of a unit and then has the unit queue up a hunt animal action. The limit is in the amount of meat to harvest (not number of animals). I may, in the future, add in the ability to select an animal limit rather than a meat limit. For a raw resource, the unit finds a resource node of the correct type and material type (but the player can always select yes to all material types). So if you create a work order for wood and said "Y" to pine, then a unit will only try to chop pine wood up to the quantity. Finally, item crafting has a unit attempt to collect resources necessary to produce the good and then go to a building to craft it.

Here is some "flour" (I think my cavemen are making crack but if I don't debug then I can feign ignorance)

Next feature will be surrounding stuff to improve item crafting before I move onto the other buttons in the industry management

Sunday, August 18, 2013

Collecting Some Thoughts

In progress right now is the industry management and work orders. Each feature at this point is taking a longer time than previous ones since they are larger pieces. For industry management there are several components before an alpha version is complete:

  • Goods Tree Screen
  • Labour Dialog, Industrial Structures Dialog and Work Order Dialog

Those UI components are completed and functionality for the work order dialog is also complete. The other component that would be necessary for the alpha version of Cultura is the full functionality of Labour Dialog. Each of these dialogs are different ways to handle industry. Labour dialog allows you to assign a number of people to work in a particular industry to produce as much as they can. It also handles tool selection and non-ideal labour assignments (for the alpha it means people who have a house that is designed for a different type of good and in the future it will also mean people who are not using their best skill). The Industrial Structures dialog allows you to easily upgrade industrial structures and/or view what type of households exist. Each house can have only one type of industrial upgrade (dedicated industrial structures don't exist in the alpha and not likely until you reach neolithic age technology). The work order dialog allows you to order up specific amounts of a good to be collected/crafted using a material selection.

Currently, the work order functionality (you set a work order and then the game automatically begins to assign people to complete the task) is code complete but not fully tested (and debugged and so on). So that'll be finished soon enough. The difficulty in getting this to completion is the rather large number of edge cases and UI design issues that come up. Cultura is a complex game and that means a complex UI. But, ideally the game offers a simple UI to the user but holds easily accessible advanced options for them to micromanage to their heart's content. Additionally, outside of the management UI, there will be a limited number of buttons when units are selected to craft items and possibly other options in the future. Much of the complexity arises from how the code should intelligently react to user input (what should a unit harvest, when should a unit stop, should a unit queue up actions or throw away actions, etc)

Collecting all the tasks together what does Cultura need? Let's ignore UI issues for now. Those will be fleshed out when a feature complete alpha is done (since it's hard to say what might be clunky before actually playing the game).

  • Managing Work Orders
  • Managing Labour Assignments
  • Managing Industrial Structures/Households
  • Tracking wealth by household
  • Family Spawning/Reproduction
  • Random Level Generation for new games
  • Data-driven tech tree and goods tree
  • Data-driven graphic resource/mesh creation
And nice to have for alpha:
  • Event-driven system
  • Graphics component with event-driven system

There are a few open design questions that haven't been fully settled upon:

There might be a UI for seasonally created work orders. For example, it might be "Hunt up to 150 gazelle meat in Summer". This is useful if you don't want to accidentally damage the ecosystem. That currently doesn't exist. There are only work orders and labour assignment.

For now, each household may have any number of bedrooms, living rooms, dining rooms and other such residential rooms but only one industrial structure. Estates are composed of different houses, each with up to one industrial room. This is to simplify gameplay and reflect the cottage-style industrial of earlier ancient times.

Reproduction is currently going to be progress based and dependent on health. Poor health leads to slow reproduction rates. After a set amount of time, children become adults. A set amount of time after that they couple with someone else and start a new family. This new family moves out immediately and requires additional housing. Insufficient housing leads to homelessness (I'm unsure whether people can just randomly build houses or whether land property is controlled). I'm also unsure if I wish to implement cultural rules (such as a daughter moves into the son's estate). I'm also unsure of how to do estate spawning or estate joining. For example, let's say a son grows up and then gets married. Does he build his house in his family estate and combined his labour with that of his extended family or does he break off and start a new estate? Estates share the fruits of their labour but not personal property.

I'm still open as to the random level design. Mostly I gravitate towards having a balanced world where each land region is of a specific type and that type determines the kind of resources it may contain but is "balanced". For example, all land regions have 5 common resources and 2 rare resources. Additionally, I'll design the goods tree to be balanced. Each type of good leads to an equal number of industries except precious metal and precious stone which lead to extra industries (and thus drives up their value in a soft manner).

Lastly, my current set of "raw item categories" is: grain, fruit/vegetable, dairy, meat, wood, stone, earth, fur/skin, fibre, filler, bone, herb, precious metal, precious stone. Each has 4 mundane and 4 fantasy style goods. Steampunk theme means they may encounter either resource. Eventually I'd like to rank the material types by rarity. An item's appearance is determined by the most rare material used in its construction. I'd like that more rare materials give a greater bonus when used. The resources are paleolithic themed and that is why there aren't apples, pears or strawberries. Although I'm not clear on whether strawberries existed back then, it got rather difficult to be too authentic so the following list is only somewhat accurate to stone age:

  • Grain: wheat, oats, rye, barley, stone grass, green brome, silk rye, bluestem
  • Fruit/Vegetable: juniper berries, radish, dates, almonds, glowing mushroom, blue leek, yellow berry, tiger nut
  • Dairy: none for now
  • Meat: gazelle, seal, mammoth, sabertooth cat, unicorn, ice crab, dragon, direwolf
  • Stone: granite, limestone, flint, chert, stonewood, rune rock, aquaferra, dark granite
  • Wood: pine, oak, cypress, sycamore, silverleaf, ironwood, amberbark, goldwood
  • Earth: clay, sand, kaolin, silt, bright clay, dark shale, fire sand, frost silt
  • Metal: tin, iron, nickel, zinc, viper stone, cold iron, frost ore, amber nickel
  • Bone: gazelle, seal, mammoth, sabertooth cat, unicorn, ice crab, dragon, direwolf
  • Fur/Skin: gazelle, seal, mammoth, sabertooth cat, unicorn, ice crab, dragon, direwolf
  • Fibre: silk, cotton, ramie, hemp, giant spider silk, thread mushroom, rock string, yarn bush
  • Filler: papyrus, ryegrass, leadtree, burclover, hollow weed, elf blade, grey shrub, goldclover
  • Herb: tea, ginger, basil, cinnamon, glowing nettle, ember flowers, comfrey root, mandrake
  • Precious Metal: gold, silver, copper, platinum, mithril, adamantium, snow silver, null iron
  • Precious Stone: turquoise, diamond, jade, sapphire, mana crystal, moonstone, sky pearl, power stone

Saturday, July 27, 2013

Technology Management

Tech

Cultura begins in the stone age and is meant to eventually go to the Early Modern age. However, for the first iteration it'll just be the paleolithic age. And for right now, let's take a look at the test UI for the technology management.

In a somewhat Diablo style interface, a list of technologies is shown and rather than be like Civilization where you have research points accumulating to a specific technology you instead receive tech points. Technologies which you can research have a "+" button next to them. I may have technologies which cost more than one point or alternatively give you less benefit per point making some technologies strictly superior to others.

I'd like to add arrows to show prerequisites more clearly and also technologies have "level" requirements not just specific tech requirements. For instance, pottery may require Level 5+ in scraper tool. For now, this screen works. When you add a tech point to tents you are then able to build tents. Once you exit from the screen and go back to the game and then go to the context menu you will see that tent indeed shows up.

Yay

Saturday, July 13, 2013

Building Construction

In order to finish off building construction to the alpha stage several pieces were needed:

  • Context Menu
  • Placement UI
  • Material Selection
  • Wealth tracking
  • Technologies

There were a few bug fixes involved: getting the wealth tracking working right, fixing the graphic for updating trees and so on. The wealth tracking revealed that my quadtree accidentally double inserted items. When I added silverleaf trees, I discovered I had a typo in my code that accidentally changed all trees to the graphic of the one that was just cut down. Imagine my surprise when all my silverleaf trees became pine trees!

Context Menu

The context menu interface has changed to be a keyboard based interface. I left the right-click to show functionality but the primary way to show it is to press the "B" key on your keyboard. The reason? I kept having units selected and then I would right-click only to order the units to do something I did not want instead of showing the right-click menu. Durr!

Basically the context menu shows the base options (which will eventually become icons) and then the sub-categories and then finally the final options. It will also let you quickly open up the faction management screen. I think there will also be a single keyboard shortcut to just go straight into the management screen but that will be for when I create those screens. For now just the context menu!

Opening up the context menu shows this:

We select build

We select Cultural buildings:

Finally, we select Inukshuk

Now we see we can place the building anywhere and also select the materials with which we can construct it.

After we place buildings we can see that there is a bunch of rocks that mark the construction site:

So we can see a preview when we move the mouse around where the building will be and in the lower right corner we see what materials we will be using to construct it. Eventually I will add a resource overlay in the top right corner so that you can see your wealth - liability. You can spend into debt and the display will show negative (indicating that you should get more resources).

Wealth Tracking

Wealth tracking is accurate to the game tick. In actions that affect faction wealth it updates it on the fly. This is a bit dangerous (if I miss a spot in the code then the wealth is incorrect). To make up for this, I have a debug assert that does a resource wealth audit every 100 game ticks. If there is a mismatch between calculation at that moment and the current cached value of wealth then an exception is thrown. This will help me debug any place I have missed proper wealth tracking.

Wealth is defined by having resources stored in structures (therefore units carrying items do not constitute as part of wealth). Liability is defined by structures placed and how much more resources they need. Once industry is added, liabilities will also include work orders and item requests.

Technologies

The technology UI will be next but for now, factions record their technology in a std::unordered_map where it is technology ID to tech level. Many techs are repeatable and so int to int is a reasonable structure. Technology limits how many materials you can select and what buildings you can construct. Right now the two test structures a inukshuks (which the faction begins with) and tents (which the faction does not have). So when you open up the menu, only buildings for which you have the technology show up. Additionally, attempting to select materials beyond the limit results in nothing happening (there will be an error message added in the future). I will also probably have to add information in the material selection on technology limits such as "You may select up 1 material per item type".

Thursday, July 11, 2013

Diplomacy

Let's take a look at Cultura's AI engine and focus on the diplomacy section.  When you trade or make deals how do they figure out how to react, how to figure out whether it's a good deal?

We start with a way rate to all items equally.  Any item is thought of in terms of how much it increases a faction's score.  What is score?  It is the health/happiness/administration provided by the deal item.

Value = health + happiness + administration

It might be possible for a faction to value these scores differently.  If health is low, health is more valuable.  Administration points are more difficult to obtain so they are more valuable.

Value = health * bias1 + happiness * bias2 + administration * bias3

Okay, but how do we calculate the score?  We can define a set of "primitive" functions that we can use:

A) Direct Function

Trade item directly represents goods that have a score rating that can be estimated.  For instance, each unit of Pine Cupboard provides +1 health, +1 happiness.  You are offered 200.  We have no bias.  Therefore it is worth 200 * 1 + 200 * 1 + 0 * 1 = 400.

(Considering existing stocks)
We already have 100 Pine Cupboards and we have 200 people.  Each person gets full benefit from 1 Pine Cupboard.  Additional pine cupboards only provide 1/10 the score.  Now the value is 100 * 1 + 100 * 1 + 0 * 1 = 200 and for the surplus amount is worth (100 * 1 + 100 * 1 + 0 * 1) / 10 = 20.  The value is 220.

B) Trade Opportunity Cost Function

The value of a particular good is the best trade you can get for it.  If there are no previous trades this value is unknown.  Thus the value is the HIGHEST score of all the goods you have traded it for.

For instance, say you have 50 oranges.  They can be traded for 1 pear (+1 health) or 1 mango (+2 health).  In the first trade it is worth 50 health.  The second trade is worth 100 health.  Therefore the trade opportunity cost is 100 value.  We are simply applying A (the direct function) to each set of goods it can be traded for.

Alright, so there's two primitives.

That's pretty good if we're exchange goods.  We calculate the value of what we are trading away.  Let's take a look at an example:

Goguryeo Offers:
200 mangoes

Asks:
50 silk

Direction Calculation
Okay, 1 mango = 2 health.  We have no existing mangoes.  Therefore it is worth 200.
Silk = 2 happiness.  We have lots of silk, overwhelming our people.  So it is worth 100 / 10 = 10.  It is worth 10.

Trade Calculation
We are being offered the mangoes.  We ignore this calculation.
The best other offer is durians which are 3 health each.  Therefore, 50 durians are 150 health.  Trade value is 150.

Using these scores we determine this deal is:

Goguryeo offers 200 and asks 150.  Deal is +50 from our perspective.  Therefore we should accept at a high percentage chance.

Alright but what about more complex deals?  War, threat and raiding.  The situation here is more difficult.  But we could try to break it down to this:

C) Threat Cost

The value of a change in relationship is the threat cost difference.  This can be both negative and positive for when relationship deteriorates or improves.  We figure out the power of an enemy military.  For now we might make a simple calculation:

Military = sum of unit power values * bias

The bias is affected by real data points.  If we fought a war previously and strength was underestimated we can push the bias value to a higher one.

We figure the amount of military needed to counter another faction to be:

MilitaryPowerNeeded = MilitaryPower * Threat

The value for threat can simply be the value of relationship score between the two factions normalized over a value range (between 0 and 1).  So for any change in relationship then the threat value will change and change the MilitaryPowerNeeded.  The difference between the new and old value is the MilitaryPowerNeededChange.  We then estimate how many goods are needed per point of MilitaryPower.  How?

ValuePerMilitaryPower = MilitaryPower / Value of Military Goods

We take the total military goods use calculations A (direct) and B (trade) to get the value of the goods, divide our military power by that and figure out the value per military point.  Let's look at an example:

Song Dynasty demands:
Submission

Okay, if we refuse then we expect -10 relationship which in threat terms means +0.1 threat.

Song Dynasty has 5000 militaryPower.  Current threat is 0.2 and we might expect +0.1 threat if we refuse or -0.1 threat if we accept.  So if we refuse, we need 500 militaryPower, if we accept then we need 500 military power less.

Currently military power of your faction is 2000, with goods valued at 4000.  Therefore each military power is worth 2 value.

So the trade deal is:

Accept: +1000
Refuse: -1000

Are we done?  Military calculations are more complicated than this, so no.

B2) Opportunity Cost of Labour

The reality is that military goods are a drag on an economy.  So we need a new calculation.  Things we could have built if we didn't make the military goods.  Let's call that calculation B2, the opportunity cost of a good in terms of production rather than trade.  If we freed up the labour used to make the military goods what could we have made and use the calculation of A and B to determine the value of those goods.

Total Good Production / Total Labour Used = labour cost of good

This cost is chained.  For instance, a Flour Mill = Gear + Spoke.  Gear = 10 stone.  Spoke = 5 wood.  Therefore Flour Mill = labour cost of each flour mill + 1 * labour cost of gear + 1 * labour cost of spoke + 10 * labour cost of stone + 5 * labour cost of wood.

Knowing that 1 unit of military power = goods whose labour cost is say 50, then we see the best highest value good we could have made instead.

We'll say that each military power could have been 3 honey bread which is worth 6 value.


D) Raid Value

We might want to attack someone for their goods.  In this case, we estimate loss of military power for goods gained.  We might simply come up with a random starting value and then shift it up/down according to actual raids conducted.  Militant powers would estimate higher at first, pacifist powers would estimate lower.  Real raids give real numbers.

As an example: We raided Song Dynasty and gained 300 rice.  Each rice is +1 health.  We lost 20 military power (calculation is the same as discussed in C).  Let's say each military power is 2 value.  We gained 300 value and lost 40 value.  The gain is 260 value.  What is the raid value?  The value is 260/20 which means each military power is worth 13 points.

Like trading, we take the opportunity cost calculation.  The best raid value is the one used.  We pretend for now that Song Dynasty is the best place to raid.  What's second best?  We'll say it is a nation called Silla.  With Silla, each lost military power results in 8 value.

Notice that a tougher target means higher losses and will lower Raid Value, so it inherently takes into account both the prosperity of a target and its defences.

That's great we have a way of figuring out military power expended and the value we get out of it.  But the problem is, how much military power are we going to expend?

Now we can combine the two calculations of C and D.

Song Dynasty demands submission.  We can submit and free up 500 military power.  Therefore submitting is valued at 3000 by calculation C (military goods no longer needed and we value it by A, B and B2).  Therefore the final value is 3000.

Or we can reject.  By calculation C that is valued at -3000.  But it means our raids continue.  In order to break even we must expend at least 3000 / 13 = 230 military power.  So the question now is whether we are willing to risk that much military power.  A faction can set a military power risk threshold.  Let's say Gogoryeo is willing to risk 300 military power.  A -3000 value is not enough to justify the stop to border attacks against Song Dynasty.  If instead Gogoryeo is only willing to risk 100 military power then it is no longer justified to reject submission.

So finally we have a faction's thresholds.  This isn't a primitive calculation.

E) Military Deployment Perceptions

Factions have two values against one another.  The first is the threshold of military they wish to deploy against someone and feel it is still reasonable as a percentage of their military power.  The second is how much military they believe an enemy nation is deploying against them.

Say you are aggravating Song Dynasty.  You injure your relations with them but you know they are already fighting a conflict with Jin Empire.  So around 70% of the Song military is deployed against Jin and of the 30% left they are deployed in various ways.  You notice that only 5% of their military is deployed against you (Gogoryeo).

Song Dynasty has 5000 military power.  Only 250 military power is deployed against you.  According to previous conflicts you trade losses at a ratio of 2:1.  For every military power you lose, they lose 2.  That means you need 125 military power to take care of this threat.

If the actual threat value is higher than this, this means they are temporarily weakly deployed against you for whatever reason.  So if threat value says you need 250 military power but military deployment perception says 125 military power, take a value in-between.  We can keep it simple and just say the half-way point.

You combine D and E and figure out that the requirement of troops is 187.5 and furthermore, increases in threat value are not as significant because if military deployment has not changed then you perceive the military threat to be less than it could be.

What else is important about E?  Shifts in military deployment from your actions.  If you sign a deal to aid someone else in their war against an enemy, you see benefit from decreased enemy deployment along your border.  You might also incite war between two factions, using this calculation to see the benefit versus the cost of goods needed to convince the others to go to war.

Alright well that was quite a bit.

With these we can compile more complicated formulas by putting them together.  For instance:

1) Damage Infliction

Song Dynasty dislikes the Gogoryeo and denounces them.  They believe this will cause the Silla to take a more aggressive stance against the Gogoryeo because then the Gorgoryeo kingdom must redeploy military against Song.

For Song Dynasty it sees by D (threat value) a value of -200 due to increased military required against Gogoryeo.  However, it looks at E (military deployment) between Gogoryeo and its neighbours.  It figures that this begins to draw military away from its other borders and invite attack because their deployment levels drop below some of the military thresholds of its neighbours, such as Silla.

So, it calculates that military losses from such conflict will drop the total size of the Gogoryeo kingdom and as such then lower their troops along the Song-Gogoryeo border.  This freed up military in the long-term is calculated by D (threat value) and is then seen to be +300.

Threatening Gogoryeo is then worth +100.

2) Accepting Roman Protectorate Status

The Romans promise military protection but then we (the Gauls) must pay tax.  By calculations A and B of the non-military goods sent we figure out that the value is -500.  In return the Romans promise protection.

Between the Gauls and the Romans, we see a threat level drop.  Using calculation D we figure out that the freed up military is than valued at +300.

The Romans also post a garrison in our lands.  Depending on our trust of the Romans we may view this as completely not a threat (100% trust) or an insidious invasion plan (0% trust).  It's likely somewhere in-between.  We calculate via D and/or E that this lowers our military deployment and so is worth +700 but due to our trust level (70%), it is lowered to +490.

The total deal is worth +290.