2010
11.02

Or maybe should I call it The cave’s fire propagation. Even though the cave had no fire, it already had everything needed for it before I start coding TreeBurner. The whole system relies on two item features :

FIRE_EFFECT : this feature represents an item that is sensitive to fire. It has two properties :

resistance (float) : how much fire damage before the fire effect is applied

itemType (string, optional) : item is transformed into this type when the fire effect is applied. If not defined, the item is simply destroyed.

HEAT : the item produces heat and deals fire damages to surrounding items (and potentially itself). Properties :

intensity : how much damages per second

radius : range in cells

The way these features work in the engine is pretty simple :

Every second, an item with HEAT feature deals heat.intensity damages to all items in heat.radius range that have FIRE_EFFECT feature.

Every frame, an item with FIRE_EFFECT feature checks it’s fire resistance. If it’s < 0, the item is destroyed. If fireEffect.itemType is not NULL, a new item is created.

This system was used in the cave to cook fishes. You create a campfire by firing a spark spell on a wooden stick. The campfire has HEAT feature. Then you put a raw fish close to it and after a few seconds, it turns into a cooked fish. If you don’t grab it, it will be destroyed. The item configuration is quite simple :
itemType "campfire" {
  heat {
    intensity=1.0
    radius=1.5
  }
}
itemType "uncooked fish" {
fireEffect {
    resistance=5.0
    itemType="cooked fish"
  }
}
itemType "cooked fish" {
  fireEffect {
    resistance=15.0
  }
}

When I started coding TreeBurner, I wasn’t sure if I could use the same system for fire propagation. In fact, I expected to spend the 4 days working on some cellular automata fire propagation algorithm. It turned out that fire propagation was the easiest to implement, because there was nothing to implement 😀 This was only possible because of the cave’s very special architecture : everything on the map is an item. Well almost, creatures aren’t, although I wonder if that wouldn’t be a good choice. That means trees are items and I can easily turn them into burning trees the same way a fish turns into a cooked fish. Except that a burning tree also produces heat, which speeds up its own destruction but also spreads the fire to surrounding trees.
itemType "tree" {
  fireEffect {
    resistance=25.0
    itemType="burning tree"
  }
}
itemType "burning tree" {
  heat {
    intensity=2.0
    radius=2.0
  }
  fireEffect {
    resistance=50.0
  }
}

Now the best part : buildings walls, doors and windows are items too.  That why I managed to have destructible buildings in a 4DRL. Only the roof is currently a hack and needed another hack to be properly destroyed.

3 comments so far

Add Your Comment
  1. Wow, extremely useful, as always! I’ve been toying around with demo programs with the Google Android phones, and I was thinking about making a firefighter type of minigame. And, lo and behold, you come up with this 😉

    Seriously, very helpful, and fantastically clever, yet simple. I’m totally stealing this for my game 🙂

  2. Yeah that’s a really neat system, and it achieves so much while being so simple! What about the graphical effect, was it simply centered on each tree? Frankly, I thought it was done with cellular-automata-type rules 😛 How about using this for other elements? For instance, items could get frozen, or turned to stone. Although in most cases they probably wouldn’t “spread” by increasing the chance that nearby objects suffer the same transformation… or would they?

  3. The fire manager keeps track of the burning zones and is responsible for updating and rendering the actual flames, using an old school pixel fire trick (the same used in TCOD’s title screen and a simplified and faster version of the cave’s burning title).
    Frozen and petrified things will appear when I start implementing water and earth magic. That’s probably a few years from now (the cave will only feature fire and air magic) 😀