Update #23: Procedurally Generating a World's History

At the request of fans above is a short-ish video demonstrating the feature we're talking about and below is a more detailed write up.

How do you make a procedurally generated world feel lived in and alive?

No really, I’m asking, because I don’t know. :-)  

Well, maybe I have some ideas...

I’ve been working on the game for just over 3 years.  About a month ago I ran into a significant problem with the world generation.  It got us this far, but it was becoming clear it won't work long term.

I started the game with the idea of “reverse generation”.  A character wants a MacGuffin found.  This creates the need for a place for it to be lost in.  We would then generate the place, it’s history, and supporting narrative for that place.  I was inspired but how Just In Time compilers compile only what they need when they need it.  It is very efficient, no wasted space or data.  Only generate what is needed when it is needed.  This works really well except for a few fringe cases I just couldn’t solve.

town approach.jpg

For instance, generating a family backwards is conceptually really hard to get right.  Take a woman running the mage shop.  The player asks about her parents.  She says she doesn’t know her father but her mom lives in the same village.  Now, clearly, she had a father or wouldn’t exist.  Perhaps she was the result of an illicit affair.  But with whom?  Given her age we have to backwards generate who was in the village 33 years ago and begat her.  Then if the narrative generator decided her father was actually still alive, we’d have to place him somewhere in the world.  This becomes a family secret (I have a daughter I have never met) the player could learn and reveal, perhaps to the elation of the mage shop woman.

If the father died, when?  And why?  Most games don’t care about these details, but it is precisely tracking and knowing (at least internally if not externally shown to the player) that makes Archmage Rises special as a living breathing world.  I can’t just throw up a curtain and ask the player not to look behind it.

The above scenario is much easier to do forward:

A woman and man of roughly the same age are in the same town.  Say the woman works in the fields and the man is a travelling trader.  The romance engine can cause sparks between these two NPCs and the result could end up being a one night stand.  Sex has a percentage chance of leading to pregnancy (instead of tracking menstrual cycles for every female we simply roll an internal d20.  We won’t disclose if pregnancy is the result of a critical success or fail).  The simulator continues as normal: The trader continues on his regular work route.  He may end up being killed by goblins, captured by bandits, or simply changing jobs and living somewhere else never aware of the consequence of one night of NPC d20 passion.

This was a small example, but the issues become larger when applied to a whole town with armies and battles.  So there was nothing to do but bite the bullet, pivot, and rework the generating engine.

So far, so good.


Good Artists Copy, Great Artists Steal

When looking for ideas, rules, even roll tables for kingdom generation I came across a Pathfinder supplement I forgot I owned: Ultimate Campaign.  Of the 258 pages a good quarter of it is dedicated to rules on founding, managing, and growing kingdoms and the mass combat that flows from kingdoms in conflict.  It is a great resource to study for my immediate problem and something I plan to utilize in my next house D&D campaign.  It even has color cut out buildings to paste onto a town grid as the players build them!  Never seen that before.

Ultimate Campaign was ultimately helpful.  I took their core concepts and translated it into what Archmage Rises needed.  Below I’ll explain some of the crunchy bits going on behind the scenes.

Lord Mayors

A town is run by a Lord Mayor (formerly I called them nobles).  A Lord Mayor has a personality type and goals that are civic, economic, or military minded.  Diplomatic relationships between towns are personal: it’s Lord Mayor to Lord Mayor.  Decisions are made by the Mayor.  If there is a spat between them it could lead to all out war.  Conversely, if they get along well, their towns help each other out.  Events and the player can affect the relationships between mayors.  It’s cheaper for a mayor to be killed through assassination by an adversary than all out war, but you wouldn’t want to do that would you?  Of course not!

Lord Mayors can lose their jobs through peasant revolts, and a new leader (usually from the nobility) will be installed in place.  The player can affect peasant revolts and know ahead of time who is most likely to fill the vacant position.

Town Stats

The next most important aspect of a town is it’s “stat block”. 

Economy – how open, powerful, lucrative, and far reaching the town economy is.  Economy drives Build Points which is the residual “stuff” used to build things

Order – While it does represent law & order, it is not just how enforced the law is by constables and guards but the citizens themselves.  It is also how organized a town is in maximizing it’s resources and working together.  The opposite of Order is chaos or anarchy.  The player can do things to increase or decrease Order in a town.

Military – How powerful, well trained, organized, and well led the military units are.  Building a barracks, town walls, or a castle increases military.  When something requires force, a check is made against the military value.  For instance: a town is in revolt.  Can the Lord Mayor stay in power by having the soldiers quell the rebellion?  A military check determines the result.

Unrest – expressed as a percentage it is the different between Unrest points and Order.  Once Unrest passes 50% Unrest Events can begin happening.  One obvious one is a peasant revolt.  Many things can lead to unrest: starvation, being attacked by town or monsters, or player actions.  Players can be agents of chaos throughout the land, but you wouldn’t want to do that would you?  Of course not!

Build Points – A representation of how many resources are at the towns disposal for taking actions.  Actions can include building new buildings, recruiting armies, passing an edit, special holidays, sending out trade caravans, and more.  Nic has pointed out we already have a currency, gold, so why not just use that?  OK he wins, we will.  But for now it uses Build Points because Pathfinder did and the numbers are smaller.

Consumption – as the population increases the drain on the economy increases.  This is called consumption.  A large town may have many buildings and resources but be breaking even because of a high consumption.  Consumption allows a town or player to undermine a large town by cutting off it’s food/resource supplies and watching.


Town Demands

With the lord mayors in place, leaning towards civic, economic, or military agendas it was time to test the world history.  Every 40-60 years a mayor would die of natural causes and be replaced by a new person with a new agenda.  Unfortunately the government ran about as effectively as the US.  A military minded mayor would single mindedly build a castle, walls, and moat during his tenure then watch as the town starved itself to death and fall into anarchy.  Only a crazed roman emperor would be so detached from the needs of the people.  Something had to be done.

Sim City 4.  The good Sim City.

Sim City 4.  The good Sim City.

I was inspired by Sim City where demand builds up in RCI.  While not the same, the idea is that people and buildings create demand for different types of buildings/actions in one of the three types: Civic, Economic, and Military.

So while a mayor may be military minded, if the demand for civic is at a critical threshold he’ll do something about it.

This leads to a much more balanced government and though simple, provides a lot of opportunity for interaction with the player to affect how a town behaves.

Great People/Events

Over time great spells will be discovered, breakthroughs in schools of magic will occur, powerful weapons or artifacts will be forged.  When these happen, a new “treasure” is created that now exists in the world and can be found by the player.  Like how Raistlin had Magius’ staff centuries later, so to it is possible for the player (or rival adventurers) to hunt down these powerful artifacts.

Wars and Rumors of Wars

Towns can recruit armies to defend themselves (ya right) or to smite their enemies (more likely).  When a town is attacked (by civilized town or monsters) it will take damage and lose population.  This creates a rich history to the town where you can see the result of their triumphs and defeats.


How Does This Make a History?

All of the above goes into crafting a world with history of over 1,000 years.  Totally unique to each player and each play through.  We do have a loose grand narrative it adheres to, but the specifics are always different.

Time passes in months, years, or decades.  There are reasons some towns survive and thrive and others fail miserably.  People go about their jobs, monsters do their monstrous things, armies battle, and mayors try to govern it all.  All the points of conflict and interaction are tracked creating a world of color and depth.

I’m still working on the systems and AI involved in all the above.  It is mostly working but I still have to get the monsters in.  Then I have to test it by simulating millions of years of history.

All this should lead to a game world that feels real.  Just like at the tabletop.


Oh, and if you are interested in the background/lore to the magic system this thread on Steam may be of interest.