//Stomp move code, created by Latius.
//I really need to make sure to double check for these coding errors I made in the past...
//Like some FREAKING TYPOS!
//Thanks to latius making this code! (only for cman) ask latius for use!

local function stompThinker(p)
	if p.mo.skin ~= "cman" then
        return
    end
	if p.isstomping == nil then p.isstomping = false end
	if p.stompready == nil then p.stompready = 0 end
	
	if (p.cmd.buttons & BT_CUSTOM1) and (not p.isstomping) and (p.stompready == 0) and (not P_IsObjectOnGround(p.mo)) then
		p.isstomping = true
		P_SetObjectMomZ(p.mo, -30*FRACUNIT, false)
		p.mo.momx = $ /4
		p.mo.momy = $ /4
		//p.mo.state = S_PLAY_ROLL
	end
	
	for fof in p.mo.subsector.sector.ffloors()
		if p.isstomping 
		and (p.mo.z <= (fof.topheight + 1*FRACUNIT)
		and (p.mo.z + p.mo.height) > fof.bottomheight)
		and (fof.flags & FF_EXISTS) and (fof.flags & FF_BUSTUP)
			--print(fof.flags & FF_BUSTUP)
			EV_CrumbleChain(p.mo.subsector.sector, fof)
		end
	end
	
	if P_IsObjectOnGround(p.mo) and p.isstomping then
		p.isstomping = false
		p.stompready = TICRATE * 2
		//Stomp effects happen here
		P_RadiusAttack(p.mo, p.mo, 256*FRACUNIT)
		for i = 1, 8
			local curangle = ANG1*45*i
			local dust = P_SpawnMobj(p.mo.x+(18*cos(curangle)), p.mo.y+(18*sin(curangle)), p.mo.z+(4*FRACUNIT), MT_DUST)
			dust.angle = curangle
			P_InstaThrust(dust, dust.angle, 5*FRACUNIT)
			dust.momz = 5*FRACUNIT/2
		end
	elseif p.stompready then
		p.stompready = $ - 1
	end
end

addHook("PlayerThink", stompThinker)