// If a player is on fire, let them ignite another player.
addHook("MobjCollide", function(mo, mo2)
	if (mo.valid and mo2.valid) and mo2.player
		if abs(mo.z - mo2.z) <= P_GetPlayerHeight(mo.player)
		and mo.player.onfire
		and not mo.player.justbump
		and not mo2.player.kartstuff[k_squishedtimer]
		and not mo2.player.kartstuff[k_spinouttimer]
		and not mo2.player.kartstuff[k_invincibilitytimer]
		and not mo2.player.powers[pw_flashing]
			K_PlayHitEmSound(mo)
			mo.player.justbump = true
			mo2.player.justbump = true
			if gametype == GT_BATTLE
				mo.player.kartstuff[k_bumper] = $1 + 1
				mo2.player.kartstuff[k_bumper] = $1 - 1
				P_AddPlayerScore(mo.player, 1)
			end
			mo2.player.onfire = 2*TICRATE
			mo.player.onfire = $ - TICRATE
			mo2.player.kartstuff[k_spinouttimer] = 2*TICRATE
		end
	end
end, MT_PLAYER)

// Let it be known that a player is on fire
addHook("MobjThinker", function(mo)
	mo.player.onfire = $ or 0

	if mo and mo.valid
		if mo.player.onfire >= 1
			mo.player.onfire = $1 - 1
			mo.colorized = true
			mo.color = SKINCOLOR_ORANGE
			mo.frame = $|FF_FULLBRIGHT
			local fire = P_SpawnMobj(mo.x+P_RandomRange(-30, 30)*mo.scale, mo.y+P_RandomRange(-30, 30)*mo.scale, mo.z+P_RandomRange(4, 30)*mo.scale, MT_THOK)
			fire.sprite = SPR_FPRT
			fire.frame = $|FF_FULLBRIGHT
			fire.destscale = 3*FRACUNIT
			fire.fuse = TICRATE
			if not S_SoundPlaying(mo, sfx_kc51) then S_StartSound(mo, sfx_kc51) end
			if mo.player.onfire <= 0
				mo.color = mo.player.skincolor
				mo.colorized = false
				mo.frame = $ & ~FF_FULLBRIGHT
			end
		end
	end
end, MT_PLAYER)