-- 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.rmFDAltOption 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", RM_FDMonitorFuseThink, MT_FDBOX_RED)
addHook("MapThingSpawn", function(mo, mthing)
	if not (mo and mo.valid and mthing and mthing.valid) then return end
	
	RM_FDMonitorTypeSpawn(mo, mthing)
	
	if mo and mo.valid then
		if ultimatemode and not G_IsSpecialStage(gamemap) then
			P_RemoveMobj(mo)
		end
	end
end, MT_FDBOX_RED)

mobjinfo[MT_FDBOX_RED] = {
	--$Name Final Demo Red Shield
	--$Sprite FBXEA0
	--$Category Monitors
	--$Flags1Text Don't "Era-Swap" Shield
	--$Flags4Text Random (Strong)
	--$Flags8Text Random (Weak) / Random (Pre-2.0)
	--$ParameterText Behavior
	--$Arg1 Respawn behavior
	--$Arg1Type 11
	--$Arg1Enum monitorrespawn
	--$Arg2 Era-Swap Shield
	--$Arg2Type 11
	--$Arg2Enum yesno
	--$Arg3 Era
	--$Arg3Type 11
	--$Arg3Enum {0 = "2.0"; 1 = "1.09-1.09.4"; 2 = "1.08"; 3 = "2K3-1.04";}
	doomednum = 472,
	spawnstate = S_FDBOX_RED_IDLE,
	spawnhealth = 1,
	painstate = S_FDBOX_RED_IDLE,
	deathstate = S_FDBOX_EXPLOSION1,
	deathsound = sfx_pop,
	speed = 1,
	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}
