//New enemies for new map (logic)
freeslot("MT_MOTOBUG", "SFX_MOTO", "MT_COCONUTS", "MT_CRABMEAT")

addHook("MobjThinker", function(motobug)
	if motobug
	and motobug.valid
	and motobug.health
	and motobug.type == MT_MOTOBUG
		if not (motobug.state == S_MOTOBUG_LOOK)
			if not S_SoundPlaying(motobug, sfx_moto)
			S_StartSound(motobug, sfx_moto)
			end
		end
		if motobug.target
		and not P_CheckSight(motobug, motobug.target)
		motobug.target = nil
		end
	end
end, MT_MOTOBUG)

addHook("MobjThinker", function(coconuts)
	if coconuts
	and coconuts.valid
	and coconuts.health
	and coconuts.type == MT_COCONUTS
	A_FindTarget(coconuts, MT_PLAYER, 0)
		if coconuts.prevangle == nil
		coconuts.prevangle = 0
		end
		if coconuts.chooseclimb == nil
		coconuts.chooseclimb = 0
		end
		if coconuts.timeclimb == nil
		coconuts.timeclimb = 0
		end
		if coconuts.chooseclimb > 1
		coconuts.chooseclimb = 0
		end
		if (coconuts.state == S_COCONUTS_CLIMB)
		coconuts.timeclimb = $1 + 1
		if coconuts.chooseclimb == 0
		P_SetObjectMomZ(coconuts, 2*FRACUNIT)
		end
		if coconuts.chooseclimb == 1
		P_SetObjectMomZ(coconuts, -2*FRACUNIT)
		end
		end
		if (coconuts.state == S_COCONUTS_CLIMB_START)
		coconuts.momz = 0
		end
		if coconuts.timeclimb >= 2*TICRATE
		coconuts.timeclimb = 0
		coconuts.state = S_COCONUTS_CLIMB_START
		coconuts.chooseclimb = $1 + 1
		end
		if coconuts.target
			if R_PointToDist2(coconuts.x, coconuts.y, coconuts.target.x, coconuts.target.y) < 512*FRACUNIT
			and not ((coconuts.state == S_COCONUTS_ATTACK1) or (coconuts.state == S_COCONUTS_ATTACK2) or (coconuts.state == S_COCONUTS_ATTACK3))
			coconuts.prevangle = coconuts.angle
			coconuts.state = S_COCONUTS_ATTACK1
			coconuts.momz = 0
			end
		end
		if (coconuts.state == S_COCONUTS_ATTACK2)
		coconuts.angle = coconuts.prevangle
		end
	end
end, MT_COCONUTS)

addHook("MobjThinker", function(crabmeat)
	if crabmeat
	and crabmeat.valid
	and crabmeat.health
	and crabmeat.type == MT_CRABMEAT
		if (crabmeat.state == S_CRABMEAT_ATTACK2)
		local ball = P_SPMAngle(crabmeat, MT_JETTBULLET, crabmeat.angle+ANGLE_90)
		local ball2 = P_SPMAngle(crabmeat, MT_JETTBULLET, crabmeat.angle-ANGLE_90)
		ball.flags = $1 & ~MF_NOGRAVITY
		ball2.flags = $1 & ~MF_NOGRAVITY
		P_SetObjectMomZ(ball, 8*FRACUNIT)
		P_SetObjectMomZ(ball2, 8*FRACUNIT)
		P_InstaThrust(ball, ball.angle, 6*FRACUNIT)
		P_InstaThrust(ball2, ball2.angle, 6*FRACUNIT)
		end
	end
end, MT_CRABMEAT)