-- Dial up brightness in stairs encore lol

freeslot("sfx_tlhury") -- Hurry up!

local function DialEncore(addition)
	for i = 0, #sectors do
		local s = sectors[i]
		if not s continue end
		if s.lightlevel <= 112 then continue end
		s.lightlevel = max($ + addition, 255)
		
		if s.floorpic == "GFZFLR01" then
			s.floorpic = "GROVF3"
		end
		if s.ceilingpic == "GFZFLR01" then
			s.ceilingpic = "GROVF3"
		end
	end
	
	for i = 0, #sides do
		local s = sides[i]
		if not s continue end
		
		local gfzrock = R_TextureNumForName("GFZROCK")
		local replace = R_TextureNumForName("GROVW4")
		
		if s.toptexture == gfzrock then
			s.toptexture = replace
		end
		
		if s.bottomtexture == gfzrock then
			s.bottomtexture = replace
		end
		
		if s.midtexture == gfzrock then
			s.midtexture = replace
		end
	end
end

addHook("LinedefExecute", function(line, mobj, sec)
	if not mobj and not mobj.valid then return end
	if not mobj.player and not mobj.player.valid then return end
	-- fake!
	local player = mobj.player
	player.laps = $ + 1
	player.kartstuff[k_lapanimation] = 80
	S_StartSound(mobj, sfx_tlhury, player)
	COM_BufInsertText(consoleplayer, "tunes toobad")
end, "STLAP2")

addHook("LinedefExecute", function(line, mobj, sec)
	if mapheaderinfo[gamemap].therealstairs then
		if encoremode then
			DialEncore(128)
		end
	end
end, "STENCO")

addHook("PostThinkFrame", function()
	if not mapheaderinfo[gamemap].therealstairs then return end
	if not kmp then return end
	for p in players.iterate do
		-- die monster, monster
		-- you you dont belong belong in this world, world
		-- it was not by my hand hand that i was once again given flesh
		-- flesh
		-- flesh
		-- flesh
		-- flesh
		p.kmp_respawn = nil
	end
end)

addHook("MusicChange", function(oldmusic, newmusic, flags, looping)
	if not mapheaderinfo[gamemap].therealstairs then return end
	for dp in displayplayers.iterate do
		if dp.exiting then
			return "toobad", flags, true
		end
	end
end)