/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Teleporter nodes
 *
 * The Utility-built "Portal" teleporter node, when built two of, creates
 * a teleporter link. Mechs cannot use this, as can't harvesters. (on the
 * interest of no quick cashing) They take a beating to take down, but have the
 * weakness that enemies can use them as well. The team distinguishing exists
 * only to serve as identification and limits.
 */

actor TeleporterNodeBlue {
	+SOLID
	+SHOOTABLE
	+BUMPSPECIAL
	+NOBLOOD
	+ISMONSTER
	+NOICEDEATH
	
	radius 16
	height 128
	health 3000
	painchance 255
	mass 0x7FFFFFF
	damagefactor "Disarm", 0.0
	damagefactor "Fist", 0.5
	damagefactor "Mechstomp", 0.0
	damagefactor "Explosion", 1.5
	damagefactor "MechExplosion", 2.5
	damagefactor "Fire", 0.6
	damagefactor "Chemical", 0.6
	Damagefactor "Plasma", 1.10
	DamageFactor "Ice", 0.1

	states {
	Spawn:
		TNT1 A 0
		TNT1 A 0 ACS_ExecuteAlways (SC_TELENODE_TIDREQUEST, 0, TEAM_BLUE)
		TNT1 A 8 A_CheckSight ("CantSeeShit")
		TNT1 A -1
		stop
	CantSeeShit:
		TNT1 A 0 A_GiveInventory ("TeleporterNodeNotInSight", 1)
		TNT1 A -1
		stop
	Inactive:
		TNT1 A 0 A_JumpIf (waterlevel >= 2, "Drown")
		TNT1 A 0 A_UnsetSolid
		TNT1 A 0 A_TakeInventory ("IsActive", 1)
		TNT1 A 35 A_CheckTerrain
		wait
	Active:
		TNT1 A 0 A_GiveInventory ("IsActive", 1)
		TNT1 A 0 A_SetSolid
	Idle:
		TNT1 A 0 A_JumpIf (waterlevel >= 2, "Drown")
		TNT1 A 0 A_JumpIfHealthLower (1500, "Damaged")
		TNT1 A 35 A_CheckTerrain
		loop
	Damaged:
		TNT1 A 0 A_JumpIf (waterlevel >= 2, "Drown")
		TNT1 AA 17 A_SpawnItemEx ("TeleporterNodeSpark", 0, 0, random(16,64), 0, 0, 0, 0, 0, (health / 7) + 30)
		loop
	Pain:
		TNT1 A 0 ACS_ExecuteAlways (930, 0, BUILDING_PORTAL, TEAM_BLUE)
		TNT1 A 0 A_JumpIfInventory ("IsActive", 1, "Idle")
		goto Inactive+2
	Death:
		TNT1 A 1
		TNT1 A 0 A_PlaySound ("weapons/rocklx")
		TNT1 A 0 A_SpawnItemEx ("ExplosionMain")
		TNT1 A 0 ACS_ExecuteAlways (345, 0, 21, tid)
		TNT1 A 0 ACS_ExecuteAlways (930, 0, BUILDING_PORTAL, TEAM_BLUE)
		TNT1 A 10
		stop
	Disapproved:
		TNT1 A 20 A_PlaySound ("misc/nope")
		stop
	Death.Deconstruction:
		TNT1 A 0 A_NoBlocking
		TNT1 A 0 ACS_ExecuteAlways (345, 0, 21, tid)
		TNT1 A 0 ACS_ExecuteAlways (930, 0, BUILDING_PORTAL, TEAM_BLUE)
		TNT1 A 10 A_PlaySound ("utility/deconstruct")
		stop
	Drown:
		TNT1 A 35 A_PlaySound ("c4/disarm")
		TNT1 A 0 A_Die
		goto Death
	}
}

// Red version
actor TeleporterNodeRed : TeleporterNodeBlue {
	states {
	Spawn:
		TNT1 A 0
		TNT1 A 0 ACS_ExecuteAlways (SC_TELENODE_TIDREQUEST, 0, TEAM_RED)
		TNT1 A 8 A_CheckSight ("CantSeeShit")
		TNT1 A -1
		stop
	Pain:
		TNT1 A 0 ACS_ExecuteAlways (930, 0, BUILDING_PORTAL, TEAM_RED)
		TNT1 A 0 A_JumpIfInventory ("IsActive", 1, "Active")
		goto Inactive+2
	Death:
		TNT1 A 1
		TNT1 A 0 A_PlaySound ("weapons/rocklx")
		TNT1 A 0 A_SpawnItemEx ("ExplosionMain")
		TNT1 A 0 ACS_ExecuteAlways (345, 0, 21, tid)
		TNT1 A 0 ACS_ExecuteAlways (930, 0, BUILDING_PORTAL, TEAM_RED)
		TNT1 A 10
		stop
	}
}

// This actor is used to check whether the portal
// fits in the space it's wanted to be spawned at.
actor TeleporterNodeCheck {
	+SOLID
	radius 80
	height 128
	states {
	Spawn:
		TNT1 A 5
		stop
	}
}

// stands.. the thing needs some structure, doesn't it?
actor TeleporterNodeStand {
	-SOLID // [Cyberkill] Why is this solid? Players always get stuck in it after teleporting!
	radius 12
	height 44
	gravity 10000
	states {
	Spawn:
		DGIZ A 0
		DGIZ A 8 A_CheckSight ("CantSeeShit")
		DGIZ A 0 A_JumpIf (waterlevel >= 1, "CantSeeShit")
		DGIZ A -1
		stop
	CantSeeShit:
		DGIZ A 0
		stop
	Disapproved:
		"----" A 0 A_NoBlocking
		"----" A 2 A_SetTranslucent (1.0, 1)
		"----" A 2 A_FadeOut 
		wait
	}
}

// Decorative spheres that spawn on top of the stands
actor TeleporterNodeSphereBlue {
	+NOINTERACTION +NOGRAVITY
	+FORCEXYBILLBOARD
	renderstyle add
	alpha 0.0
	scale 0.5
	states {
	Spawn:
		TNT1 A -1
		stop
	Init.Active:
		GIZB CDABCD 3 bright A_FadeIn (0.1)
		goto Active
	Init.Inactive:
		GIZB CCDD 3 A_FadeIn (0.1)
		goto Inactive
	Active:
		GIZB A 0 A_SetTranslucent (0.6)
		GIZB ABCD 3 bright
		goto Active+1
	Inactive:
		GIZB A 0 A_SetTranslucent (0.4)
		GIZB ABCD 6
		goto Inactive+1
	}
}

actor TeleporterNodeSphereRed : TeleporterNodeSphereBlue {
	states {
	Init.Active:
		GIZR CDABCD 3 bright A_FadeIn (0.1)
		goto Active
	Init.Inactive:
		GIZR CCDD 3 A_FadeIn (0.1)
		goto Inactive
	Active:
		GIZR A 0 A_SetTranslucent (0.6)
		GIZR ABCD 3 bright
		goto Active+1
	Inactive:
		GIZR A 0 A_SetTranslucent (0.4)
		GIZR ABCD 6
		goto Inactive+1
	}
}

// Effect cluster, designates active portal
actor TeleporterNodeFX {
	gravity 10000
	translation "144:159=226:242"
	states {
	Spawn:
	Active:
		TNT1 A 5
		TNT1 A 35 A_SpawnItemEx ("TeleporterNodeTelefogCluster", 0,0,0,0,0,0,0,SXF_TRANSFERTRANSLATION)
		wait
	Init.Inactive:
	Inactive:
		TNT1 A -1
		stop
	}
}

actor TeleporterNodeFXBlue : TeleporterNodeFX {
	translation "144:159=193:207"
}

actor TeleporterNodeTelefogCluster {
	+NOINTERACTION
	+CLIENTSIDEONLY
	states {
	Spawn:
		TNT1 A 0
		TNT1 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 1 A_SpawnItemEx ("TeleporterNodeTelefog",
			32,0,random(-8,8), 0,0,random(2,6), random(0,360), SXF_TRANSFERTRANSLATION)
		stop
	}
}

actor TeleporterNodeTelefog {
	+NOINTERACTION
	+CLIENTSIDEONLY
	renderstyle add
	alpha 0.75
	states {
	Spawn:
		TFOG ABCDEFGHIJ 3 bright A_FadeOut (0.05)
		stop
	}
}

// Effect sparks, designates damaged portals.
actor TeleporterNodeSpark {+NOCLIP
	states {
	Spawn:
		TNT1 A 0
		TNT1 A 0 A_PlaySound ("world/spark")
		TNT1 AAAAAAAAAAA 0 A_CustomMissile ("TeleporterNodeSparkFX", 0, 0, random(-180,180), 2, random (8, 32))
		stop
	}
}

actor TeleporterNodeSparkFX {
	PROJECTILE
	+CLIENTSIDEONLY
	+FORCEXYBILLBOARD
	+NOCLIP
	-NOGRAVITY
	radius 8
	height 8
	speed 4
	renderstyle add
	alpha 0.75
	scale 0.05
	states {
	Spawn:
		TNT1 A 0
		TNT1 A 0 ThrustThingZ (0, random(15,40), 0, 0)
		TNT1 A 0 A_Jump (256, "Spawn1", "Spawn2", "Spawn3", "Spawn4", "Spawn5", "Spawn6")
		goto Spawn1
	Spawn1:
		SPKY A 15
		goto Death
	Spawn2:
		SPKY B 12 bright
		goto Death
	Spawn3:
		SPKY C 16 bright
		goto Death
	Spawn4:
		SPKY D 14 bright
		goto Death
	Spawn5:
		SPKY E 13 bright
		goto Death
	Spawn6:
		SPKY F 11 bright
		goto Death
	Death:
		"----" AAAAAAAA 1 A_FadeOut (0.05)
		stop
	}
}

Actor teleporterNode_SanityCheck
{
	States
	{
		Spawn:
			TNT1 A 0
			TNT1 A 0 A_CheckSight("niceTryBitch")
			TNT1 A -1
			Stop
		
		niceTryBitch:
			TNT1 A 0
			TNT1 A 0 A_GiveInventory("TeleporterNodeNotInSight", 1)
			TNT1 A -1
			Stop
	}
}

// Dummy item to mark the portal as invalid with
actor TeleporterNodeNotInSight : Inventory {}
actor IsActive : Inventory {}
