actor ChillSpikeWep : BaseMM8BDMWep 10100
{
//$Category MM8BDM-Weapons
//$Title Chill Spike
//$Sprite CHILA0
Weapon.AmmoUse 2
Weapon.AmmoGive 28
Weapon.SlotNumber 4
Obituary "$OB_CHILLSPIKE"
Tag "$TAG_CHILLSPIKE"
Inventory.Pickupmessage "$PU_CHILLSPIKE"
weapon.ammotype "ChillSpikeAmmo"
inventory.icon "CHILLI"
States
{
SpawnLoop:
CHIL A -1
loop
Ready:
CHIS D 0 ACS_ExecuteAlways(998,0,203)
CHIS D 1 A_WeaponReady
Goto Ready+1
Deselect:
TNT1 AAAAAAAAAAAAAAAAAAAAAA 0 A_Lower
CHIS D 1 A_Lower
Loop
Select:
TNT1 AAAAAAAAAAAAAAAAAAAAAA 0 A_Raise
CHIS D 1 A_Raise
Loop
Fire:
CHIS D 0 A_JumpIfNoAmmo("NoAmmo")
CHIS D 0 A_PlaySoundEx("weapon/chillshot","Weapon")
CHIS D 0 A_FireCustomMissile("ChillSpikeEX",0,1,8,0)
CHIS EFD 4
CHIS D 15
CHIS D 0 //A_Refire
Goto Ready+1
NoAmmo:
CHIS D 1 ACS_Execute(979,0)
Goto Ready+1
}
}

actor ChillSpikeAmmo : Ammo
{
inventory.amount 1
inventory.maxamount 28
+INVENTORY.IGNORESKILL
}

actor ChillShot
{
PROJECTILE
-NOGRAVITY
Obituary "$OB_CHILLSPIKE"
Radius 12
Height 20
scale 2.5
gravity 1.8
damage (20)
speed 45
damagetype "ChillShot"
States
{
Spawn:
CHIL B 0
CHIL B 0 A_SetPitch(5)
CHIL B 2 ThrustThingZ(0,20,0,1)
CHIL CD 2
SpawnLoop:
CHIL BCD 2
loop
Death:
CHIL B 0 A_JumpIf(z-floorz<=16,"Death2")
CHIL B 0 A_JumpIf(ceilingz-z<=25,"Death3")
// [Russ] Compensation for the object's height.
CHIL B 0 A_SpawnItemEx("WallSpike", 0, 0, -(ceilingz-z < 56)*(56-(ceilingz-z)) - (z-floorz > (ceilingz-z < 56)*(56-(ceilingz-z))+14)*14)
CHIL E 0
stop
XDeath:
TNT1 A 0
CHIL E 0
Stop
Death2:
CHIL B 0 A_SpawnItemEx("ChillSpike", 0, 0, -(z-floorz), 0, 0, 0, 0, SXF_TRANSFERPITCH)
CHIL E 0
stop
Death3:
CHIL B 0 A_SpawnItemEx("CeilingSpike", 0, 0, 0, 0, 0, 0, 0, SXF_TRANSFERPITCH)
CHIL E 0
stop
}
}

const int CHILLRADIUS = 20;

actor ChillSpikeEX
{
Obituary "$OB_CHILLSPIKE2"
DamageType "ChillSpike"
PROJECTILE
-NOGRAVITY
Radius 12
Height 20
Gravity 1.8
Damage (20)
Speed 45
Scale 2.5

States
{
Spawn:
TNT1 A 0
TNT1 A 0 ThrustThingZ(0,10,0,1)
SpawnL:
CHIL BCD 2
loop
		
Death:
CHIL B 0 A_JumpIf(z-floorz<=16,"Death2")
CHIL B 0 A_JumpIf(ceilingz-z<=25,"Death3")
CHIL B 0 A_PlaySoundEx("weapon/chillbreak","Weapon")
// [Russ] Compensation for the object's height.
CHIL B 0 A_SpawnItemEx("WallSpike", 0, 0, -(ceilingz-z < 56)*(56-(ceilingz-z)) - (z-floorz > (ceilingz-z < 56)*(56-(ceilingz-z))+14)*14)
CHIL E 0
stop

		
XDeath:
TNT1 A 0
CHIL E 0
Stop
		
Death2:
CHIL A 0 A_SpawnItemEx("ChillFloorSpike",0,0,0,0,0,0,0,1)
CHIL A 0 A_SpawnItemEx("ChillFloorSpikeSpawner",0,0,0,10,0,0,0,1)
CHIL A 0 A_SpawnItemEx("ChillFloorSpikeSpawner",0,0,0,10,0,0,60,1)
CHIL A 0 A_SpawnItemEx("ChillFloorSpikeSpawner",0,0,0,10,0,0,120,1)
CHIL A 0 A_SpawnItemEx("ChillFloorSpikeSpawner",0,0,0,10,0,0,180,1)
CHIL A 0 A_SpawnItemEx("ChillFloorSpikeSpawner",0,0,0,10,0,0,240,1)
CHIL A 0 A_SpawnItemEx("ChillFloorSpikeSpawner",0,0,0,10,0,0,300,1)
//CHIL A 0 A_SpawnItemEx("ChillFloorSpikeSpawner",0,0,0,10,0,0,90,1)
//CHIL A 0 A_SpawnItemEx("ChillFloorSpikeSpawner",0,0,0,10,0,0,-90,1)
stop

Death3:
CHIL A 0 A_SpawnItemEx("ChillCeilingSpike",0,0,0,0,0,0,0,1)
CHIL A 0 A_SpawnItemEx("ChillCeilingSpikeSpawner",0,0,0,10,0,0,0,1)
CHIL A 0 A_SpawnItemEx("ChillCeilingSpikeSpawner",0,0,0,10,0,0,60,1)
CHIL A 0 A_SpawnItemEx("ChillCeilingSpikeSpawner",0,0,0,10,0,0,120,1)
CHIL A 0 A_SpawnItemEx("ChillCeilingSpikeSpawner",0,0,0,10,0,0,180,1)
CHIL A 0 A_SpawnItemEx("ChillCeilingSpikeSpawner",0,0,0,10,0,0,240,1)
CHIL A 0 A_SpawnItemEx("ChillCeilingSpikeSpawner",0,0,0,10,0,0,300,1)
//CHIL A 0 A_SpawnItemEx("ChillCeilingSpikeSpawner",0,0,0,10,0,0,90,1)
//CHIL A 0 A_SpawnItemEx("ChillCeilingSpikeSpawner",0,0,0,10,0,0,-90,1)
stop
	}
}

actor ChillFloorSpikeSpawner
{
	PROJECTILE
	+FLOORHUGGER
	+THRUACTORS
	+DONTBLAST
	Radius 6
	Height 6
	ReactionTime 6
	States
	{
		Spawn:
		TNT1 A 0
		TNT1 A 2
		SpawnX:
		TNT1 A 2 A_SpawnItemEx("ChillFloorSpike",0,0,0,0,0,0,0,1)
		TNT1 A 0 A_Countdown
		loop
		Death:
		TNT1 A 0
		stop
	}
}

actor ChillCeilingSpikeSpawner
{
	PROJECTILE
	+CEILINGHUGGER
	+THRUACTORS
	+DONTBLAST
	Radius 6
	Height 6
	ReactionTime 6
	States
	{
		Spawn:
		TNT1 A 0
		TNT1 A 2
		SpawnX:
		TNT1 A 2 A_SpawnItemEx("ChillCeilingSpike",0,0,0,0,0,0,0,1)
		TNT1 A 0 A_Countdown
		loop
		Death:
		TNT1 A 0
		stop
	}
}

actor ChillFloorSpike
{
	Obituary "$OB_CHILLSPIKE2"
	DamageType "ChillSpike"
	PROJECTILE
	+FLOORHUGGER
	+THRUACTORS
	+DONTBLAST
	Scale 2.5
	Radius 6
	Height 8
	Damage (3)
	
	States
	{
		Spawn:
		TNT1 A 0
		SpawnLOOP:
		CHIL E 0 A_PlaySound("weapon/chillspike",1,0.45)
		CHIL EE 2
		CHIL E 0 A_ChangeFlag(THRUACTORS,false)
		CHIL FFFFFFFFFFFF 8
		CHIL E 0 A_ChangeFlag(THRUACTORS,true)
		CHIL B 0 A_PlaySoundEx("weapon/chillbreak","Weapon")
		CHIL H 0 A_SpawnItemEx("ChillDebris", random(0,20), 0, 0, random(6,12),random(6,12),random(6,12), 0)
		TNT1 A 15
		stop
	}
}


actor ChillCeilingSpike : ChillFloorSpike
{
	Obituary "$OB_CHILLSPIKE2"
	DamageType "ChillSpike"
	-FLOORHUGGER
	+CEILINGHUGGER
	Radius 8
	Height 12
	Damage (12)
	States
	{
		Spawn:
		TNT1 A 0
		SpawnLOOP:
		CHIL I 0 A_PlaySound("weapon/chillspike",1,0.35)
		CHIL II 2
		CHIL I 0 A_ChangeFlag(THRUACTORS,false)
		CHIL JJJJJJJJJJJJJJJ 4
		CHIL J 0 A_ChangeFlag(CEILINGHUGGER,false)
		CHIL J 0 A_ChangeFlag(NOGRAVITY,false)
		CHIL J 1
		wait
		
		Death:
		CHIL B 0 A_PlaySoundEx("weapon/chillbreak","Weapon")
		CHIL H 0 A_SpawnItemEx("ChillDebris", random(0,20), 0, 0, random(6,12),random(6,12),random(6,12), 0)

		stop
	}
}

actor ChillSpike
{
PROJECTILE
+DONTBLAST
Obituary "$OB_CHILLSPIKE2"
Scale 2.5
damagetype "ChillSpike"
Speed 0
Radius 12
Height 20
Damage (27)
reactiontime 140
States
{
Spawn:
TNT1 A 0
TNT1 A 0 A_SetAngle(random(1, 360))
TNT1 A 0 A_PlaySoundEx("weapon/chillspike","Weapon")
CHIL E 0 A_SpawnItemEx("ChillSpikeFloorFX1", CHILLRADIUS, 0, 0, 0, 0, 0, 0)
CHIL E 0 A_SpawnItemEx("ChillSpikeFloorFX1", CHILLRADIUS, 0, 0, 0, 0, 0, 120)
CHIL E 0 A_SpawnItemEx("ChillSpikeFloorFX1", CHILLRADIUS, 0, 0, 0, 0, 0, 240)
CHIL E 2
Spawn2:
CHIL F 0 A_SpawnItemEx("ChillSpikeFloorFX2", CHILLRADIUS, 0, 0, 0, 0, 0, 0)
CHIL F 0 A_SpawnItemEx("ChillSpikeFloorFX2", CHILLRADIUS, 0, 0, 0, 0, 0, 120)
CHIL F 0 A_SpawnItemEx("ChillSpikeFloorFX2", CHILLRADIUS, 0, 0, 0, 0, 0, 240)
CHIL F 1 A_CountDown
loop
XDeath:
CHIL B 0
stop
Death:
CHIL B 0 A_PlaySoundEx("weapon/chillbreak","Weapon")
CHIL H 0 A_SpawnItemEx("ChillDebris", 0, 0, 0, random(6,12),random(6,12),random(6,12), 0)
CHIL H 0 A_SpawnItemEx("ChillDebris", CHILLRADIUS, 0, 0, random(6,12),random(6,12),random(6,12), 0)
CHIL H 0 A_SpawnItemEx("ChillDebris", CHILLRADIUS, 0, 0, random(6,12),random(6,12),random(6,12), 120)
CHIL H 0 A_SpawnItemEx("ChillDebris", CHILLRADIUS, 0, 0, random(6,12),random(6,12),random(6,12), 240)
TNT1 A 15
stop
}
}

actor ChillSpikeFloorFX1 : BasicGraphicEffect
{
    renderstyle "Normal"
	Scale 2.5
	States
	{
	Spawn:
		CHIL E 3
		stop
	}
}

actor ChillSpikeFloorFX2 : ChillSpikeFloorFX1
{
	States
	{
	Spawn:
		CHIL F 2
		stop
	}
}

actor WallSpike : ChillSpike
{
radius 10
Height 50
-FLOORHUGGER
var int user_angle;
States
{
Spawn:
TNT1 A 0
TNT1 A 1
TNT1 A 0 A_GiveInventory("Once", 1)
TNT1 A 0 A_SetUserVar(user_angle, random(1, 120))
TNT1 A 0 A_PlaySoundEx("weapon/chillspike","Weapon")
CHIL F 0 A_SpawnItemEx("ChillSpikeWallFX1", 3, cos(user_angle)*CHILLRADIUS, sin(user_angle)*CHILLRADIUS, 0, 0, 0, 0)
CHIL F 0 A_SpawnItemEx("ChillSpikeWallFX1", 3, cos(user_angle+120)*CHILLRADIUS, sin(user_angle+120)*CHILLRADIUS, 0, 0, 0, 0)
CHIL F 0 A_SpawnItemEx("ChillSpikeWallFX1", 3, cos(user_angle+240)*CHILLRADIUS, sin(user_angle+240)*CHILLRADIUS, 0, 0, 0, 0)
CHIL G 2
Spawn2:
CHIL F 0 A_SpawnItemEx("ChillSpikeWallFX2", 3, cos(user_angle)*CHILLRADIUS, sin(user_angle)*CHILLRADIUS, 0, 0, 0, 0)
CHIL F 0 A_SpawnItemEx("ChillSpikeWallFX2", 3, cos(user_angle+120)*CHILLRADIUS, sin(user_angle+120)*CHILLRADIUS, 0, 0, 0, 0)
CHIL F 0 A_SpawnItemEx("ChillSpikeWallFX2", 3, cos(user_angle+240)*CHILLRADIUS, sin(user_angle+240)*CHILLRADIUS, 0, 0, 0, 0)
CHIL H 1 A_CountDown
loop
Death:
CHIL B 0 A_JumpIfInventory("Once", 1, "DeathReal")
CHIL B 1 A_JumpIf(true, "DeathVanish")
wait
DeathReal:
CHIL B 0 A_PlaySoundEx("weapon/chillbreak","Weapon")
CHIL F 0 A_SpawnItemEx("ChillDebris", 0, 0, 28, -random(6,12), 0, random(2,6), random(-6, 6))
CHIL F 0 A_SpawnItemEx("ChillDebris", 0, cos(user_angle)*CHILLRADIUS, sin(user_angle)*CHILLRADIUS, -random(6,12), 0, random(4,8), random(-6, 6))
CHIL F 0 A_SpawnItemEx("ChillDebris", 0, cos(user_angle+120)*CHILLRADIUS, sin(user_angle+120)*CHILLRADIUS, -random(6,12), 0, random(4,8), random(-6, 6))
CHIL F 0 A_SpawnItemEx("ChillDebris", 0, cos(user_angle+240)*CHILLRADIUS, sin(user_angle+240)*CHILLRADIUS, -random(6,12), 0, random(4,8), random(-6, 6))
DeathVanish:
TNT1 A 0 A_ChangeFlag(NOINTERACTION, true)
TNT1 A 15
stop
}
}

actor ChillSpikeWallFX1 : ChillSpikeFloorFX1
{
	States
	{
	Spawn:
		CHIL G 3
		stop
	}
}

actor ChillSpikeWallFX2 : ChillSpikeFloorFX1
{
	States
	{
	Spawn:
		CHIL H 2
		stop
	}
}

actor CeilingSpike : ChillSpike
{
-FLOORHUGGER
+CEILINGHUGGER
States
{
Spawn:
TNT1 A 0
TNT1 A 0 A_SetAngle(random(1, 360))
TNT1 A 0 A_PlaySoundEx("weapon/chillspike","Weapon")
CHIL E 0 A_SpawnItemEx("ChillSpikeCeilingFX1", CHILLRADIUS, 0, 0, 0, 0, 0, 0)
CHIL E 0 A_SpawnItemEx("ChillSpikeCeilingFX1", CHILLRADIUS, 0, 0, 0, 0, 0, 120)
CHIL E 0 A_SpawnItemEx("ChillSpikeCeilingFX1", CHILLRADIUS, 0, 0, 0, 0, 0, 240)
CHIL I 2
Spawn2:
CHIL F 0 A_SpawnItemEx("ChillSpikeCeilingFX2", CHILLRADIUS, 0, 0, 0, 0, 0, 0)
CHIL F 0 A_SpawnItemEx("ChillSpikeCeilingFX2", CHILLRADIUS, 0, 0, 0, 0, 0, 120)
CHIL F 0 A_SpawnItemEx("ChillSpikeCeilingFX2", CHILLRADIUS, 0, 0, 0, 0, 0, 240)
CHIL J 1 A_CountDown
loop
}
}

actor ChillSpikeCeilingFX1 : ChillSpikeFloorFX1
{
	States
	{
	Spawn:
		CHIL I 3
		stop
	}
}

actor ChillSpikeCeilingFX2 : ChillSpikeFloorFX1
{
	States
	{
	Spawn:
		CHIL J 2
		stop
	}
}

actor ChillDebris
{
+CLIENTSIDEONLY
+DOOMBOUNCE
+FORCEXYBILLBOARD
-SOLID
scale 2.5
height 1
radius 1
States
{
Spawn:
CHID A 0
TNT1 A 1 A_Jump(256, "SpawnA", "SpawnB")
wait
SpawnLoop:
"----" A 2 A_JumpIf(momz==0, "Death")
wait
SpawnA:
CHID A 0
Goto SpawnLoop
SpawnB:
CHID B 0
Goto SpawnLoop
Death:
TNT1 A 0
stop
}
}

// Damage effects

actor ChillFreeze : CustomInventory
{
	+INVENTORY.AUTOACTIVATE
	States
	{
	Use:
		TNT1 A 0 A_JumpIfInventory("ChillFreezeTimer", 1, "End")
		TNT1 A 0 A_PlaySoundEx("weapon/chillspike","Weapon")
		TNT1 A 0 A_ChangeVelocity(0, 0, momz, CVF_REPLACE)
		TNT1 A 0 A_GiveInventory("ChillFreezeVision", 1)
		TNT1 A 0 A_SpawnItemEx("ChillFreezeWatcher")
	End:
		TNT1 A 0 A_GiveInventory("ChillFreezeTimer", 1)
		TNT1 A 0
		stop
	}
}

actor ChillFreezeTimer : Powerup
{
	powerup.duration 45
}

actor ChillFreezeVision : PowerSpeed
{
	speed 0
	powerup.color "98 F8 F0"
}

actor ChillFreezeWatcher
{
	+MISSILE
	+NOINTERACTION
	Scale 2.5
	States
	{
	Spawn:
		CHIL K 0 A_Warp(AAPTR_TARGET, 0, 0, 0, 0, WARPF_INTERPOLATE)
		CHIL K 1 A_GiveToTarget("ChillGravity", 1)
		CHIL K 0 A_JumpIfInTargetInventory("ChillFreezeTimer", 1, "Spawn")
		CHIL K 1 A_JumpIf(true, "Death")
		wait
	Death:
		TNT1 A 0 A_GiveToTarget("ChillUnfreeze", 1)
		stop
	}
}

actor ChillGravity : CustomInventory
{
States
{
Pickup:
TNT1 A 0
TNT1 A 0 A_JumpIf(z-floorz<5, "End")
TNT1 A 0 ThrustThingZ(0, 20, 1, 1)
stop
End:
TNT1 A 0
stop
}
}

actor ChillUnfreeze : ChillFreeze
{
	States
	{
	Use:
		CHIL B 0 A_PlaySoundEx("weapon/chillbreak","Weapon")
		TNT1 A 0 A_TakeInventory("ChillFreezeVision", 1)
		CHIL H 0 A_SpawnItemEx("ChillDebris", CHILLRADIUS, 0, 0, random(6,12),random(6,12),random(6,12), 0)
		CHIL H 0 A_SpawnItemEx("ChillDebris", CHILLRADIUS, 0, 0, random(6,12),random(6,12),random(6,12), 120)
		CHIL H 0 A_SpawnItemEx("ChillDebris", CHILLRADIUS, 0, 0, random(6,12),random(6,12),random(6,12), 240)
		stop
	}
}
