Developer Diary 14

This developer diary was first posted in the M&T forum here, and team members answered some questions in the thread. It was further posted on the M&T subreddit here, and team members also commented there.

Dev Diary #14 - Diseases
Hello all, I am ShirokumaCoffee and I'm proud to be the newest member of M.E.I.O.U. and Taxes.

Before anything, I want to tell everyone that M&T 3.0 has come a long way over the past few months and if there were not many dev diaries, it was mainly because the team has been hard at work on features and pushing forward with 3.0 development. Expect a couple of consecutive dev-diaries in the coming weeks!

We also post teasers every now and then in https://discord.gg/kDJn3d, our official discord.

Today, we are going to start nice and slow with something everyone is at least somewhat familiar with, especially in these peculiar times: diseases.

The 2.52 Plague system has gotten quite a rework for 3.0. This is the result so far of a long lasting work that started with @DuckTapeMan bringing the concept of SIR model (see below) and went extensively through @FireKahuna before reaching my hands. The entire team has helped with ideas, historical research and so forth. So, let's start!

Firstly, there isn’t just one generic ‘Plague’. 3.0 has a way more complex disease system, which includes, for now, Bubonic Plague, Smallpox, Salmonella, Typhus and Malaria.

Secondly, the new disease system has a calculated Susceptible-Infected-Removed-Dead (SIR) mathematical model. In a nutshell, the model is based on a susceptible population (Susceptible), out of which a percentage gets infected (Infected)... and these infected either get cured or die, which both cannot be infected again and no longer participate as an active population for further spreading of the disease (Removed).

Here are three pictures of the SIR model in action:



Each province has a base susceptible population based on several factors such as terrain, population density and immunity. Once a disease reaches a province, the amount of susceptible people decays over time. This is to represent the nature of some people avoiding infection, as well as the limited lifespan of some diseases’ transmitters.

Every province tracks each population’s immunity or resistance to a disease. America for example starts with 0 immunity to every disease endemic to the Old World. The disease spreading chance through land includes physical land size, and that can double the spread if the province is extremely small, making a double jump at once. Trading spread is somewhat limited to connected trading centers and ports.

Immunity is the main factor that decides the potential of how fast and far a disease can spread and the death rate that occurs. The more people die or get infected, the higher the resistance to that specific disease goes in that province. The main goal of the 3.0 system is stepping away from the idea of forcing severe random diseases and letting diseases be handled by resistance and immunity.

1356 starts with every province having a fixed starting immunity value, but then each can have a different fate in every different game start. Immunity decays over time, so a province that hasn’t been hit by a disease in many years can lose its resistance to that specific disease and if infection comes, the aftermath can be disastrous.

Beyond immunity, other factors for death rate and infection percentage are life quality (see DD#9), population density, terrain, environment, temperature, amongst others.

Each province in the game has a hardcoded chance based on, again, many factors (temperature, density, sanitation, life quality, immunity, some historical animal infested places / malaria) to spawn each type of disease throughout the game. We also have non-hardcoded elements that increase the chance of spawning, like if the province is under siege or at war, devastation, if it was looted, etc.

In the case of Malaria, places where the Anopheles mosquito (responsible for the spreading of the disease) cannot live won’t have a chance of spawning it. Another example, sub-saharan Africa didn’t have smallpox until the Portuguese brought it there.

Now, regarding the cases where a disease is nonexistent until some external agent brings it in, this system allows us to do some cool stuff.

Let’s consider Malaria in the New World which was introduced by the Europeans. The 3.0 Disease system allows for a situation where if a Colonizer conquered or colonized a tropical province, if that colonizer owns provinces where the Anopheles mosquito currently lives and reproduces itself (for example England and the eastern marshes), they will bring the Malaria mosquito with them making it so that that tropical province is now an infested Anopheles place that can spawn and spread malaria to its neighbors. If the colonization happened in Canada, because of the inhospitable environment for the Anopheles, this wouldn’t happen.

If the tropical case happens and gets Malaria, spawns an outbreak and spreads, all provinces that become infested by infection and contagion and are a hospitable environment for the mosquito will become a permanent living place for the guy as well. The spreading will be systematic throughout the entire continent. In a few words, If the mosquito can live, it will start reproducing there and then the province becomes a potential Malaria nightmare.

Another cool thing this system allows for is more realistic and different types of spreading scenarios. Some diseases can travel internationally through trade, like the Bubonic Plague, while others like Typhus are more concentrated in certain regions. We can adjust spreading rates, spawning chances and each disease acts differently depending on the environment, landscape and population density. A disease that spawns in a very remote low-density province will likely only have a minor impact, while one that spawns in a high-density trade center can wreak havoc around the globe.

This system does not deal nor aims to represent exceedingly small outbreaks that lead to only 1% of the population dead in just one province, like a minor Influenza case. It may happen because the system allows it to happen, but it is not the target.

Lastly, as a small note, I want to mention that while this may sound super performance heavy, special measures were taken to make sure it isn’t and the player should not notice any performance differences between when plagues are active and when they are not.

So, with all that said, I leave you with a video. The first part of the video is a demonstration of the Bubonic Plague spawning in Paris with the entire world having 0 immunity to it. Note that this is a mere example/demonstration and it would never happen inside the game.

The second part is more realistic, as in it’s a scenario that can very well happen during a regular game. Every province is set up with 50% immunity. The result is that the disease is more like a regional outbreak, that has a much tougher time spreading and eventually fades out and dies.

For clarification, the province modifier being present does not mean that the disease is still active, infecting or killing, it’s only for display purposes, for the player to see what is left behind. Diseases are coded to infect and kill as fast as they did in the past. (e.g. The Bubonic Plague does its job in maximum four months).

Lastly, diseases are so dynamic and random not only in spawning but spreading, that it’s almost impossible to have the same outcome twice. Every time I recorded I was achieving different results. Sometimes diseases are just unlucky with their spawning places, or just unlucky when infecting and trying to spread to other provinces. If a disease just manages to spread with its last impulse and driving force and reaches a dense trade hub like Alexandria just before dying, a butterfly effect can happen and kick off a large second infection wave. Nothing is fixed or set in stone.

Youtube link to Bubonic Plague video

To be transparent about the performance of 3.0, this footage was recorded real-time running on an i9-9900k from an SSD, with all 3.0 mechanics and scripts running in the background. The lag is concentrated in January, as that is when we run all the main systems such as trade, economy and politics.