// Hardcoded functions. These could probably stand to be done in a better, more reusable way at some point.
// The title is NOT about erections.

local ggzmap = 141 // B5
local rrzmap = 146 // BA

addHook("MapLoad", function(mapnum) // Handles sounds.
		if mapnum == ggzmap then
				for i = 0, #sfxinfo
						if (i == sfx_steam1) then
								sfxinfo[i].flags = $1|SF_X8AWAYSOUND
						end
				end
		else
				for i = 0, #sfxinfo
						if (i == sfx_steam1) then
								sfxinfo[i].flags = $1 & ~SF_X8AWAYSOUND
						end
				end
		end
end)

addHook("MobjSpawn", function(mo) // Handles the spawning of the ball.
		if gamemap == ggzmap then
				mo.checker = 1
		else
				mo.checker = 2
		end
end, MT_BIGTUMBLEWEED)

addHook("MobjThinker", function(mo) // Handles the ejection of the ball from the tube.
		if gamemap == ggzmap and (mo.checker == 1 and mo.z > -392*FRACUNIT) then
				S_StartSound(mo, sfx_steam1)
				mo.checker = 2
		end
end, MT_BIGTUMBLEWEED)

addHook("MobjThinker", function(mo) // Made by Zipper. Ball teleport.
	if gamemap == rrzmap then
		if (mo.subsector.sector.tag == 62) then
			P_MoveOrigin(mo, mo.x + 9600*FRACUNIT, mo.y, mo.z);
		elseif(mo.subsector.sector.tag == 65)
			P_MoveOrigin(mo, mo.x - 9600*FRACUNIT, mo.y, mo.z);
		end
	end
end, MT_BIGTUMBLEWEED)
