if solsetup then return end --IVO - you might wanna start thinking about shoving all of these into one lua if you're gonna release 'em all.

--We're gonna freeslot some stuff here because this gets loaded before any SOC.
freeslot("MT_BADNIKSOL", "MT_SOLFIRE", "S_SOLPATROL", "S_SOLFIRE")

mobjinfo[MT_BADNIKSOL] = {
	doomednum = 3766,
	spawnstate = S_SOLPATROL,
	spawnhealth = 1000,
	radius = 16*FRACUNIT,
	height = 32*FRACUNIT,
	painchance = MT_SOLFIRE,
	damage = 5,
	speed = 2,
	mass = 4*FRACUNIT,
	flags = MF_SPECIAL|MF_ENEMY|MF_NOGRAVITY
}
mobjinfo[MT_SOLFIRE] = {
	spawnstate = S_SOLFIRE,
	spawnhealth = 1000,
	painchance = 20*FRACUNIT,
	speed = FRACUNIT, --IVO: change the number to make it spin faster [times FRACUNIT, this need to be fixed point :V]
	radius = 13*FRACUNIT,
	height = 26*FRACUNIT,
	damage = 8,
	flags = MF_PAIN|MF_NOGRAVITY|MF_NOCLIP|MF_NOCLIPHEIGHT
}

--i left the state info in the soc because without it the sprite refused to render 

--i will figure this out and maybe do it more proper when a power outage isn't breathing on my laptop's battery life

local ball --'in
local orbcount = 4 --IVO: this number can be changed [result will be +1 what you type there]
local function spawnSolBalls(mo)
	mo.scale = $*2
	for i = 0, orbcount
		ball = P_SpawnMobj(mo.x, mo.y, mo.z, MT_SOLFIRE)
		ball.destscale = mo.scale
		P_SetScale(ball, mo.scale)
		ball.target = mo
		ball.movedir = FixedAngle(FixedMul(FixedDiv(i<<FRACBITS, 5<<FRACBITS), 360<<FRACBITS))
		ball.threshold = ball.radius + mo.radius + FixedMul(7*FRACUNIT, ball.scale)
		ball.frame = P_RandomRange(0, 11)
	end
end
addHook("MobjSpawn", spawnSolBalls, MT_BADNIKSOL)

local framedelay = 4 --IVO: change this to make it animate faster
local function forcedball(mo)
	if mo and mo.valid and mo.target
	
		--"but ang just call the action in the soc :))))"
		A_UnidusBall(mo)
		--how about no because for some reason it will call the func ONCE and never again in its pitiful aimless life
		
		--and let's just hack FF_ANIMATE too shall we; since var1 is being used to make sure the fucking balls don't fly off the handle which means frame anims can't be handled by the soc
		--this game is popsicle sticks and i am out of glue.
		if leveltime%framedelay == 0
			if mo.frame == 11 then mo.frame = 0 end
			mo.frame = $ + 1
		end
		
	end
end

addHook("MobjThinker", forcedball, MT_SOLFIRE)

--Callmore's sawblade movement.
local function mmSolPatrolThink(mo)
	local xdir = sin(mo.angle - ANGLE_90)
	local ydir = cos(mo.angle + ANGLE_90)
	
	local didMove
	if mo.currentmovement then
		didMove = P_TryMove(mo, mo.x + (xdir * mo.info.speed), mo.y + (ydir * mo.info.speed))
	else
		didMove = P_TryMove(mo, mo.x - (xdir * mo.info.speed), mo.y - (ydir * mo.info.speed))
	end
	if not didMove then
		--print("Flipping sawblade")
		--mo.currentmovement = not $
		mo.angle = $+ANGLE_180
	end

end

addHook("MobjThinker", mmSolPatrolThink, MT_BADNIKSOL)
/* -- IVO: feel free to delete this
addHook("ThinkFrame", do 
	if not(leveltime == 10*TICRATE) then return end
	for p in players.iterate do	
        if not p.mo or not p.mo.valid continue end 
		P_SpawnMobj(p.mo.x, p.mo.y, p.mo.z, MT_BADNIKSOL)
	end
end)*/
rawset(_G, "solsetup", true) 