The mechanics of fire.

Started by Zerkuran, January 04, 2015, 08:40:43 PM

Previous topic - Next topic

Zerkuran

Hi there,

I got annoyed lately by some fire spreading at the border of my homezone. So I was thinking of something and asking myself: How does fire work in Rimworld?

As far as I know:
-fire spreads by chance.
-It can only spread if there is something to burn
-Colonist are able to put them out
-rain extinguishes fire
-fire melts down snow
-fire increases heat indoors

Things I don`t know:
-is the overall temperature affecting fire?
-how far can it "jump"? (for example tile 1 burns, tile right next to it (Nr.2) does not, tile next to this (Nr.3) ignite)

Maybe there is more I don`t know. If I miss some facts/mechanics about it please consider to reply. I really want to come up with some strategies, but i think I miss something important to fully understand it.

Utherix

#1
The code for how fire spreads is actually given in the source folder so we know exactly how fire spreads.

Fires aren't effected by heat, but they do emit a ton of heat every 150 ticks. That heat can cause items to catch on fire I believe (that's handled elsewhere).

ticksSinceRoomHeat++;
        if (ticksSinceRoomHeat >= 150)
        {
//Push some heat
            // enough energy to heat up 100 cells by 1 degree for a size 1.0 fire
            float fireEnergy = fireSize * 100.0f;
GenTemperature.PushHeat(Position, fireEnergy);

//Clear some snow around the fire
{
float snowClearRadius = fireSize * SnowClearRadiusPerFireSize;
SnowUtility.AddSnowRadial( Position, snowClearRadius, -(fireSize * SnowClearDepthFactor) );
}


            ticksSinceRoomHeat = 0;
        }


Also, fire will "throw sparks" a random distance. Sparks will attempt to catch an object on fire, whether that be another object in the tile or in a distant tile. Larger fires will throw more sparks
(bigger flame graphic shows this).

I imagine that when a spark hits an object, its flammability % decides whether it ignores the spark or sets on fire. Thats how some object may seem to ignore fire for a minute and then, as they are hit with more sparks, eventually be set on fire.


//Spread randomly to one Thing in this or an adjacent square
protected void ThrowSpark()
{
IntVec3 targLoc = Position;
if( Rand.Value < 0.8f )
targLoc = Position + GenRadial.ManualRadialPattern[ Rand.RangeInclusive(1,8) ]; //Spark adjacent
else
targLoc = Position + GenRadial.ManualRadialPattern[ Rand.RangeInclusive(10,20) ]; //Spark distant


Spark sp = (Spark)GenSpawn.Spawn( ThingDef.Named("Spark"), Position );
sp.Launch( this, new TargetPack(targLoc) );
}


I'm not sure what range 1-8 and 10-20 translates to exactly, but the code above basically says that there's an 80% chance that the fire spreads to an adjacent tile and a 20% chance that the spark is thrown over adjacent tiles.

Zerkuran

#2
Thanks for reply. with your information I did some testing and it seems that the numbers 1-8 and 10-20 are the adjacent tiles numerated.

1-8 are in toal 8 tiles, (X means can sparkle O means can not) with an 80% chance:

XXX
XOX
XXX

10-20 are in total 12 tiles. In my testing I never saw fire sparkles to the outer corners. If we assume they can not ignite we get this with a 20% chance:

OXXXO
XOOOX
XOOOX
XOOOX
OXXXO

So in total we get this spreding behavior:
0 = can not spread, 8 = can spread with 80% chance, 2 = can spread with 20% chance, X = burning fire

02220
28882
28X82
28882
02220

If this is correct we may come up with some strategy to prevent fire from spreading out of control.

Goo Poni

Fire can jump as far as two tiles which means it can go through a wall/door if there are things directly on the other side of said wall or door to burn. Consider that as the wall in between getting hot enough that things start to catch light on the other side of an inferno. Those tiny fire particles that make raging infernos look a little bit cooler are actually the game's method of spreading fire, they're sparks. They're spat at any random tile within two tiles of the fire, there's no secret tidbit of code to make fires try and target other burnable objects to my knowledge. So if you want to build large cremating zones out of dumping stockpiles, make sure that the borders of the zone are surrounded on all sides by a two tile wide floor like concrete.

As for overall temperature affecting fire, I'm not sure what you mean. Do you mean the overall temperature of the environment, like room temperature or outdoor temperature? I think for the most part, fire has to be instigated by something. An inferno cannon. A raider and their box of matches. An incendiary launcher. Molotovs. Lightning strikes. However, fires can start themselves, but at this point something is already way out of the ordinary or is going wrong because in order for fires to start by themselves, room temperature has to rise dramatically to an excess of 200C and you start to break past autoignition points. Things will spontaneously catch fire if the room is hot enough in the first place, which only adds to the temperature further.

Zerkuran

#4
If fire can spread in above decribed pattern and walls can not stop it, then a two tiles wide firebreak can do the trick if we assume that the fire does not start at those. But if they start on the 2 tiles firebreak (e.g. mechs fire cannon) then we need more tiles.

I don`t know the aoe of the inferno cannon but for the Molotov thrown against a wall it has the center ignite and also up to 4 adjacent tiles which would lead to this figure:

0022200
0288820
288X882
28XXX82
288X882
0288820
0022200

So for Molotov safety we would need a firebreak of 7 tiles or more.

Zerkuran

Quote from: Utherix on January 04, 2015, 09:29:28 PM
The code for how fire spreads is actually given in the source folder so we know exactly how fire spreads.

Fires aren't effected by heat, but they do emit a ton of heat every 150 ticks. That heat can cause items to catch on fire I believe (that's handled elsewhere).

How long does a tick take?

Zerkuran

Well, just the moments I try to understand the underlying mechanics of fire in Rimworld I see this in the DevLog:

"Jan 5

    Finished up core of AI optimization for hauling. Massive gains have been achieved.
    Optimized fire."

I hope the mechanic itself won`t be changed.

milon