// Gun turret
actor Utility_GunTurretRed : Utility_TurretBase {
	obituary "%o was owned by a \cgRed \c-turret."
	health 250
	painchance 50
	//seesound "turret/sight"
	attacksound "minigun/fire2"
	activesound "turret/sight"
	states {
	Spawn:
		CIGN AA 0 A_CheckSight("Death.Deconstruction")
		CIGN A 0 Thing_SetSpecial (0, 84, 345, 0, TEAM_RED)
	Idle:
		CIGN A 0 A_TakeInventory ("GunTurretClip", 23)
		CIGN A 0 A_StopSound (6)
		CIGN AAAAA 6 A_Look
		goto Idle+2
	See:
		CIGN A 0 A_GiveInventory("IsRed",1)
		CIGN A 2 A_ChangeFlag("FRIENDLY",0)
		CIGN A 8 A_StopSoundEx("SoundSlot6")
		CIGN A 2 A_JumpIfTargetInLOS("Missile")
		CIGN A 0 A_TakeInventory("GunTurretClip",23)
		CIGN A 2 A_ClearTarget
		goto Spawn+3
	Clear:
		CIGN A 2 A_ClearTarget
		goto See
	See3:
		CIGN A 1 A_JumpIfInTargetInventory ("IsBlue", 1, 1)
		goto Clear
		CIGN A 0 A_Jump(16,"MissileGo")
		CIGN A 0 A_JumpIfCloser(128,"MissileGo")
		goto See
	MissileCheck:
		CIGN A 0 A_JumpIfInTargetInventory ("IsBlue", 1, 1)
		goto Clear
		CIGN A 0 A_Chase("","",CHF_DONTMOVE)
		CIGN A 0 
		goto MissileGo+2
	Missile:
		CIGN A 0 
		CIGN A 1 A_JumpIfInTargetInventory ("IsBlue", 1, 1)
		goto Clear
		CIGN A 0 A_JumpIfInTargetInventory("StealthMode",1,"Clear")
		CIGN A 1 A_JumpIfCloser(3072,"MissileGo")
		CIGN A 0 
		goto Clear
	MissileGo:
		CIGN B 8 A_FaceTarget
		CIGN F 0 A_CPosRefire
		CIGN B 2 A_PlaySoundEx("minigun/loop","SoundSlot6",1)
		CIGN B 0 A_JumpIfInventory("GunTurretClip",23,"Pain")
		CIGN B 0 A_CustomBulletAttack (2.5, 2, 1, 3, "RiflePuff")
		CIGN B 0 A_SpawnItemEx ("Flash")
		CIGN B 0 A_FaceTarget
		CIGN C 2 BRIGHT A_SpawnItemEx("ShellCasing",8,8,48,random(1,3),random(0,1),random(1,3),random(45,60),128)
		CIGN B 1 BRIGHT
		CIGN B 0 A_CustomBulletAttack (2.5, 2, 1, 3, "RiflePuff")
		CIGN B 0 A_SpawnItemEx ("Flash")
		CIGN B 0 A_PlaySoundEx("minigun/fire2","Weapon")
		CIGN B 0 A_FaceTarget
		CIGN C 2 BRIGHT A_SpawnItemEx("ShellCasing",8,8,48,random(1,3),random(0,1),random(1,3),random(45,60),128)
		CIGN B 1 BRIGHT A_ChangeFlag("FRIENDLY",0)
		CIGN F 0 A_CPosRefire
		CIGN F 0 A_GiveInventory("GunTurretClip",1)
		goto MissileCheck
	Pain:
		CIGN A 0 A_StopSoundEx("SoundSlot6")
		CIGN A 0 A_ClearTarget
		CIGN A 9 A_TakeInventory("GunTurretClip",23)
		goto See
	Death:  
		TC4T A 0     
		CIGN A 0 A_StopSoundEx("SoundSlot6")
		TC4T A 0 A_NoBlocking
		TNT1 A 0 A_SpawnItemEx("ExplosionMain", 0, 0, 32)
		TC4T A 0 A_PlaySound("weapons/rocklx")
		TNT1 A 0 A_SpawnItemEx("FlameWallDecay")
		TNT1 A 4
		stop
	}
}

actor Utility_GunTurretBlue : Utility_TurretBase {
	obituary "%o was owned by a \chBlue \c-turret."
	health 250
	painchance 50
	//seesound "turret/sight"
	attacksound "minigun/fire2"
	activesound "turret/sight"
	states {
	Spawn:
		CIGN AA 0 A_CheckSight("Death.Deconstruction")
		CIGN A 0 Thing_SetSpecial (0, 84, 345, 0, TEAM_BLUE)
	Idle:
		CIGN A 0 A_TakeInventory ("GunTurretClip", 23)
		CIGN A 0 A_StopSound (6)
		CIGN AAAAA 6 A_Look
		goto Idle+2
	See:
		CIGN A 0 A_GiveInventory("IsBlue",1)
		CIGN A 2 A_ChangeFlag("FRIENDLY",0)
		CIGN A 8 A_StopSoundEx("SoundSlot6")
		CIGN A 2 A_JumpIfTargetInLOS("Missile")
		CIGN A 0 A_TakeInventory("GunTurretClip",12)
		CIGN A 2 A_ClearTarget
		goto Spawn+3
	See3:
		CIGN A 1 A_JumpIfInTargetInventory ("IsRed", 1, 1)
		goto Clear
		CIGN A 0 A_Jump(16,"MissileGo")
		CIGN A 0 A_JumpIfCloser(128,"MissileGo")
		goto See
	Clear:
		CIGN A 2 A_ClearTarget
		goto See
	MissileCheck:
		CIGN A 0 A_JumpIfInTargetInventory ("IsRed", 1, 1)
		goto Clear
		CIGN A 0 A_Chase("","",CHF_DONTMOVE)
		CIGN A 0 
		goto MissileGo+2
	Missile:
		CIGN A 0 
		CIGN A 1 A_JumpIfInTargetInventory ("IsRed", 1, 1)
		goto Clear
		CIGN A 0 A_JumpIfInTargetInventory("StealthMode",1,"Clear")
		CIGN A 1 A_JumpIfCloser(3072,"MissileGo")
		CIGN A 0 
		goto Clear
	MissileGo:
		CIGN B 8 A_FaceTarget
		CIGN F 0 A_CPosRefire
		CIGN B 2 A_PlaySoundEx("minigun/loop","SoundSlot6",1)
		CIGN B 0 A_JumpIfInventory("GunTurretClip",23,"Pain")
		CIGN B 0 A_CustomBulletAttack (2.5, 2, 1, 3, "RiflePuff")
		CIGN B 0 A_SpawnItemEx ("Flash")
		CIGN B 0 A_FaceTarget
		CIGN C 2 BRIGHT A_SpawnItemEx("ShellCasing",8,8,48,random(1,3),random(0,1),random(1,3),random(45,60),128)
		CIGN B 1 BRIGHT 
		CIGN B 0 A_CustomBulletAttack (2.5, 2, 1, 3, "RiflePuff")
		CIGN B 0 A_SpawnItemEx("Flash",0,0,0,0,0,0,0,128,0)
		CIGN B 0 A_PlaySoundEx("minigun/fire2","Weapon")
		CIGN B 0 A_FaceTarget
		CIGN C 2 BRIGHT A_SpawnItemEx("ShellCasing",8,8,48,random(1,3),random(0,1),random(1,3),random(45,60),128)
		CIGN B 1 BRIGHT A_ChangeFlag("FRIENDLY",0)
		CIGN F 0 A_CPosRefire
		CIGN F 0 A_GiveInventory("GunTurretClip",1)
		goto MissileCheck
	Pain:
		CIGN A 0 A_StopSoundEx("SoundSlot6")
		CIGN A 0 A_ClearTarget
		CIGN A 9 A_TakeInventory("GunTurretClip",23)
		goto See
	Death:  
		TC4T A 0     
		CIGN A 0 A_StopSoundEx("SoundSlot6")
		TC4T A 0 A_NoBlocking
		TNT1 A 0 A_SpawnItemEx("ExplosionMain", 0, 0, 32)
		TC4T A 0 A_PlaySound("weapons/rocklx")
		TNT1 A 0 A_SpawnItemEx("FlameWallDecay")
		TNT1 A 4
		stop
	}
}

actor GunTurretClip : Inventory {inventory.maxamount 23}