freeslot(
	"MT_PURPLESPROINGER",
	"S_PSPROINGER_IDLE",
	"S_PSPROINGER_MOVE",
	"S_PSPROINGER_MOVE2",
	"S_PSPROINGER_MOVE3",
	"S_PSPROINGER_MOVE4",
	"S_PSPROINGER_SPRING",
	"S_PSPROINGER_SPRING2",
	"SPR_SPSH"
)


states[S_PSPROINGER_IDLE] = {
	sprite = SPR_SPSH,
	frame = A,
	tics = 4,
	action = A_Look,
	nextstate = S_PSPROINGER_IDLE
}

states[S_PSPROINGER_MOVE] = {
	sprite = SPR_SPSH,
	frame = A,
	tics = 4,
	action = A_Chase,
	nextstate = S_PSPROINGER_MOVE2
}

states[S_PSPROINGER_MOVE2] = {
	sprite = SPR_SPSH,
	frame = A,
	tics = 4,
	action = A_Chase,
	nextstate = S_PSPROINGER_MOVE3
}

states[S_PSPROINGER_MOVE3] = {
	sprite = SPR_SPSH,
	frame = A,
	tics = 4,
	action = A_Chase,
	nextstate = S_PSPROINGER_MOVE4
}

states[S_PSPROINGER_MOVE4] = {
	sprite = SPR_SPSH,
	frame = A,
	tics = 4,
	action = A_Chase,
	nextstate = S_PSPROINGER_MOVE
}

states[S_PSPROINGER_SPRING] = {
	sprite = SPR_SPSH,
	frame = A,
	tics = 4,
	action = A_Pain,
	nextstate = S_PSPROINGER_SPRING2
}

states[S_PSPROINGER_SPRING2] = {
	sprite = SPR_SPSH,
	frame = A,
	tics = 3,
	nextstate = S_PSPROINGER_MOVE
}

mobjinfo[MT_PURPLESPROINGER] = {
	spawnstate = S_PSPROINGER_IDLE,
	seestate = S_PSPROINGER_MOVE,
	painsound = sfx_spring,
	deathstate = S_XPLD_FLICKY,
	deathsound = sfx_pop,
	raisestate = S_PSPROINGER_SPRING,
	spawnhealth = 1,
	reactiontime = 32,
	painchance = 0,
	speed = 6,
	radius = 24*FRACUNIT,
	height = 40*FRACUNIT,
	mass = 15*FRACUNIT,
	flags = MF_ENEMY|MF_SPECIAL|MF_SHOOTABLE
}

addHook("MobjThinker", function(egg)
	for p in players.iterate do
		if not (p.mo and p.mo.valid) then return end
		if p.mo.skin ~= "specki" and p.mo.skin ~= "mechaspecki" then return end
		if not egg and egg.valid then return end
		if not egg.health then return end
		local aggro = P_SpawnMobj(egg.x, egg.y, egg.z, MT_PURPLESPROINGER)
		aggro.flags = egg.flags
		aggro.flags2 = egg.flags2
		aggro.eflags = egg.eflags
		aggro.health = egg.health
		aggro.scale = egg.scale
		aggro.angle = egg.angle
		P_RemoveMobj(egg)
		return
	end
end, MT_SPRINGSHELL)

addHook("MobjCollide", function(thing, tmthing)
	if (thing == tmthing)
		return
	end

	// Ignore... things.
	if not (tmthing and tmthing.valid) or not (thing and thing.valid) then
		return
	end

	if ((thing.type == MT_PURPLESPROINGER) and thing.health > 0 and (tmthing.player or (tmthing.flags & MF_PUSHABLE)) and tmthing.health > 0) then
		local tmz = tmthing.z
		if (thing.eflags & MFE_VERTICALFLIP) then
			tmz = -(tmthing.z + tmthing.height)
		end

		local tmznext = tmthing.momz + tmz
		if (thing.eflags & MFE_VERTICALFLIP) then
			tmznext = -tmthing.momz
		end
		
		local thzh = thing.z + thing.height
		if (thing.eflags & MFE_VERTICALFLIP) then
			thzh = -thing.z
		end
		
		local sprarea = FixedMul(8*FRACUNIT, thing.scale) * P_MobjFlip(thing)

		if ((tmznext <= thzh and tmz > thzh) or (tmznext > thzh - sprarea and tmznext < thzh)) then
			P_DoSpring(thing, tmthing)
			return false
		elseif (tmz > thzh - sprarea and tmz < thzh) // Don't damage people springing up / down
			return false
		end
	end
end)