User:Ambience/Warfare

This project aims to create an automated system within the game to simulate a war between two factions.

Steps to Completion
The sub-elements of this project will be as follows:

Asset Ownership/Presence Change API
To even begin to script a war scenario, we need to be able to change the ownership of an asset if another faction captures it. We also need to make a system to actively change the presence of factions involved in this war throughout the map. These things will be done by adding a set of LUA commands to change the owner of an asset (unistate, short for universe state). Such commands will be as follows: Current commands such as those in the planet.whatever tree will likely need to be changed as well to account for this.
 * unistate.changeFaction(p) will change the owner of the asset
 * unistate.changePresence(p) will change the presence of an asset

uni_state.xml
To keep track of active ownership and presence changes, the state of the universe will be loaded into a list stored in memory during the game that will be saved into the game save file upon exit. Format:

Upon game quit the contents of this file will be appended to the user's game save file. Upon game launch the universe will be altered upon load.

The War Script
Once the LUA api functions are implemented, it will serve as the groundwork of a large "war script" that will be updated once in a short interval.

Script Outline
The "war" would start by an event (player triggered or not). This would begin the first "turn", which would last for a set amount of game time.

At the beginning of each turn, for each system with presences for both factions, the game gets the current presences from  each faction, and adds a small amount to each system that has both  warring forces.

Then, the turn is calculated. The formula for how much presence each faction loses (this can be changed) is as follows: where random is a random decimal between 0 and 1. This gives a bit of risk-style randomization.

This number is then subtracted from the current presences for both factions, and that is stored as the new presence. The asset capture formula (this can also be changed) is as follows: This is the multiple of presence needed to capture an asset owned by the enemy. For instance, if there are three enemy planets in a system, the attacker needs to have a presence 1+3/(3-0)=2 times as much as the  defender to capture their first asset.

This cycle repeats until a truce is declared (player triggered or not), or one faction is wiped from the map.

What do those equations do?
The equations above represent a way to manipulate presence in a way that simulates war. If you feel that the equations need modifying at all, leave a message on my talk page.
 * Equation 1 calculates the presence lost from a faction this "turn". The equation should be based off of the ratio of presences between the two dueling factions, and should have a faction of randomization to it so that no war happens the same way twice.
 * Equation 2 calculates the ratio of presences needed to capture a planet from another faction. It should be dependent on ratio of presences, how many planets belonging to the two factions that are in the system, and how many planets each faction have already captured.

How long is a cycle?
A cycle should be a relatively short period of time, probably around 5-10 seconds. This should be optimized with Equation 1 so that the typical system capture sequence takes around four or five minutes.

Current Progress
As of 3 February 2014, I am almost through with the file interaction part of the code. Next I will be working on actually having the game change the ownership of the planets.

Links

 * Code (GitHub)
 * Forum post