Caching the data

Core Design

Atlas in detail

Script example:

Code: Unit_infantry_brigade = { -- Division Type Comp_Default = { -- "Country" (DEFAULT, NATO, WP, country tag..) "infantry_brigade", "infantry_brigade", "infantry_brigade", "StdSupportUnit", nil }, Comp_NATO = { -- NATO "infantry_brigade", "infantry_brigade", "infantry_brigade", "infantry_brigade", "StdSupportUnit" }, Comp_WP = { -- WP "infantry_brigade", "infantry_brigade", "infantry_brigade", "infantry_brigade", "StdSupportUnit" }, Comp_StdSupportUnit = { Default = "artillery_brigade", } },

Welcome to a new development diary for East vs. West. This time, we’re going to introduce you to some of our new designs around the AI. The new core of the East vs. West Lua-AI, which is the Rucksack we’ve named Atlas.Like the mythological figure (wikipedia link) , it has the really titanic task to hold the “Lua-celestial sphere” of the game. Here we store all the repeatedly needed data that will be reused and continually referenced for several major tasks undertaken by one country or between countries. The aim for the AI is “bigger, better, faster, and more everything”; more accessible, more intelligent and easier to mod. Welcome face to face with a true titan, “Atlas the Rucksack”.East vs West has many new features which have lead to an extended Lua-AI. More features means that there is a bigger need of CPU power, so we thought about how to counter this with improved code design not only in the .exe file, but also in the Lua itself. We came up with the idea of a container (the rucksack), that caches all information that the Lua will have to query the exe for. Generally speaking, each .exe request you do within the Lua will slow down the game. So caching the data reduces the burden of these requests. For the purpose of optimizing memory, we don't keep a shadow copy of all static data from the exe in the Lua. We lower the overall RAM required from your computer since we just make sure we have the data we need, when we need it – smoothly and quickly.The game engine is based on Hearts of Iron III Causewitz, with many added features. Regarding the Lua code, we have completely dropped the old scripts and wrote all new ones. HoI3 only needed to cover roughly 12 years of game time; in East vs. West the Lua must cover a timeline that could potentially last 45 years. So things that worked for HoI3 (like heavy usage of country-specific scripts linear scripts) would not be a wise choice if you have to cover a four times the number of years for around 260 countries. Instead, we implemented a system based on the idea of the Pareto principle (also known as 80–20 rule). The main functions should take care of nearly all situations. If needed, we can still use the country specific files for rare exceptions or for situational Mods.“Atlas the Rucksack” will feed this core function with the needed data and also serves as a cache memory. It also contains the helper functions to feed other Lua functions and some basic data, like the different build compositions for army divisions.Sometimes the Lua-AI may need to ask for data from other countries if we want it to react better to unusual player activity, such as trying various ”exploits”. We wanted to reduce the exe Lua communication to a minimum at the same time, so we set up the rucksack functions that way, so we can easily use these functions also for other country tags and refresh that data from other countries as well within our own countries cycle. The Lua "ai_rucksack.lua" will hold the code to query the exe and can be called from other Lua functions if the needed data is empty, if the timestamp is out of date or we have an urgent need for „superactual“ info (for example in case we get into a war).This data is stored in global tables and accessible for all other Lua areas of the game. We can now get more detailed info of other countries without the need to query the exe again. So each country’s Lua code works all the time with the global rucksack created tables, and all without the need of another call of the exe. There are a few exceptions which will need different treatment, like the ai: post commands used to build units. But these will be executed in the end of each game tick and only if, in this case, a unit build is initiated, so that is no big issue in the long run.As a result we have reduced the exe Lua communication to a "maximun minimum", as with each game tick all the needed data is only requested once, and some of that data can be used for several days without needing to be refreshed.Below is a diagram of a rough comparison of the two designs. It easily shows where the Lua exe communication was minimized in order to make. In addition to this, not using country specific files reduces the communication between Lua and the exe again.What you can’t see is that the Lua communication between Lua functions as such is also reduced as much as possible. The usage of subfunctions was minimized, due to the way how the Lua language is designed and to maximize speed gains.So, each function should be as straightforward as possible without the need of checking many subfunctions. Also the code as such we’ve kept in pretty simple syntax in most cases which we believe will make it easier for modders, and beginners should have an easier time if they choose to start experiment with Lua scripting in East vs West.This is an example of one of the tables we use in the Rucksack.It is from the „BuildsTable“ which contains entries for the Divisions/Ships/Planes.Below is an example of how an Infantry Divsion can be designed for the AI.You can of course add your own template in here and the production AI will check for your faction or country and build that type of Divsion with the composition you put in here.I hope you all enjoyed this outlook and stay tuned for more amazing news around this game made for gamers by gamers as we move towards the Beta.- (Politics and Lead AI Developer)- (Game Design)- (Game Design)- (Hardcoding)