Getting Hacky with Townscaper

Chris Love
3 min readJul 7, 2020

--

Yesterday I started playing with a new “game”, Townscaper. It’s basically a town building design application from Oskar Stålberg (the creator of Bad North).

I clicked and built and built and clicked. The game is a joy and very relaxing.

However, my mind soon turned to how to procedurally generate some towns and so I jumped into a conversation with Oscar on Twitter.

Having been previously unable to find the save files I set off with renewed vigour to find them. I eventually tracked them down to this directory:

C:\Users\<user>\AppData\LocalLow\Oskar Stalberg\Townscaper

Looking at the results of certain actions in game led to these discoveries. The file is for the town shown here:

The colour of the voxels is 15 for the base, and 0–14 for the 15 colours of building (based on the order in the palette on the left of the UI).

Generating towns is therefore relatively easy if you remember the following steps.

  1. YOU CAN REALLY MESS UP YOUR GAME, PROCEED WITH CAUTION. BACKUP SAVE FILES IF YOU CARE ABOUT THEM.
  2. The grid is unknown — we can generate any possible grid coordinate and the game will remove it if it is invalid. However there are limitations to the size of the game world. Try to get a “base” build first that works with just height 1 and voxels of t=15, h=0.
  3. Once you have the base build add a building and the save file will update to the valid co-ordinates. You can then use this as a better base for later builds by extracting the co-ordinates. [Patrick saved one for you — see tweetbelow]
  4. The order of the Voxels is very important, they need to match up exactly with the order of the corners.
  5. Every Corner with count=2, say, needs 2 Voxels (h=0 and h=1) to build it up from the ground. Adding just a h=1 will result in scaffolding.
  6. Don’t worry about parks and cloths lines, etc. These will be generated by the game on load.

Personally I’m a data analyst, not a great coder so I use a data manipulation tool called Alteryx which I have access to at work (I recommend it for the non-programmer to do ANY data manipulation very quickly). However, for a programmer (or even using Excel) it should be possible to knock up a solution to suit you.

I then simply pasted them into a template copy of the save files (and just incremented the number on the save files to add a new copy).

The result? Random Town:

Limitations

The maximum size of the town is limited in the game. It isn’t huge (the town above is the biggest I’ve managed) and so procedurally generating large towns doesn’t appear possible.

Any questions let me know @ChrisLuv on Twitter.

--

--

Chris Love
Chris Love

Written by Chris Love

data, photography, and everything else - any opinions expressed are mine and not my employers.

Responses (4)