Developer Diary #26 -
Scripts, or, Domesticating the Monster
Scripts, or, Domesticating the Monster
This week's Developer Diary is dedicated to the extensive work that has gone into scripting Magna Mundi. As we are about to lift a few veils, let me begin by introducing myself. I am Lars Maischak, aka Helius, and I am the Script Team Leader of Magna Mundi. I hold a PhD in History, and teach at a state college in California.
While this Developer Diary (and subsequent ones on the topic of scripts) will be informative for all players, especially modders will enjoy seeing some previews of the greatly-expanded potential for making this game into the sandbox of your dreams. Today, we shall start with a broad introduction.
Making Magna Mundi, the mod, into a game in its own right posed some challenges for the developer team. As is the nature of a mod, all our work consisted of scripts. For the benefit of any layperson who may have strayed into this thread, “scripts” are the instructions to the game’s engine, contained in easy-to-edit text files. The “engine”, on the other hand, is the machine at the heart of the game, the hard-coded mechanisms contained in the exe-file – off-limits to modders.
As modders, David, Carlos and I had created several megabytes worth of scripts. Catholic Church, Holy Roman Empire, Barbary Pirates and other sub-systems of the mod each required complex systems of code that used sometimes ingenious, but more often awkward work-arounds to make the monolithic Europa Universalis engine do our bidding.
When Magna Mundi became a game, we acquired access to the source code of the engine. Now, the only limit to our ability to make it do our bidding was the skills of the programmers who set to work on it. From the beginning, the team’s approach had been to make unnecessary the scripts we had so painstakingly developed over the years, by instead having the engine do what the scripts had initially been intended to accomplish.
To give an example, the mod had introduced the concept of administrative efficiency, a mechanic brilliantly abstracted by Alvya more than three years ago that later on was scripted into the mod. A country receives bonuses if its administration – the capability of the ruler and advisors, and the traditions, institutions and policies of the country – is up to the task of ruling over the territory under its control, taking into account the specific challenges posed by ruling over ethnic or religious minorities; and penalties if it is not.
In the mod, a dance of code so complex that it makes the Lindy Hop look like a Viennese Waltz was required. Every so often, all the factors that determine administrative efficiency were invited into a ‘maintenance event’ that happened in the background, away from the attention of the player, where they swirled around until they produced, for every country in the world, one administrative efficiency ranking, each. This event could cause lag on slower systems; and even on fast ones, it clearly took up computational resources that could be used for other purposes, if freed up.
Administrative efficiency became one of the first scripts, then, that was ‘ported to the engine’, if you pardon the use of jargon. What our scripts had done awkwardly and at intermittent intervals, the engine now does elegantly and instantly.
As this example shows, the primary task of the scripting team, at least at the outset, was to make redundant the old scripts, inherited from the mod. Scripts in Magna Mundi Ultimate (all events, decisions, and mission), the last version of the mod, comprised 23.5 MB in 221 files. In Magna Mundi, the game, at the current stage of development, there are scripts of just 12.9 MB in 232 files. This is a sign of tremendous success. While it may sound odd to advertise that we have less voluminous scripts in the game than in the mod, it should be evident from what I said before that in this case, less is more.
For one thing, the sheer numbers mask an important improvements for those on the team who are concerned with scripts - many things that the EUIII engine handled internally are now 'exposed to script.' That means that, while the engine crunches the numbers, the scripts tell it how to do so. Since the engine is more efficient than scripts at pure computation, this means that scripts can get smaller, while getting more things done in the same time.
One example of things being 'exposed to script' that you will know from EUIII is the file common/defines.txt. Here, things like the cost of sending a merchant or missionary, the size of a garrison, and the speed of travel of military units are defined, and can be easily changed by the user.
In Divine Wind, the latest installment of the Europa Universalis series, the file defines.txt has fifty-six entries - that means that fifty-six values in the game can be easily tweaked by the user.
In Magna Mundi, more than four hundred values and factors can be easily adjusted by the user in defines.txt:
More than 400 different values and factors for any player, independent of his skill to just tweak - Here you can check variables affecting different types of combat
The same file, in the section that deals with factions... lots of things to tweak!
Beyond that, formulas that were hidden away in the engine are now out in the scripts, where we can tweak them until the cows come home, or the game is released; whichever happens sooner:
Check here the definition of loans. You can create how many you wish, with whatever conditions you want! Yes, this is Magna Mundi and we WANT YOU TO BEAT US AT OUR GAME: DESIGN IT BETTER!
If you have been following the previous Developer Diaries, you will have noticed that not only have we retained and improved upon all the tried and true systems we had thought up for the mod, but added more content than before. Much of that added gameplay complexity, narrative density, and immersive depth is possible because of this fundamental overhaul the engine has received. And based on that overhaul, the script team has been able to add bells and whistles to the overall experience of Magna Mundi.
In the process, what had resembled Frankenstein’s Monster – a creature cobbled together of many disparate parts of uneven provenance – has been turned into a handsome creature whose coming-to-life, sometime early next year, none have to fear, and many will celebrate.