The Democracy 4 Modding Guide

The Democracy 4 Modding Guide

Basics


The Democracy 4 Modding Guide image 1

The Democracy 4 Modding Guide image 2
The Democracy 4 Modding Guide image 3

What can be modded in the game?Democracy 4 is certainly a complex game, and coding and designing it was no easy task, but actually, modding the game is surprisingly easy. Almost all of the simulation elements within the game are loaded from simple text or csv files, which can be edited using any (free) text editor or spreadsheet program. You don't need to download any SDK, learn any languages or install any software. Anyone can mod Democracy 4, even if you've never done any modding or scripting of a game before. You can add new countries, situations, dilemmas, policies and more, using nothing more than a copy of windows notepad (or similar). You may need a graphics program to create any new icons for your policies though...

The basic modding principlesDemocracy 4's simulation engine is based on a neural network. This is a computer simulation designed to work in a similar way to the human brain. Pretty much everything in the game is simulated in the same way, such as a voter, a group of voters, a policy or an event. All of these 'objects' are connected to each other by 'effects'. So an object might be 'IncomeTax' and an effect might be the link between IncomeTax and the happiness of the middle class voter group. The objects and effects in the game are not hard coded, they are all loaded in from 'csv' files, which can be opened in a text editor, or more conveniently by a spreadsheet program such as Microsoft Excel. You can edit these files, and save them, then start a new game and immediately play with the changed simulation.

CSV FilesYou will find the majority of the CSV files for the game inside the games \program files\democracy 4 \data\simulation folder. the names should be pretty self-explanatory. The most interesting one is probably 'policies.csv'. You should be able to open this up directly using Microsoft Excel. If you edit and then save this file be SURE that it gets saved out as a CSV file, if you let the file format change in any way, it will be unusable by the game, and you will need to start again. For this reason, always back up any files before you edit them! The CSV files for the game all have the same format with a line that starts with '#' indicating that this is an object that should be loaded into the game. Any line without a starting '#' is effectively ignored, so can be used as a comment, to help you organize things.

EffectsLooking at the policies file, you will see a whole bunch of columns in there that load in various bits of data, but towards the end of the list of columns you will see the 'effects' for that policy. For clarity, the effects are denoted as any column to the right of the '#effects' column, and there can be as many there as you like. Some policies have a few effects, some have many, but each effect entry takes up one 'cell' and has the same format which is...

[target],[value1][operator1]([value2][operator2][values3])[operator3][value4],[inertia]

Now this may be confusing because [operator3][value4] is entirely OPTIONAL, and not often included. Lets look at an actual example,. which is the second effect in that spreadsheet, and represents adult education subsidies first effect. it reads...

Education,0.04+(0.04*x),4

In this case the target of the effect is Education. because the effect is an output coming from a policy, the magic value 'x' gets substituted with the current value of the slider for AdultEducationSubsidies.The final value gives us an 'inertia' of 4 for this effect, meaning it averages out over the last 4 values of the slider (in other words it takes up to 4 turns for any slider changes to fully take effect on Education). So let's say that the AdultEducationSubsides policy has been consistently set to 0.5 for 4 turns. What would the value of the effect be?

Final Effect = 0.04 + (0.04 * 0.5) = 0.06

In other words, with the slider at 50%, we are saying we want a 6% boost to the value of our countries education, coming from the AdultEducationSubsidies policy. This is not the *whole* story, because as this is a government policy, that final value might be a bit lower if the policy is not fully implemented yet, plus it may be tweaked up or down slightly depending how competent your minister for public services is, but the principle remains the same. So what happens if we add in those optional extra values? lets look at that, along with another special ability we have, which is to reference another object from the game, for example another statistic: 'Technology'.

Education,0.04+(0.04*x)*Technology,4

In this case, the equation is entirely the same, but we end up multiplying the bracketed result by the current level of technology. like everything in the game, we can assume that the value for Technology is between 0 and 1. This lets you scale the effectiveness of a policy on the level of another value, and it is used in various places especially Taxes, where the income from alcohol tax is dependent upon the current level of alcohol consumption, as well as the slider for alcohol tax itself. To be absolutely clear, I'll add some brackets to show you how this last bit is calculated:

Education,0.04+((0.04*x)*Technology),4

You don't have to just have + or * as your operators, you can also use - / and ^. ^ is 'power', and is used to generate a lot of the fancy curves that make some of the equations so interesting. I recommend playing around with the free 'graphcalc' program to see the exact effects you can achieve. Get it here.

Installation and PreparationEach mod is basically a folder containing subfolders that mirror the folder structure of the base game. The folders all sit within a master mod folder in \my documents\my games\democracy 4\mods. (This location is different when steam workshop installs the mod).

Almost any folder within the default install of the game can be mirrored to a mod folder, and the game expects to find each file in the same place it would in the main install, so any non-vector graphics inside 'data\bitmaps', the main spreadsheets are inside 'data\simulation' and so on.

A special mod file will exist inside each mods folder called config.txt stuff in this format:

[config]

name = rural internet subsidies

path = C:\Users\cliffski\Documents/My Games/democracy4/mods/rural_internet_subsidies

guiname = rural internet subsidies

author = cliffski

description = the rural internet description

This is the file that the game looks for, and reads to gather information to display to the player in the games mod control panel:

Translated textAll of the text that is display to the player is located outside the folder structure described on the other modding pages. To isolate the text to make it easy to provide translations for a mod, the human-readable text is within folders found inside a 'translations' folder for each mod. These file exactly mirror the data inside the translations folder in the main game.

Policies

Modding New PoliciesPolicies are basically just a line in a spreadsheet. In this case that spreadsheet is in \program files\democracy 4\data\simulation\policies.csv, and each row that starts with a '#' in the first column becomes a policy that gets loaded into the game. The key to adding policies is to understand what all those columns do, so here is a breakdown of each one, and what it means. I'm using the titles for each column taken from the very first row to describe them...

NameThe Name is the word or words used to reference this object internaly within the game by other objects. This is never shown in the game.

Sliderif set to 'default' then the slider for this policy has no specific features. If set to a name, this name is used inside 'sliders.csv' to select a bunch of names for the different slider positions, and optionally to 'clamp' them to a series of fixed options.

FlagsCan be blank, or one of a number of presets. UNCANCELLABLE means the cancel button is greyed out and the policy is always implemented at 0.5 strength unless specified at a different level. MULTIPLYINCOME means that when determining the amount of income generated by the policy, the various inputs to the income get multiplied rather than added (see below).

OppositesComma-separated list of the names of policies that conflict with this one. They should also list this policy in their opposites. This ensures that any conflicting policies are automatically cancelled when this one is implemented.

Introduce,Cancel,Raise,LowerThis is the amount of political capital required to introduce this as a new policy, cancel it, and raise or lower the current slider level once it's implemented.

DepartmentDecides which 'zone' on the screen the icon for this policy will appear in, which category on the new policies screen it will be listed under, and also which cabinet minister will be in charge of the policy, and thus affect the efficiency with which it is implemented.

PreReqsValues that *must* be true if this policy is to be available to the player. This can be any entry found in the file \democracy 4\data\simulation\prereqs.txt

MinCost, MaxCostThese show the cost of the policy per turn at a level of 0 on the slider and at maximum on the slider. This is a fixed value, which then gets multiplied by a set multiplier for each country (specified within the country file) and then adjusted for ministerial competence to get an actual cost for this policy (This is then adjusted by the next column...)

CostFunctionThe equation determining how costs are calculated, at a base level. Best to leave this at 0+(1.0*x) to get a nice smooth linear increase in cost as the slider goes from 0 to 1

Cost MultiplierA series of inputs, separated by colons, which determine how we get a 'cost multiplier' for the policy, which is a value by which the final cost of the policy is multiplied. Each entry in the list is either _default_ and a set value or it's an actual effect, as specified here.

ImplementationHow many turns it will take for this policy to be fully implemented (or cancelled). This will be adjusted in practice for the competence of the minister in charge of this policy.

MinIncome,MaxIncomeSame as MinCost,MaxCost but for income

IncomeFunctionThe equation determining how income is calculated, at a base level. Best to leave this at 0+(1.0*x) to get a nice smooth linear increase in income as the slider goes from 0 to 1

Income MultiplierExactly the same as Cost Multiplier, except the flag MULTIPLYINCOME under flags can convert this to be a value where the inputs are multiplied together rather than added.

nationalisation GDP percentageThe value to the player as a percentage of current GDP, credited to the players funds if this policy is cancelled leading to a privatisation, or vice versa during a nationalisation.

#EffectsThis special column marks the start of the effects list (one in each cell) for this policy. These are all 'outputs' from this policy to other items, probably voter groups, situations and simulation values/statistics.

Dilemmas

Modding DilemmasDilemmas are not loaded from a CSV file but from individual files for each dilemma within \program files\democracy 3 \data\simulation\dilemmas. Each one has certain criteria that may cause it to trigger. The dilemmas can be shown again and again, but once triggered will not be eligible for triggering again for 32 turns.

GrudgesGrudges are created by various parts of the game. They are basically a hidden 'temporary' object (although theoretically they can have a 100% 'decay' value which means they last forever...) that can have an effect on another game object. For example, many game events create a grudge which has effects on public opinion, allowing them to have a temporary and fading out value as they drift from memory. The grudges are created by a special bit of 'script' which is used a lot in the dilemma code. A grudge has a target object, a value and a decay, although technically it's the inverse of a decay, meaning that a decay of 0.9 means that each turn the value of the grudge is multiplied by 0.9, so gradually fading out. The higher that value, the longer the effect will last. Here is a breakdown of the data you will find in a dilemma file...

[dilemma]This section loads in a name, used internally by the program

[influences]This is a numbered list of input 'effects' which are calculated each turn to give the 'likelihood' of this dilemma being triggered. The top dilemma each turn is triggered, unless an event has also triggered that turn. For more on how to format an effect see here, although note you cannot use inertia for these effects. The name at the start of the effect here is the 'source' rather than the target (which is clearly this dilemma). So for example this influence:

1 = Health,0.8-(0.6*x)

Says that the value of this dilemma (Chance of it triggering) has 0.8 added to it, then (0.6*Health) is subtracted from it. In other words, the higher your health value, the less chance of this dilemma being triggered. There is also a special class of effect for these influences which is the random influence which is formatted like this:

0 = _random_,0,0.3

What this means is to generate a random number between 0 and 0.3, and add that number to the dilemmas current value. This is to give some random variation to the probability of this dilemma being triggered.

You can have as many influences to a dilemma as you like.

[option0] (and also [option1] and...)These two (or optionally 3) sections represent the options the player must choose from. Each one has a line called 'OnImplement' which is only processed if this is the option which the player selects. This line is a 'script' which is run to implement the effects of this decision. For example:

OnImplement = CreateGrudge(Health,-0.05,0.9f);CreateGrudge(Liberal,0.10,0.9f);CreateGrudge(Parents,-0.06,0.9f);CreateGrudge(Obesity,0.05,0.9f);

The script is almost always just a string of CreateGrudge() statements separated by a semicolon. Each of these calls creates a new grudge with the given values. For example:

CreateGrudge(Health,-0.05,0.9f);

This creates a new grudge that is targeted at 'Health'. The two values are the 'effect' of the grudge and it's decay. In this case, the grudge reduces Health by 0.05, but that value is itself multiplied by 0.9 each turn. So a turn after the choice, it will be just -0.045, and so on. You can have a high but quickly trailing off effect, or vice-versa, by fiddling with those two numbers. You can also make those effects positive or negative, and the target can be any named object.

Events

Modding EventsEvents can be found as simple text files within \democracy 4\data\simulation\events. Every text file in the folder is considered to be a separate events. every 3 turns, the 'event manager' will evaluate the chances of every single event happening, and if the highest-scoring one has a value above 70%, it is triggered. The score of an event is based on a number of 'influences' that are effects from other items in the game, and once triggered the event runs a script, which effectively creates temporary effects.

The config sectionThe [config] section of an event has lines for Name and Texture. These are the internal name and the graphic used for display when the player clicks to see details of the event. (we recomend a 512x512 png file anywhere inside your mods 'bitmaps' folder). There is also a GUISound line, which is the name of a sound effect file that will be played while that window is active.

OnImplementThat section also has a line called 'OnImplement' which looks like this:

OnImplement = CreateGrudge(Unemployment,-0.080,0.650);CreateGrudge(GDP,0.030,0.880);CreateGrudge(AerospaceBoom,-0.950,0.970);

This is a 'script' which has a number of 'functions' each of which are separated by a semicolon (;). The functions are always called 'CreateGrudge', and what these do is to create a 'temporary' and hidden object called a grudge, which decays over time, but while it is active, will exert an effect on another object within the game. The Parameters to the function are as follows:

Target Object Name (Internal name for the object we wish to affect...)

Effect value (At the maximum, ie: the start of the grudge)

Decay (Actually the inverse of a decay, so a 0.97 is multiplied by 0.97 each turn. Higher numbers lead to slower decays)

There is no limit to the number of grudges an event can create. Note that most effects create a negative grudge against themselves, to prevent frequent repetition.

The influences sectionThis is a numbered list of inputs into the event, to determine the likelihood of it being triggered. You can have any input into these items, and also use the magic value of "_random_" which then takes a minimum and a maximum value to be calculated each time the event score is evaluated. This is used to add some random variation. See the basic modding intro for more information on the syntax of effects.

Situations

Modding SituationsSituations are rows loaded in from the CSV file found at \program files\democracy 4\data\simulation\situations.csv. Each line that starts with a '#' is a situation that is loaded in and may be triggered. The game will pre-calculate to see if any situations should be running given the situation at the start of the game. From left to right, the different columns of data are as follows...

NameThe internally used 'object' name of the situation, not shown in the game.

DepartmentThis picks which area of the main screen shows this situation

Pre-ReqsThe names of any pre-requisites for this situation to trigger, such as requiring a coastline, or WMD tech.

IconThe name of the file used to display this situation. This is an SVG file (vector graphics) which you can create using a free program like inkscape, available here. It should be inside the mods 'svg' folder.

PositiveA value of 1 means this situation is shown in the game with a green background. 0 means a red background.

Start and stop triggersThese are the values for this situation that conform to triggering a 'start' or a 'stop'. By default these values are all set with a similar gap, but you can set them however you want, although I can't vouch for what happens if they are reversed or the same!

Cost per turnThis is a fixed value spent each turn that the situation is on-going. This crude value are then multiplied by the multiplier value set up in each country's country file to get the final figure applied in the game.

CostFunctionThe equation determining how costs are calculated, at a base level. Best to leave this at 0+(1.0*x) to get a nice smooth linear increase in cost as the situation strength goes from 0 to 1

Income per turnThis is a fixed value earned each turn that the situation is on-going. This crude value are then multiplied by the multiplier value set up in each country's country file to get the final figure applied in the game.

IncomeFunctionThe equation determining how income is calculated, at a base level. Best to leave this at 0+(1.0*x) to get a nice smooth linear increase in cost as the situation strength goes from 0 to 1

Inputs and EffectsAll the remaining entries represent the effects for this situation, but some are inputs which cause the event to trigger (or to stop) and the others are the outputs which represent the impact this situation has on everyone else when it is running. The effects are all inputs, up until the '#' entry, after which the remaining ones are effects. Obviously with inputs, the first item is the source of the effect, and with outputs the first item is the target of the effect. There is support for a special 'default' object, which can be used to set a 'base' level for the situation.

Simulation

Modding Simulation ValuesSimulation values are the blue icons. These are loaded in from a spreadsheet found here: \Democracy 4 \data\simulation\simulation.csv. Each line of the CSV that starts with a '#' is loaded in as a new simulation value. The columns in the spreadsheet all do different things and are explained below:

Name(column B)Used internally as the 'object name' for this value in effects.

ZoneChooses which of the screen areas and policy groups this simulation value is displayed under. This is purely visual so that the player has all of the same kind of data in the same place.

DefaultThis is the initial value given to this object regardless of what other effects may have an influence. Should be between 0 and 1.0

Min and MaxGenerally set these to be 0 and 1.0.

EmotionDecides whether a change in the value is portrayed as good or bad or unknown on the 'changes' graph for showing what has changed since you were elected. This sets a value to red, green or black depending what you select and what direction the value has moved in. Try to avoid any partisan value judgements.

IconThe name of the icon used to display this item. (This is just the central icon, the blue circle surround is added automatically).This is an SVG file (vector graphics) which you can create using a free program like inkscape, available here. It should be inside the mods 'svg' folder.

# (Start of inputs)This column denotes that the columns to the right of it represent inputs into this simulation value. These are then effects added in the standard format, which create a link from other objects feeding into this one. You can have as many as you like, or none at all, and they end at the next '#' entry.

# (Start of outputs)The second '#' denotes the start of outputs from this simulation value, which are basically effects FROM this TO other items, so they are the equations that represent the effect of this value on everything else in the game. Don't forget that can be other simulation values, voter groups, situations, events, anything you like :D.

Countries

Modding CountriesAdding a new country to the game takes some work, but can be done. The countries are folders under the path \democracy 4\data\missions. Each folder contains a number of additional files and information.

File StructureInside the folder for your new country you need one text file and two more folders. The folders are 'overrides' and 'scripts' and the file is called countryname.txt where countryname is the same as the folder. That text file contains the majority of the information for controlling the state of the country, split into four sections called [config], [options], [stats] and [policies].This file should be saved in UTF8 format, so that symbols like the Euro are preserved.

[config]There are a large number of lines in this section which control how the country looks and behaves. Here is a breakdown:

currencyThis is the text used to denote the currency for this country as is used throughout the GUI. See note above about UTF8populationThis is the amount of voters represented by each simulated voter. there are 2,000 simulated voters so divide the countries true population by 2,000 to get this figureeconomic_cycle_startThe global economic cycle works on a sine wave, and this shows the percentage through the route of that sine wave that the missions starts at with regards to the state of the global economy. Experiment to see different resylts. value 0 to 1min_income and max_incomeThe range, in the currency listed above, which voters salaries are distributed between. Makes no difference to the simulation, it is entirely for visual purposes.min_gdp,max_gdpOnly the max works, and it is used as a scalar against which debt is measured to calculate debt as a percentage of GDP, and thus credit ratings. It is probably best calculated by comparing as nations debt against an existing mission nations debt and adjusting accordingly.wealth_modA relative multiplier showing the cost and income of things relative to other countries. All policy costs and incomes and other values are multiplied by this amount. So again, it's best to compare a country to an existing one and pick an appropriate value based on the size of their economy.fx_rate_to_poundSet this to be the exchange rate between this countries currency and the UK pound (GBP).starting_debtThe level of government debt at the start of the missions.nameUsed internallynames_filefilename of the file used to load in a list of first, last and surnames for ministers and citizens in this country. That file can of course be modded.flagsmall flag icon used in some screens. Thgis should be a dds file (or png) found inside your mods 'bitmaps' folder.apathyDefault value. This affects the likelihood of people voting, and should be adjusted based on real world turnout in the country.mapThe filename of an SVG (vector) file that shows an outline map (white color, will get re-colored by the game) of the country. Should be inside this mods 'svg' folder, and can be made using the free app inkscape available here [inkscape.org] GUIDUsed to locate the mission in the list of missions on the choose mission screen.

[policies]Each line in this section is a policy name and it's starting value. There are some 'uncancellable' policies which are always set (like labourlaws) and if their value is not overidden here, those policies will default to a value of 0.5. Any policy listed here is automatically set as active, with the slider set to the given value. It is entirely implemented at the start of the mission, and it's effects should be fully worked-through the simulation at the start of the game. Not that this section also includes any entries from the \data\simulation\prereqs.txt that would apply to this country.

OptionsAny special options that apply to the country such as MULTIPLEPARTIES or COMPULSORY_VOTING.

The overrides filesif you open up the folder called 'overrides' in any of the mission folders you will find a new bunch of text files. This is where you can put files that denote changes to the simulation that take place only for that mission. Each file represents a single override, and you can have as many as you like. The format is as follows:

TargetName This helps identify the effect that you want to change in the game. This is the object name of the target of the effect. There does not already have to be an effect with this combination, it can be used to create entirely new effects between items just for this mission. HostName As above, but this is the target of the effect. Equation Either a new standard 'effect' style equation for this effect (perhaps stronger or weaker than the existing one) or the word DELETE meaning just remove the existing effect. Inertia Inertia that is applied to the given effect.

The scripts filesThis folder contains scripts run at the start of that mission, basically to create grudges. See the 'Events' modding page for more details. The most obvious uses here are to create changes in the composition of voter groups for each country, but you may also wish to start off a country with a GDP boost or cut, or some other temporary or permanent feature to it's economy or society.

Custom Pre-Requisites

The game comes with a list of special hidden 'pre-requisite' values which may be set to 1 or 0 depending on which country is played, or other factors. You can see the list of these values in this file: data/simulation/prereqs.txt

Here are some of them:

0 = _prereq_has_coast

1 = _prereq_mining_industry

2 = _prereq_deadly_animals

3 = _prereq_preindustrialized

4 = _prereq_royal_family

5 = _prereq_land_border

6 = ...

and so on...

These are valuable because you might want to have an event in your mod that is only triggerable if a country has a coastline, and you can add this special value as a pre-requisite to ensure it does not trigger otherwise.

As of build 1.38 of the game, you will be able to add your own pre-requisite values to the game. You simply create a similar named file, in the relevant location in your mod so:

mymodname/data/simulation/prereqs.txt

And enter any new pre-requisite names that you would like. Once you have done this, its then safe to make references to the new names elsewhere in your mod, maybe in dilemmas or events.

Note to modders without english as your first language:

'pre-requisite' basically means 'something that needs to be true for this to happen'.

Source: https://steamcommunity.com/sharedfiles/filedetails/?id=2242250360					

More Democracy 4 guilds