freeslot(
"MT_DECOPETAL",
"S_DECOPETAL",
"SPR_PETL"
)


function A_DecoPetalThink(actor, var1, var2) 

	actor.reactiontime = $+1
	
	if not (actor.rollDir) then
		actor.rollDir = 1
		actor.cycleLength = P_RandomRange(30,50)
		actor.rollangle = ANG1*-90
		actor.speed = 20
	end
	
	if (actor.reactiontime%actor.cycleLength  < actor.cycleLength /2) then
		actor.momx = ($*90)/100
		actor.momy = ($*90)/100
		actor.momz = ($*90)/100
		actor.rollangle = $+(ANG1*5)*actor.rollDir
	elseif (actor.reactiontime%actor.cycleLength  == actor.cycleLength /2) then
		actor.angle =  P_RandomKey(360)*ANG1
		actor.rollDir = $*-1
	else
		P_Thrust(actor, actor.angle, FRACUNIT/4)
		actor.rollangle = $+(ANG1*10)*actor.rollDir
	end
	
	P_SetObjectMomZ(actor, -FRACUNIT/20, true)
	if (actor.z-actor.floorz < 32*FRACUNIT) then
	P_SetObjectMomZ(actor, (FRACUNIT*P_RandomKey(16)), true)
	end

end


mobjinfo[MT_DECOPETAL] = {
//$Name Decorative Petal
//$Category Tarnish Ward
//$Sprite PETLA0
spawnstate = S_DECOPETAL,
speed = 1,
radius = 16*FRACUNIT,
height = 16*FRACUNIT,
doomednum = 1519,
reactiontime = 8,
damage = 3,
spawnhealth = 1,
dispoffset = 0,
flags =  	MF_NOGRAVITY|MF_NOBLOCKMAP|MF_NOCLIPHEIGHT
}


states[S_DECOPETAL] = {
sprite = SPR_PETL,
frame = A,
tics = 1,
action = A_DecoPetalThink,
nextstate = S_DECOPETAL
}


addHook("MobjSpawn", function(actor) 
	actor.color = P_RandomRange(10, 68)
	actor.scale = $+(P_RandomRange(-30, 30)*(FRACUNIT/100))
	if (P_RandomChance(FRACUNIT/2)) then
		actor.renderflags =  $1|RF_HORIZONTALFLIP
	end
	
end, MT_DECOPETAL)


addHook("MobjLineCollide", function(actor, line) 
	if (line.flags & ML_BLOCKMONSTERS) then
		return true
	end
	return false
end, MT_DECOPETAL)