// ==================================================================================
// MEDICATION FIELD

actor MedicationFieldItem : InventoryItem 29017 {
	//$Category Pickups
	Tag "Medication Field"
	Inventory.MaxAmount 3
	Inventory.PickupMessage "Picked up a medication field."
	Inventory.Icon "hradicon"
	states {
	Spawn:
		HRAD A -1
		stop
	Use:
		TNT1 A 0 A_JumpIfInventory ("IsInSpawnRoom", 1, "Failure")
		TNT1 A 0 A_JumpIfInventory ("IsMech", 1, "Use.Mech")
		TNT1 A 0 A_JumpIfInventory ("StealthMode", 1, "Destealth")
		TNT1 A 0 A_JumpIfInventory ("PowerBerserk", 1, "Failure")
		TNT1 A 0 A_FireCustomMissile ("MedicationFieldThrown", 0, 0)
		stop
	}
}

// ==================================================================================
// How many "slots" of med fields does the player have?
// This amount of med fields are restored by full refills.
actor MedicationFieldCount : Inventory {
	Inventory.MaxAmount 9999 // [TT] Double definition removal
}

// ==================================================================================
// Medication field pad being casted to the field
actor MedicationFieldThrown {
	PROJECTILE
	+DOOMBOUNCE
	-NOGRAVITY
	Speed 15
	Gravity 0.75
	BounceCount 1
	States {
	Spawn:
		HRAD A -1
		stop
	Death:
		TNT1 A 0 A_SpawnItemEx ("MedicationField", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION)
		stop
	}
}

// ==================================================================================
// The actual medication field
actor MedicationField {
	-SOLID
	+SHOOTABLE
	+NOBLOOD
	+NOCLIP
	+ISMONSTER
	+NOICEDEATH
	Radius 16
	Height 44
	Health 150
	Mass 0x7FFFFFFF
	DeathSound "weapons/rocklx"
	Obituary "$OB_HEALRAD"
	DamageFactor "Disarm", 0.0
	DamageFactor "Mechstomp", 0.0
	DamageFactor "Ice", 0.0
	States {
	Spawn: 
		HRAD ABCDE 6 // Unfold
		DGIZ A 10
		DGIZ A 0 A_SpawnItemEx ("MedicationFieldBall", 0,0,52, 0,0,0, 0, SXF_SETMASTER|SXF_NOCHECKPOSITION)
		DGIZ A 0 A_PlaySound ("healradius/active", CHAN_VOICE, 1.0, 1)
		goto Idle
	Idle:
		DGIZ A 0 bright ACS_ExecuteAlways (952, 0, 0)
		DGIZ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 1 A_SpawnItemEx ("MedicationFieldFX",
			random (-48, 48), random (-48, 48), random (8, 20), 0, 0, random (3, 6))
		DGIZ A 0 bright A_GiveInventory ("MedicationFieldCount", 1)
		DGIZ A 0 bright A_JumpIfInventory ("MedicationFieldCount", 60, "Done")
		loop
	Done:
		DGIZ A 0 A_KillChildren // Remove the ball
		HRAD EDCBA 6 // Fold down
		HRAD A 2 A_FadeOut
		wait
	Death:
		TNT1 A 0 A_StopSound (CHAN_VOICE)
		TNT1 A 0 A_KillChildren
		TNT1 A 0 A_Scream
		TNT1 A 0 A_SpawnItemEx ("ExplosionMain", 0, 0, 32)
		stop
	}
}

// ==================================================================================
// Decorative ball that floats on top of the field.
actor MedicationFieldBall {
	+NOINTERACTION
	+NOGRAVITY
	+SHOOTABLE
	+NOBLOCKMAP
	+NOTARGET
	+ISMONSTER
	+FORCEXYBILLBOARD
	Alpha 0.0
	RenderStyle add
	Scale 0.5
	States {
	Spawn:
		GIZR CDABCD 3 bright A_FadeIn (0.1)
		GIZR A 0 A_SetTranslucent (0.6)
		goto Idle
	Idle:
		GIZR ABCD 3 bright
		loop
	Death:
		GIZR ABCD 3 bright A_FadeOut
		loop
	}
}

// ==================================================================================
// "Plus sign" effects spawned by the field
actor MedicationFieldFX {
	+NOGRAVITY
	+CLIENTSIDEONLY
	RenderStyle add
	Alpha 1.0
	Scale 0.35
	States {
	Spawn:
		PLUS A 2 bright A_FadeOut
		wait
	}
}

// ==================================================================================
// Map-spawnable medfield that does not dissipate and cannot be destroyed
actor MedicationFieldPermanent : MedicationField 29015 {
	//$Category Objects
	Tag "Medication Field (permanent)"
	-SHOOTABLE
	States {
	Spawn:
		DGIZ A 0
		DGIZ A 0 A_SpawnItemEx ("MedicationFieldBallPerm", 0,0,52, 0,0,0, 0, SXF_NOCHECKPOSITION)
		DGIZ A 0 A_SpawnItemEx ("MedicationFieldFXPerm", 0,0,52, 0,0,0, 0, SXF_NOCHECKPOSITION)
		DGIZ A 0 A_PlaySound ("healradius/active", CHAN_VOICE, 1.0, 1)
		goto Idle
	Idle:
		DGIZ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 1 A_SpawnItemEx ("MedicationFieldFXPerm",
			random (-48, 48), random (-48, 48), random (8, 20), 0, 0, random (3, 6))
		DGIZ A 0 bright ACS_ExecuteAlways (952, 0, 0)
		loop
	}
}

// ==================================================================================
actor MedicationFieldBallPerm : MedicationFieldBall {
	Translation "224:246=176:191"
	Alpha 0.6
	States {
	Spawn:
		GIZR A 0
		goto Idle
	}
}

// ==================================================================================
actor MedicationFieldFXPerm : MedicationFieldFX {
	States {
	Spawn:
		PLUS B 2 bright A_FadeOut
		wait
	}
}
