freeslot("S_TERRA_DAMAGE1", "S_TERRA_DAMAGE2", "S_TERRA_DAMAGE3", "S_TERRA_DAMAGE4")

addHook("PlayerCanDamage", function(player)
	if (player.mo.skin == "terra")
	and player.playerstate == PST_LIVE
		if player.mo.terrakick > 1
		or player.mo.state == S_TERRA_DAMAGE1
		or player.mo.state == S_TERRA_DAMAGE2
		or player.mo.state == S_TERRA_DAMAGE3
		or player.mo.state == S_TERRA_DAMAGE4 then
			return true
		end
    end
end)

local BattleFuncSet = false

addHook("ThinkFrame",function()
	if (BattleFuncSet) or not(CBW_Battle and CBW_Battle.SkinVars) then return end
		BattleFuncSet = true
		local TerraPriority = function(player)
			if player.mo.terrakick > 1
			or player.mo.state == S_TERRA_DAMAGE1
			or player.mo.state == S_TERRA_DAMAGE2
			or player.mo.state == S_TERRA_DAMAGE3
			or player.mo.state == S_TERRA_DAMAGE4
				CBW_Battle.SetPriority(player,1,0,nil,1,0,"Kick Damage")
			end
			if player.mo.state == S_THEH
				CBW_Battle.SetPriority(player,1,0,nil,1,0,"Hyper Dash")
			end
		end
		local TerraBattle = function(mo,doaction,pressedaction)
		local player = mo.player
		if not(CBW_Battle.CanDoAction(player))
			player.actionstate = 0
			return
		end
		player.actiontext = "Kick Damage"
		player.actionrings = 10	
		if player.actionstate != 0
			player.canguard = false
		end
		if player.actionstate == 0
			if doaction == 1
				CBW_Battle.PayRings(player)
				CBW_Battle.ApplyCooldown(player,TICRATE*2)
				player.mo.terrakick = 14
				player.mo.state = S_TERRA_DAMAGE1
				player.pflags = $1 & ~PF_SPINNING
				player.pflags = $ & ~PF_JUMPED
				//Fix a Abilities
				player.upped = false
				player.uptime = 0
				player.forwarded = false
				player.fwrdtime = 0
				player.charflags = $ & ~SF_CANBUSTWALLS
			end
			if not P_IsObjectOnGround(mo)
			and player.mo.state == S_THEH
				player.canguard = false
			else
				player.canguard = true
			end
			if player.upped == true
				if not (player.uptime == 17)
					player.canguard = false
				else
					player.canguard = true
				end
			end
			if player.mo.terrakick > 1
				player.canguard = false
			end
			if player.mo.terrakick == 1
				player.canguard = true
			end
		end
	end
	CBW_Battle.SkinVars["terra"] = {
		flags = SKINVARS_GUARD|SKINVARS_NOSPINSHIELD,
		weight = 100,
		shields = 1,
		special = TerraBattle,
		func_collide = TDCollide,
		func_priority_ext = TerraPriority
	}
	print("Terra the Pangolin Battle Mode support has been added!")
end)