//All the stuff that doesn't need it's own file goes here.

freeslot(
	"MT_THEKNIGHT",
	"S_HOLLOW",
	"S_KNIGHT",
	"SPR_HOLO"
)


addHook("MapThingSpawn", function(mo, mthing)
	if not (mo and mo.valid
	and mthing and mthing.valid)
		return
	end
	
	if mthing.args[0] == 1 
		mo.scale = 2*FRACUNIT
	end
	
	if (mthing.options & MTF_EXTRA and mthing.options & MTF_OBJECTSPECIAL)
		mo.scale = 2*FRACUNIT
	end
	
	if (mthing.options & MTF_AMBUSH and mthing.options & MTF_OBJECTSPECIAL)
		mo.scale = 3*FRACUNIT
	end
	
	if (mthing.options & MTF_AMBUSH and mthing.options & MTF_EXTRA and mthing.options & MTF_OBJECTSPECIAL)
		mo.scale = 6*FRACUNIT
	end
end, MT_REDCRAWLA)

addHook("MapThingSpawn", function(mo, mthing)
	if not (mo and mo.valid
	and mthing and mthing.valid)
		return
	end
	
	if mo.valid then
		mo.spriteyscale = 1*FRACUNIT/2
		mo.spritexscale = 1*FRACUNIT/2
	end
end, MT_THEKNIGHT)

mobjinfo[MT_REDCRAWLA] = {
	--$Name Crawla (Red)
	--$Sprite SPOSA1
	--$Category Enemies
	--$Flags1Text Size change X2
	--$Flags4Text Hitbox Scale
	--$Flags8Text Size change X3
	doomednum = 101,
	spawnstate = S_SPOS_STND,
	spawnhealth = 1,
	seestate = S_SPOS_RUN1,
	reactiontime = 32,
	painchance = 170,
	raisestate = S_NULL,
	deathstate = S_XPLD_FLICKY,
	deathsound = sfx_pop,
	speed = 3,
	radius = 24*FRACUNIT,
	height = 64*FRACUNIT,
	flags = MF_ENEMY|MF_SPECIAL|MF_SHOOTABLE
}

mobjinfo[MT_THEKNIGHT] = {
	//$Name Ghost
	//$Sprite HOLOA1
	//$Category Easter Eggs
	doomednum = 908,
	spawnstate = S_HOLLOW,
	seestate = S_KNIGHT,
	spawnhealth = 1,
	reactiontime = 0,
	painchance = 1,
	speed = 0,
	radius = 16*FRACUNIT,
	height = 32*FRACUNIT,
	mass = 18*FRACUNIT,
	damage = 30*FRACUNIT,
	flags = MF_SCENERY|MF_SOLID
}

states[S_HOLLOW] =	{SPR_HOLO,	A,	2,	A_Look,	0,	0,	S_HOLLOW}
states[S_KNIGHT] =	{SPR_HOLO,	A,	2,	A_FaceTarget,	0,	0,	S_KNIGHT}

//Easter Eggs

addHook("PlayerThink", function(p)

local deathsoundrandom = 1

if p.playerstate == PST_DEAD and p.deadtimer == 1 and usedCheats == true then
deathsoundrandom = P_RandomRange(1, 100)
CONS_Printf(p, "\x83"+"Random number...\x82 "+deathsoundrandom)
end

if p.playerstate == PST_DEAD and deathsoundrandom == 100 then
S_StopSound(p.mo)
S_StartSound(p.mo,sfx_idiots)
end
end)

addHook("ThinkFrame", function()

local musicrandom = 1

if gamestate == GS_TITLESCREEN and leveltime == 1 then
musicrandom = P_RandomRange(1, 200)
end

if gamestate == GS_TITLESCREEN and musicrandom == 200 then
COM_BufInsertText(player, "tunes _OTIL")
end
end)

--https://cdn.discordapp.com/attachments/1184342086342934539/1379956418962001940/image.png?ex=68422010&is=6840ce90&hm=2ede39b875429ec23b0ce8a6f7e114b9098bf7a279e4967ce82b0e86b48bf0b6&

addHook("PlayerThink", function(p)
if p.mo and p.mo.valid
and p.mo.skin == "xsonic" or p.mo.skin == "xsonicserious" and p.name == "Jay"  then
p.mo.health = 0
p.lives = $ - 1
end

if p.mo and p.mo.valid
and p.mo.skin == "xsonic" or p.mo.skin == "xsonicserious" and p.name == "Jay" and p.mo.health == 0 and not (leveltime%2) then
COM_BufInsertText(p, "quit")
end
end)


addHook("BossThinker", function(mo, player)
	if not (mo and mo.valid) then return end
	if mo.health <= 0 then return end
	
	if mo.health < 4 then
		P_LinedefExecute(999, mo, nil)
	end
	
		for player in players.iterate do
	if player.mo.health <= 0 then continue end
	if not player.valid or player.spectator then continue end
	if not (player.mo and player.mo.valid) then continue end
	
	if player.undershocker == nil then
	player.undershocker = 0
	end
	
	if mo.health < 4 and (player.mo.eflags & MFE_UNDERWATER) and player.undershocker > 31
	and not (player.powers[pw_flashing] and not (player.powers[pw_ignorelatch] & (1<<15))) then
		P_DamageMobj(player.mo, mo, mo, 1)
		S_StartSound(player.mo, sfx_s3k79, player)
		P_FlashPal(player, PAL_RECYCLE, 8)
		player.undershocker = 0
		end
	end
end, MT_EGGMOBILE3)

addHook("PlayerThink", function(player)

	if player.undershocker == nil then
		player.undershocker = 0
	end

	if player and player.valid and (player.mo.eflags & MFE_UNDERWATER) then
		player.undershocker = $ + 1
		return true
		end

	if player and player.valid and player.undershocker > 32 then
		player.undershocker = 0
		end
		if player and player.valid and not (player.mo.eflags & MFE_UNDERWATER) then
		player.undershocker = 0
	end
end)

addHook("PlayerThink", function(player)

local hub = mapheaderinfo[gamemap].hubscale

if hub and player.mo and player.mo.valid
and leveltime == 0 then

P_SetScale(player.mo, 19661, true)
	end
end)
