ACTOR PistolZombie: RifleZombie
{
DropItem "PistolSpawner"
Tag "Pistol Zombie"
	States
	{
	Spawn:
		PSSS B 0
		TNT1 A 0 A_GiveInventory("TypeZombieMan", 1)
		TNT1 A 0 A_TakeInventory("ZombiemanAmmo", 20)
		TNT1 A 0 A_GiveInventory("SKZombieMan", 1)
		TNT1 A 0 A_GiveInventory("ZombieManAmmo", random(1,10))
		PSPO A 1
	Goto Stand
	
	Stand:
		PSSS B 0
		TNT1 A 0 A_CheckSight("Stand2")
		TNT1 AA 0 A_SpawnItem ("HeadshotTarget20", 4, 44,0)
		
		PSPO A 10 A_Look
		Loop
	
	Stand2:
		PSPO A 10 A_Look
		TNT1 A 0 A_CheckSight("Stand2")
		Goto Stand
		
	
	SearchForPlayer:
	Idle:
	    TNT1 A 0 A_ClearTarget
	    TNT1 A 0 A_TakeInventory("EnemyMemory", 30)
		TNT1 A 0 A_GiveInventory("SKZombieMan", 1)
        TNT1 A 0 A_SpawnItem ("HeadshotTarget10", 4, 44,0)
		TNT1 A 0 A_SpawnItem ("LegTargetBase", 10)
		PSPO A 10 A_Look
        TNT1 A 0 A_SpawnItem ("HeadshotTarget10", 4, 44,0)
		TNT1 A 0 A_SpawnItem ("LegTargetBase", 10)
		PSPO A 10 A_Look
		TNT1 A 0 A_SpawnItem ("HeadshotTarget10", 4, 44,0)
		TNT1 A 0 A_SpawnItem ("LegTargetBase", 10)
		PSPO A 10 A_Look
        TNT1 A 0 A_SpawnItem ("HeadshotTarget10", 4, 44,0)
		TNT1 A 0 A_SpawnItem ("LegTargetBase", 10)
		PSPO A 10 A_Look
		TNT1 A 0 A_SpawnItem ("HeadshotTarget10", 4, 44,0)
		TNT1 A 0 A_SpawnItem ("LegTargetBase", 10)
		PSPO A 10 A_Look
		TNT1 A 0 A_SpawnItem ("HeadshotTarget10", 4, 44,0)
		TNT1 A 0 A_SpawnItem ("LegTargetBase", 10)
		PSPO A 10 A_Look
		TNT1 A 0 A_SpawnItem ("HeadshotTarget10", 4, 44,0)
		TNT1 A 0 A_SpawnItem ("LegTargetBase", 10)
		PSPO A 10 A_Look
		
	StartSearching:	
		PSPO A 2 A_Look
		TNT1 A 0 A_SpawnItem ("HeadshotTarget4", 4, 44,0)
		TNT1 A 0 A_Wander
		PSPO A 2 A_Look
		TNT1 A 0 A_Wander
		
		PSPO B 2 A_Look
		TNT1 A 0 A_SpawnItem ("HeadshotTarget4", 4, 44,0)
		TNT1 A 0 A_Wander
		PSPO B 2 A_Look
		TNT1 A 0 A_Wander
		
		
		PSPO C 2 A_Look
		TNT1 A 0 A_SpawnItem ("HeadshotTarget4", 4, 44,0)
		TNT1 A 0 A_Wander
		PSPO C 2 A_Look
		TNT1 A 0 A_Wander
		
		PSPO D 2 A_Look
		TNT1 A 0 A_SpawnItem ("HeadshotTarget4", 4, 44,0)
		TNT1 A 0 A_Wander
		PSPO D 2 A_Look
		TNT1 A 0 A_Wander
		
		
		TNT1 A 0 A_Jump(64, "Idle")
		Goto StartSearching
		
		
	FallBack:
		TNT1 A 0 A_CheckSight("Advance")
		TNT1 A 0 A_ChangeFLag("NODROPOFF", 1)
		TNT1 A 0 A_SpawnItem ("HeadshotTarget4", -4, 44,0)
		TNT1 A 0 A_SpawnItem ("LegTarget4", 10)
		PSPO D 2 A_FaceTarget
		PSPO D 2 A_Recoil(4)
		TNT1 A 0 A_jump(64, "Missile")
		TNT1 A 0 A_SpawnItem ("HeadshotTarget4", -4, 44,0)
		TNT1 A 0 A_SpawnItem ("LegTarget4", 10)
		PSPO C 2 A_FaceTarget
		PSPO C 2 A_Recoil(4)
		TNT1 A 0 A_SpawnItem ("HeadshotTarget4", -4, 44,0)
		TNT1 A 0 A_SpawnItem ("LegTarget4", 10)
		PSPO B 2 A_FaceTarget
		PSPO B 2 A_Recoil(3)
		TNT1 A 0 A_SpawnItem ("HeadshotTarget4", -4, 44,0)
		TNT1 A 0 A_SpawnItem ("LegTarget4", 10)
		PSPO A 2 A_FaceTarget
		PSPO A 2 A_Recoil(3)
		TNT1 A 0 A_ChangeFLag("NODROPOFF", 0)
		GOto Missile
		
	See:
		TNT1 A 0 A_ChangeFLag("NODROPOFF", 0)
		TNT1 A 0 A_TakeInventory("SKZombieman", 1)
		TNT1 A 0 A_TakeInventory("EnemyMemory", 15)
		TNT1 A 0 A_CheckSight("SeeNeverSeen")
		TNT1 A 0 A_TakeInventory("SKZombieman", 1)
		Goto SeeContinue
	
	SeeContinue:
		TNT1 A 0 A_JumpIfCloser(200, "FallBack")
		Advance:
		TNT1 A 0 A_ChangeFLag("NODROPOFF", 0)
        //TNT1 A 0 A_SpawnItemEx("FootSep", 0, 0, 10, 0, 0)
		TNT1 A 0 A_JumpIfInventory("EnemyMemory", 15, "SearchForPlayer")
		TNT1 A 0 A_GiveInventory("EnemyMemory", 1)
		
		
		TNT1 A 0 A_SpawnItem ("HeadshotTarget6", 4, 44,0)
		TNT1 A 0 A_SpawnItem ("LegTargetBase", 10)
		PSPO AAA 2 A_Chase
		
		TNT1 A 0 A_SpawnItem ("HeadshotTarget6", 4, 44,0)
		TNT1 A 0 A_SpawnItem ("LegTargetBase", 10)
		PSPO BBB 2 A_Chase
		
		TNT1 A 0 A_SpawnItem ("HeadshotTarget6", 4, 44,0)
		TNT1 A 0 A_SpawnItem ("LegTargetBase", 10)
		PSPO CCC 2 A_Chase
		
		TNT1 A 0 A_SpawnItem ("HeadshotTarget6", 4, 44,0)
		TNT1 A 0 A_SpawnItem ("LegTargetBase", 10)
		PSPO DDD 2 A_Chase
		
		TNT1 A 0 A_JumpIfInTargetInventory("IsInvisible", 1, "Idle")
		Loop
		
	SeeNeverSeen:
	Advance:
		TNT1 A 0 A_ChangeFLag("NODROPOFF", 0)
		
		TNT1 A 0 A_SpawnItem ("HeadshotTarget4", 4, 44,0)
		TNT1 A 0 A_SpawnItem ("LegTargetBase", 10)
		PSPO AA 2 A_Chase
		
		TNT1 A 0 A_SpawnItem ("HeadshotTarget4", 4, 44,0)
		TNT1 A 0 A_SpawnItem ("LegTargetBase", 10)
		PSPO BB 2 A_Chase
		
		TNT1 A 0 A_SpawnItem ("HeadshotTarget4", 4, 44,0)
		TNT1 A 0 A_SpawnItem ("LegTargetBase", 10)
		PSPO CC 2 A_Chase
		
		TNT1 A 0 A_SpawnItem ("HeadshotTarget4", 4, 44,0)
		TNT1 A 0 A_SpawnItem ("LegTargetBase", 10)
		PSPO DD 2 A_Chase
		TNT1 A 0 A_CheckSIght("SeeNeverSeen")
		Goto SeeContinue	
		
	Pain.Taunt:
		TNT1 A 0
		TNT1 A 0 A_JumpIfInventory("Enraged", 1, "Missile")
		PSPO B 0 A_Pain
		TNT1 A 0 A_ChangeFlag("FASTER", 1)
		TNT1 A 0 A_ChangeFlag("MISSILEMORE", 1)
		TNT1 A 0 A_ChangeFlag("MISSILEEVENMORE", 1)
		TNT1 A 0 A_PlaySound("grunt/sight")
		PSPO B 1 A_FaceTarget
		PSPO B 10
		TNT1 A 0 A_GiveInventory("Enraged", 1)
		TNT1 A 0 A_PlaySound("grunt/sight", 1)
		Goto Missile
		
	Pain.Head:
		TNT1 A 0 A_TakeInventory("SKZombieman", 1)
		TNT1 A 0 A_SpawnItem ("HeadshotTarget4", 0, 40,0)
		POSH G 5 A_Pain
		TNT1 A 0 A_FaceTarget
		TNT1 A 0 A_SpawnItem ("HeadshotTarget20", 4, 35,0)
		POSH H 20
		TNT1 A 0 A_SpawnItem ("HeadshotTarget20", 4, 35,0)
		POSH H 20
		Goto SeeContinue	
		
	Missile:
	    TNT1 A 0 A_Stop
		
		TNT1 A 0 A_ChangeFlag("GHOST", 0)
		TNT1 A 0 A_ChangeFLag("NODROPOFF", 0)
		TNT1 A 0 A_TakeInventory("SKZombieman", 1)
		TNT1 A 0 A_TakeInventory("EnemyMemory", 10)
		
        //TNT1 A 0 A_Jump(8, "Grenade")
		TNT1 A 0 A_SpawnItem ("HeadshotTarget20", 0, 44,0)
		TNT1 A 0 A_SpawnItem ("LegTarget20", 10)
		
		//TNT1 A 0 A_TakeInventory("CantFire", 1)
		//TNT1 A 0 A_CustomMissile("MonsterTargetCheck", 34, 0, 0, 0) 
		//TNT1 A 0 A_CustomMissile("MonsterTargetCheckFaster", 34, 0, 0, 0)  
		PSPO E 14 A_FaceTarget
		
		FireGun:
		TNT1 A 0 A_SpawnItem ("HeadshotTarget20", 0, 44,0)
		TNT1 A 0 A_GiveInventory("ZombieManAmmo", 1)
        TNT1 A 0 A_PlaySound("pfire")
		TNT1 A 0 A_CustomMissile("DistantFireSoundRifle", 32, 0, 0, 1, 0)
		PSPO F 2 BRIGHT A_CustomMissile("ZombieManTracer", 48, 0, random(-2, 2), 1, random(-2, 2))
		TNT1 A 0 A_SpawnItem ("PistolCaseSpawn", 0, 30,0)
		PSPO E 12 A_FaceTarget
		TNT1 A 0 A_Jump(96, "FireGun")
       
        TNT1 A 0 A_JumpIfInventory("ZombieManAmmo", 15, "Reload")
		TNT1 A 0 A_JumpIfInTargetInventory("IsInvisible", 1, "SearchForPlayer")
        Goto SeeContinue
		
		
	
  Reload:
		TNT1 A 0 A_TakeInventory("ZombieManAmmo", 20)
		TNT1 A 0 A_SpawnItem ("HeadshotTarget20", 4, 44,0)
		TNT1 A 0 A_SpawnItem ("LegTarget20", 10)
        PSPR A 1
		PSPR A 1 A_CustomMissile("EmptyClipSpawn", 38, 0, random(-11, 11), 0)
        TNT1 A 0 A_PlaySound("Reload")
        PSPR ABACDED 3
        Goto SeeContinue

   Pain.Avoid:
	    TNT1 A 0
	    TNT1 A 0 A_Jump(256, "AvoidLeft", "AvoidRight")
        Goto AvoidLeft
	  
   AvoidLeft:
	    PSPO A 1 A_FaceTarget
	    TNT1 A 0 ThrustThing(angle*256/360+192, 15, 0, 0)
        ZRO2 ABCDEFGH 3 A_FaceTarget
        Goto Missile
	AvoidRight:
	    PSPO A 1 A_FaceTarget
	    TNT1 A 0 ThrustThing(angle*256/360+64, 15, 0, 0)
        ZRO1 ABCDEFGH 3 A_FaceTarget
        Goto Missile

   //If the monster is hit by the "Killme" damage (which is "exploded" by the captured marine), automatically start firing at the target.
    Pain.KillMe:
        TNT1 A 0
		TNT1 A 0 HEalThing(1)
        Goto Missile
	//Emergency manuever in case the monster gets killed by an "alerter" actor	
    Death.KillMe:
    Death.Taunt:
    Death.Avoid:
	    TNT1 A 0
		TNT1 A 0 A_ChangeFlag("SOLID", 0)
        TNT1 A 0 A_SpawnItem("PistolZombie")
		TNT1 A 0
        Stop


	Pain.Cut:
	Pain.Saw:
		TNT1 A 0
		TNT1 A 0 A_Stop
	Pain:
	    
        TNT1 A 0 A_JumpIfInventory ("IsDown", 1, 8)
		TNT1 A 0 A_SpawnItem ("HeadshotTarget4", 0, 40,0)
		PSPO G 2
		TNT1 A 0 A_TakeInventory("SKZombieman", 1)
		TNT1 A 0 A_SpawnItem ("HeadshotTarget4", 0, 40,0)
		PSPO G 2 A_Pain
		TNT1 A 0 A_Jump(196, "Missile")
	    Goto SeeContinue
        TNT1 AAAA 0
        TNT1 A 0 A_Pain
        ID11 F 6
        Goto GetUp
		
	Pain.LowKick:
		TNT1 A 0
		TNT1 A 0 A_JumpIfInventory("IsDown", 1, "Death.LowKick")
		Goto Pain
		
	Death.LowKick:
		TNT1 A 0 A_NoBlocking
		TNT1 A 0 A_GiveToTarget("GoFatality", 1)
        TNT1 A 0 A_GiveToTarget("IsCurbstompingZombieman", 1)
        Stop	

    Pain.Melee:
	Pain.Fatality:
		TNT1 A 0
		TNT1 A 0 A_JumpIfInventory ("SKZombieman", 1, "GotoStealthKill")
        TNT1 A 0 A_JumpIfInventory ("IsDown", 1, 8)
		TNT1 A 0 A_SpawnItem ("HeadshotTarget4", 0, 40,0)
	    PSPO G 4
		TNT1 A 0 A_SpawnItem ("HeadshotTarget4", 0, 40,0)
		PSPO G 4 A_Pain
		Goto SeeContinue
        TNT1 AAAA 0
        TNT1 A 0 A_Pain
        ID11 FRRRQ 10
		TNT1 A 0 A_TakeInventory("SKZombieman", 1)
        TNT1 A 0 A_TakeInventory("IsDown", 1)
        Goto SeeContinue
		
		GotoStealthKill:
		TNT1 A 1
		//TNT1 A 0 A_JumpIfInTargetInventory("PowerStrength", 1, "BecomeMeatShield")
		TNT1 A 0 A_Explode(100, 1, 1)
		TNT1 A 1
		Goto SeeContinue
		
		BecomeMeatShield:
		TNT1 A 0 A_NoBlocking
        TNT1 A 0 A_GiveToTarget("HasZManShield", 1)
		TNT1 A 0 A_GiveToTarget("GotMeatShield", 1)
        Stop
	
	Pain.ExtremePunches:
	Pain.ExplosiveImpact:
	Pain.Explosive:
	     TNT1 A 0
		 TNT1 A 0 A_ChangeFlag("NOBLOCKMONST", 1)
		 TNT1 A 0 A_ChangeFLag("NODROPOFF", 0)
	     TNT1 A 0 A_Pain
		 TNT1 A 0 A_JumpIfInventory ("IsDown", 1, "Pain")
		 TNT1 A 0 A_TakeInventory("SKZombieman", 1)
         TNT1 A 0 A_GiveInventory("IsDown", 1)
         TNT1 A 0 ThrustThingZ(0,40,0,1)
         POS4 UVWXY 5
		 Goto FallingAfterImpact
		
	Pain.Slide:
         TNT1 A 0
		 TNT1 A 0 A_ChangeFlag("NOBLOCKMONST", 1)
		 TNT1 A 0 A_ChangeFLag("NODROPOFF", 0)
		 TNT1 A 0 A_ChangeFlag("NOPAIN", 1)
		 TNT1 A 0 A_ChangeFlag("GHOST", 1)
		 TNT1 A 0 A_ChangeFlag("THRUGHOST", 1)
		 TNT1 A 0 A_ChangeFlag("USESPECIAL", 1)
         POS4 U 0 A_Pain
		 TNT1 A 0 A_ChangeFlag("FORCEXYBILLBOARD", 1)
		 TNT1 A 0 A_JumpIfInventory ("IsDown", 1, "Pain")
		 TNT1 A 0 A_TakeInventory("SKZombieman", 1)
		 POS4 U 1 A_facetarget
         TNT1 A 0 ThrustThingZ(0,50,0,1)
		 TNT1 A 0 A_FaceTarget
         POS4 U 3 
		 TNT1 A 0 A_Recoil(-8)
		 TNT1 A 0 A_GiveInventory("IsDown", 1)
		 TNT1 A 0 A_ChangeFlag("NOPAIN", 0)
		 TNT1 A 0 A_ChangeFlag("GHOST", 0)
		 TNT1 A 0 A_ChangeFlag("THRUGHOST", 0)
         POS4 UVWXY 3
		 Goto FallingAfterImpact
		 
    Pain.Kick:
	Pain.HeavyImpact:
         TNT1 A 0
		 TNT1 A 0 A_ChangeFlag("NOBLOCKMONST", 1)
		 TNT1 A 0 A_ChangeFLag("NODROPOFF", 0)
		 TNT1 A 0 A_ChangeFlag("NOPAIN", 1)
		 TNT1 A 0 A_ChangeFlag("USESPECIAL", 1)
         POS4 U 0 A_Pain
		 TNT1 A 0 A_ChangeFlag("NOPAIN", 0)
		 TNT1 A 0 A_ChangeFlag("FORCEXYBILLBOARD", 1)
		 TNT1 A 0 A_JumpIfInventory ("IsDown", 1, "Pain")
		 TNT1 A 0 A_TakeInventory("SKZombieman", 1)
		 POS4 U 1 A_facetarget
         TNT1 A 0 ThrustThingZ(0,30,0,1)
		 TNT1 A 0 A_FaceTarget
         POS4 U 3 ThrustThing(angle*256/360+128, 10, 0, 0)
		 TNT1 A 0 A_GiveInventory("IsDown", 1)
		 
         POS4 UVWXY 3
		 Goto FallingAfterImpact
		
	FallingAfterImpact:
		ID11 F 1 A_GiveInventory ("FallingHeight", 1)
		ID11 F 1 A_CheckFloor ("GetUp")
		NULL A 0 A_JumpIf (momz == 0, "GetUp")
		Loop
		
	GetUp:
		TNT1 A 0
		MARN A 0 A_SpawnItem("bdbodythud")
		TNT1 A 0 A_JumpIfInventory ("FallingHeight", 5, "FallingDie")
		TNT1 A 0 A_TakeInventory("FallingHeight", 100)
		TNT1 A 0 A_Stop
		ID11 RRRRRRRRRRRRRR 5 A_JumpIf(momz < 0, "FallingAfterImpact")
		
        TNT1 A 0 A_TakeInventory("IsDown", 1)
		ID11 Q 10
		TNT1 A 0 A_ChangeFlag("FORCEXYBILLBOARD", 0)
		TNT1 A 0 A_ChangeFlag("USESPECIAL", 0)
        Goto SeeContinue
		
	Active:
		TNT1 A 0
		
		TNT1 A 0 A_GiveToTarget("ExecuteDownedZombieman", 1)
		TNT1 A 0 A_GiveToTarget("GoSpecial", 1)
		IZD4 M 0
		ID11 RRRRRR 2 A_JumpIfInTargetInventory("IsExecutingOnAir", 1, "FinishActive")
		TNT1 A 0 A_JumpIfInTargetInventory("ExecuteBashWall", 1, "FinishActive")
		TNT1 M 1
		TNT1 A 0 A_JumpIfInTargetInventory("ExecuteStompWall", 1, "GetUp")
	  FinishActive:
		TNT1 A 0 A_NoBlocking
		TNT1 A 0 A_ChangeFlag("SHOOTABLE", 0)
		TNT1 A 0 A_ChangeFlag("THRUACTORS", 1)
		TNT1 A 0 A_ChangeFlag("COUNTKILL", 0)
		TNT1 A 0 A_ChangeFlag("USESPECIAL", 0)
		Stop	
	}
}