// Spectra's Hot Potato code.

-- Damage Tagging
local function ckHotPotatoTag(p, inflictor, source)
	if (p and p.mo) and (inflictor and inflictor.player)
		if inflictor.player.hashotpotato -- Source must have the hot potato
		and (chaosmod.hotpotato >= 1) -- Hot potato must be active
		and (p ~= inflictor.player) -- Cant tag yourself!
		and not p.kartstuff[k_squishedtimer] -- Cant be squished
		and not p.kartstuff[k_spinouttimer] -- Cant be spun out
		and not p.powers[pw_flashing] -- Cant have invincibility frames.
			K_PlayHitEmSound(inflictor)
			inflictor.player.hashotpotato = false
			p.hashotpotato = true
			p.kartstuff[k_spinouttimer] = TICRATE/20
			print(inflictor.player.name.." tagged "..p.name.."!")
		end
	end
end

addHook("PlayerSpin", function(p, inflictor, source)
	if (p and p.mo) and (source and source.player)
		if source.player.hashotpotato -- Source must have the hot potato
		and (chaosmod.hotpotato >= 1) -- Hot potato must be active
		and (p ~= source.player) -- Cant tag yourself!
			K_PlayHitEmSound(source)
			source.player.hashotpotato = false
			p.hashotpotato = true
			p.kartstuff[k_spinouttimer] = TICRATE/20
			print(source.player.name.." tagged "..p.name.."!")
		end
	end
end)

addHook("PlayerSquish", function(p, inflictor, source)
	if (p and p.mo) and (inflictor and inflictor.player)
		if inflictor.player.hashotpotato -- Source must have the hot potato
		and (chaosmod.hotpotato >= 1) -- Hot potato must be active
		and (p ~= inflictor.player) -- Cant tag yourself!
			K_PlayHitEmSound(inflictor)
			inflictor.player.hashotpotato = false
			p.hashotpotato = true
			p.kartstuff[k_spinouttimer] = TICRATE/20
			print(inflictor.player.name.." tagged "..p.name.."!")
		end
	end
end)

addHook("PlayerExplode", function(p, inflictor, source)
	if (p and p.mo) and (inflictor and inflictor.player)
		if inflictor.player.hashotpotato -- Source must have the hot potato
		and (chaosmod.hotpotato >= 1) -- Hot potato must be active
		and (p ~= inflictor.player) -- Cant tag yourself!
			K_PlayHitEmSound(inflictor)
			inflictor.player.hashotpotato = false
			p.hashotpotato = true
			p.kartstuff[k_spinouttimer] = TICRATE/20
			print(inflictor.player.name.." tagged "..p.name.."!")
		end
	end
end)

-- Collision Tagging.
addHook("MobjCollide", function(mo, mo2)
	if leveltime > 7*TICRATE
		if (mo.valid and mo2.valid) and mo2.player
			if abs(mo.z - mo2.z) <= P_GetPlayerHeight(mo.player)
			and mo.player.hashotpotato
			and chaosmod.hotpotato >= 1
			and not mo.player.justbump
			and not mo2.player.kartstuff[k_squishedtimer]
			and not mo2.player.kartstuff[k_spinouttimer]
			and not mo2.player.powers[pw_flashing]
				K_PlayHitEmSound(mo)
				mo.player.justbump = true
				mo2.player.justbump = true
				mo.player.hashotpotato = false
				mo2.player.hashotpotato = true
				mo2.player.kartstuff[k_spinouttimer] = TICRATE/20
				print(mo.player.name.." tagged "..mo2.player.name.."!")
			end
		end
	end
end, MT_PLAYER)