Actor IsPioneerClass : ClassToken {}

ACTOR PioneerClass : PlayerPawn
{
  Speed 0.9
  Radius 16
  Height 56
  Mass 100
  PainChance 255
  Health 125
  Player.MaxHealth 125
  Player.DisplayName "Ravnor"
  Player.ScoreIcon "RavIcon"
  Player.WeaponSlot 1, PioneerFist, SFortWrench
  Player.WeaponSlot 2, PioneerPistol
  Player.WeaponSlot 3, PioneerPlasmaShotgun, PioneerSuperShotgun
  Player.WeaponSlot 4, PioneerMachinegun
  Player.WeaponSlot 5, PioneerSpreadCannon
  Player.WeaponSlot 6, PioneerPulseRifle
  Player.WeaponSlot 7, PioneerOmegaSplicer
  Player.SoundClass "Pioneer"
  Player.StartItem "IsPioneerClass"
  Player.StartItem "IsPlayer", 1
    Player.StartItem "DefaultHud", 1
	Player.StartItem "DefaultAmmo", 1
  Player.StartItem "DefaultMisc", 1
  	Player.StartItem "hatCharacterOffset", 93
  Species "Player"
  Player.StartItem "PioneerPistol"
  Player.StartItem "PioneerFist"
  Player.StartItem "Clip", 150
  Player.ColorRange 112, 127
  DamageFactor "Electric", 0.50
  States
  {
  Spawn:
    PPIO A -1
    Loop
  See:
    PPIO ABCD 4
    Loop
  Missile:
    PPIO E 9
    Goto Spawn
  Melee:
    PPIO F 5 Bright
    Goto Missile
  Pain:
	TNT1 A 0 A_JumpIfInventory("PowerQuarterDamage",1,"Guard")
    PPIO G 6 A_Pain
    Goto Spawn
  Guard:
    TNT1 A 0 A_Playsound("misc/gdhit",CHAN_7)
	Goto Pain+1
  Death:
	TNT1 A 0 A_StopSound(CHAN_WEAPON)
	TNT1 A 0 A_DropItem("BYOCBackpack",1)
    PPIO H 10 A_PlayerScream
    PPIO I 8
    PPIO J 8 A_NoBlocking
    PPIO KLM 8
    PPIO N -1
    Stop
  XDeath.Suicide:
    PPIO P 5 A_XScream
    PPIO Q 5 A_NoBlocking
    PPIO RSTUV 5
    PPIO W -1
    Stop
  }
}

ACTOR SFortBulletPuff : BulletPuff
{
  +PUFFGETSOWNER
  +PUFFONACTORS
  +CLIENTSIDEONLY
  AttackSound "misc/ricochet"
  Seesound "misc/bullethit"
  DamageType "Bullet"
  States
  {
  Spawn:
  See:
  Crash:
    PUFF A 4 Bright
    PUFF B 4
  Melee:
    PUFF CD 4
    Stop
  XDeath:
	TNT1 A 1
	Stop
  }
}

ACTOR SFortSentryPuff : BulletPuff
{
  +PUFFGETSOWNER
  +PUFFONACTORS
  +CLIENTSIDEONLY
  +MTHRUSPECIES
  +THRUSPECIES
  +FRIENDLY
  +FOILINVUL
  Species "Player"
  Obituary "%o was shot down by %k's sentry gun."
  AttackSound "misc/ricochet"
  Seesound "misc/bullethit"
  DamageType "Bullet"
  States
  {
  Spawn:
  See:
  Crash:
    PUFF A 4 Bright
    PUFF B 4
  Melee:
    PUFF CD 4
    Stop
  XDeath:
	TNT1 A 1
	Stop
  }
}

ACTOR SFortWrench : Weapon
{
  Weapon.SelectionOrder 4000
  Inventory.RestrictedTo "PioneerClass"
  Tag "Pipe"
  +WEAPON.NOAUTOAIM
  +WEAPON.NOLMS
  +WEAPON.ALLOW_WITH_RESPAWN_INVUL
  States
  {
  Ready:
	PIPW A 1 A_WeaponReady(WRF_ALLOWRELOAD)
	Loop
  Deselect:
	PIPW A 0 A_Lower
	Loop
  Select:
	PIPW A 0 A_Raise
	PIPW A 1 A_Raise
	Loop
  Fire:
	TNT1 A 0 ACS_NamedExecute("DispenserPlacing",0)
	PIPW A 1 A_SpawnItemEx("DispenserShadow", 35, 0, 4, 0, 0, 0, 0, SXF_TRANSFERTRANSLATION|SXF_CLIENTSIDE)
	TNT1 A 0 A_Refire("Fire")
	TNT1 A 0 A_ChangeFlag(ISMONSTER,1)
	TNT1 A 0 A_SpawnItemEx("Dispenser", 35, 0, 4, 0, 0, 0, 0, SXF_SETMASTER|SXF_TRANSFERTRANSLATION)
	TNT1 A 0 A_ChangeFlag(ISMONSTER,0)
	PIPW BCDEFGHI 1
	TNT1 A 4
	PIPW CB 1
	Goto Ready
  AltFire:
	TNT1 A 0 ACS_NamedExecute("SentryPlacing",0)
	PIPW A 1 A_SpawnItemEx("SentryGunShadow", 35, 0, 4, 0, 0, 0, 0, SXF_TRANSFERTRANSLATION|SXF_CLIENTSIDE)
	TNT1 A 0 A_Refire("AltFire")
	TNT1 A 0 A_ChangeFlag(ISMONSTER,1)
	TNT1 A 0 A_SpawnItemEx("PioneerSentryGun", 35, 0, 4, 0, 0, 0, 0, SXF_SETMASTER|SXF_TRANSFERTRANSLATION)
	TNT1 A 0 A_ChangeFlag(ISMONSTER,0)
	PIPW BCDEFGHI 1
	TNT1 A 4
	PIPW CB 1
	Goto Ready
  }
}


ACTOR SentryGunShadow
{
	Projectile
	Radius 14
	Height 56
	Speed 0
	Alpha 0.5
	Renderstyle Translucent
	+NOGRAVITY
	+TOUCHY
	+CLIENTSIDEONLY
	-DROPOFF
	States
	{
	Spawn:
	  TNT1 A 0
	  RSEN A 1
	  Stop
	Death:
	  TNT1 A 1
	  Stop
	}
}

ACTOR PioneerSentryGun
{
  Obituary "%o was ventilated by %k's Sentry."
  Health 300
  Radius 14
  Height 56
  Mass 1000000000
  AttackSound "sentry/attack"
  ActiveSound "sentry/active"
  MONSTER
  Species "Sentry"
  MinMissileChance 0
  PainChance 0
  MaxTargetRange 2048
  Tag "Sentry Gun Mk. II"
  DamageType "Bullet"
  DamageFactor "Normal", 0.50
  DamageFactor "Melee", 2.0
  -SOLID
  +FLOORCLIP
  +NOBLOOD
  +NOPAIN
  +PAINLESS
  +LOOKALLAROUND
  +NEVERRESPAWN
  +NOINFIGHTING
  +STANDSTILL
  +FRIENDLY
  +DONTIDENTIFYTARGET
  States
  {
  Missile:
  // Missile goes to spawn state at first, because if the sentry is attacked
  // when it's being summoned, it would immediately retaliate and skip the
  // spawning of the sentry completely.
	TNT1 A 0
    TNT1 A 0 A_JumpIfInventory("SentryActiveToken",1,"Shoot")
  Spawn:
	TNT1 A 0
	TNT1 A 0 A_GiveToSiblings("SentryRemover",1)//A_RemoveSiblings(1)
	TNT1 A 0 A_PlaySound("Sentry/Building")
	RSEN C 280 A_GiveInventory("SentryBuildingToken",1,AAPTR_MASTER)
	TNT1 A 0 A_GiveInventory("SentryActiveToken")
    TNT1 A 0 A_GiveInventory("SentryCompleteToken",1,AAPTR_MASTER)
	TNT1 A 0 A_PlaySound("Sentry/Ready",CHAN_AUTO)
	Goto Idle
  FastSpawn:
	RSEN C 140 A_GiveInventory("FastSentryBuildingToken",1,AAPTR_MASTER)
    Goto Spawn+5
  Idle:
	RSEN A 1 A_ClearTarget
  // The FLOAT flag makes the sentry able to target enemies from a ledge:
	TNT1 A 0 A_ChangeFlag(FLOAT,1)
    RSEN A 1 A_Look
  // But it still needs to have gravity in case it's on the ledge of a lift:
	TNT1 A 0 A_ChangeFlag(FLOAT,0)
    RSEN A 1 A_Look
	TNT1 A 0 A_Jump(1,"SeeSound")
	TNT1 A 0 A_JumpIfInventory("IsPioneerClass",1,"See",AAPTR_MASTER)
	Goto Death.SelfDestruct
  IdleSound:
    TNT1 A 0 A_Playsound("Sentry/Active",CHAN_VOICE)
	Goto Idle
  See:
	TNT1 A 0 A_ChangeFlag(FLOAT,1)
    RSEN A 1 A_Chase("","Missile",CHF_NOPLAYACTIVE)
	TNT1 A 0 A_ChangeFlag(FLOAT,0)
    RSEN A 1 A_Chase("","Missile",CHF_NOPLAYACTIVE)
	TNT1 A 0 A_Jump(1,"SeeSound")
	TNT1 A 0 A_JumpIfInventory("IsPioneerClass",1,"See",AAPTR_MASTER)
	Goto Death.SelfDestruct
  SeeSound:
    TNT1 A 0 A_Playsound("Sentry/Active",CHAN_VOICE)
	Goto See
  Shoot:
	TNT1 A 0 A_ChangeFlag(FLOAT,0)
	TNT1 A 0 A_PlaySound("Sentry/Target")
    RSEN A 3 Bright A_FaceTarget
    RSEN A 3 A_FaceTarget
    RSEN A 3 Bright A_FaceTarget
    RSEN A 3 A_FaceTarget
    RSEN A 3 Bright A_FaceTarget
    RSEN A 3 A_FaceTarget
	TNT1 A 0 A_JumpIfInventory("IsPioneerClass",1,"ShootLoop",AAPTR_MASTER)
	Goto Death.SelfDestruct
  ShootLoop:
	TNT1 A 0 A_JumpIfInventory("SentryAmmoFired",999999,"ShootEmpty")
	TNT1 A 0 A_GiveInventory("SentryAmmoFired",0)
    RSEN B 2 Bright A_CustomBulletAttack(6.0,3.0,1,18,"SFortSentryPuff",2048,CBAF_NORANDOM)
    RSEN A 1
    RSEN B 2 Bright A_CustomBulletAttack(6.0,3.0,1,18,"SFortSentryPuff",2048,CBAF_NORANDOM)
    RSEN A 1 A_MonsterRefire(0,"Idle")
	TNT1 A 0 A_JumpIfCloser(2048,"ShootLoop")
    Goto Idle
  ShootEmpty:
	TNT1 A 0 A_FaceTarget
	TNT1 A 0 A_GiveInventory("SentryAmmoDepletedToken",1,AAPTR_MASTER)
    RSEN A 3 A_Playsound("Sentry/Empty",CHAN_WEAPON)
    RSEN A 2 A_Playsound("Sentry/Empty",CHAN_WEAPON)
	Goto ShootLoop+5
  Death:
    TNT1 A 0 A_GiveInventory("SentryDestroyedToken",1,AAPTR_MASTER)
	RSEN # 1
	TNT1 A 0 A_NoBlocking
	TNT1 A 0 A_ChangeFlag(SHOOTABLE,false)
    RSEN D 1 A_PlaySound("Sentry/Death")
    TNT1 A 0 A_PlaySoundEx("weapons/rocklx", "SoundSlot6")
    TNT1 A 0 A_PlaySoundEx("weapons/debris", "SoundSlot7")
    TNT1 A 0 A_SpawnItem ("SentryBoom", 0, 48)
    RSEN DDDDDDDDDDDDDDDDD 1 A_SpawnItemEx("SentrySpark", frandom(-2,2),frandom(-2,2), 32, frandom(-5,5),random(-5,5),random(0,10),random(0,359))
    RSEN DDDDDDDDD 2 A_SpawnItemEx("SentrySpark", frandom(-2,2),frandom(-2,2), 32, frandom(-5,5),random(-5,5),random(0,10),random(0,359))
    RSEN DDDDDDD 5 A_SpawnItemEx("SentrySpark", frandom(-2,2),frandom(-2,2), 32, frandom(-5,5),random(-5,5),random(0,10),random(0,359))
  FadeOut:
    RSEN D 2 A_FadeOut (0.1)
    loop
  Death.SelfDestruct:
    RSEN # 10
	TNT1 A 0 A_NoBlocking
	TNT1 A 95
	Stop
  }
}

ACTOR SentryAmmoFired : Inventory
{
	Inventory.MaxAmount 999999
}

ACTOR SentryBoom
{
  radius 2
  height 2
  renderstyle Add
  +NOINTERACTION
  +CLIENTSIDEONLY
  states
  {
  Spawn:
    XPL1 ABCDEF 3 bright
    stop
  }
}

ACTOR SentrySpark : BulletPuff
{
	VSpeed 0
	-NOGRAVITY
}


ACTOR SentryActiveToken : Inventory
{
	Inventory.MaxAmount 1
}

ACTOR SentryBuildingToken : CustomInventory
{
	+INVENTORY.AUTOACTIVATE
	-INVENTORY.INVBAR
	+CLIENTSIDEONLY
	Inventory.MaxAmount 1
	States
	{
	Pickup:
	  TNT1 A 0 ACS_NamedTerminate("SentryBuilding",0)
	  TNT1 A 0 ACS_NamedExecute("SentryBuildingStart",0)
	  Stop
	}
}

ACTOR FastSentryBuildingToken : CustomInventory
{
	+INVENTORY.AUTOACTIVATE
	-INVENTORY.INVBAR
	+CLIENTSIDEONLY
	Inventory.MaxAmount 1
	States
	{
	Pickup:
	  TNT1 A 0 ACS_NamedTerminate("FastSentryBuilding",0)
	  TNT1 A 0 ACS_NamedExecute("FastSentryBuildingStart",0)
	  Stop
	}
}

ACTOR SentryCompleteToken : SentryBuildingToken
{
	States
	{
	Pickup:
	  TNT1 A 0 ACS_NamedExecute("SentryComplete",0)
	  Stop
	}
}

ACTOR SentryDestroyedToken : SentryBuildingToken
{
	-CLIENTSIDEONLY
	Inventory.MaxAmount 1
	States
	{
	Pickup:
	  TNT1 A 0 ACS_NamedTerminate("SentryBuilding",0)
	  TNT1 A 0 ACS_NamedTerminate("FastSentryBuilding",0)
	  TNT1 A 0 ACS_NamedExecute("SentryDestroyed",0)
	  TNT1 A 0 ACS_NamedExecute("SentryDestroyedGlobal",0)
	  Stop
	}
}

ACTOR SentryAmmoDepletedToken : SentryBuildingToken
{
	Inventory.MaxAmount 1
	States
	{
	Pickup:
	  TNT1 A 0 ACS_NamedExecute("SentryAmmoDepleted",0)
	  Stop
	}
}

ACTOR SentryRemover : CustomInventory
{
	+INVENTORY.AUTOACTIVATE
	-INVENTORY.INVBAR
	States
	{
	Pickup:
	  TNT1 A 1
	  TNT1 A 1 A_JumpIf(ACS_NamedExecuteWithResult("SentryRemoverChecker") == 1,"Remove")
	  Stop
	Remove:
	  TNT1 A 1 Thing_Remove(0)
	  Stop
	}
}

ACTOR DispenserShadow
{
	Projectile
	Radius 16
	Height 56
	Speed 0
	Scale 0.7
	Alpha 0.5
	Renderstyle Translucent
	+NOGRAVITY
	+TOUCHY
	+CLIENTSIDEONLY
	-DROPOFF
	States
	{
	Spawn:
	  TNT1 A 0
	  DISP I 1
	  Stop
	Death:
	  TNT1 A 1
	  Stop
	}
}

ACTOR Dispenser
{
	Health 200
	Radius 16
	Height 56
	Scale 0.7
	Mass 1000000000
	MONSTER
	PainChance 0
	Tag "Dispenser"
	Species "Dispenser"
	DamageFactor "Melee", 2.0
	-SOLID
	-NOGRAVITY
	+FLOORCLIP
	+NOBLOOD
	+NEVERRESPAWN
	+STANDSTILL
	+FRIENDLY
	+DONTIDENTIFYTARGET
	States
	{
	Spawn:
	  TNT1 A 0
	  TNT1 A 0 A_GiveToSiblings("DispenserRemover",1)
      TNT1 A 0 A_PlaySound("Sentry/Building")
	  DISP J 280 A_GiveInventory("DispenserBuildingToken",1,AAPTR_MASTER)
      TNT1 A 0 A_GiveInventory("DispenserCompleteToken",1,AAPTR_MASTER)
	  TNT1 A 0 A_PlaySound("Sentry/Ready",CHAN_AUTO)
	  Goto Idle
	FastSpawn:
	  DISP J 140 A_GiveInventory("FastDispenserBuildingToken",1,AAPTR_MASTER)
	  Goto Spawn+5
	Idle:
	  TNT1 A 0
	  TNT1 A 0 A_Jump(32,"IdleB")
	  DISP A 4 A_RadiusGive("DispenserItem",128,RGF_PLAYERS,1)
	  DISP A 0 A_RadiusGive("DispenserFriendlyMonsterItem",256,RGF_MONSTERS,1)
	  DISP BCD 4
	  TNT1 A 0 A_JumpIfInventory("IsPioneerClass",1,"Idle2",AAPTR_MASTER)
	  Goto Death.SelfDestruct
	IdleB:
	  TNT1 A 0 A_PlaySound("Dispenser/Idle",CHAN_AUTO)
	  DISP I 4 A_RadiusGive("DispenserItem",128,RGF_PLAYERS,1)
	  DISP A 0 A_RadiusGive("DispenserFriendlyMonsterItem",256,RGF_MONSTERS,1)
	  DISP BCD 4
	  TNT1 A 0 A_JumpIfInventory("IsPioneerClass",1,"Idle2",AAPTR_MASTER)
	  Goto Death.SelfDestruct
	Idle2:
	  DISP E 4 A_RadiusGive("DispenserItem",128,RGF_PLAYERS,1)
	  DISP A 0 A_RadiusGive("DispenserFriendlyMonsterItem",256,RGF_MONSTERS,1)
	  DISP FGH 4
	  TNT1 A 0 A_JumpIfInventory("IsPioneerClass",1,"Idle",AAPTR_MASTER)
	  Goto Death.SelfDestruct
    Death:
	  TNT1 A 0 A_GiveInventory("DispenserDestroyedToken",1,AAPTR_MASTER)
	  DISP # 1
	  TNT1 A 0 A_NoBlocking
      DISP K 1 A_PlaySound("Sentry/Death")
      TNT1 A 0 A_PlaySoundEx("weapons/rocklx", "SoundSlot6")
      TNT1 A 0 A_PlaySoundEx("weapons/debris", "SoundSlot7")
      TNT1 A 0 A_SpawnItem ("SentryBoom", 0, 56)
	  DISP KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK 1 A_SpawnItemEx("SentrySpark", frandom(-2,2),frandom(-2,2), 32, frandom(-5,5),random(-5,5),random(0,10),random(0,359))
	  DISP KKKKKKK 5 A_SpawnItemEx("SentrySpark", frandom(-2,2),frandom(-2,2), 32, frandom(-5,5),random(-5,5),random(0,10),random(0,359))
	FadeOut:
      DISP K 2 A_FadeOut (0.1)
      Loop
	Death.SelfDestruct:
	  DISP # 10
	  TNT1 A 0 A_NoBlocking
	  TNT1 A 95
	  Stop
	}
}

ACTOR DispenserItem : CustomInventory
{
	Inventory.PickupMessage "Received Dispenser health, armor & ammo."
	+INVENTORY.AUTOACTIVATE
	-INVENTORY.INVBAR
	States
	{
Pickup:
	  TNT1 A 0 A_PlaySound("dispenser/pkup",CHAN_BODY)
	  TNT1 A 0 A_PlaySound("misc/ammo_pkup",CHAN_6)
	  TNT1 A 0 A_PlaySound("misc/bonus_pkup",CHAN_ITEM)
	  TNT1 A 0 ACS_NamedExecuteWithResult("GiveArmorWithItem",5,1)
	  TNT1 A 0 ACS_NamedExecuteWithResult("GiveHealthWithItem",5,1)
	ArmorDone:
	  TNT1 A 0 A_GiveInventory("ClipMapPickup",1)
	  TNT1 A 0 A_GiveInventory("ShellMapPickup",1)
	  TNT1 A 0 A_GiveInventory("RocketMapPickup",1)
	  TNT1 A 0 A_GiveInventory("CellMapPickup",1)
	  Stop
	  Goto MediDone
	}
}

ACTOR DispenserFriendlyMonsterItem : CustomInventory
{
	Inventory.PickupMessage "Received Dispenser health, armor & ammo."
	+INVENTORY.AUTOACTIVATE
	-INVENTORY.INVBAR
	States
	{
Pickup:
	  TNT1 A 0 A_PlaySound("dispenser/pkup",CHAN_BODY)
	  TNT1 A 0 A_PlaySound("misc/ammo_pkup",CHAN_6)
	  TNT1 A 0 A_PlaySound("misc/bonus_pkup",CHAN_ITEM)
	  TNT1 A 0 ACS_NamedExecuteWithResult("PioneerDispenserFriendlyMonsterFilter",1)
	  Stop
	}
}

ACTOR DispenserBuildingToken : SentryBuildingToken
{
	States
	{
	Pickup:
	  TNT1 A 0 ACS_NamedTerminate("DispenserBuilding",0)
	  TNT1 A 0 ACS_NamedExecute("DispenserBuildingStart",0)
	  Stop
	}
}

ACTOR FastDispenserBuildingToken : SentryBuildingToken
{
	States
	{
	Pickup:
	  TNT1 A 0 ACS_NamedTerminate("FastDispenserBuilding",0)
	  TNT1 A 0 ACS_NamedExecute("FastDispenserBuildingStart",0)
	  Stop
	}
}

ACTOR DispenserCompleteToken : SentryBuildingToken
{
	States
	{
	Pickup:
	  TNT1 A 0 ACS_NamedExecute("DispenserComplete",0)
	  Stop
	}
}

ACTOR DispenserDestroyedToken : SentryBuildingToken
{
	States
	{
	Pickup:
	  TNT1 A 0 ACS_NamedTerminate("FastSentryBuilding",0)
	  TNT1 A 0 ACS_NamedTerminate("DispenserBuilding",0)
	  TNT1 A 0 ACS_NamedExecute("DispenserDestroyed",0)
	  Stop
	}
}

ACTOR DispenserRemover : SentryRemover
{
	+INVENTORY.AUTOACTIVATE
	-INVENTORY.INVBAR
	States
	{
	Pickup:
	  TNT1 A 0 A_JumpIf(ACS_NamedExecuteWithResult("DispenserRemoverChecker") == 1,"Remove")
	  Stop
	Remove:
	  TNT1 A 0 Thing_Remove(0)
	  Stop
	}
}
