/*
CREDITS:
Sprites - Marty Kirra
Pickup by me.

Sounds:
Swing, Impact, KA-BOOOOM! - Valve (Team Fortress)
Screaming, evil chanting - ID (Doom 3)
Kick - ?
Throw - ID (Quake 2)
Bouncing - Raven (Wolfenstein 3)
*/

ACTOR Caber : DoomWeapon 24501 //One of more messy code around here, shoulda clean it up someday.
{
	//$Category Weapons
	//$Title Ullapool Caber
	//$Sprite CBRGX0
   Tag "Ullapool Caber"
   Inventory.PickupSound "misc/w_pkup"
   Inventory.PickupMessage "You got the ''Ullapool Caber'' grenade! A sober person would throw it... (1)"
   Obituary "%o was slammed in the face with %k's high-yield face remover."
   Weapon.UpSound "Weapons/KhaBoom"
   Weapon.SelectionOrder 7
   Weapon.Kickback 250
   Weapon.SlotNumber 1
   /*Weapon.BobStyle InverseSmooth
   Weapon.BobSpeed 1.6
   Weapon.BobRangeY 0.6
   Weapon.BobRangeX 1.2*/
   AttackSound ""
   +NOALERT
   States
   {
   Spawn:
      CBRG X -1
      Loop
   Ready:
      TNT1 A 0 A_JumpIfInventory("TwinCaberMode",1,"TwinReady")
      CBRG A 0 SetPlayerProperty(0,0,0)
      CBRG A 0 A_JumpIfInventory("CaberPower",100,"ReadyFull")
      CBRG A 0 A_GiveInventory("CaberPower",1)
   ReadyMain:
      CBRG A 1 A_WeaponReady
	  TNT1 A 0 A_JumpIfInventory("RO_GotoReload", 1, "Reload")
	  TNT1 A 0 A_JumpIfInventory("RO_GotoZoom", 1, "Zoom")
      Goto Ready
   ReadyFull:
      CBRG A 0 A_PlaySoundEx("Weapons/CaberCharged","SoundSlot5",1)
	  TNT1 A 0 A_JumpIfInventory("RO_GotoReload", 1, "Reload")
	  TNT1 A 0 A_JumpIfInventory("RO_GotoZoom", 1, "Zoom")
      CBRG A 1 A_WeaponReady
      Goto Ready
   Reload:
      CBRG A 0 A_JumpIfInventory("TwinCaberMode",1,"UnReload")
      CBRG A 0 A_StopSoundEx("SoundSlot5")
      CBRG A 0 A_GiveInventory("TwinCaberMode",1)
	  CBRM ABCDE 1
	  2BRG A 10
	  Goto Ready
   UnReload:
      CBRG A 0 A_TakeInventory("TwinCaberMode",1)
	  CBRM EDCBA 1
	  CBRG A 10
	  Goto Ready
   Deselect:
      CBRG A 0 A_StopSoundEx("SoundSlot5")
      TNT1 A 0 A_JumpIfInventory("TwinCaberMode",1,"TwinDeselect")
      CBRG A 1 A_Lower
      CBRG A 0 A_Lower
      Loop
   Select:
      TNT1 A 0 A_JumpIfInventory("TwinCaberMode",1,"TwinSelect")
      CBRG A 1 A_Raise
      CBRG A 0 A_Raise
      Loop
   Fire:
      TNT1 A 0 A_JumpIfInventory("TwinCaberMode",1,"TwinFire") //Dual Wield
   NormalHold:
      TNT1 A 0 A_JumpIfInventory("CaberCounter",1,"SMASH")
      CBRU ABCDE 1
      TNT1 A 0 A_PlaySoundEx("Weapons/CaberSwing","SoundSlot6")
      CBRU DB 1
      CBRG A 1
      CBRD B 1
      CBRD D 0 A_FireCustomMissile("BoomJack",0,1,0,0)
      CBRD DE 1 A_JumpIfInventory("CaberFlyTrigger",1,"FLYING")
      TNT1 AAAAA 1 A_JumpIfInventory("CaberFlyTrigger",1,"FLYING")
      TNT1 A 5 A_TakeInventory("CaberFlyTrigger",1)
      CBRD EDCBA 1
      CBRG A 5
      Goto Ready
   FLYINGWithScream:
      TNT1 A 0 A_PlaySoundEx("Weapons/CaberYeah","SoundSlot5") //When charging and hit is succesful
   FLYING:
      TNT1 A 1 ThrustThingZ(0, 120, 0, 1)
      TNT1 A 28
      CBRD EDCBA 1
      CBRG A 1 A_TakeInventory("CaberFlyTrigger",1)
      CBRG A 4
      Goto Ready
   Hold:
      TNT1 A 0 A_JumpIfInventory("TwinCaberMode",1,"TwinHold")
      Goto NormalHold
   StopThisMadness:
      CBRU EDCBA 1
      CBRG A 5
      Goto Ready
   AltFire:
      TNT1 A 0 A_JumpIfInventory("TwinCaberMode",1,"TwinAltFire") //Caber Wall Climb
      Goto ChargeAltFire
   AltHold:
      TNT1 A 0 A_JumpIfInventory("TwinCaberMode",1,"TwinAltHold")
      Goto Ready

   //THROWKICK
   Zoom:
      TNT1 A 0 A_JumpIfInventory("TwinCaberMode",1,"TwinZoom")
      CBRU ABCDE 1
      CBRK AB 1
      TNT1 A 0 A_PlaySoundEx("Weapons/CaberThrowKick","SoundSlot6")
      CBRK CDEFG 1
      CBRD D 0 A_FireCustomMissile("CaberGrenade",0,1,2,0)
      CBRK HIJKL 1
      TNT1 A 17
      CBRD EDCBA 1
      CBRG A 5
      Goto Ready
   TwinZoom:
      3BRU ABCDE 1
      2BRK AB 1
      2BRK X 0 A_PlaySoundEx("Weapons/CaberThrowKick","SoundSlot6")
      2BRK CDEFG 1
      2BRD D 0 A_FireCustomMissile("CaberGrenade",0,1,2,0)
      2BRK HIJKL 1
      2BRK X 17
      3BRD EDCBA 1
      2BRG A 5
      Goto Ready

   //CHARGE
   ChargeAltFire:
      CBRG A 0 A_JumpIfInventory("CaberPower",100,1)
      Goto Ready
      CBRG A 0 SetPlayerProperty(0,1,0)
      TNT1 A 0 A_GiveInventory("CaberBoost")
      TNT1 A 0 A_GiveInventory("CaberCounter",85)
      TNT1 A 0 A_PlaySoundEx("Weapons/CaberScream","SoundSlot5")
      TNT1 A 0 A_Recoil(-2)
      CBRU A 1 A_Quake(9,3,0,32,"none")
      TNT1 A 0 A_Recoil(-3)
      CBRU B 1 A_Quake(9,3,0,32,"none")
      TNT1 A 0 A_Recoil(-2)
      CBRU C 1 A_Quake(9,3,0,32,"none")
      TNT1 A 0 A_Recoil(-3)
      CBRU D 1 A_Quake(9,3,0,32,"none")
   Looplet:
      TNT1 A 0 A_JumpIfInventory("CaberCounter",1,1)
      Goto StopThisMadness
      TNT1 A 0 A_TakeInventory("CaberPower",3)
      TNT1 A 0 A_TakeInventory("CaberCounter",1)
      CBRU E 0 A_Recoil(-5)
      CBRU E 0 A_Quake(9,3,0,32,"none")
      CBRU E 1 A_WeaponReady(WRF_NOSECONDARY|WRF_NOSWITCH)
      Loop
   SMASH:
      TNT1 A 0 SetPlayerProperty(0,0,0)
      TNT1 A 0 A_PlaySoundEx("Weapons/CaberSwoosh","SoundSlot6")
      CBRU DB 1
      CBRG A 1
      CBRD B 1
      TNT1 A 0 A_JumpIfInventory("CaberCounter",75,"Whoop5") //Weakest
      TNT1 A 0 A_JumpIfInventory("CaberCounter",65,"Whoop4")
      TNT1 A 0 A_JumpIfInventory("CaberCounter",55,"Whoop3")
      TNT1 A 0 A_JumpIfInventory("CaberCounter",45,"Whoop2") //Full Power
      TNT1 A 0 A_JumpIfInventory("CaberCounter",10,"Whoop1")  //To reward someone who will wait till the end of the charge - superpowered!
   Whoop5:
      TNT1 A 0 A_FireCustomMissile("BoomJackOnCharge5",0,1,0,0)
      Goto Aye
   Whoop4:
      TNT1 A 0 A_FireCustomMissile("BoomJackOnCharge4",0,1,0,0)
      Goto Aye
   Whoop3:
      TNT1 A 0 A_FireCustomMissile("BoomJackOnCharge3",0,1,0,0)
      Goto Aye
   Whoop2:
      TNT1 A 0 A_FireCustomMissile("BoomJackOnCharge2",0,1,0,0)
      Goto Aye
   Whoop1:
      TNT1 A 0 A_FireCustomMissile("BoomJackOnCharge1",0,1,0,0)
      Goto Aye
   Aye:
      TNT1 A 0 A_TakeInventory("CaberCounter",99)
      TNT1 A 1 A_PlaySoundEx("Weapons/CaberDarn","SoundSlot5")
      CBRD DE 1 A_JumpIfInventory("CaberFlyTrigger",1,"FLYINGWithScream")
      TNT1 AAAAA 1 A_JumpIfInventory("CaberFlyTrigger",1,"FLYINGWithScream")
      TNT1 A 5 A_TakeInventory("CaberFlyTrigger",1)
      CBRD EDCBA 1
      CBRG A 5
      Goto Ready


   //Twin DUAL WIELD
   TwinReady:
      TNT1 A 0 A_JumpIfInventory("RO_GotoReload", 1, "Reload")
	  TNT1 A 0 A_JumpIfInventory("RO_GotoZoom", 1, "Zoom")
      2BRG A 1 A_WeaponReady
      Loop
   TwinDeselect:
      2BRG A 0 A_StopSoundEx("SoundSlot5")
      2BRG A 1 A_Lower
      2BRG A 0 A_Lower
      Loop
   TwinSelect:
      2BRG A 1 A_Raise
      2BRG A 0 A_Raise
      Loop
   TwinFire:
      2BRU ABCDE 1
      TNT1 A 6 A_ReFire
      2BRU EDCBA 1
      Goto Ready
   Hold:
      TNT1 A 0 A_JumpIfInventory("CaberSide",1,"SwingLeft")
   SwingRight:
      TNT1 A 0 A_GiveInventory("CaberSide",1)
      TNT1 A 0 A_PlaySoundEx("Weapons/CaberSwing","SoundSlot6")
      CBRU DB 1
      CBRG A 1
      CBRD B 1
      CBRD D 0 A_FireCustomMissile("BoomJack",0,1,0,0)
      CBRD DE 1 A_JumpIfInventory("CaberFlyTrigger",1,"FLYINGDual")
      TNT1 A 2 A_JumpIfInventory("CaberFlyTrigger",1,"FLYINGDual")
      TNT1 A 1 A_TakeInventory("CaberFlyTrigger",1)
      TNT1 A 0 A_ReFire
      Goto UpThisShit
   SwingLeft:
      TNT1 A 0 A_TakeInventory("CaberSide",1)
      TNT1 A 0 A_PlaySoundEx("Weapons/CaberSwing","SoundSlot6")
      CBLU DB 1
      CBLG A 1
      CBLD B 1
      CBLD D 0 A_FireCustomMissile("BoomJack",0,1,0,0)
      CBLD DE 1 A_JumpIfInventory("CaberFlyTrigger",1,"FLYINGDual")
      TNT1 A 2 A_JumpIfInventory("CaberFlyTrigger",1,"FLYINGDual")
      TNT1 A 1 A_TakeInventory("CaberFlyTrigger",1)
      TNT1 A 0 A_ReFire
      Goto UpThisShit
   FLYINGDual:
      TNT1 A 5 ThrustThingZ(0, 20, 0, 1)
      TNT1 A 0 A_TakeInventory("CaberFlyTrigger",1)
      TNT1 A 0 A_ReFire
      Goto UpThisShit
   UpThisShit:
      TNT1 A 4
      2BRD EDCBA 1
      2BRG A 5
      Goto Ready
   TwinFire:
      2BRU ABCDE 1
      TNT1 A 6 A_ReFire
      2BRU EDCBA 1
      Goto Ready
   TwinAltFire:
      2BRU ABCDE 1
      TNT1 A 6 A_ReFire
      2BRU EDCBA 1
      Goto Ready
   TwinAltHold:
      TNT1 A 0 A_JumpIfInventory("CaberSide",1,"AltSwingLeft")
   AltSwingRight:
      TNT1 A 0 A_GiveInventory("CaberSide",1)
      TNT1 A 0 A_PlaySoundEx("Weapons/CaberSwing","SoundSlot6")
      CBRU DB 1
      CBRG A 1
      CBRD B 1
      CBRD D 0 A_FireCustomMissile("BoomJack",0,1,0,0)
      CBRD DE 1 A_JumpIfInventory("CaberFlyTrigger",1,"AltFLYINGDual")
      TNT1 A 2 A_JumpIfInventory("CaberFlyTrigger",1,"AltFLYINGDual")
      TNT1 A 1 A_TakeInventory("CaberFlyTrigger",1)
      TNT1 A 0 A_ReFire
      Goto UpThisShit
   AltSwingLeft:
      TNT1 A 0 A_TakeInventory("CaberSide",1)
      TNT1 A 0 A_PlaySoundEx("Weapons/CaberSwing","SoundSlot6")
      CBLU DB 1
      CBLG A 1
      CBLD B 1
      CBLD D 0 A_FireCustomMissile("BoomJack",0,1,0,0)
      CBLD DE 1 A_JumpIfInventory("CaberFlyTrigger",1,"AltFLYINGDual")
      TNT1 A 2 A_JumpIfInventory("CaberFlyTrigger",1,"AltFLYINGDual")
      TNT1 A 1 A_TakeInventory("CaberFlyTrigger",1)
      TNT1 A 0 A_ReFire
      Goto UpThisShit
   AltFLYINGDual:
      TNT1 A 5 ThrustThingZ(0, 70, 0, 1) //Now you fly for real.
      TNT1 A 0 A_TakeInventory("CaberFlyTrigger",1)
      TNT1 A 0 A_ReFire
      Goto UpThisShit
   }
}

ACTOR TwinCaberMode : Inventory { Inventory.MaxAmount 1 }

ACTOR CaberBoost : PowerupGiver //Even if you don't hit the target, you get short speed boost!
{
	Inventory.Amount 1
	+INVENTORY.AUTOACTIVATE
	+INVENTORY.ALWAYSPICKUP
	powerup.duration 85
	Powerup.Type Speed
	States
	{
	Spawn:
		TNT1 A -1
		Stop
	}
}

//CABER MELEE HIT

actor BoomJack
{
  PROJECTILE
  +NOGRAVITY
  Radius 11
  Height 5
  Speed 40
  Damage 10
  States
  {
  Spawn:
    TNT1 A 2
    Stop
  Death:
    TNT1 A 0
    TNT1 A 0 A_PlaySound("Weapons/PushkaExp")
    TNT1 A 0 A_PlaySoundEx("Weapons/CaberHit","SoundSlot6")
    TNT1 A 0 A_JumpIfInTargetInventory("NukerUpgrade",1,"NDeath")
    TNT1 A 0 A_GiveToTarget("CaberFlyTrigger",1)
    TNT1 A 0 A_Explode(100,164,0,1)
    TNT1 A 1 A_SpawnItemEx("CaberExplode",0,0,0,0,0,0,0,128,0)
    TNT1 A 0 A_Explode(100,256,0)
    TNT1 BBBCCCDDD 2 A_Explode(25,256,0)
    Stop
  NDeath:
    TNT1 A 0 A_GiveToTarget("CaberFlyTrigger",1)
    TNT1 A 0 A_Explode(200,192,0,1)
    TNT1 A 1 A_SpawnItemEx("NukerCaberExplode",0,0,0,0,0,0,0,128,0)
    TNT1 A 0 A_Explode(200,384,0)
    TNT1 BBBCCCDDD 2 A_Explode(50,256,0)
    Stop
  }
}

//ALOSZA THROWNKICKED CABER

ACTOR CaberGrenade
{
	Radius 12
	Height 8
	Speed 35
	Damage 40
	PROJECTILE
	BounceType Hexen
	Gravity 0.85
	-NOGRAVITY
	+EXPLODEONWATER
	BounceFactor 0.5
	BounceCount 5
	ReactionTime 10
	Obituary "%k shoved upon %o's ass quite well thrownkicked ullapool caber."
	Bouncesound "Weapons/CaberBounce"
	States
	{
	Spawn:
		ULLA A 0
		ULLA A 0 ThrustThingZ(0, 32, 0, 1)
	Loople:
		ULLA A 0 A_CountDown
		ULLA ABCDEFGH 2 A_SpawnItemEx("CaberGrenadeTrail",0,0,0,0,0,0,0,128,0)
		Loop
	Death:
		ULLA E 45
	XDeath:
		TNT1 A 0 A_Stop
		TNT1 A 0 A_ChangeFlag(NOGRAVITY,1)
		TNT1 A 0 A_PlaySound("Weapons/PushkaExp")

		TNT1 A 0 A_JumpIfInTargetInventory("NukerUpgrade",1,"NDeath")
		TNT1 A 0 A_Explode(100,164,0,1)
		TNT1 A 1 A_SpawnItemEx("CaberExplode",0,0,0,0,0,0,0,SXF_TRANSFERPOINTERS,0)
		TNT1 A 0 A_Explode(100,256,0)
		TNT1 BBBCCCDDD 2 A_Explode(25,256,0)
		Stop
	NDeath:
		TNT1 A 0 A_GiveToTarget("CaberFlyTrigger",1)
		TNT1 A 0 A_Explode(200,192,0,1)
		TNT1 A 1 A_SpawnItemEx("NukerCaberExplode",0,0,0,0,0,0,0,SXF_TRANSFERPOINTERS,0)
		TNT1 A 0 A_Explode(200,384,0)
		TNT1 BBBCCCDDD 2 A_Explode(50,256,0)
		Stop
	}
}

ACTOR CaberGrenadeTrail
{
	Alpha 0.4
	+NOINTERACTION
	Renderstyle Normal
	Scale 0.65
	States
	{
		Spawn:
			TNT1 A 0
			ULLA ABCDEFGH 1 A_FadeOut(0.05)
			Stop
	}
}

//Charge CHARGE

actor BoomJackOnCharge1 : BoomJack
{
 Damage 100000
}

actor BoomJackOnCharge2 : BoomJack
{
 Damage 150
}

actor BoomJackOnCharge3 : BoomJack
{
 Damage 100
}

actor BoomJackOnCharge4 : BoomJack
{
 Damage 50
}

actor BoomJackOnCharge5 : BoomJack
{
 Damage 25
}

//EXPLOSION

ACTOR CaberExplode
{ 
    +NOINTERACTION
    +NOGRAVITY
    States
    {
    Spawn:
    TNT1 A 0
    TNT1 AA 0 A_SpawnItemEx("DeathHeadSmoke", random(35,-35), random(35,-35), random(35,-35), 0.1*random(4,6), 0.1*random(4,6), 0.1*random(3,5), random(0,360),0,0)
    TNT1 AAAAAAA 0 A_SpawnItemEx("CaberExploder", random(2,-2), random(2,-2), random(2,-2), random(1,-1), random(1,-1), random(1,-1), random(0,360), SXF_TRANSFERPOINTERS, 0)
    TNT1 A 1
    TNT1 A 0 A_SpawnItemEx("DeathHeadAfterSmoke",0,0,0,0,0,0,0,128,0)
    TNT1 AAAAA 2 A_SpawnItemEx("DeatheadAfterboom", random(20,-20), random(20,-20), random(20,-20), 0.1*random(3,4), 0.1*random(3,4), 0.1*random(2,3), random(0,360), SXF_TRANSFERPOINTERS, 0)
    Stop
    }
}

ACTOR CaberExploder : DeathHeadExploder
{ 
    +NOINTERACTION
    +FORCERADIUSDMG
    +NOGRAVITY
    ReactionTime 5
    States
    {
    Spawn:
    TNT1 A 0
    TNT1 A 0 A_Countdown
    TNT1 A 2 A_SpawnItemEx("DeathHeadExp", random(28,-28), random(28,-28), random(28,-28), 0, 0, 0, 0, SXF_TRANSFERPOINTERS, 0)
    Loop
    Death:
    TNT1 A 1
    Stop
    }
}

ACTOR NukerCaberExplode
{ 
    +NOINTERACTION
    +NOGRAVITY
    States
    {
    Spawn:
      TNT1 A 0
      TNT1 A 0 A_SpawnItemEx("NukerPushkaFlash",0,0,0,0,0,0,0,128,0)
      TNT1 A 0 A_SpawnItemEx("NukerCaberExploder",0,0,0,0,0,0,0,SXF_TRANSFERPOINTERS,0)
      TNT1 A 0 A_SpawnItemEx("NukerPushkaSmoker",0,0,0,0,0,0,0,128,0)
      Stop
    }
}

ACTOR NukerCaberExploder
{
    +NOINTERACTION
    +NOGRAVITY
    +FORCERADIUSDMG
    ReactionTime 14
    States
    {
    Spawn:
    TNT1 A 0
    TNT1 A 0 A_Countdown
    TNT1 A 2 A_SpawnItemEx("NukerPushkaExp", random(41,-41), random(41,-41), random(41,-41), 0, 0, 0, 0, SXF_TRANSFERPOINTERS, 0)
    Loop
    Death:
    TNT1 A 1
    Stop
    }
}

//TRIGGERS

ACTOR CaberPower : Inventory //Caber Power - When full, alt-fire is enabled.
{
	Inventory.MaxAmount 100
}

ACTOR CaberCounter : Inventory //Charge Time. How long will the charge last.
{
	Inventory.MaxAmount 999
}

ACTOR CaberFlyTrigger : Inventory //Fly Check.
{
	Inventory.MaxAmount 1
}

ACTOR CaberSide : Inventory //Twin caber side checker.
{
	Inventory.MaxAmount 1
}
