// Final Demo Red Shield Box - Ported by MIDIMan
// Use with LUA_FBOX

/*
The red shield in pre-2.0 versions was called the "Inferno Shield". It protected 
the player from fire damage and disintegrated in water, but it also allowed the 
player to spawn tiny flames while spinning, similar to the Elemental Shield. 
In 2.0, the red shield's behavior was switched to that of the Armageddon Shield.
*/

freeslot(
	"SPR_FBXE",
	"MT_FDBOX_RED",
	"MT_FDBOX_RED_ICON",
	"S_FDBOX_RED_IDLE",
	"S_FDBOX_RED_ICON1",
	"S_FDBOX_RED_ICON2"
)

function A_FDRedShield(actor, var1, var2)
	if not (actor and actor.valid) then return end
	
	if actor.FDAltOption then
		// Give the player a flame shield (1.01-1.09.4 behavior)
		A_GiveShield(actor, SH_FLAMEAURA, var2) // Replace SH_FLAMEAURA with SH_ELEMENTAL if you'd rather have that shield
	else
		// Give the player a armageddon shield (2.0 behavior)
		A_GiveShield(actor, SH_ARMAGEDDON, var2)
	end
end

addHook("MobjFuse", function(mobj)
	if not (mobj and mobj.valid) then return end
	
	P_FDMonitorFuseThink(mobj)
	return true
end, MT_FDBOX_RED)

addHook("MapThingSpawn", function(mobj, mthing)
	if not (mobj and mobj.valid
	and mthing and mthing.valid) then
		return
	end
	
	P_FDMonitorTypeSpawn(mobj, mthing)
	
	if mobj and mobj.valid then
		if ultimatemode and not G_IsSpecialStage(gamemap) then
			P_RemoveMobj(mobj)
		end
	end
end, MT_FDBOX_RED)

mobjinfo[MT_FDBOX_RED] = {
	//$Name Final Demo Red Shield
	//$Sprite FBXEA0
	//$Category Monitors
	//$Flags4Text Random (Strong)
	//$Flags8Text Random (Weak) / Random (Pre-2.0)
	//$ParameterText Behavior
	doomednum = 472,
	spawnstate = S_FDBOX_RED_IDLE,
	spawnhealth = 1,
	painstate = S_FDBOX_RED_IDLE,
	deathstate = S_FDBOX_EXPLOSION1,
	deathsound = sfx_pop,
	radius = 16*FRACUNIT,
	height = 32*FRACUNIT,
	damage = MT_FDBOX_RED_ICON,
	flags = MF_SOLID|MF_SHOOTABLE|MF_MONITOR|MF_GRENADEBOUNCE
}

states[S_FDBOX_RED_IDLE] =	{SPR_FBXE,	A,	2,	nil,	0,	0,	S_FDBOX_FLICKER}

mobjinfo[MT_FDBOX_RED_ICON] = {
	doomednum = -1,
	spawnstate = S_FDBOX_RED_ICON1,
	spawnhealth = 1,
	seesound = sfx_shield,
	speed = 4*FRACUNIT,	// Originally 2*FRACUNIT; Changed to match pre-2.1's speed
	radius = 8*FRACUNIT,
	height = 14*FRACUNIT,
	damage = 62*FRACUNIT,
	flags = MF_NOBLOCKMAP|MF_NOCLIP|MF_SCENERY|MF_NOGRAVITY|MF_BOXICON
}

states[S_FDBOX_RED_ICON1] =	{SPR_FBXE,	B,	18,	nil,			0,	0,	S_FDBOX_RED_ICON2}
states[S_FDBOX_RED_ICON2] =	{SPR_FBXE,	B,	18,	A_FDRedShield,	0,	0,	S_NULL}
