Diving into WOOLLY FIRE's grid system
Hi guys, Pierre here.
I wanted to talk about the way i developped our grid generation tool during the Jam 51. Nothing revolutionary, but I’m sure it will be interesting for some. But first of all, I need to pitch the game since most of you didn’t test it :
A fire has start in the countryside and your job is to manage the firefighters response. EVERY TEN SECONDS, the fire will grow and try to spread through the grid. Fill your trucks and send them on the firefront. Try to understand how the cellular automaton works
(Play and rate us here: https://ldjam.com/events/ludum-dare/51/fires-away)
OK, so let’s start with our grid system with a bit of oubviousness A grid is a group of connected cells. Those can be the same (like in chess) and be seen as physical container that can be fill by a pawn, an agent or a unit (or whatever, name it as you wish). But it’s not the case in our game, every single cell has in reality a ‘cell type’ that influence the behavior of fire in it. For instance, a wheat cell burn faster than a forest cell, and water cell just can’t.
In the curent game, there are 5 different cell type : Forest, Plain, Village, Water and Wheat. Each of these have an interest in the game. Plain is kind of the base type, Forest and Wheat are reskin with diferent fire propagation values that make fire slow or speed up. Water refill the tanks in the next cells and villages are a losing condition. I won’t dive into details because it already a long post and I didn’t even start to talk about texture.
So ! We want to have a grid containing cells but each of them is one of the 5 types we just saw. We could just create 5 prefabs and smile to the level designer and say : « Your turn to place the 256 prefabs ! Good luck ! … And do it well otherwise you’ll have to iterate :D ». But we’re not this kind of person, obviously not. We actualy are the rock of the team, the one without nothing could be done, the all mighty programmer and it is time to be merciful.
In order to ease their job, I personnaly thought about texture almost instantly. What are texture if it’s not a grid of pixel having each a diferent type (i mean color) ? I paired a cellType with a color, made my very best piece of art in microsoft paint and loop through every pixel comparing the color of it with the types color. If match then cellType prefab instantiation ! Et voilà ! To edit your level, you just have to edit the texture.
In out game, each cell has an ‘int’ attribute to discribe the fire state (0 = normal, 1 = low fire, 2 = medium, 3 = high, 4 = burnt). So i used the same technique and paired a fire state with a color. I created a second texture and job’s done.
The more I look at my code, the more I feel inconfortable. But it’s a jam, that’s OK, i’ll share it (if you copy it, please make it clean) :

NOTE : - when you import a texture, you have to enable the READ/WRITE to be able to read the pixel value. Anyway, if not Unity will return you an error. BUT it won’t let you any advice if you let the default parameters for COMPRESSION and FILTER MODE. Deactivate them otherwise the engine will try to smooth your texture and it will modify you pixels color.
for the fire state, i could have used a RGB chanel wich is already an int. That should saved some memory, but since there are 5 states, I chose to ease the color differentiation while editing the texture and saving others time instead of 5 Vector4 in the RAM.
To create the diferent cellTypes, FireState, etc. I used the ScriptableObject tool. This allow you to create preset for non MonoBehavior classes and structures in the editor. I won’t dive deeper into it, bur I recommand you to learn, practise and master this tool. Here is what it looks like :

Thank you for reading, I hope this would help someone.


