// Chemical sprayer
actor ChemicalSprayer : AOWWeapon 21066 {
    Weapon.BobSpeed 1.75
    Weapon.BobRangeX 0.2
    Weapon.BobRangeY 0.4
    Weapon.BobStyle Alpha
	//$Category Weapons
	+ALT_AMMO_OPTIONAL
	Inventory.PickupMessage "You got the chemical sprayer!"
	AttackSound "Chem/fire"
	Weapon.SelectionOrder 9
	Weapon.Kickback 1
	Weapon.AmmoType "ChemicalAmmo"
	Weapon.AmmoUse 1
	Weapon.AmmoGive 25
	Weapon.AmmoType2 "ChemicalGrenadeAmmo"
	Weapon.AmmoUse2 1
	Weapon.AmmoGive2 0
	Weapon.PreferredSkin "MarineChem"
	Weapon.UpSound "weapons/up/chem"
	Tag "Chemical Sprayer"
	states {
	Spawn:
		CHMG X -1
		stop
    Select:
		CHMS A 1 offset (-90,100)
		CHMS A 1 offset (-80,89)
		CHMS A 1 offset (-70,79)
		CHMS A 1 offset (-60,70)
		CHMS A 1 offset (-50,62)
		CHMS A 1 offset (-40,55)
		CHMS A 1 offset (-30,49)
		CHMS A 1 offset (-20,44)
		CHMS A 1 offset (-15,40)
		CHMS A 1 offset (-10,37)
		CHMS A 1 offset (-5,34)
		CHMS A 1 offset (0,0)
		TNT1 A 0 A_TakeInventory("SelectAnimation",1)
		goto ready
	Deselect:
	    TNT1 A 0 A_TakeInventory("ActionFragGrenade",1)	
        TNT1 A 0 A_TakeInventory("ActionFlashbang",1)
        TNT1 A 0 A_TakeInventory("ActionRemoteC4",1)	
        TNT1 A 0 A_TakeInventory("ActionMeleeAttack",1)
		TNT1 A 0 A_TakeInventory("ActionReload",1)	
		CHMS A 1 offset (-4,34)
		CHMS A 1 offset (-8,40)
		CHMS A 1 offset (-16,49)
		CHMS A 1 offset (-24,62)
		CHMS A 1 offset (-32,79)
		CHMS A 1 offset (-40,100)
		TNT1 A 0 offset (-1, 33)
		TNT1 A 0 A_Lower
		wait
	Ready:
	    TNT1 A 0 A_JumpIfInventory("SelectAnimation",1,"Select")
	    TNT1 A 0 A_JumpIfInventory("ActionFragGrenade",1,"UseFragGrenade")
		TNT1 A 0 A_JumpIfInventory("ActionFlashbang",1,"UseFlashbang")
		TNT1 A 0 A_JumpIfInventory("ActionRemoteC4",1,"UseRemoteC4")
		TNT1 A 0 A_JumpIfInventory("ActionMeleeAttack",1,"UseMeleeAttack")
		TNT1 A 0 A_TakeInventory("ActionReload",1)
		CHMS A 1 A_WeaponReady
		Loop
	Fire:
		TNT1 A 0 A_JumpIfInventory ("IsInSpawnRoom", 1, "Ready")
		TNT1 A 0 A_JumpIfInventory ("InMenu", 1, "Ready")
	Spam:
		CHMS A 0 A_PlaySound ("chem/fire", CHAN_WEAPON, 1.0, true)
		CHMS A 0 A_GunFlash
		CHMS A 1 bright offset (0, 35) A_FireCustomMissile ("ChemicalShot",random(-2,2),0,8,random(-2,2))
		CHMS A 1 bright offset (2, 36) A_FireCustomMissile ("ChemicalShotDummy",random(-2,2),0,8,random(-2,2))
		CHMS A 1 bright offset (3, 37) A_FireCustomMissile ("ChemicalShot",random(-2,2),1,8,random(-2,2))
		CHMS A 1 bright offset (1, 36) A_FireCustomMissile ("ChemicalShotDummy",random(-2,2),0,8,random(-2,2))
		CHMS A 6 bright offset (-1, 34) A_ReFire("Spam")
		CHMS A 1 A_StopSound (CHAN_WEAPON)
		CHMS A 1
		goto Ready
	AltFire:
		CHMS A 0 A_JumpIfNoAmmo ("AltRejected")
		TNT1 A 0 A_JumpIfInventory ("IsInSpawnRoom", 1, "Ready")
		TNT1 A 0 A_JumpIfInventory ("InMenu", 1, "Ready")
		CHMS B 1 A_PlaySound ("chem/grenade", 5)
		CHMS C 1
		TNT1 A 0 Radius_Quake(4,6,0,1,0)
		CHMS D 1 bright A_SetPitch(pitch-1.0)
		TNT1 A 0 bright A_FireCustomMissile ("ChemicalGrenade", 0, 1, 8, 0)
		CHMS E 1 bright A_SetPitch(pitch+1.0)
		CHMS FGH 1 bright
		TNT1 A 0 A_WeaponReady(WRF_NOBOB | WRF_NOFIRE)
		CHMS AA 4 A_JumpIfInventory("ActionMeleeAttack",1,"UseMeleeAttack")
		TNT1 A 0 A_WeaponReady(WRF_NOBOB | WRF_NOFIRE)
		CHMS AA 4 A_JumpIfInventory("ActionMeleeAttack",1,"UseMeleeAttack")
		TNT1 A 0 A_WeaponReady(WRF_NOBOB | WRF_NOFIRE)
		CHMS AA 4 A_JumpIfInventory("ActionMeleeAttack",1,"UseMeleeAttack")
		TNT1 A 0 A_WeaponReady(WRF_NOBOB | WRF_NOFIRE)
		CHMS A 4 A_JumpIfInventory("ActionMeleeAttack",1,"UseMeleeAttack")
		CHMS A 0 A_ReFire
		CHMS A 15 A_WeaponReady // This is to prevent the altfire sound from cutting off
		goto Ready
	AltRejected:
		CHMS A 35 A_WeaponReady (WRF_NOSECONDARY)
		goto Ready
	Flash:
		TNT1 A 2 A_Light1
		TNT1 A 2 A_Light2
		TNT1 A 0 A_Light0
		stop
	}
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
actor ChemicalShot {
	PROJECTILE
	+FORCEXYBILLBOARD
	Obituary "$OB_CHEMSPRAYER"
	Renderstyle Add
	Alpha 0.9
	Radius 8
	Height 8
	Speed 30 //
	Damage (random (3,5))
	DamageType "Chemical"
	decal "ChemScorch"
	Scale 0.5
	States {
	Spawn:
		TNT1 A 4
		TIBX ABCDEFGHIJK 1 bright
	Clear:
		TNT1 A 0 A_SpawnItemEx("AnthraxDecay", random(-16,16), random(-16,16), 4, 0, 0, 0, 0, SXF_TRANSFERPOINTERS, 240)
		TIBX L 2 bright
		TIBX MMNNOOPPQQ 1 bright A_FadeOut(0.1)
		stop
	Death:
		TNT1 A 1 A_Explode(3,140)
		TNT1 A 0 A_SpawnItemEx("AnthraxDecay", random(-16,16), random(-16,16), 4, 0, 0, 0, 0, SXF_TRANSFERPOINTERS, 240)
		TIBX H 3 bright A_SpawnItemEx("ChemFakeDeath",0,0,0,momx,momy,momz,0,SXF_ABSOLUTEMOMENTUM|SXF_CLIENTSIDE)
		//^ Dat is optimization sir. Instead of 4 Kb/s out when shooting MCT, it's about 2.3 Kb/s.
		stop
	}
}

actor ChemFakeDeath : ChemicalShot {
	Damage (0)
	Alpha 0.375
	+CLIENTSIDEONLY // This guy decreases network usage, remember? :(
	States {
	Death:
	Spawn:
		TIBX IIJJKKLLMMOOPPQQ 1 bright A_FadeOut(0.035)
		stop
	}
}

actor AnthraxDecay {
	+NOBLOCKMAP
	+NODAMAGETHRUST
	renderstyle None
	alpha 0.5
	Gravity 0.125
	Scale 2.0
	DamageType "Chemical"
	obituary "$OB_CHEMICALS"
	states {
	Spawn:
		TNT1 AA 0 A_PlaySound("chem/chem")
		TNT1 A 0 A_SpawnItemEx ("AnthraxDecayFX")
		TNT1 AAAAAAAAAAA 15 BRIGHT A_Explode(4, 128)
		stop
	}
}

actor AnthraxDecayFX {
	+NOBLOCKMAP
	+CLIENTSIDEONLY
	Gravity 0.125
	reactiontime 33
	states {
	Spawn:
		TNT1 A 0
		TNT1 A 5 A_SpawnItemEx("ChemicalFlame", random(-16,16), random(-16,16), random(8,16), 0, 0, random(1,3), 0, 128, 32)
		TNT1 A 0 A_Countdown
		loop
	Death:
		TNT1 A 0
		stop
	}
}

actor AnthraxDecaySpecial : AnthraxDecay {
	damagetype "ChemicalSpecial"
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
actor ChemicalGrenade {
	PROJECTILE
	-RANDOMIZE
	-NOGRAVITY
	Gravity 0.125
	radius 11
	height 8
	speed 35
	damage (30)
	seesound ""
	deathsound "weapons/rocklx"
	obituary "$OB_CHEMSPRAYER_GRENADE"
	damagetype "Chemical"
	decal "ChemScorchStrong"
	translation "2:30=202:223"
	states {
	Spawn:
		SGRN A 2 bright A_SpawnItemEx ("PulseBallSmokePuff", -25)
		wait
	Death:
		TNT1 A 0 bright A_SpawnItem ("ChemicalExplosion")
		TNT1 A 0 bright A_Gravity
		TNT1 A 0 bright A_Explode (90, 128, 1)
		goto Decay
	Decay:
		TNT1 AAAAAAAAA 70 A_SpawnItemEx("AnthraxDecay", random(-64,64), random(-64,64), 4, 0, 0, 0, 0, SXF_TRANSFERPOINTERS)
		stop
	}
}

// if not kept it crashes.
actor ChemicalShotDummy {
	PROJECTILE
	//+CLIENTSIDEONLY
	+FORCEXYBILLBOARD
	-ACTIVATEIMPACT
	-ACTIVATEPCROSS
	renderstyle Add
	alpha 0.9
	Radius 8
	Height 8
	Speed 30 //20% faster than flamershot
	Damage (0)
	Scale 0.5
	States {
	Spawn:
		// [Dusk] If we're in low-fx mode, potentially just remove the actor
		TNT1 A 0
		CHMS A 0 A_JumpIf (ACS_ExecuteWithResult(910, 0) < 0, "MightClear")
		goto Idle
	MightClear:
		TNT1 A 0 A_Jump (128, 1)
		goto Idle
		TNT1 A 0
		stop
	Idle:
		TNT1 A 4
		TIBX ABCDEFGHIJKL 2 bright
		TIBX MMNNOOPPQQ 1 bright A_FadeOut(0.1)
		stop
	Death:
		TIBX H 3 bright A_Stop
		TIBX IIJJKKLLMMOOPPQQ 1 bright A_FadeOut(0.07)
		stop
	}
}
