-- Touchpop Cvar
local cv_touchpop = CV_RegisterVar({
	name = "touchpop",
	defaultvalue = "On",
	flags = 0,
	PossibleValue = CV_OnOff
})

-- Sapheros' edit
-- Combine touchpop and regular pop

addHook("MobjCollide", function(you, monitor)
	if (cv_touchpop.value)
	and monitor.valid
	and (monitor.flags & MF_MONITOR)
	and (you.player and you.player.realmo == you)
	and (you.player.speed or you.momz)
	
	and not (you.z > monitor.z+monitor.height+(10*FRACUNIT))
	and not (monitor.z > you.z+you.height+(10*FRACUNIT))
	
	and not ((you.player.pflags & PF_JUMPED) or (you.player.pflags & PF_SPINNING))
	and monitor.health
	
		if G_GametypeHasTeams() and you.player.ctfteam
			if you.player.ctfteam == 1 --Red Team
			and monitor.type == MT_RING_BLUEBOX --Blue Ring Box
				return
			elseif you.player.ctfteam == 2 --Blue Team
			and monitor.type == MT_RING_REDBOX --Red Ring Box
			return
			end
		end
		
		P_KillMobj(monitor, you, you)
		return false
	end
end, MT_PLAYER)

addHook("MobjMoveCollide", function(you, monitor) 
	if (cv_touchpop.value)
	and monitor.valid
	and (monitor.flags & MF_MONITOR)
	and (you.player and you.player.realmo == you)
	and not (you.z > monitor.z+monitor.height+(10*FRACUNIT)) and not (monitor.z > you.z+you.height+(10*FRACUNIT))
	and (you.player.speed or you.momz)
	and not ((you.player.pflags & PF_JUMPED) or (you.player.pflags & PF_SPINNING))
	and monitor.health
		if G_GametypeHasTeams()  and you.player.ctfteam
			if you.player.ctfteam == 1 -- Red Team
			and monitor.type == MT_RING_BLUEBOX -- Blue Ring Box
				return
			elseif you.player.ctfteam == 2 -- Blue Team
			and monitor.type == MT_RING_REDBOX -- Red Ring Box
				return
			end
		end
		
		P_KillMobj(monitor, you, you)
		return false
	end
end, MT_PLAYER)