/*
CREDITS:
(I guess I was sleeping too, when I was making this weapon...)
Sprite - ?
Cluster bomb - ?

Sounds:
Up sound - ?
Fire - Blizzard (Starcraft 2)
Alt-Fire - ?
Cluster bomb pellets and bomb's impact - Westwood (C&C1)
Missile flight - ?
Fire mode change - ID (Quake 2)
*/

ACTOR Katyusha : Weapon 24508
{
   //$Category Weapons
   //$Title Katyusha
   //$Sprite M202A0
   Inventory.PickupSound "misc/w_pkup"
   Inventory.PickupMessage "You got the ''Katyusha'' Multi-Launch Rocket System! Let's play on Stalin's Organs... A SONG DEDICATED TO HIS LIVER AND VERTEBRAE! (6)"
   Obituary "%o was swarmed %k's missile hail."
   Weapon.UpSound "weapons/katyushaup"
   Weapon.SelectionOrder 3
   Weapon.AmmoGive 0
   Weapon.AmmoGive2 20
   Weapon.AmmoType "RawketAmmo"
   Weapon.AmmoType2 "RawketAmmo"
   Weapon.AmmoUse 2
   Weapon.AmmoUse2 2
   Weapon.Kickback 45
   Weapon.SlotNumber 6
   States
   {
   Spawn:
      M202 A -1
      Stop
   Ready:
      ROCG A 1 A_WeaponReady
	  TNT1 A 0 A_JumpIfInventory("RO_GotoReload", 1, "Reload")
      Loop
   Deselect:
      ROCG A 0 A_ZoomFactor(1)
      ROCG A 1 A_Lower
      ROCG A 0 A_Lower
      Loop
   Select:
      ROCG A 1 A_Raise
      ROCG A 0 A_Raise
      Loop
   Fire:
      ROCF A 0 A_PlaySoundEx("weapons/katyushafire","Auto")
      ROCG A 0 A_Recoil(7.5)
      ROCG A 0 A_GunFlash
      ROCF A 1 Bright
      ROCF AAAAAAAAA 0 A_FireCustomMissile("BarrageMissile",0.1*random(50,-50),0,10,0,0,0.1*random(30,-30))
      ROCF A 0 A_FireCustomMissile("BarrageMissile",0.1*random(50,-50),1,10,0,0,0.1*random(30,-30))

      ROCF B 1 Bright A_ZoomFactor(0.9)
      ROCF C 1 Bright A_ZoomFactor(0.92)
      ROCF D 1 A_ZoomFactor(0.94)
      ROCF E 1 A_ZoomFactor(0.96)
      ROCF F 1 A_ZoomFactor(0.98)
      ROCG A 0 SetPlayerProperty(0,0,0)
      ROCF G 1 A_ZoomFactor(1)
      ROCF FED 1
      ROCG A 3
      ROCG A 0 A_Refire
      ROCG A 12
      Goto Ready
   AltFire:
      ROCG A 0 A_Recoil(4.5)
      ROCG A 0 A_GunFlash
      ROCG A 0 A_AlertMonsters
      ROCF A 0 A_FireCustomMissile("LarpaShot",0,1,10,0,0,0)

      ROCF A 0 Bright A_PlayWeaponSound("weapons/larpafire")
      ROCF B 1 Bright A_ZoomFactor(0.9)
      ROCF C 1 Bright A_ZoomFactor(0.92)
      ROCF D 1 A_ZoomFactor(0.94)
      ROCF E 1 A_ZoomFactor(0.96)
      ROCF F 1 A_ZoomFactor(0.98)
      ROCG A 0 SetPlayerProperty(0,0,0)
      ROCF G 1 A_ZoomFactor(1)
      ROCF FED 1
      ROCG A 24
      Goto Ready
   Reload:
   	TNT1 A 0 A_JumpIfInventory("SeekerActive",1,"UnReload")

	TNT1 A 0 A_SetBlend("Green",0.085,15)
	TNT1 A 0 A_PlaySound("Weapons/KatyushaMode",6)
	TNT1 A 0 A_GiveInventory("SeekerActive")
	TNT1 A 0 A_Print("Seeker Mode")
        ROCG A 18 A_WeaponReady(WRF_NOSWITCH|WRF_NOBOB)
	Goto Ready
   UnReload:
	TNT1 A 0 A_SetBlend("Red",0.085,15)
	TNT1 A 0 A_PlaySound("Weapons/KatyushaMode",6)
 	TNT1 A 0 A_TakeInventory("SeekerActive")
	TNT1 A 0 A_Print("Dumb Mode")
        ROCG A 18 A_WeaponReady(WRF_NOSWITCH|WRF_NOBOB)
	Goto Ready
   Flash:
      TNT1 A 3 BRIGHT A_Light2
      TNT1 A 2 BRIGHT A_Light1
      TNT1 A 0 BRIGHT A_Light0
      Stop
   }
}

//Homing Trigger

ACTOR SeekerActive : Inventory
{
   Inventory.MaxAmount 1
}

//Fire
ACTOR BarrageMissile
{
   Obituary "%o was ran over by %k's missile stampede."
   Radius 6
   Height 9
   Speed 40
   Damage 35
   Scale 0.9
   DeathSound "Weapons/BustExplo"
   PROJECTILE
   +RANDOMIZE
   +THRUGHOST
   +EXPLODEONWATER
   +SEEKERMISSILE
   +SCREENSEEKER
   +DONTSEEKINVISIBLE
   SeeSound ""
   States
   {
   Spawn:
      MIST A 0
      MIST A 0 A_PlaySoundEx("weapons/katyushaloop","SoundSlot5",1)
      TNT1 A 0 A_JumpIfInTargetInventory("SeekerActive",1,"Maocopter")
      Goto Roflcopter
   Roflcopter:
      MIST A 0 A_ChangeVelocity (frandom(-0.4, 0.4), frandom(-0.4, 0.4), frandom(-0.4, 0.4), 0)
      MIST A 1 Bright A_SpawnItemEx("BarrageTrail",0.1*random(8,12),0.1*random(8,12),0.1*random(8,12),0.1*random(1,3),0.1*random(1,3),0.1*random(1,3),random(0,359),0)
      Goto Spawn
   Maocopter:
      MIST A 0 A_SeekerMissile(2,5,SMF_LOOK|SMF_PRECISE,48,4)
      MIST A 0 A_ChangeVelocity (frandom(-0.4, 0.4), frandom(-0.4, 0.4), frandom(-0.4, 0.4), 0)
      MIST A 1 Bright A_SpawnItemEx("BarrageTrail",0.1*random(8,12),0.1*random(8,12),0.1*random(8,12),0.1*random(1,3),0.1*random(1,3),0.1*random(1,3),random(0,359),0)
      Goto Spawn
   Death:
      TNT1 A 0 A_JumpIfInTargetInventory("NukerUpgrade",1,"NukerDeath")
      TNT1 A 0 A_StopSoundEx("SoundSlot5")
      TNT1 A 0 A_Explode(125,128)
      TNT1 A 0 A_SpawnItemEx("MissileExplode",0,0,0,0,0,0,0,128,0)
      TNT1 BCD 5
      stop
   NukerDeath:
      TNT1 A 0 A_StopSoundEx("SoundSlot5")
      TNT1 A 0 A_Explode(250,192)
      TNT1 A 1 A_SpawnItemEx("NukerMissileExplode",0,0,0,0,0,0,0,128,0)
      TNT1 BCD 5
      stop
   }
}

ACTOR BarrageTrail
{
	Radius 0
	Height 0
	Speed 0
	PROJECTILE
	Scale 0.14
	Alpha 0.2
	Renderstyle Normal
	+NOGRAVITY
	+NOINTERACTION
	+THRUGHOST
	+CLIENTSIDEONLY
	+DONTSPLASH
	+DONTBLAST
	States
	{
	Spawn:	
		SMKE A 0
		SMKE A 0 A_FadeOut(0.01)
		SMKE ABCDEFGHI 2 A_FadeOut(0.01)
		SMKE JKLMNOPQ 2 A_FadeOut(0.02)
		Stop
	}
}

//Alt-Fire
actor LarpaShot
{
  Radius 12
  Height 8
  Speed 25
  Damage 0
  Projectile
  -NOGRAVITY
  +RIPPER
  +THRUGHOST
  +DONTSPLASH
  +EXPLODEONWATER
  Gravity 0.35
  SeeSound ""
  DeathSound ""
  Obituary "%o was humilated by %k's larpa emitter."
  Scale 0.25
  States
  {
  Spawn:
    LARP AAAAAAAAAAA 1 bright A_SpawnItemEx("LarpaTrail",-4+random(-3,3),random(-3,3),random(-3,3),0,0,0,0,128,0)
  AAAAA:
    TNT1 A 0 A_JumpIfInTargetInventory("NukerUpgrade",1,"NukerAAAAA")
    LARP A 0 bright A_SpawnItemEx("LarpaTrail",-4+random(-3,3),random(-3,3),random(-3,3),0,0,0,0,128,0)
    LARP AA 0 bright A_SpawnItemEx("LarpaPellet",0,0,0,4,0,3+random(-1,2),random(0,360),160,0)
    LARP A 1
    loop
  NukerAAAAA:
    LARP A 0 bright A_SpawnItemEx("LarpaTrail",-4+random(-3,3),random(-3,3),random(-3,3),0,0,0,0,128,0)
    LARP AA 0 bright A_SpawnItemEx("NukerLarpaPellet",0,0,0,4,0,3+random(-1,2),random(0,360),160,0)
    LARP A 1
    loop
  Death:
    TNT1 A 0 A_JumpIfInTargetInventory("NukerUpgrade",1,"NukerDeath")
    TNT1 A 0 A_AlertMonsters
    TNT1 A 0 A_PlaySoundEx("weapons/larpaboom","Soundslot5")
    TNT1 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 0 A_SpawnItemEx("LarpaPellet",0,0,0,4,0,9+random(-1,3),random(0,360),160,0)
    TNT1 A 0 A_Explode(100,128)
    TNT1 A 0 A_SpawnItemEx("MissileExplode",0,0,0,0,0,0,0,128,0)
    TNT1 BBBBBBBCCCCCCCDDDDDDD 1 A_SpawnItemEx("LarpaPellet",0,0,0,4,0,6+random(-1,3),random(0,360),160,0)
    stop
  NukerDeath:
    TNT1 A 0 A_AlertMonsters
    TNT1 A 0 A_PlaySoundEx("weapons/larpaboom","Soundslot5")
    TNT1 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 0 A_SpawnItemEx("NukerLarpaPellet",0,0,0,4,0,9+random(-1,3),random(0,360),160,0)
    TNT1 A 0 A_Explode(200,192)
    TNT1 A 0 A_SpawnItemEx("NukerMissileExplode",0,0,0,0,0,0,0,128,0)
    TNT1 BBBBBBBCCCCCCCDDDDDDD 1 A_SpawnItemEx("NukerLarpaPellet",0,0,0,4,0,6+random(-1,3),random(0,360),160,0)
    stop
  }
}

ACTOR LarpaTrail
{
	Scale 0.1
	Alpha 0.6
	+NOINTERACTION
	+NOGRAVITY
	+THRUGHOST
	+DONTSPLASH
	+DONTBLAST
	+CLIENTSIDEONLY
	Renderstyle Add
	States
	{
		Spawn:
			SMKE A 0
			SMKE A 0 A_Jump(255,2,4,6,8,10)
			SMKE ABCDEFGHJIKLMNOPQ 1 A_FadeOut(0.025)
			Stop
	}
}

actor LarpaPellet
{
  Radius 4
  Height 6
  Damage 30
  Projectile
  +RANDOMIZE
  -NOGRAVITY
  +THRUGHOST
  Gravity 0.35
  SeeSound ""
  DeathSound "weapons/larpaexp"
  Scale 0.45
  States
  {
  Spawn:
    LARP B 2 A_SpawnItemEx("LarpaTrail",random(-1.5,1.5),random(-1.5,1.5),random(-1.5,1.5),0,0,0,0,128,0)
    loop
  Death:
    TNT1 A 0 A_Explode(40,96,0)
    TNT1 A 0 A_Explode(10,96)
    TNT1 A 0 A_SpawnItemEx("PelletExplode",0,0,0,0,0,0,0,128,0)
    TNT1 BCD 4
    stop
  }
}

actor NukerLarpaPellet : LarpaPellet
{
  States
  {
  Death:
    TNT1 A 0 A_Explode(80,144,0)
    TNT1 A 0 A_Explode(20,144)
    TNT1 A 1 A_SpawnItemEx("NukerPelletExplode",0,0,0,0,0,0,0,128,0)
    TNT1 BCD 4
    stop
  }
}

ACTOR LarpaPelletTrail : LarpaTrail
{
	Scale 0.05
	Alpha 0.35
	+CLIENTSIDEONLY
	Renderstyle Add
}
