/*
CREDITS:
Sprite - NMN\Paul
Pickup by me from some other weapon bits by Paul.

Fire, reload - Westwood (C&C Renegade)
Add fire - Blizzard ( Starcraft II)
Tank shell bouncing - ID (ET:Quake Wars)
*/

ACTOR Pushka : Weapon 24506
{
   //$Category Weapons
   //$Title Pushka
   //$Sprite ERMGX0
   Inventory.PickupSound "misc/w_pkup"
   Inventory.PickupMessage "You got the ''Pushka'' 100mm portable cannon! Where is my tank!? Oh wait, I am the tank itself. (5)"
   Obituary "%o was command and conquered by %k's 100mm caliber gift."
   Weapon.UpSound "Weapons/PushkaUp"
   Weapon.SelectionOrder 4
   Weapon.AmmoType "100MMAmmo"
   Weapon.AmmoGive 6
   Weapon.AmmoUse 1
   Weapon.AmmoType2 "100MMAmmo"
   Weapon.AmmoUse2 3
   Weapon.Kickback 50
   Weapon.SlotNumber 5
   +NOAUTOFIRE
   +NOALERT
   Scale 0.78
   States
   {
   Spawn:
      ERMG X -1
      Loop
   Ready:
      ERMG A 1 A_WeaponReady
      Loop
   Deselect:
      ERMG A 0 A_ZoomFactor(1)
      ERMG A 1 A_Lower
      ERMG A 0 A_Lower
      Loop
   Select:
      ERMG A 0 A_Jump(128,2)
      ERMG A 0 A_PlaySoundEx("misc/w_pushka_pkup","Voice")
      ERMG A 1 A_Raise
      ERMG A 0 A_Raise
      Goto Select+2
   Fire:
      ERMF A 0 A_GunFlash
      ERMF A 0 A_Recoil(14)
      ERMF A 0 A_AlertMonsters
      ERMF A 0 A_PlayWeaponSound("Weapons/PushkaAltFire")
      ERMF A 0 A_PlaySoundEx("Weapons/PushkaFire","Auto")
      ERMF A 0 A_PlaySoundEx("Weapons/PushkaFireAdd","SoundSlot6")
      ERMF A 0 A_FireCustomMissile("100MMShell",0,1,10,0)
      ERMF A 0 ACS_Execute(851,0,50+random(2,-2),20+random(2,-2))
      ERMF A 1 Bright A_ZoomFactor(0.9)
      ERMF B 1 Bright A_ZoomFactor(0.92)
      ERMF C 1 Bright A_ZoomFactor(0.93)
      ERMF D 1 A_ZoomFactor(0.94)
      ERMF E 1 A_ZoomFactor(0.95)
      ERMF F 1 A_ZoomFactor(0.96)
      ERMG A 1 A_ZoomFactor(0.97)
      ERMG A 1 A_ZoomFactor(0.98)
      ERMG A 1 A_ZoomFactor(0.995)
      ERMG A 3 A_ZoomFactor(1)
      ERMG A 0 A_PlaySoundEx("weapons/PushkaReload","SoundSlot5")
      ERMG A 3
      ERMR ABCDE 1
      ERMR E 4 A_FireCustomMissile("100MMCasingSpawner", 0, 0, 36, 8)
      ERMR EDCBA 1
      ERMG A 3
      Goto Ready
   AltFire:
      ERMF A 0 A_JumpIfInventory("VortexOut",1,"Nope")
      ERMF A 0 A_GiveInventory("VortexOut",1)
      ERMF A 0 A_GunFlash
      ERMF A 0 A_Recoil(5)
      ERMF A 0 A_AlertMonsters
      ERMF A 0 A_PlaySoundEx("Weapons/PushkaFire","Auto")
      ERMF A 0 A_PlaySoundEx("Weapons/BlasterAltFire","SoundSlot6")
      ERMF A 0 A_FireCustomMissile("BlasterShell",0,1,10,0)
      ERMF A 0 ACS_Execute(851,0,50+random(2,-2),20+random(2,-2))
      ERMF A 1 Bright A_ZoomFactor(0.93)
      ERMF B 1 Bright A_ZoomFactor(0.96)
      ERMF C 1 Bright A_ZoomFactor(0.97)
      ERMF D 1 A_ZoomFactor(0.98)
      ERMF E 1 A_ZoomFactor(0.99)
      ERMF F 1 A_ZoomFactor(0.995)
      ERMG A 6 A_ZoomFactor(1)
      ERMG A 0 A_PlaySoundEx("Weapons/PushkaAltReload","SoundSlot5")
      ERMG A 3
      ERMR ABCDE 2
      ERMR E 4 A_FireCustomMissile("100MMCasingSpawner", 0, 0, 36, 8)
      ERMS ABCDEFABCDEFABCDEF 1
      ERMR EDCBA 2
      ERMG A 5
      Goto Ready
   Nope:
      ERMG A 0 A_PlaySoundEx("Weapons/PushkaNope","SoundSlot5")
      ERMG A 2 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
      ERMF F 2 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
      ERMG A 3 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
      Goto Ready
   Flash:
      TNT1 A 3 Bright A_Light2
      TNT1 A 3 Bright A_Light1
      TNT1 A 0 Bright A_Light0
      Stop
   }
}

//Fire

ACTOR 100MMTrailSpawner
{ 
    +NOGRAVITY
    +NOINTERACTION
	+CLIENTSIDEONLY
    States
    {
    Spawn:
      TNT1 A 0
      TNT1 A 1 A_SpawnItemEx("100MMTrail",-23+random(5,-5),random(5,-5),7,0,0,0,0,128,0)
      Stop
    }
}

ACTOR 100MMTrail
{ 
    Scale 0.175
    Alpha 0.3
    Renderstyle Add
    +NOGRAVITY
    +NOINTERACTION
	+CLIENTSIDEONLY
    States
    {
    Spawn:
      SMKE ABCDEFGHIJKLMNOPQ 1 A_FadeOut(0.01)
      Stop
    }
}

actor 100MMShell : FastProjectile
{
  Radius 11
  Height 8
  Speed 150
  Damage 300
  Projectile
  +NOGRAVITY
  +THRUGHOST
  +DONTSPLASH
  +EXPLODEONWATER
  +DONTBLAST
  DeathSound "Weapons/PushkaExp"
  Obituary "%o was command and conquered by %k's 100mm caliber gift."
  Scale 1
  MissileType "100MMTrailSpawner"
  States
  {
  Spawn:
    10MM A 1 bright
    10MM A 1 bright ThrustThingZ(0,random(-1,-3),0,1)
    10MM A 0 A_PlaySoundEx("Weapons/PushkaLoop","Body",1,0)
    Loop
  Death:
    TNT1 A 0 A_JumpIfInTargetInventory("NukerUpgrade",1,"NukerDeath")
    TNT1 B 0 A_Explode(150,164)
    TNT1 A 0 A_SpawnItemEx("PushkaExplode",0,0,0,0,0,0,0,SXF_TRANSFERPOINTERS,0)
    TNT1 A 0 A_Explode(150,256,0)
    TNT1 BCD 6
    stop
  NukerDeath:
    TNT1 B 0 A_Explode(300,192)
    TNT1 A 0 A_SpawnItemEx("NukerPushkaExplode",0,0,0,0,0,0,0,SXF_TRANSFERPOINTERS,0)
    TNT1 A 0 A_Explode(300,384,0)
    TNT1 BCD 6
    stop
  }
}

//100MMCasing

ACTOR 100MMCasingSpawner
{
    Radius 1
    Height 1
    Speed 17
    PROJECTILE
    States
    {
    Spawn:
        TNT1 A 1
        TNT1 A 0 A_Die
        Goto Death
    Death:
        TNT1 A 0 A_CustomMissile("100MMCasing",-22+random(-4,4),0+random(-4,4),-45,2,45)
        Stop
    }
}

ACTOR 100MMCasing
{ 
    Radius 11
    Height 8
    Speed 3
    Damage 5
    Mass 300
    +NOBLOCKMAP +DROPOFF +MISSILE +NOTELEPORT +FLOORCLIP +FORCEXYBILLBOARD +DONTBLAST
    BounceType "Doom"
    BounceCount 2
    BounceFactor 0.75
    Gravity 1.5
    BounceSound "Weapons/100MMCasing"
    DeathSound "Weapons/100MMCasing"
    Scale 0.9
    States
    {
    Spawn:
      10MM B 1 A_SpawnItemEx("CasingSmoke",0.1*random(85,-85),0.1*random(85,-85),0.1*random(35,10),0,0,0.1*random(6,11),0,128,0)
      Loop
    Death:
      10MM BBBBBBBBBBBB 1 A_SpawnItemEx("CasingSmoke",0.1*random(85,-85),0.1*random(85,-85),0.1*random(35,10),0,0,0.1*random(6,11),0,128,0)
      10MM BBBBBBBBBBBBBBBBBB 2 A_SpawnItemEx("CasingSmoke",0.1*random(85,-85),0.1*random(85,-85),0.1*random(35,10),0,0,0.1*random(6,11),0,128,0)
      10MM BBBBBBBBBBBBBBBBBBBBBBBBBBBB 3 A_SpawnItemEx("CasingSmoke",0.1*random(85,-85),0.1*random(85,-85),0.1*random(35,10),0,0,0.1*random(6,11),0,128,0)
      10MM B 75
      10MM BBBBBBBBBBBBBBBBBBBB 1 A_FadeOut(0.05)
      Stop
    }
}

ACTOR CasingSmoke
{ 
    Scale 0.15
    Alpha 0.15
    RenderStyle Normal
    +NOINTERACTION
    +NOGRAVITY
    +THRUGHOST
    +DONTSPLASH
	+CLIENTSIDEONLY
    States
    {
    Spawn:
      SMKE A 0
      SMKE A 0 A_FadeOut(0.025)
      SMKE ABCDEFGHIJKLMNOPQ 3 //A_SetScale(ScaleX -0.005, ScaleY -0.005)
      Stop
    }
}

//Alt-Fire

actor VortexOut : Inventory
{
  Inventory.MaxAmount 1
}

actor BlasterShell : FastProjectile
{
  Speed 50
  Damage 2
  Projectile
  +NOGRAVITY
  +THRUGHOST
  +DONTSPLASH
  +EXPLODEONWATER
  +SKYEXPLODE
  +RIPPER
  +DONTBLAST
  DeathSound ""
  Obituary "%o was strucked by %k's blaster shell."
  Renderstyle Add
  Scale 1
  MissileType "BlasterTrailSpawner"
  States
  {
  Spawn:
    10MM A 0
    10MM A 0 A_SpawnItemEx("BlasterRing",frandom(3,-3),frandom(3,-3),frandom(3,-3),0,0,0,0,128,0)
    BLSB M 1 bright A_Blast(0, 128, 128, 15, "BlastEffect", None)
    10MM A 0 A_PlaySoundEx("Weapons/BlasterLoop","Body",1,0)
    Loop
  Death:
    TNT1 A 0 A_PlaySound("Weapons/BlasterStruck")
    TNT1 A 0 A_Quake(8,17,0,256,none)
    TNT1 A 0 A_Blast(BF_AFFECTBOSSES, 128, 256, 20, "BlastEffect", None)
    TNT1 A 0 A_SpawnItemEx("BlasterVortex",0,0,0,0,0,0,0,0,0)
    TNT1 AAAAAAAAAAAAAAAAA 0 A_SpawnItemEx("BlasterVortexParticle",frandom(2,-2),frandom(2,-2),frandom(2,-2),frandom(0.25,3),frandom(0.25,3),frandom(-3,3),frandom(0,359),128,0)
    TNT1 A 1
    Stop
  }
}

ACTOR BlasterRing
{
  +DONTBLAST
  +NOGRAVITY
  +NOINTERACTION
  +CLIENTSIDEONLY
  Renderstyle Add
  Alpha 0.99
  Scale 0.15
  States
  {
  Spawn:
  	TNT1 A 0
  	TNT1 A 0 A_FadeOut(0.05)
	BLSR A 1 Bright //A_SetScale(ScaleX +0.025+random(-0.01,-0.015), ScaleY+0.01+random(-0.015,-0.25))
  	TNT1 A 0 A_FadeOut(0.05)
	BLSR A 1 Bright //A_SetScale(ScaleX +0.025+random(-0.01,-0.015), ScaleY+0.01+random(-0.015,-0.25))
  	TNT1 A 0 A_FadeOut(0.05)
	BLSR A 1 Bright //A_SetScale(ScaleX +0.025+random(-0.01,-0.015), ScaleY+0.01+random(-0.015,-0.25))
  	TNT1 A 0 A_FadeOut(0.05)
	BLSR A 1 Bright //A_SetScale(ScaleX +0.025+random(-0.01,-0.015), ScaleY+0.01+random(-0.015,-0.25))

  	TNT1 A 0 A_FadeOut(0.05)
	BLSR A 1 Bright //A_SetScale(ScaleX -0.025+random(+0.01,+0.015), ScaleY-0.01+random(-0.015,-0.25))
  	TNT1 A 0 A_FadeOut(0.05)
	BLSR A 1 Bright //A_SetScale(ScaleX -0.025+random(+0.01,+0.015), ScaleY-0.01+random(-0.015,-0.25))
  	TNT1 A 0 A_FadeOut(0.05)
	BLSR A 1 Bright //A_SetScale(ScaleX -0.025+random(+0.01,+0.015), ScaleY-0.01+random(-0.015,-0.25))
  	TNT1 A 0 A_FadeOut(0.05)
	BLSR A 1 Bright //A_SetScale(ScaleX -0.025+random(+0.01,+0.015), ScaleY-0.01+random(-0.015,-0.25))
	Loop
  Death:
  	TNT1 A 1
	Stop
  }
}

ACTOR BlasterVortex
{
  +DONTBLAST
  +NOGRAVITY
  +NOINTERACTION
  ReactionTime 17
  Renderstyle Add
  Alpha 0.4
  States
  {
  Spawn:
  	TNT1 A 0
  	BLSB MLKJI 2 Bright A_FadeIn(0.1)
   	TNT1 A 0 A_SpawnItemEx("BlasterSmokeSpawner",0,0,0,0,0,0,0,128,0)
  Looplet:
  	TNT1 A 0 A_Countdown
  	TNT1 A 0 A_PlaySoundEx("Weapons/BlasterLoop","SoundSlot5",1,0)
  	TNT1 A 0 A_SpawnItemEx("BlasterRingLoop",0,0,0,0,0,0,0,128,0)
  	TNT1 A 0 A_Blast(BF_AFFECTBOSSES, 64, 256, 15, "BlastEffect", None)
  	TNT1 A 0 A_Quake(1,14,0,256,none)
	BLSB A 2 Bright
	BLSB C 0 //A_SetScale(ScaleX-0.05,ScaleX)
	BLSB C 2 Bright A_FadeOut(0.05)
	BLSB D 0 //A_SetScale(ScaleX-0.05,ScaleX)
	BLSB D 2 Bright A_FadeOut(0.05)
	BLSB E 0 //A_SetScale(ScaleX-0.05,ScaleX)
	BLSB E 2 Bright A_FadeOut(0.05)
	BLSB F 0 //A_SetScale(ScaleX+0.05,ScaleX)
	BLSB F 2 Bright A_FadeIn(0.05)
	BLSB G 0 //A_SetScale(ScaleX+0.05,ScaleX)
	BLSB G 2 Bright A_FadeIn(0.05)
	BLSB H 0 //A_SetScale(ScaleX+0.05,ScaleX)
	BLSB H 2 Bright A_FadeIn(0.05)
  	Loop
  Death:
  	TNT1 A 0 A_TakeFromTarget("VortexOut",1)
  	TNT1 A 0 A_SpawnItemEx("BlasterVortexGL",0,0,0,0,0,0,0,128,0)
  	TNT1 AAAAAAAAAAAAAAAAAAAAAAAAA 0 A_SpawnItemEx("BlasterVortexParticle",frandom(12,-12),frandom(12,-12),frandom(12,-12),frandom(2.25,3),frandom(2.25,3),frandom(-1,4),frandom(0,359),128,0)
   	TNT1 A 0 A_Blast(BF_AFFECTBOSSES, 255, 304, 45, "BlastEffect", None)
   	TNT1 A 0 A_SpawnItemEx("BlasterRingBig",0,0,0,0,0,0,0,128,0)
  	TNT1 A 0 A_PlaySoundEx("Weapons/BlasterEnd","SoundSlot5")
  	TNT1 A 0  A_Quake(8,21,0,304,none)
  	BLSB IJKLM 2 Bright A_FadeOut(0.1)
	Stop
  }
}

ACTOR BlasterSmokeSpawner
{ 
    ReactionTime 238
    +DONTBLAST
    +NOGRAVITY
    +NOINTERACTION
	+CLIENTSIDEONLY
    States
    {
    Spawn:
      TNT1 A 0
      TNT1 A 0 A_Countdown
      TNT1 AA 0 A_SpawnItemEx("BlasterSmokey",frandom(23,-23),frandom(23,-23),frandom(23,-23),frandom(-2,2),frandom(-2,2),frandom(-2,2),frandom(0,359),128,0)
      TNT1 A 1
      Loop
    Death:
      TNT1 A 1
      Stop
    }
}

ACTOR BlasterSmokey
{ 
    Scale 0.33
    Alpha 0.55
    Renderstyle Add
    +DONTBLAST
    +NOGRAVITY
	+CLIENTSIDEONLY
    +NOINTERACTION
    States
    {
    Spawn:
      ISMK A 0 A_ChangeVelocity (frandom(-1.5, 1.5), frandom(-1.5, 1.5), frandom(-1.5, 1.5), 0)
    GoOn:
      ISMK ABCDEFGHIJK 2 //A_SetScale(ScaleX+0.02,ScaleY+0.02)
      ISMK LMNOPQ 2 A_FadeOut(0.02)
      Stop
    }
}

ACTOR BlasterRingLoop : BlasterRing
{
  Scale 0.4
  States
  {
  Spawn:
  	TNT1 A 0
  	TNT1 A 0 A_FadeOut(0.075)
	BLSR A 1 Bright //A_SetScale(ScaleX +0.15, ScaleY +0.15)
	Loop
  Death:
  	TNT1 A 1
	Stop
  }
}

ACTOR BlasterRingBig : BlasterRing
{
  Scale 0.65
  States
  {
  Spawn:
  	TNT1 A 0
  	TNT1 A 0 A_FadeOut(0.02)
	BLSR A 1 Bright //A_SetScale(ScaleX +0.1, ScaleY +0.1)
	Loop
  Death:
  	TNT1 A 1
	Stop
  }
}

ACTOR BlasterVortexHit
{
  +DONTBLAST
  +NOGRAVITY
  +NOINTERACTION
  +CLIENTSIDEONLY
  Renderstyle Add
  Alpha 0.6
  Scale 0.75
  States
  {
  Spawn:
  	TNT1 A 0
  	TNT1 AA 0 A_SpawnItemEx("BlasterVortexParticle",frandom(2,-2),frandom(2,-2),frandom(2,-2),frandom(0.25,3),frandom(0.25,3),frandom(-3,3),frandom(0,359),128,0)
  	TNT1 A 1
	Stop
  }
}

ACTOR BlasterVortexParticle
{
  +DONTBLAST
  -NOGRAVITY
  +DONTSPLASH
  +NOTELEPORT
  Renderstyle Add
  Alpha 0.99
  Gravity 0.1
  +CLIENTSIDEONLY
  Scale 0.125
  BounceType Hexen
  States
  {
  Spawn:
  	TNT1 A 0
	BLSP A 0 A_FadeOut(0.04)
	BLSP A 0 A_ChangeVelocity (frandom(-0.4, 0.4), frandom(-0.4, 0.4), frandom(-0.4, 0.4), 0)
	BLSP A 2 Bright //A_SetScale(ScaleX -0.001, ScaleY -0.001)
	Loop
  }
}

ACTOR BlasterVortexGL //Used by GLDEFS for explosion light.
{
  +DONTBLAST
  +NOGRAVITY
  +NOINTERACTION
  +CLIENTSIDEONLY
  States
  {
  Spawn:
  	TNT1 A 35
	Stop
  }
}

ACTOR BlasterTrailSpawner
{ 
    +DONTBLAST
    +NOGRAVITY
    +NOINTERACTION
	+CLIENTSIDEONLY
    States
    {
    Spawn:
      TNT1 A 0
      TNT1 A 1 A_SpawnItemEx("BlasterTrail",-23+random(5,-5),random(5,-5),7,0,0,0,0,128,0)
      Stop
    }
}

ACTOR BlasterTrail
{ 
    Scale 0.175
    Alpha 0.3
    Renderstyle Add
    +DONTBLAST
    +NOGRAVITY
    +NOINTERACTION
	+CLIENTSIDEONLY
    States
    {
    Spawn:
      ISMK ABCDEFGHIJKLMNOPQ 1 A_FadeOut(0.01)
      Stop
    }
}

//Unused

actor 100MMBall
{
  Speed 70
  Damage 150
  Projectile
  -NOGRAVITY
  +THRUGHOST
  +DONTSPLASH
  +EXPLODEONWATER
  Gravity 0.6
  DeathSound "Weapons/PushkaExp"
  Renderstyle Add
  Obituary "%o was command and conquered by %k's flaming ball of steel."
  Scale 0.6
  States
  {
  Spawn:
    10BA A 1 bright
    10BA A 0 A_PlaySoundEx("Weapons/PushkaLoop","Body",1,0)
    10BA A 0 A_SpawnItemEx("100MMTrail",-15+random(-1,1),random(-1,1),random(-1,1),0,0,0,0,128,0)
    Loop
  Death:
    TNT1 A 0 A_JumpIfInTargetInventory("NukerUpgrade",1,"NukerDeath")
    TNT1 B 0 A_Explode(100,164)
    TNT1 A 1 A_SpawnItemEx("PushkaExplode",0,0,0,0,0,0,0,128,0)
    TNT1 A 0 A_Explode(100,256,0)
    stop
  NukerDeath:
    TNT1 B 0 A_Explode(200,192)
    TNT1 A 1 A_SpawnItemEx("NukerPushkaExplode",0,0,0,0,0,0,0,128,0)
    TNT1 A 0 A_Explode(200,384,0)
    stop
  }
}
