local CVARBOUNCYFLOORVERSION = 1

if jug_bouncyfloordef == nil then
	rawset(_G, "jug_bouncyfloordef", {})
end

if jug_bouncyfloordef.ver == nil or jug_bouncyfloordef.ver < CVARBOUNCYFLOORVERSION then
-- start

local NOSOFTLOCK			= ML_NOSONIC	-- no sonic flag
local SPRINGJUMP			= ML_NOKNUX 	-- no knuckles flag
local SOCFREESLOT			= ML_NOTAILS 	-- no tails flag

local FRACUNIT				= FRACUNIT
-- oh man, flags to check against
local MF_SHOOTABLE			= MF_SHOOTABLE

jug_bouncyfloordef.doTheBounce = function(line, playerMo, sector)
	if playerMo == nil then return end
	-- IGNORE THESE FLAGS
	if (playerMo.flags & MF_SHOOTABLE) ~= MF_SHOOTABLE then return end
	if P_IsObjectOnGround(playerMo) == false then return end

	local hopStrength = line.frontside.textureoffset
	if hopStrength == 0 then return end
	
	local sfx = "sfx_thok"
	if line.backside ~= nil then
		local str = line.backside.text
		if str ~= nil and str ~= "" then
			if (line.flags & SOCFREESLOT) == SOCFREESLOT then
				sfx = "sfx_"..str
			else 
				sfx = "sfx_"..str:lower()
			end
		end
	end

	playerMo.momz = $ + hopStrength
	S_StartSound(playerMo, _G[sfx])

	if playerMo.player ~= nil then
		if ((line.flags & SPRINGJUMP) == SPRINGJUMP) then
			playerMo.player.kartstuff[k_pogospring] = 1
		elseif ((line.flags & NOSOFTLOCK) == NOSOFTLOCK) and
			playerMo.player.speed < (10*FRACUNIT) then
			P_InstaThrust(playerMo, playerMo.angle, (35*FRACUNIT))
		end
	end

end

if jug_bouncyfloordef.ver == nil then
	addHook("LinedefExecute",
	function(line, playerMo, sector)
		jug_bouncyfloordef.doTheBounce(line, playerMo, sector)
	end, "BOINGFLR")
end

-- end
jug_bouncyfloordef.ver = CVARBOUNCYFLOORVERSION
end

-- By JugadorXEI#1815 on Discord, @JugadorXEI on Twitter.
