//==============================================================================
//
// SKULLTAG STUFF
//
//==============================================================================
//Token items to know the state of the skull, score, etc.

ACTOR HasRedSkull : Inventory {Inventory.MaxAmount 1 +INTERHUBSTRIP}
ACTOR SpawnRedSkull : Inventory {Inventory.MaxAmount 1 }
ACTOR SpawnFakeRedSkull : Inventory {Inventory.MaxAmount 1 }

ACTOR HasBlueSkull : Inventory {Inventory.MaxAmount 1 +INTERHUBSTRIP}
ACTOR SpawnBlueSkull : Inventory {Inventory.MaxAmount 1 }
ACTOR SpawnFakeBlueSkull : Inventory {Inventory.MaxAmount 1 }

ACTOR GetRedSkull : Inventory {Inventory.MaxAmount 1 +INTERHUBSTRIP}
ACTOR GetBlueSkull : Inventory {Inventory.MaxAmount 1 +INTERHUBSTRIP}

ACTOR IsPlayingST : Inventory {Inventory.MaxAmount 1}

ACTOR STScoreSystem //It isn't necessary to define another one but it's tidier this way
{
Health 100
Radius 1
Height 1
+NOCLIP
-SOLID
-SHOOTABLE
+NOBLOCKMAP
+THRUACTORS
+INVULNERABLE
+DONTGIB
States
{
Spawn:
TNT1 A 1
TNT1 A 0 A_GiveInventory("IsPlayingST", 1)
TNT1 A 0 Thing_ChangeTID(0, 1898669)
TNT1 A -1
Wait
}
}

//Other stuff like skulls and the score pillar
ACTOR HellScorePillar : CustomInventory 5020
{
	Game Doom
	Radius 20
	Height 26
	-NOTDMATCH
	+DONTGIB
	Inventory.PickupMessage ""
	States
	{
	Spawn:
		HLSP A 1
		Loop
	Pickup:
	    HLSP A 1 A_JumpIfInventory("HasBlueSkull", 1, "TagBlueSkull")
		HLSP A 1 A_JumpIfInventory("HasRedSkull", 1, "TagRedSkull")
		Fail
	TagRedSkull:
		TNT1 A 1 ACS_NamedExecuteAlways("ST4ZD_CaptureRedSkull", 0)
		HLSP D 35
		HLSP E 140
		Fail
	TagBlueSkull:
		TNT1 A 1 ACS_NamedExecuteAlways("ST4ZD_CaptureBlueSkull", 0)
		HLSP B 35
		HLSP C 140
		Fail
	}
}

//New score pillar things because it is far too stupid to allow the
//player to capture in the enemy base

ACTOR HellScorePillarBlue : CustomInventory 10022
{
	//$Category ZCTF Stuff
	//$Title Blue Skull Pillar
	//$Sprite HLSPA0
	//$NotAngled
	Game Doom
	Radius 20
	Height 26
	-NOTDMATCH
	+DONTGIB
	Inventory.PickupMessage ""
	States
	{
	Spawn:
		HLSP A 1
		Loop
	Pickup:
		HLSP A 1 A_JumpIfInventory("HasRedSkull", 1, "TagRedSkull")
		Fail
	TagRedSkull:
		TNT1 A 1 ACS_NamedExecuteAlways("ST4ZD_CaptureRedSkull", 0)
		HLSP D 35
		HLSP E 140
		Fail
	TagBlueSkull:
		TNT1 A 1 ACS_NamedExecuteAlways("ST4ZD_CaptureBlueSkull", 0)
		HLSP B 35
		HLSP C 140
		Fail
	}
}

ACTOR HellScorePillarRed : CustomInventory 10021
{
	//$Category ZCTF Stuff
	//$Title Red Skull Pillar
	//$Sprite HLSPA0
	//$NotAngled
	Game Doom
	Radius 20
	Height 26
	-NOTDMATCH
	+DONTGIB
	Inventory.PickupMessage ""
	States
	{
	Spawn:
		HLSP A 1
		Loop
	Pickup:
	    HLSP A 1 A_JumpIfInventory("HasBlueSkull", 1, "TagBlueSkull")
		Fail
	TagRedSkull:
		TNT1 A 1 ACS_NamedExecuteAlways("ST4ZD_CaptureRedSkull", 0)
		HLSP D 35
		HLSP E 140
		Fail
	TagBlueSkull:
		TNT1 A 1 ACS_NamedExecuteAlways("ST4ZD_CaptureBlueSkull", 0)
		HLSP B 35
		HLSP C 140
		Fail
	}
}
//Had to make up a new number for the skulls since in the regular
//ST they are the same as the normal skullkeys, that means that
//you have to go through a teeny tiny bit of extra effort to make
//maps work for this mod
ACTOR RedSkullSpot : CustomInventory 10131
{
	//$Category ZCTF Stuff
	//$Title Red Skull
	//$Sprite RSKUA0
	//$NotAngled
	Game Doom
	Radius 1
	Height 1
	Inventory.PickupMessage "Lol"
	-PICKUP
	+THRUACTORS
	+DONTGIB
	+NOBLOCKMAP
	States
	{
	Spawn:
		TNT1 A 1
		TNT1 A 0 A_TakeInventory("SpawnRedSkull", 100)
		TNT1 A 0 Thing_ChangeTID(0, 10131)
		TNT1 A 0 A_SpawnItem("RedSkullST")
		TNT1 A 0 A_SpawnItem("STScoreSystem")
		Goto Waiting
	Spawn2:
		TNT1 A 1
		TNT1 A 0 A_TakeInventory("SpawnRedSkull", 100)
		TNT1 A 0 Thing_ChangeTID(0, 10131)
		TNT1 A 0 A_SpawnItem("RedSkullST")
		Goto Waiting
	Waiting:
	    TNT1 A 1 A_JumpIfInventory("SpawnRedSkull", 1, "Spawn2")
		Loop
	Pickup:
		TNT1 A 0
		Goto Waiting
	}
}

ACTOR BlueSkullSpot : CustomInventory 10130
{
	//$Category ZCTF Stuff
	//$Title Blue Skull
	//$Sprite BSKUA0
	//$NotAngled
	Game Doom
	Radius 1
	Height 1
	Inventory.PickupMessage "Lol"
	-PICKUP
	+DONTGIB
	+THRUACTORS
	+NOBLOCKMAP
	States
	{
	Spawn:
		TNT1 A 1
		TNT1 A 0 A_TakeInventory("SpawnBlueSkull", 100)
		TNT1 A 0 Thing_ChangeTID(0, 10130)
		TNT1 A 0 A_SpawnItem("BlueSkullST")
		TNT1 A 0 A_SpawnItem("STScoreSystem")
		Goto Waiting
	Spawn2:
		TNT1 A 1
		TNT1 A 0 A_TakeInventory("SpawnBlueSkull", 100)
		TNT1 A 0 Thing_ChangeTID(0, 10130)
		TNT1 A 0 A_SpawnItem("BlueSkullST")
		Goto Waiting
	Waiting:
	    TNT1 A 1 A_JumpIfInventory("SpawnBlueSkull", 1, "Spawn2")
		Loop
	Pickup:
		TNT1 A 0 A_Print("Crap!")
		Goto Waiting
	}
}

ACTOR RedSkullST : CustomInventory
{
	Game Doom
	Radius 20
	Height 26
	Inventory.PickupMessage ""
	Inventory.PickupFlash ""
	+NEVERRESPAWN
	+DONTGIB
	//+NOSCREENFLASH
	States
	{
	Spawn:
	    RSKU A 10
		RSKU B 10 BRIGHT
		loop
	Pickup:
	    TNT1 A 0 A_TakeInventory("RedSkullST", 100)
	    TNT1 A 0 A_JumpIfInventory("GetRedSkull", 1, "DoGiveFlag")
		//TNT1 A 0 ACS_NamedExecuteAlways("ST4ZD_ReturnRedSkull", 0)
		Fail
	DoGiveFlag:
		TNT1 A 0 ACS_NamedExecuteAlways("ST4ZD_StealRedSkull", 0)
		TNT1 A 0 A_PlaySound("GetRedSkull", 9, 100, 0, 0)
		TNT1 A 0 A_GiveInventory("HasRedSkull", 1)
		Stop
	}
}

ACTOR RedSkullDrop : CustomInventory
{
	Game Doom
	Radius 20
	Height 26
	Inventory.PickupMessage ""
	Inventory.PickupFlash ""
	+NEVERRESPAWN
	+DONTGIB
	//+NOSCREENFLASH
	States
	{
	Spawn:
	    RSKU A 10
		RSKU B 10 BRIGHT
		TNT1 A 0 A_GiveInventory("LoopsLeftToReturn", 1)
		TNT1 A 0 A_JumpIfInventory("LoopsLeftToReturn", 40, "ReturnThis")
		loop
	//Pickup:
	    //TNT1 A 0 A_TakeInventory("RedSkullDrop", 100)
	    //TNT1 A 0 A_JumpIfInventory("GetRedSkull", 1, "DoGiveFlag")
		//TNT1 A 0 ACS_NamedExecuteAlways("ST4ZD_ReturnRedSkull", 0)
		//TNT1 A 0 A_JumpIfInventory("STZD_ImmaBot", 1, "FailedBoi")
		//Stop
	FailedBoi:
	    RSKU A 10
		RSKU B 10 BRIGHT
		Fail
	Pickup:
	    TNT1 A 0 A_TakeInventory("BlueSkullST", 100)
	    TNT1 A 0 A_JumpIfInventory("GetRedSkull", 1, "DoGiveFlag")
		TNT1 A 0 A_JumpIfInventory("GetBlueSkull", 1, "ReturnThis")
		//TNT1 A 0 ACS_NamedExecuteAlways("ST4ZD_ReturnBlueSkull", 0)
		//TNT1 A 0 A_JumpIfInventory("STZD_ImmaBot", 1, "FailedBoi")
		Stop
	ReturnThis:
	    TNT1 A 0 ACS_NamedExecuteAlways("ST4ZD_ReturnRedSkull", 0)
		Stop
	DoGiveFlag:
		TNT1 A 0 ACS_NamedExecuteAlways("ST4ZD_StealRedSkull", 0)
		TNT1 A 0 A_PlaySound("GetRedSkull", 9, 100, 0, 0)
		TNT1 A 0 A_GiveInventory("HasRedSkull", 1)
		Stop
	}
}

ACTOR BlueSkullST : CustomInventory
{
	Game Doom
	Radius 20
	Height 26
	Inventory.PickupMessage ""
	Inventory.PickupFlash ""
	-PICKUP
	+DONTGIB
	+NEVERRESPAWN
	States
	{
	Spawn:
	    BSKU A 10
		BSKU B 10 BRIGHT
		loop
	Pickup:
	    TNT1 A 0 A_TakeInventory("BlueSkullST", 100)
	    TNT1 A 0 A_JumpIfInventory("GetBlueSkull", 1, "DoGiveFlag")
		//TNT1 A 0 ACS_NamedExecuteAlways("ST4ZD_ReturnBlueSkull", 0)
		Fail
	DoGiveFlag:
		TNT1 A 0 ACS_NamedExecuteAlways("ST4ZD_StealBlueSkull", 0)
		TNT1 A 0 A_PlaySound("GetBlueSkull", 9, 100, 0, 0)
		TNT1 A 0 A_GiveInventory("HasBlueSkull", 1)
		Stop
	}
}

ACTOR BlueSkullDrop : CustomInventory
{
	Game Doom
	Radius 20
	Height 26
	Inventory.PickupMessage ""
	Inventory.PickupFlash ""
	-PICKUP
	+DONTGIB
	+NEVERRESPAWN
	States
	{
	Spawn:
	    BSKU A 10
		BSKU B 10 BRIGHT
		TNT1 A 0 A_GiveInventory("LoopsLeftToReturn", 1)
		TNT1 A 0 A_JumpIfInventory("LoopsLeftToReturn", 40, "ReturnThis")
		loop
	Pickup:
	    TNT1 A 0 A_TakeInventory("BlueSkullST", 100)
	    TNT1 A 0 A_JumpIfInventory("GetBlueSkull", 1, "DoGiveFlag")
		TNT1 A 0 A_JumpIfInventory("GetRedSkull", 1, "ReturnThis")
		//TNT1 A 0 ACS_NamedExecuteAlways("ST4ZD_ReturnBlueSkull", 0)
		//TNT1 A 0 A_JumpIfInventory("STZD_ImmaBot", 1, "FailedBoi")
		Stop
	DoGiveFlag:
		TNT1 A 0 ACS_NamedExecuteAlways("ST4ZD_StealBlueSkull", 0)
		TNT1 A 0 A_PlaySound("GetBlueSkull", 9, 100, 0, 0)
		TNT1 A 0 A_GiveInventory("HasBlueSkull", 1)
		Stop
	ReturnThis:
	    TNT1 A 0 ACS_NamedExecuteAlways("ST4ZD_ReturnBlueSkull", 0)
		Stop
	FailedBoi:
	    BSKU A 10
		BSKU B 10 BRIGHT
		Fail
	}
}

ACTOR STRSkullIcon
{
Health 100
Radius 1
Height 1
Scale 1.5
+NOCLIP
-SOLID
-SHOOTABLE
+NOBLOCKMAP
+THRUACTORS
+NOGRAVITY
+INVULNERABLE
States
{
Spawn:
RSKU A 2 BRIGHT
Stop
}
}

ACTOR STBSkullIcon
{
Health 100
Radius 1
Height 1
Scale 1.5
+NOCLIP
-SOLID
-SHOOTABLE
+NOBLOCKMAP
+THRUACTORS
+NOGRAVITY
+INVULNERABLE
States
{
Spawn:
BSKU A 2 BRIGHT
Stop
}
}

ACTOR STRedSkullIconSpawner : CustomInventory
{
	Game Doom
	Radius 20
	Height 26
	Inventory.PickupMessage ""
	+INVENTORY.AUTOACTIVATE
	States
	{
	Spawn:
		TNT1 A 1
		Loop
	Pickup:
    Use:
	    TNT1 A 0 A_SpawnItem("STRSkullIcon", 0, 55)
		Stop
	}
}

ACTOR STBlueSkullIconSpawner : CustomInventory
{
	Game Doom
	Radius 20
	Height 26
	Inventory.PickupMessage ""
	+INVENTORY.AUTOACTIVATE
	States
	{
	Spawn:
		TNT1 A 1
		Loop
	Pickup:
    Use:
	    TNT1 A 0 A_SpawnItem("STBSkullIcon", 0, 55)
		Stop
	}
}

//==============================================================
//
// POSSESSION AND TERMINATOR STUFF
//
//==============================================================

Actor ST4ZD_SpawnSpotTeleport
{
Radius 1
Height 1
+NOBLOCKMAP
-SOLID
-SHOOTABLE
states
{
Spawn:
TNT1 AA 0 Thing_ChangeTID(0, 29999)
TNT1 A -1
stop
}
}

//Just an actor that runs around until the ACS script spawns
//the possession stone / terminator sphere at it's position
//for a random spawn place
Actor RunningSpawnSpot
{
Height 20
Radius 20 //a bit fat so it doesn't spawn the artifact in a stupid place
Speed 30 //sanic speed
MaxStepHeight 128
MaxDropOffHeight 128 //can go wherever it wants
+FLOORCLIP
+DROPOFF
+DONTGIB
-SHOOTABLE
+THRUACTORS
+INVISIBLE
states
{
	Spawn:
		TNT1 A 0 A_JumpIf(waterlevel == 1, "Submerge")
		TNT1 A 0 A_JumpIf(waterlevel == 2, "Escape")
		TNT1 A 0 A_JumpIf(waterlevel == 3, "Escape")
		TNT1 A 0 A_JumpIf(waterlevel == 4, "Escape")
		TROO AAAAAAAAAAAAAA 0 A_Wander //SPEEEEEED
		TROO A 1 A_Wander
		Loop
	Submerge:
		TROO AAA 1 A_ChangeVelocity(0, 0, -400)
		TROO AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 0 A_Wander
		TROO A 1 A_Wander
		Goto Spawn
	Escape:
		TROO AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 0 A_Wander
		TROO A 1 A_Wander
		Goto Spawn
	}
}

Actor IsTerminator : Inventory {Inventory.MaxAmount 1}

Actor PowerTerminator : PowerQuadDamage {Powerup.Duration 0x7FFFFFFD}

Actor TerminatorArtifact : PowerupGiver
{
	Game Doom
	Game Heretic
	Game Hexen
	+COUNTITEM
	+INVENTORY.AUTOACTIVATE
	+INVENTORY.ALWAYSPICKUP
	Inventory.MaxAmount 0
	Powerup.Duration 0x7FFFFFFD
	Powerup.Type Terminator
	Inventory.PickupMessage "Terminator!"
	Inventory.PickupAnnouncerEntry "terminator"
}

ACTOR Terminator : CustomInventory
{
	Game Doom
	Game Heretic
	Game Hexen
	+COUNTITEM
	+INVENTORY.AUTOACTIVATE
	+INVENTORY.ALWAYSPICKUP
	Inventory.MaxAmount 0
	Inventory.PickupMessage "Terminator!"
	Inventory.PickupAnnouncerEntry "terminator"
	States
	{
	Spawn:
		ARNO ABCD 6 Bright
		Loop
	Use: //You are the terminator!
		TNT1 A 0 A_GiveInventory("IsTerminator")
		TNT1 A 0 A_GiveInventory("TerminatorArtifact")
		TNT1 A 0 A_GiveInventory("MegaSphere")
		TNT1 A 0 ACS_NamedExecuteAlways("ST4ZD_IsTerminator", 0)
		Stop
	}
}

Actor HasStone : Inventory {Inventory.MaxAmount 1}

Actor PossessionStone : CustomInventory
{
Inventory.MaxAmount 1
+INVENTORY.AUTOACTIVATE
states
{
	Spawn:
		PPOS ABCDEF 6 Bright
		Loop
	Use: //Constantly strip all weapons and ammo while holding the stone
		TNT1 A 0 A_GiveInventory("HasStone")
		TNT1 A 0 ACS_NamedExecuteAlways("ST4ZD_GotStone", 0)
		Stop
	}
}

ACTOR ST4ZD_StoneIcon
{
Health 100
Radius 1
Height 1
+NOCLIP
-SOLID
-SHOOTABLE
+NOBLOCKMAP
+THRUACTORS
+NOGRAVITY
+INVULNERABLE
States
{
Spawn:
PPOS A 2 BRIGHT
Stop
}
}

ACTOR ST4ZD_StoneIconSpawner : CustomInventory
{
	Game Doom
	Radius 20
	Height 26
	Inventory.PickupMessage ""
	+INVENTORY.AUTOACTIVATE
	States
	{
	Spawn:
		TNT1 A 1
		Loop
	Pickup:
    Use:
	    TNT1 A 0 A_SpawnItem("ST4ZD_StoneIcon", 0, 55)
		Stop
	}
}	

ACTOR ST4ZD_TerminatorIcon
{
Health 100
Radius 1
Height 1
+NOCLIP
-SOLID
-SHOOTABLE
+NOBLOCKMAP
+THRUACTORS
+NOGRAVITY
+INVULNERABLE
States
{
Spawn:
ARNO A 2 BRIGHT
Stop
}
}

ACTOR ST4ZD_TerminatorIconSpawner : CustomInventory
{
	Game Doom
	Radius 20
	Height 26
	Inventory.PickupMessage ""
	+INVENTORY.AUTOACTIVATE
	States
	{
	Spawn:
		TNT1 A 1
		Loop
	Pickup:
    Use:
	    TNT1 A 0 A_SpawnItem("ST4ZD_TerminatorIcon", 0, 55)
		Stop
	}
}			