Central Economy setup for custom terrains – DayZ
Overview
This page describes basic steps to get a custom terrain working within the Central Economy system in DayZ.
Requirements:
- DayZ and DayZ Tools package installed.
- Have a working custom terrain (mod) files, binarized and packed into pbo.
If you want to see an example of a terrain, I highly suggest you to take a look on a terrain sample in DayZ Samples package (look out for Test_Terrain) and read more about it on terrain sample page.
Mission files
Central Economy setup can handled within the mission folder if user chooses to do so. One other advantage is that Central Economy works in single-player too, which simplifies the whole process and makes it easier to debug using single-player only diagnostics features, that are available in DayZDiag_x64.exe (more on that at LINK).
But before delving into that, we need to check the basics - mission folder name tells the game which terrain to load.
It is essential to follow this naming convention mission_name.terrain_name.
If you do not know the name of your terrain, I suggest you to take a look into a config.cpp file near your wrp file (name of the class in CfgWorlds).
Mission folder can be placed anywhere on your PC (launch parameter or server config can contain a full path).
Assuming your terrain is based on ChernarusPlus terrain assets, you can base your own mission on the mission files that are available in DZ\worlds\chernarusplus\ce (extracted game data from worlds_chernarusplus_ce.pbo).
This folder contains all default Central Economy files for this terrain.
Copy all of those files into your newly created mission folder.
In order to run a mission, you need to add a init.c script, which is responsible for the mission logic itself (creating playable character, initializing Central Economy,..).
Content of init.c should look like following:
void main()
{
// economy init
CreateHive();
GetHive().InitOffline();
// player creation
vector spawnPos = "3372 0 3090";
Entity playerEnt = GetGame().CreatePlayer(NULL, "SurvivorF_Eva", spawnPos, 0, "NONE");
PlayerBase player = (PlayerBase) playerEnt;
GetGame().SelectPlayer(NULL, player);
};
This simple init.c will attempt to initialize Central Economy and will create a playable character on given coordinates at spawnPos (you can change this vector to suit a location on your terrain and restart mission).
Lets take a quick look at the other files inside the mission folder:
File name | Purpose of the file |
---|---|
db\economy.xml | Main economy configuration file. Allows you to switch on and off init, load from storage, save to storage, respawn for selected groups of entities in CE (dynamic=loot, animals, zombies,..). |
db\events.xml | Dynamic events configuration file. Used to define events such as helicrashes, cars, but also AI presence. |
db\globals.xml | Global variables configuration file. Used to change several variables affecting spawning mechanism, but also global limit of infected and animals. |
db\types.xml | Spawnable types configuration file. Used to define all available spawnable types and limiters of their presence in the world (min, nominal values, tags, categories, flags,..). |
env\.. | Place for all animal and infected territory files. |
init.c | Mission init script file. |
cfgeconomycore.xml | Basic configuration of Central Economy, do not change unless you know what you are doing. |
cfgenvironment.xml | Configuration of animal herd and their territories. |
cfgareaflags.xml | Used to define limiter flags (usage and value) and their names used Central Economy Tool. |
cfglimitsdefinition.xml | Similar to cfgareaflags.xml, but this one in addition also contains definition for tag and category limiters. |
cfglimitsdefinitionuser.xml | User definitions for the limiters, defined in cfglimitsdefinition.xml. Usually allows a simpler definitions such as Tier234 and so on (to save space in db\types.xml file). |
cfgeventspawns.xml | Used to define positions (and rotation) for certain types of dynamic events (helicrashes, car spawns,..). |
cfgplayerspawnpoints.xml | Contains base positions for the player spawn point generation (only for the multiplayer mission). Resulting binary file will be generated into the storage folder during first new-player connection. |
cfgspawnabletypes.xml | Used to define random contents of cargo (inventory) or random attachments for selected spawnable types (defined in db\types.xml). |
cfgrandompresets.xml | Definitions of presets for random cargo or attachment spawning. Used in cfgspawnabletypes.xml. |
mapclusterproto.xml | Prototypes for cluster-type map groups (fruit trees, objects that spawn mushrooms,..). Each prototype contains containers with spawn-points for loot. |
mapgroupcluster.xml | Exported positions of all cluster-type map groups. There can be more of these files (because of a limit on xml file-size). In that case, additional files end with number. |
mapgrouppos.xml | Prototypes for standard map groups (buildings). Each prototype contains containers with spawn-points for loot. |
mapgroupproto.xml | Exported positions of all standard map groups (buildings). |
As you can see, lot of important info is stored in the mission folder.
Before proceeding any further I highly suggest to modify db\events.xml file.
This file is really important as pretty much everything is driven by a dynamic event (including the loot that appears in houses).
Why modify it now?
We are basically using a Central Economy setup from another terrain and trying to fit it on your terrain.
The less we have active at this point, the better.
How to deactivate events?
Open db\events.xml and search for <active> element.
Set it to zero everywhere except an event called Loot.
Running the game
Once the init.c has been changed and dynamic events were deactivated, you can proceed by trying it in the game.
As I have already mentioned, I recommend testing Central Economy in single-player mode.
Here is what you should do in order to run it:
DayZDiag_x64.exe -window -nopause -mod=yourmodfolder -mission=path_to_mission_folder
You can also use DayZ Launcher and select mentioned parameters from the user interface, but it will run the standard DayZ_x64.exe.
Right now, it does not matter which exe file you choose as additional Central Economy diagnostics were not made public, but once they will, this guide will be updated and you will want to use DayZDiag_x64 over DayZ_x64 as default DayZ exe does not have these diagnostics.
Lets take a look on what you should do each time you change a file in the mission folder (except the init.c).
- Make sure the game is not running.
- Do the modifications within the mission files.
- Run DayZ using the parameters provided earlier.
- Once you are done observing the changes and ready to make additional changes, close the game and remove storage_-1.
Please note that storage_-1 folder is the actual state of the Central Economy in your mission.
This folder contains binary files only and their backups (you cant modify them, only the game does) and changes to the Central Economy mission files in most cases wont be applied unless you remove this folder and thus forcing the game to create a new one during the mission init.
Also note that the storage folder may not always end with -1.
In that case, just remove any folder starting with storage_.
Exporting data from the game
Now that you know how to run the game with a proper mission, its time to take a look how to generate key terrain-related data for your mission.
Central Economy can initiate export (usually takes few seconds) of positions for:
- standard map groups (buildings) - mapgrouppos.xml, export is limited to a circle with specified center and radius (set it in a way it covers the whole terrain)
- cluster-type map groups (fruit trees etc.) - mapgroupscluster xml files, export is done across the whole terrain
These files can be generated by executing a following init.c:
void main()
{
// economy init
CreateHive();
GetHive().InitOffline();
// comment/remove following 2 lines when not exporting (can cause further issues if you do this each time you start a mission!)
GetCEApi().ExportProxyData("2560 0 2560", 5120); // standard map groups (buildings) export, terrain center and radius needs to be specified
GetCEApi().ExportClusterData(); // cluster-type map groups export (fruit trees etc.)
// player creation
vector spawnPos = "3372 0 3090";
Entity playerEnt = GetGame().CreatePlayer(NULL, "SurvivorF_Eva", spawnPos, 0, "NONE");
PlayerBase player = (PlayerBase) playerEnt;
GetGame().SelectPlayer(NULL, player);
};
It is essential to call these methods after the GetHive().InitOffline() and not before.
The output of these calls are xml files, which will be stored in storage_-1\export folder.
These should be (assuming they look correct) be copied over to the root of the mission and overwrite the previously available (if any).
After this is done, you can close the game, remove storage folder and remove export lines (or add // to comment them).
After you start the game again, you should see loot the correctly placed where it should be.
Look out for a building to quickly test it (you can change spawnPos of the player character).
Adjusting parameters
Exporting data from the game is just a tiny part of the process.
Adjusting specific contents of the mission files is where most of the work is.
So lets go through several things that you should be keeping an eye on when transforming ChernarusPlus Central Economy setup to suit your custom terrain.
db\types.xml
It is very likely that your terrain will either have too little or too much space for loot (number of map groups - buildings will differ from ChernarusPlus) and thus you will need to modify min and nominal values for each spawnable type.
This is important as it is necessary to prevent Central Economy from getting choked up with the spawn requests (to prevent search overtimes).
You can also attempt to make less or more space by modifying/adding lootmax parameter to map groups and their containers in mapgroupproto.xml.
But be aware that only one piece of loot can end up on a spawnpoint, so essentially number of spawnpoints within a container equals max loot of that container.
Unfortunately, tweaking the values without any feedback from the system is rather challenging, but there will be diagnostics available (as mentioned earlier), which will make this process a bit easier.
cfgeventspawns.xml
As already mentioned, this file contains positions and rotations for position-based dynamic events (cars, helicrashes and so on).
There are several types of these coordinates (depending on the event type) and number of ways you can get to these coordinates, but best is probably to use Terrain Builder to add dummy objects on selected positions and export the selection/layer from TB into txt file - just keep in mind that map frame border should be subtracted so the coordinates match the in-game coordinates.
Once you have coordinates ready for a certain event, you can proceed in re-enabling such event in db\events.xml file.
cfgplayerspawnpoints.xml
This is tied to a multiplayer (server) mission (you cant really test the player spawnpoints in a singleplayer mode).
Nonetheless, you need to prepare a set of spawnspoints first.
Can be done the same way as the positions for dynamic events (mentioned above), coordinates are 2D and after you have them, you can put them into <generator_posbubbles> within the player spawnpoints xml file.
areaflags.map
As already mentioned, this file is optional and it is one of the outputs of Central Economy Tool.
It allows you to limit loot to specific places, where individual standard map groups (buildings) will have usage or value flags assigned based on the info stored within this file.
You should either not have it at all or have your own version as using one from ChernarusPlus mission will definitely not make your life easier.
If you are interested in creating one, I suggest you take a look into the samples package, into the CETool project for ChernarusPlus terrain (LINK) to an idea how does it look like.
AI support
Adding a support for AI on your terrain is perhaps a bit more challenging as it involves already mentioned Central Economy Tool, but samples can help here again.
Take a look at the CETool project for ChernarusPlus (available in the samples package here) to get an idea how that looks like.
Similar CETool project can be created for your custom terrain too.
The tool can export already mentioned areaflags.map, but also territory/zone files for AI.
AI also needs a link created between the territory/zone files and appropriate dynamic events.
This can be done by modifying cfgenvironment.xml file in your mission.
I would recommend to look at default file, used on ChernarusPlus (located at DZ\worlds\chernarusplus\ce or worlds_chernarusplus_ce.pbo).
As with everything else, AI spawners are also dynamic events so make sure you re-enable them once you feel that you have prepared rest of the things (they start with Animal or Infected words).
Default files
Update 1.04 has brought the ability to define default Central Economy files.
Previously, If you wanted to run a mission with Central Economy, all of the files were required in the mission folder itself. This often resulted in un-necessary data duplication.
That is why default files were implemented.
With 1.04, your completely vanilla ChernarusPlus mission requires only a init.c file, rest is taken automatically from a newly added pbo file (for ChernarusPlus it is worlds_chernarusplus_ce.pbo).
Additionally, you can override any file from the default folder by simply putting it into your mission folder on correct place and with correct name.
This feature can be implemented the same way for your own terrain, just make sure you add following parameter into the config:
ceFiles = "yourprefix\yourterrain\ce";
You can also look at the terrain sample to get an idea how the implementation of default Central Economy files should look like.