-- hacky fix for the ERZ1 softlock

---@param p player_t
addHook("PlayerThink", function(p)
    if gamemap ~= 22*FRACUNIT then return end
    
    --check if were inside the conveyor area
    if p.mo.x < 4192*FRACUNIT then return end
    if p.mo.x > 7360*FRACUNIT then return end
    if p.mo.y < -11008*FRACUNIT then return end
    if p.mo.y > -6272*FRACUNIT then return end

    --now check the height
    if p.mo.z > 3648*FRACUNIT then
        P_KillMobj(p.mo, nil, nil, DMG_DEATHPIT)
    end
end)


local vars = {}

-- Fang can't beat this map.
-- So, we skip it, but only in singleplayer.

---@param p player_t
addHook("PlayerThink", function(p)

    -- don't do this if these arent met
    if netgame then return end
	if p.mo.skin ~= "fang" then return end
	if gamemap ~= 22 then return end
	vars.skipping = 1
	vars.tics = $ - 1
	if vars.tics > 0 then return end

    --don't try to cheat in record attack
    p.realtime = 209999
    p.rings = 0
    p.score = 0

    -- exit
	G_ExitLevel()
end)

addHook("MapChange", function(mapnum)
	vars.tics = 105
end)

-- 2.0's final day code

---comment
---@param v any
---@param p player_t
hud.add(function(v, p)
	if netgame then return end
	if p.mo.skin ~= "fang" then return end
	if gamemap ~= 22 then return end
	v.drawString(312, 8, "Map unbeatable as Fang,\nskipping...", V_SNAPTOTOP|V_SNAPTORIGHT|V_ALLOWLOWERCASE, "right")
end, "game")