class BabelShotgunGuy : SyncEnabledMonster Replaces ShotGunGuy
{
	int user_loopCounter;
	int baseHealth;
	default
	{
		Health 30;
		Radius 20;
		Height 56;
		Mass 100;
		Speed 8;
		Monster;
		+FLOORCLIP;
		SeeSound "shotguy/sight";
		PainSound "shotguy/pain";
		DeathSound "shotguy/death";
		ActiveSound "shotguy/active";
		Obituary "$OB_SHOTGUY";
		DropItem "Shotgun";
		PainChance 48;
		Species "Zombie";
		+DOHARMSPECIES;
		MinMissileChance 150;
		ReactionTime 4;
		PainChance "PlayerPistol", 224;
		DamageType "Monster";
		Tag "Shotgun Guy (Babel)";
		
		BabelMonster.SyncChainCheckLOS	true;
		BabelMonster.SyncChainCheckLOF	true;
	}
	
	override void BeginPlay()
	{
		super.BeginPlay();
		
		baseHealth = health;
	}
	
//This is (mostly) just a copy of A_BabelZMShot because I don't feel like making a horrible inheritance tree
	action void A_BabelSGShot(double xspread, double yspread, string attackSound = "grunt/attack")
	{
		string missileType = "ZManShot";
		if(CVar.FindCVar("egr_enemy_tracer_type").GetInt() == 3)
		{
			missileType = "ClassicZManShot";
		}
		if(attackSound != "")
			invoker.A_PlaySound(attackSound);
		A_SpawnProjectile(missileType,32.0,0,(Random2[GunShot]() * (xspread / 256)), CMF_OFFSETPITCH, frandom(-yspread, yspread));

	}
	
	States
	{
	Spawn:
		TNT1 A 0 Nodelay 
		{
			return ResolveState("Look");
		}
	Wander:
		SPOS AABBCCDD 3 Fast 
		{
			A_Wander();
			A_Look();
		}
		Loop;
	Look:
		SPOS AB 10 A_Look();
		Loop;
	See:
		TNT1 A 0 ReleaseState();
		SPOS AABBCCDD 3 Fast A_Chase();
		Goto See;
	Melee:
	Missile:
		TNT1 A 0 
		{
			TriggerSync("BabelZombieMan", 45.0);
			TriggerSync("BabelChaingunGuy", 35.0);
			TriggerSync("BabelShotgunGuy", 40.0);
			TriggerSync("BabelNazi", 75.0);
		}
	MissileNoSignal:
		TNT1 A 0 JumpIfCannotTarget("See");
		TNT1 A 0 HoldState();
		//----------------------------
		//need 36 frame cycle
		SPOS E 9 A_FaceTarget();
		SPOS E 1 A_FaceTarget();
		//Shotgun has a 36 frame cooldown
		TNT1 A 0 bright A_PlaySound("weapons/shotgf", CHAN_WEAPON);
		SPOS FFF 0 A_BabelSGShot(11.3, 7.2, "");
		SPOS F 5 bright;
		SPOS F 3;
		SPOS E 4;
		//10+5+3+4 = 22
		SPOS AA 3 A_Chase(null, null);
		SPOS BBC 3 A_Chase(null, null);
		Goto See+6;
	Pain:
		SPOS G 3 Fast;
		SPOS G 3 Fast A_BabelPain();
		Goto See;
	Death:
		TNT1 A 0 
		{
			if(random(0, 255) < 208)
			{
				TriggerSync("BabelZombieMan", 45.0);
				TriggerSync("BabelChaingunGuy", 35.0);
				TriggerSync("BabelShotgunGuy", 40.0);
				TriggerSync("BabelNazi", 75.0);
			}
		}
	Death.Monster:
	XDeath.Massacre:
		SPOS H 5; 
		SPOS I 5 A_Scream();
		SPOS J 5 A_NoBlocking();
		SPOS K 5;
		SPOS L -1;
		Stop;
	XDeath:
		TNT1 A 0 A_Jump(64, "XDeath.Monster");
		TNT1 A 0 
		{
			TriggerSync("BabelZombieMan", 45.0);
			TriggerSync("BabelChaingunGuy", 35.0);
			TriggerSync("BabelShotgunGuy", 40.0);
			TriggerSync("BabelNazi", 75.0);
		}
	XDeath.Monster:
		TNT1 A 0
		{
			if(CVar.FindCVar("egr_gore").GetInt())
			{
				for(user_loopCounter = 0; user_loopCounter < 4*CVar.FindCVar("egr_gore_level").GetInt(); user_loopCounter++)
				{
					
					A_SpawnProjectile("Bits", random(24, 48), random(-10, 10), random (0, 360), CMF_OFFSETPITCH, -random (0, 160));
					A_SpawnItemEx("BloodSpew", random(-10, 10), random(-10, 10), random(24, 56));
				}
				for(user_loopCounter = 0; user_loopCounter < CVar.FindCVar("egr_gore_level").GetInt()/2; user_loopCounter++)
				{
					A_SpawnProjectile("Chunks", random(24, 48), random(-10, 10), random (0, 360), CMF_OFFSETPITCH, -random (0, 160));
				}
			}
		}
		SPOS M 5;
		SPOS N 5 A_XScream();
		SPOS O 5 A_NoBlocking;
		SPOS PQRST 5;
		SPOS U -1;
		Stop;
	Raise:
		SPOS L 5;
		SPOS KJIH 5;
		Goto See;
	}
}