/* The pelter, an ammo-less starting weapon inspired by the Quake II blaster.
 * Shoots a slow particle-laden projectile that does minimal damage.
 *
 * Based on the Raygun from Realm 667.  Original DECORATE and sprite edits by
 * Captain Toenail, based on sprites from Doom, Hexen, Strife, and CyClones.
 * Sounds from TimeSplitters.
 */

actor Anachrony_Pelter : DoomWeapon replaces Pistol 12634
{
	//$Category Weapons
	//$Title Pelter
	Weapon.AmmoUse 0
	Weapon.AmmoGive 0
	Obituary "%o was vaporized by %k's pelter."
	Inventory.Pickupmessage "Picked up a pelter!"
	Weapon.SlotNumber 2
	weapon.slotpriority 0
	weapon.selectionorder 1800  // slightly worse than pistol
	States
	{
	Ready:
		RAYG A 1 A_WeaponReady
		loop
	Deselect:
		RAYG A 1 A_Lower
		loop
	Select:
		RAYG A 1 A_Raise
		loop
	Fire:
		RAYG A 2
		RAYG B 1 bright A_FireCustomMissile("Anachrony_PelterShot")
		RAYG B 1 bright A_GunFlash
		RAYG CD 2 bright
		RAYG EF 3
		RAYG A 10
		RAYG A 4 A_ReFire
		Goto Ready
	AltFire:
		RAYG A 4
		RAYG B 0 bright A_FireCustomMissile("Anachrony_PelterSpiral1", 0, 0, 0, 16 * 1.0/1.732)
		RAYG B 0 bright A_FireCustomMissile("Anachrony_PelterSpiral2", 0, 0, -16/2, -16 * 1.732/6.0)
		RAYG B 1 bright A_FireCustomMissile("Anachrony_PelterSpiral3", 0, 0, 16/2, -16 * 1.732/6.0)
		RAYG B 1 bright A_GunFlash
		RAYG CD 4 bright
		RAYG EF 10
		RAYG A 10
	ForceAltRefire:
		RAYG A 3
		// can't hold down the button for continuous fire
		RAYG A 0 A_ReFire("ForceAltRefire")
		Goto Ready
	Flash:
		TNT1 A 2 bright A_Light1
		TNT1 B 3 bright A_Light2
		TNT1 A 0 bright A_Light0
		stop
	Spawn:
		RAYP A -1
		stop
  }
}

actor Anachrony_PelterShot
{
	radius 6
	height 8
	speed 20
	damage (randompick(4, 4, 6, 6, 8, 8, 12, 12, 20))
	projectile
	seesound "Raygun/Fire"
	+BLOODLESSIMPACT
	+NODAMAGETHRUST
	+NOEXTREMEDEATH

	var int user_ttl;

	states
	{
	Spawn:
		TNT1 A 0 NoDelay A_SetUserVar("user_ttl", 768 / speed)
	Move:
		TNT1 A 1 A_JumpIf(user_ttl < 0, "Vanish")
		TNT1 A 0 A_SetUserVar("user_ttl", user_ttl - 1)
		// Render ourselves with some particles
		TNT1 A 0 A_SpawnParticle(
			"ff 20 00", SPF_RELATIVE|SPF_FULLBRIGHT, 1, 6, 0,
			0.0, -1.0, 0.0)
		TNT1 A 0 A_SpawnParticle(
			"ff 20 00", SPF_RELATIVE|SPF_FULLBRIGHT, 1, 6, 0,
			0.0, 1.0, 0.0)
		TNT1 A 0 A_SpawnParticle(
			"ff 20 00", SPF_RELATIVE|SPF_FULLBRIGHT, 1, 6, 0,
			0.0, 0.0, -1.0)
		TNT1 A 0 A_SpawnParticle(
			"ff 20 00", SPF_RELATIVE|SPF_FULLBRIGHT, 1, 6, 0,
			0.0, 0.0, 1.0)
		// Primary particle trail, marking trajectory
		TNT1 A 0 A_SpawnParticle(
			"ff 40 00", SPF_RELATIVE|SPF_FULLBRIGHT, 20, 4, 0,
			0.0, 0.0, 0.0,
			0.0, frandom(-0.25, 0.25), frandom(-0.25, 0.25))
		TNT1 A 0 A_SpawnParticle(
			"ff 40 00", SPF_RELATIVE|SPF_FULLBRIGHT, 10, 4, 0,
			speed * -0.5, 0.0, 0.0,
			0.0, frandom(-0.25, 0.25), frandom(-0.25, 0.25))
		// Secondary particle trail, expanding outwards
		TNT1 AA 0 A_SpawnParticle(
			"ff 80 00", SPF_RELATIVE, 40, 3, 0,
			speed * -0.25, 0.0, 0.0,
			0.0, frandom(-0.5, 0.5), frandom(-0.5, 0.5))
		TNT1 A 0 A_SpawnParticle(
			"ff ff 00", SPF_RELATIVE, 30, 3, 0,
			speed * -0.75, 0.0, 0.0,
			0.0, frandom(-0.75, 0.75), frandom(-0.75, 0.75))
		TNT1 A 0 A_SpawnParticle(
			"ff ff 00", SPF_RELATIVE, 30, 2, 0,
			0.0, 0.0, 0.0,
			0.0, frandom(-1.0, 1.0), frandom(-1.0, 1.0))
		// virtual jump, for benefit of children
		TNT1 A 0 A_Jump(256, "Move")
	Vanish:
		TNT1 A 0
		stop
	Death:
		// Explode in a little cloud of particles
		TNT1 AAAAAAAAAAAA 0 A_SpawnParticle(
			"ff 00 00", SPF_RELATIVE|SPF_FULLBRIGHT, 50, 8, 0,
			0.0, 0.0, 0.0,
			frandom(-4.0, 4.0), frandom(-4.0, 4.0), frandom(-4.0, 4.0))
		TNT1 A 2
		TNT1 AAAAAAAAAAAA 0 A_SpawnParticle(
			"ff 40 00", SPF_RELATIVE|SPF_FULLBRIGHT, 50, 6, 0,
			0.0, 0.0, 0.0,
			frandom(-4.0, 4.0), frandom(-4.0, 4.0), frandom(-4.0, 4.0))
		TNT1 A 2
		TNT1 AAAAAAAAAAAA 0 A_SpawnParticle(
			"ff 80 00", SPF_RELATIVE|SPF_FULLBRIGHT, 50, 4, 0,
			0.0, 0.0, 0.0,
			frandom(-4.0, 4.0), frandom(-4.0, 4.0), frandom(-4.0, 4.0))
		// Linger briefly for the sake of gldefs
		// TODO would be nice to fade out?  how do defs for other projectiles work
		TNT1 A 20
		stop
	}
}

actor Anachrony_PelterSpiral1 : Anachrony_PelterShot
{
	WeaveIndexXY 0
	WeaveIndexZ 16
	states
	{
	Move:
		TNT1 A 0 A_Weave(4, 4, 1.0, 1.0)
		goto super::Move
	}
}
actor Anachrony_PelterSpiral2 : Anachrony_PelterSpiral1
{
	WeaveIndexXY 21
	WeaveIndexZ 37
}
actor Anachrony_PelterSpiral3 : Anachrony_PelterSpiral1
{
	WeaveIndexXY 42
	WeaveIndexZ 58
}
