// Nu-NU-Bullet
/*
class LonghornChainBullet : Actor
{
	const TRAILCOUNT = 3;
	const TOTALHITCOUNT = 8;
	int hitcount;
	Actor lasthitenemy, secondlasthitenemy;
	
	Default
	{
		Radius 11;
		Height 8;
		Speed 60;
		DamageFunction (4);
		DamageType "LightningBlue";
		Projectile;
		ProjectileKickback 800;
		Renderstyle "Add";
		Obituary "%o was traced by %k's magic Longhorn shot.";
		Scale 2.5;
		Decal "LonghornStamp";
		BounceFactor 1.0;
		WallBounceFactor 1.0;
		//+BOUNCEONWALLS
		//+BOUNCEONFLOORS
		//+BOUNCEONCEILINGS
		//+USEBOUNCESTATE
		//+NOGRAVITY
		//+EXTREMEDEATH
		//+RIPPER
		+FORCERADIUSDMG
		+MTHRUSPECIES
	}

	// Function credits to kodi, borrowed silently from ZDoom Discord.
	vector3 BounceNormal(vector3 MoveVector, vector3 SurfNormal)
    {
        vector3 ret = MoveVector-2*SurfNormal*(MoveVector dot SurfNormal);
        return ret;
    }

	override bool CanCollideWith (Actor other, bool passive)
	{
		// It doesn't collide with anything.
		// It warps to the next point and
		// acts according to what that point is.
		return false;
	}
	
	
	
}
*/

//Nu-Bullet
class LonghornChainBullet : Actor
{
	const TRAILCOUNT = 3;
	const TOTALHITCOUNT = 8;
	int timefired;
	int hitcount;
	int faceanglepitch;
	bool diedonenemy;
	bool diedonwall;
	bool enterzap;
	Actor lasthitenemy, secondlasthitenemy;
	
	Default
	{
		Radius 11;
		Height 8;
		Speed 60;
		DamageFunction (4);
		DamageType "LightningBlue";
		Projectile;
		ProjectileKickback 800;
		Renderstyle "Add";
		Obituary "%o was traced by %k's magic Longhorn shot.";
		Scale 2.5;
		Decal "LonghornStamp";
		BounceFactor 1.0;
		WallBounceFactor 1.0;
		+BOUNCEONWALLS
		+BOUNCEONFLOORS
		+BOUNCEONCEILINGS
		+USEBOUNCESTATE
		+NOGRAVITY
		+FORCERADIUSDMG
		//+EXTREMEDEATH
		//+RIPPER
		+MTHRUSPECIES
	}
	
	override void Tick()
	{	
		let last_pos = pos;
		super.tick();
		if(!InStateSequence(CurState, ResolveState("ZapLoop")) && !globalfreeze)
		{
			// Faking FastProjectile's trail.
			let diff = pos - last_pos;
			diff /= TRAILCOUNT;
		
			for(int i = 0; i < TRAILCOUNT; i++) {
				let spawn_pos = last_pos + i * diff;
				Actor trail = Actor.Spawn("LonghornChainTrail", spawn_pos);
				trail.angle = angle;
				trail.pitch = pitch;
			
				if(trail != NULL) {
					trail.master = master;
					trail.target = target;
					trail.tracer = tracer;
				}
			}
	
			// Lift the angle and pitch restrictions on
			// facing a new target by 5 degrees every second.
			// Prevents stupid orbiting.
			if(tracer && !(level.time-timefired % 5) && faceanglepitch > 0 && faceanglepitch < 180)
			{
				faceanglepitch++;
			}
			if(faceanglepitch >= 180)
			{
				faceanglepitch = 0;
			}
		}
	}
	
	override int SpecialMissileHit(Actor victim)
	{
		// Always apply direct damage to anything shootable.
		victim.DamageMobj(self, target, GetMissileDamage(0, 1), damagetype);
	
		if(InStateSequence(CurState, ResolveState("ZapLoop")))
		{
			// The zap sequence has its own hit behavior.
			return 1;
		}
		
		// Living monsters take special explosive damage
		// and decrease the hit counter.
		if(victim.bIsMonster && victim.health > 0)
		{
			// Increase the hit count.
			hitcount++;
			// If we haven't reached our hit count, the bullet keeps going.
			if(hitcount < TOTALHITCOUNT)
			{
				// Spawn effects here.
				A_Explode(35*random(1,3),56,0);
				A_PlaySound("Longhorn/LightningHit",5);
				A_SpawnItemEx("LonghornChainHit",0,0,0,0,0,0,0,SXF_CLIENTSIDE,0);
				if(!tracer)
				{
					tracer = victim;
				}
				hitcount++;
				// Enter the zap state.
				enterzap = TRUE;
				return 1;
			}
			// If we have, die on this actor.
			else
			{
				bBounceOnWalls = FALSE;
				bBounceOnFloors = FALSE;
				bBounceOnCeilings = FALSE;
				diedonenemy = TRUE;
				return 1;
			}
		}
		return 1;
	}
	
	override bool CanCollideWith (Actor other, bool passive)
	{
		// Collide with shootable objects.
		// Special missile hit handles the hit behavior.
		if(!passive && other.bShootable && !other.bFriendly)
		{
			return true;
		}
		// Pass harmlessly through every other actor.
		// It's a magic bullet.
		return false;
	}
	
	void SetClosestAsTracer(bool firstfire = FALSE)
	{
		Actor ClosestEnemy;
		Array<Actor> ValidEnemies;
		int lowestdistance = 0x7FFFFFFF, i;
		let gvars = GC_GlobalVariables.Get();
		
		// Gather together a list of monsters that are
		// valid for striking, for counting purposes.
		for(i = 0; i < gvars.MonsterList.Size(); i++)
		{
			// Add an additional sight check on the first trace
			// for the roam loop.
			if(firstfire)
			{
				if(CheckSight(gvars.MonsterList[i]) &&
					target.CheckSight(gvars.MonsterList[i]))
				{
					ValidEnemies.Push(gvars.MonsterList[i]);
				}
			}
			// First off, can the enemy be seen?
			else
			{
				if(CheckSight(gvars.MonsterList[i]))
				{
					ValidEnemies.Push(gvars.MonsterList[i]);
				}
			}
		}
		
		
		if(ValidEnemies.Size() <= 1)
		{
			// Only one valid enemy or less?
			// Set our tracer to it. The
			// projectile itself will clear
			// out dead ones automatically.
			secondlasthitenemy = null;
			lasthitenemy = null;
			if(ValidEnemies.Size())
			{
				tracer = ValidEnemies[0];
			}
			else
			{
				tracer = null;
			}
			return;
		}
		else if(ValidEnemies.Size() == 2)
		{
			// Only two valid enemies?
			// Set up the projectile to
			// jump between them.
			secondlasthitenemy = null;
			lasthitenemy = tracer;
		}
		else
		{
			// In any other case, use
			// two pointers to keep the
			// projectile traveling in
			// a chain.
			secondlasthitenemy = lasthitenemy;
			lasthitenemy = tracer;
		}
		
		// Now find the enemy with the shortest distance.
		for(i = 0; i < ValidEnemies.Size(); i++)
		{
			// The last hit enemy or current tracer is not valid.
			if(ValidEnemies[i] == lasthitenemy ||
				ValidEnemies[i] == secondlasthitenemy)
			{
				continue;
			}
		
			// Next, see if its distance is shorter
			// than to the previous monster.
			if(Distance3D(ValidEnemies[i]) < lowestdistance)
			{
				// Lowest distance wins.
				lowestdistance = Distance3D(ValidEnemies[i]);
				ClosestEnemy = ValidEnemies[i];
			}
		}
		// If there is a tracer to be had, set it.
		if(ClosestEnemy)
		{
			tracer = ClosestEnemy;
		}
		ValidEnemies.Clear();
		return;
	}
	
	// A function that spawns a trail along the length of
	// an instant-traveling projectile. Special thanks to
	// Kom for the example of calculating the next point.
	void ZapTrail(Class<Actor> ZapTrailActor = "LonghornChainTrail")
	{
		double TrailRadius = GetDefaultByType(ZapTrailActor).Radius;
		double totaldistance = Distance3D(tracer);
		double nextdistance = TrailRadius;
		vector3 StartPos = Pos;
		vector3 GoalPos = tracer.Pos + (0, 0, tracer.height/2);
		vector3 Normal = (GoalPos - StartPos) / totaldistance;
		vector3 NextPoint;
		Actor TrailActorRef;
		
		if(totaldistance < TrailRadius*2.0)
		{
			NextPoint = StartPos + Normal * (totaldistance / 2);
			TrailActorRef = Spawn(ZapTrailActor, NextPoint);
			TrailActorRef.Angle = Angle;
			TrailActorRef.Pitch = Pitch;
			return;
		}
		
		while(nextdistance < totaldistance)
		{
			NextPoint = StartPos + Normal * nextdistance;
			TrailActorRef = Spawn(ZapTrailActor, NextPoint);
			TrailActorRef.Angle = Angle;
			TrailActorRef.Pitch = Pitch;
			nextdistance += TrailRadius*2.0;
		}
		return;
	}
	
	// Note from Keks:
	//[10:36 AM] KeksDose:
	//if u is a unit length vector, R*v = v - 2v dot u * u is the reflection of v in that direction
	//if it isn't unit length, v - 2v dot u / (u dot u) * u it is
	//uuuuvvuvvuvuvuvuvuvuuvvvu

	// R = v - 2(v dot u)u

	//[Friday 7:51 PM] KeksDose:
	//secplane has a normal field
	//lines is a bit different
	//floorplane and ceilingplane are secplanes in cursector
	//for a line, take
	//(-delta.y, delta.x, 0)
	//it's not unit length, so watch out

	
	States
	{
	Spawn:
		TRAC B 0 NoDelay {
			// Initialize some things.
			timefired = level.time;
			hitcount = 0;
			faceanglepitch = 30;
			lasthitenemy = null;
			secondlasthitenemy = null;
			diedonenemy = FALSE;
			diedonwall = FALSE;
			A_PlaySound("Augur/Fly",5,0.6,1);
			}
			
		TRAC B 1 {
			FLineTraceData traceshot;
			// When fired, test for a target under crosshairs.
			// Immediately enter zap if it exists.
			if(target.LineTrace(target.angle, 4096, target.pitch, 0, (target.height/2)+PlayerPawn(target).AttackZOffset, data:traceshot))
			{
				if(traceshot.HitType == traceshot.TRACE_HitActor &&
					traceshot.HitActor.bIsMonster)
				{
					// Set the hit actor as tracer and start the zap sequence.
					tracer = traceshot.HitActor;
					return Resolvestate("ZapLoop");
				}
			}
			// If not, start in Roam and start heading for the closest target.
			SetClosestAsTracer(TRUE);
			return ResolveState("RoamLoop");
		}
	ZapLoop:
		// The "jump between enemies" chain lightning state.
		TRAC B 1 {
			A_ChangeVelocity(0,0,0);
		
			if(hitcount >= TOTALHITCOUNT)
			{
				bBounceOnWalls = FALSE;
				bBounceOnFloors = FALSE;
				bBounceOnCeilings = FALSE;
				return ResolveState("DiedOnEnemy");
			}
			
			if(tracer && tracer.health > 0)
			{
				A_FaceTracer(max_pitch:0, flags:FAF_MIDDLE);
				ZapTrail();
				Warp(tracer, zofs:tracer.height/2);
				A_Explode(30*random(1,3),56,0);
				A_PlaySound("Longhorn/LightningHit",5);
				A_SpawnItemEx("LonghornChainHit",0,0,0,0,0,0,0,SXF_CLIENTSIDE,0);
				hitcount++;
				SetClosestAsTracer();
				return ResolveState(null);
			}
			else
			{
				faceanglepitch = 30;
				tracer = null;
				return ResolveState("RoamLoop");
			}
		}
	Loop;
	RoamLoop:
		// Roam around looking for something to hit.
		TRAC B 1 Bright {
			// Clear these if they still exist.
			lasthitenemy = null;
			secondlasthitenemy = null;
			
			// Death jumps.
			if(diedonwall)
			{
				return ResolveState("DiedOnWall");
			}
			if(diedonenemy)
			{
				return ResolveState("DiedOnEnemy");
			}
			
			// Zap state jump.
			if(enterzap)
			{
				enterzap = FALSE;
				return ResolveState("ZapLoop");
			}
			
			if(tracer && (tracer.health < 0))
			{
				tracer = null;
			}
			
			if(tracer)
			{
				A_FaceTracer(faceanglepitch, faceanglepitch, z_ofs:tracer.height/2);
				A_ChangeVelocity(Speed, 0, -sin(pitch)*Speed, CVF_RELATIVE|CVF_REPLACE);
			}
			else
			{
				A_FaceMovementDirection(0, 0, 0, FMDF_NOANGLE); // Only pitch is stupid.
				A_ChangeVelocity(Speed, 0, -sin(pitch)*Speed, CVF_RELATIVE|CVF_REPLACE);
				SetClosestAsTracer();
			}
			return ResolveState(null);
		}
		Loop;
	Bounce:
		TRAC B 1 {
			hitcount++;
			A_PlaySound("Longhorn/LightningHit",5);
			if(hitcount >= TOTALHITCOUNT)
			{
				bBounceOnWalls = FALSE;
				bBounceOnFloors = FALSE;
				bBounceOnCeilings = FALSE;
				diedonwall = TRUE;
			}
		}
		Goto RoamLoop;
	DiedOnEnemy:
		TNT1 A 0 {
			A_Explode((90),56,0);

			A_PlaySound("Longhorn/LightningHit",5);
			A_PlaySound("Longhorn/LightningHit",6);
			A_SpawnItemEx("LonghornChainImpact",0,0,0,0,0,0,0,SXF_CLIENTSIDE,0);
		}
		Stop;
	DiedOnWall:
		TNT1 A 0 {
			A_Explode((90),56,0);
			A_PlaySound("Longhorn/LightningHit",5);
			A_PlaySound("Longhorn/LightningHit",6);
			A_SpawnItemEx("LonghornChainImpact",0,0,0,0,0,0,0,SXF_CLIENTSIDE,0);
			A_SpawnItemEx("ChainHuegPuff_Spark1", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE, 0);
			A_SpawnItemEx("ChainHuegPuff_Spark2", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE, 0);
			for(int cunt = 0; cunt < 6; cunt++)
			{
				A_SpawnItemEx("ChainHuegPuff_Smoke", 0, 0, 0, frandom(0.15,0.25), 0, frandom(-0.1,0.45), 0, SXF_CLIENTSIDE, 0);
			}
		}
		Stop;
	Death: // Should never be reached.
		TNT1 A 1;
		Stop;
	}
}

//Trail
class LonghornChainTrail : Actor
{
	Default
	{
		Radius 8;
		+NOINTERACTION
		Renderstyle "Add";
		Scale 0.3;
	}
	
	States
	{
	Spawn:
		TNT1 A 0 NoDelay {
			if(!GetCvar("GC_ToasterMode")) {
			for(int fuck = 0; fuck < 5; fuck++)
			{
				A_SpawnItemEx("LonghornChainSpark",
					frandom(10.0,-10.0),frandom(1.0,-1.0),frandom(1.0,-1.0),
					frandom(1.0,-1.0),0,frandom(1.0,-1.0),frandom(0.0,360.0),
					SXF_CLIENTSIDE,128);
			}
			}
			Return A_Jump(256,1,4,7);
		}
	Looplet:
		LNL1 AAABBBCCC 1 Bright A_FadeOut(0.05);
		Loop;
	}
}

class LonghornChainSpark : LonghornChainTrail
{
	Default
	{
		Scale 0.2;
	}
	
	States
	{
	Spawn:
		TNT1 A 0 NoDelay { A_SetScale(Scale.X * random(1,-1), Scale.Y * random(1,-1)); }
		LNL3 AAAABBBBCCCC 1 Bright {
			A_ChangeVelocity(frandom(0.25,-0.25),frandom(0.25,-0.25),frandom(0.1,-0.1));
		}
		LNL3 DDDDEEEEFFFF 1 Bright {
			A_ChangeVelocity(frandom(0.25,-0.25),frandom(0.25,-0.25),frandom(0.1,-0.1));
			A_FadeOut(frandom(0.05,0.07));
		}
		LNL3 F 1 Bright {
			A_ChangeVelocity(frandom(0.25,-0.25),frandom(0.25,-0.25),frandom(0.1,-0.1));
			A_FadeOut(frandom(0.05,0.07));
		}
		Wait;
	}
}

//Hit spark
class LonghornChainHit : LonghornChainTrail
{
	Default
	{
		Scale 0.6;
	}
	
	States
	{
	Spawn:
		TNT1 A 0 NoDelay {
			if(!GetCvar("GC_ToasterMode")) {
			for(int fuck = 0; fuck < 12; fuck++)
			{
				A_SpawnItemEx("LonghornChainSpark2",
					frandom(15.0,-15.0),frandom(15.0,-15.0),frandom(15.0,-15.0),
					frandom(3.0,-3.0),0,frandom(4.0,-1.0),frandom(0.0,360.0),
					SXF_CLIENTSIDE,64);
			}
			}
		}
		TNT1 A 0 A_Jump(256,1,4,7,10,13);
	Looplet:
		LNL2 AAABBBCCCDDDEEE 1 Bright {
			A_SetScale(Scale.X - 0.025);
			A_FadeOut(0.025);
			Return A_JumpIf(Scale.X <= 0, "Null");
		}
		Loop;
	}
}

class LonghornChainSpark2 : LonghornChainSpark
{
	States
	{
	Spawn:
		LNL3 AAABBBCCCDDDEEEFFF 1 Bright A_ChangeVelocity(frandom(0.5,-0.5),frandom(0.5,-0.5),frandom(0.15,-0.35));
		Stop;
	}
}

//Bullet puff
class LonghornChainImpact : Actor
{
	Default
	{
		+NOINTERACTION
	}
	
	States
	{
	Spawn:
		TNT1 A 0 NoDelay {
			for(int cunt = 0; cunt < 3; cunt++)
			{
				A_SpawnItemEx("ChainHuegPuff_Main", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE, 0);
			}
			for(int cunt = 0; cunt < 2; cunt++)
			{
				A_SpawnItemEx("ChainHuegPuff_Flash", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE, 0);
			}
			A_SpawnItemEx("ChainHuegPuff_Shock", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE, 0);
		}
		Stop;
	}
}

class ChainHuegPuff_Shock : Actor
{
	Default
	{
		RenderStyle "AddShaded";
        StencilColor "0263ff";
		Scale 0.035;
		Alpha 0.99;
		+NOINTERACTION
	}
	
	States
	{
		Spawn:
			SHCK C 1 Bright NoDelay {
				A_FadeOut(0.15);
				A_SetScale(Scale.X + frandom(0.045, 0.035));
			}
			Wait;
	}
}

class ChainHuegPuff_Flash : ChainHuegPuff_Shock
{
	Default
	{
		Scale 0.2;
		Alpha 0.3;
	}
	
	States
	{
		Spawn:
			TNT1 A 0 NoDelay A_SetScale(frandom(0.175, 0.2));
			TNT1 A 0 A_Jump(256,"SpriteA","SpriteB","SpriteC","SpriteD");
			Goto Spawn;
		SpriteA:
			2PUF A 0 A_Jump(256,"Idle");
		SpriteB:
			2PUF B 0 A_Jump(256,"Idle");
		SpriteC:
			2PUF C 0 A_Jump(256,"Idle");
		SpriteD:
			2PUF D 0 A_Jump(256,"Idle");
		Idle:
			"####" "#" 1 Bright A_FadeOut(0.125);
			"####" "#" 0 A_SetScale(Scale.X + frandom(0.04, 0.065));
			//"####" "#" 0 A_JumpIf(Scale.X <= 0.0, "Null");
			Loop;
	}
}

class ChainHuegPuff_Main : ChainHuegPuff_Shock
{
	Default
	{
		Scale 0.15;
	}
	
	States
	{
		Spawn:
			TNT1 A 0 NoDelay A_Jump(256,"SpriteA","SpriteB","SpriteC","SpriteD");
			Goto Spawn;
		SpriteA:
			1PUF A 0 A_Jump(256,"FadeIn");
		SpriteB:
			1PUF B 0 A_Jump(256,"FadeIn");
		SpriteC:
			1PUF C 0 A_Jump(256,"FadeIn");
		SpriteD:
			1PUF D 0 A_Jump(256,"FadeIn");
		FadeIn:
			"####" "#" 0 Bright A_SetScale(frandom(0.15, 0.125));
			Goto Idle;
		Idle:
			"####" "#" 1 Bright A_Jump(192,"FadeOut");
			Loop;
		FadeOut:
			"####" "#" 1 Bright {
				A_FadeOut(0.2);;
				A_SetScale(Scale.X + frandom(0.01, 0.005));;
			}
			Loop;
	}
}

class ChainHuegPuff_Spark1 : ChainHuegPuff_Shock
{
	Default
	{
		Scale 0.15;
	}
	
	States
	{
		Spawn:
			TNT1 A 0 NoDelay A_Jump(256,"SpriteA","SpriteB","SpriteC","SpriteD");
			Goto Spawn;
		SpriteA:
			1SPK A 0 A_Jump(256,"FadeIn");
		SpriteB:
			1SPK B 0 A_Jump(256,"FadeIn");
		SpriteC:
			1SPK C 0 A_Jump(256,"FadeIn");
		SpriteD:
			1SPK D 0 A_Jump(256,"FadeIn");
		SpriteE:
			1SPK E 0 A_Jump(256,"FadeIn");
		SpriteF:
			1SPK F 0 A_Jump(256,"FadeIn");
		SpriteG:
			1SPK G 0 A_Jump(256,"FadeIn");
		SpriteH:
			1SPK H 0 A_Jump(256,"FadeIn");
		FadeIn:
			"####" "#" 0 Bright A_SetScale(frandom(0.15, 0.125));
			Goto Idle;
		Idle:
			"####" "#" 1 Bright A_Jump(192,"FadeOut");
			Loop;
		FadeOut:
			"####" "#" 1 Bright {
				A_FadeOut(0.2);
				A_SetScale(Scale.X + frandom(0.01, 0.0125));
			}
			Loop;
	}
}

class ChainHuegPuff_Spark2 : ChainHuegPuff_Shock
{
	Default
	{
		Scale 0.15;
	}
	
	States
	{
		Spawn:
			TNT1 A 0 NoDelay A_Jump(256,"SpriteA","SpriteB","SpriteC","SpriteD");
			Goto Spawn;
		SpriteA:
			2SPK A 0 A_Jump(256,"FadeIn");
		SpriteB:
			2SPK B 0 A_Jump(256,"FadeIn");
		SpriteC:
			2SPK C 0 A_Jump(256,"FadeIn");
		SpriteD:
			2SPK D 0 A_Jump(256,"FadeIn");
		SpriteE:
			2SPK E 0 A_Jump(256,"FadeIn");
		SpriteF:
			2SPK F 0 A_Jump(256,"FadeIn");
		SpriteG:
			2SPK G 0 A_Jump(256,"FadeIn");
		SpriteH:
			2SPK H 0 A_Jump(256,"FadeIn");
		FadeIn:
			"####" "#" 0 Bright A_SetScale(frandom(0.15, 0.125));
			Goto Idle;
		Idle:
			"####" "#" 1 Bright A_Jump(192,"FadeOut");
			Loop;
		FadeOut:
			"####" "#" 1 Bright {
				A_FadeOut(0.2);
				A_SetScale(Scale.X + frandom(0.01, 0.0125));
			}
			Loop;
	}
}

class ChainHuegPuff_Smoke : Actor
{
	Default
	{
		Alpha 0.0;
		RenderStyle "Translucent";
		+NOINTERACTION;
	}
	
	States
	{
		Spawn:
		    TNT1 A 3;
			TNT1 A 0 A_Jump(256, "SpriteA", "SpriteB", "SpriteC", "SpriteD");
		SpriteA:
			DYMI A 0 A_Jump(256, "FadeIn");
		SpriteB:
			DYMI B 0 A_Jump(256, "FadeIn");
		SpriteC:
			DYMI C 0 A_Jump(256, "FadeIn");
		SpriteD:
			DYMI D 0 A_Jump(256, "FadeIn");
		FadeIn:
			"####" "#" 0 A_SetScale(frandom(0.025, 0.03));
			Goto RealFadeIn;
		RealFadeIn:
			"####" "#" 1 A_FadeIn(frandom(0.06, 0.08));
			"####" "#" 0 A_JumpIf(Alpha >= 0.25, "Idle");
			Loop;
		Idle:
			"####" "#" 5 A_Jump(200, "FadeOut");
			Loop;
		FadeOut:
			"####" "#" 1 {
				A_FadeOut(frandom(0.01,0.02));
				A_SetScale(Scale.X + frandom(0.03, 0.0025));
			}
			Loop;
	}
}



//Ol' bullet
class LonghornBullet : FastProjectile
{
	Default
	{
		Radius 13;
		Height 11;
		MissileHeight 8;
		Speed 200;
		DamageFunction (18*random(1,3));
		Projectile;
		ProjectileKickback 200;
		Renderstyle "Add";
		Obituary "%o's cranium got devastasted by %k's Longhorn hammer shot.";
		Scale 0.5;
		MissileType "LonghornTrail";
		Decal "LonghornChip";
		+NOGRAVITY
		+FORCERADIUSDMG
		//+EXTREMEDEATH
		+RIPPER
		+MTHRUSPECIES
	}
	
	States
	{
	Spawn:
		TRAC A 0 NoDelay A_ChangeVelocity(0, 0, -2.0, CVF_RELATIVE);
	Looplet:
		TRAC A 1 Bright A_ChangeVelocity(0, 0, -0.25, CVF_RELATIVE);
		Loop;
	Death:
		TNT1 A 1 {
			A_Explode(25*random(1,3),56,0);
			A_PlaySound("LeadBullet/Hit",4,0.2);
			A_SpawnItemEx("LonghornImpact",0,0,0,0,0,0,0,SXF_CLIENTSIDE,0);
			A_SpawnItemEx("HuegPuff",0,0,0,0,0,0,0,SXF_CLIENTSIDE,0);
		}
		Stop;
	XDeath:
		TNT1 A 0;
		Stop;
	}
}

class LonghornImpact : actor
{
	Default
	{
		RenderStyle "Add";
		Scale 0.035;
		+NOINTERACTION
	}
	
	States
	{
		Spawn:
			SHCK C 1 NoDelay Bright {
				A_SetScale(Scale.X + frandom(0.1, 0.15));
				A_FadeOut(0.15);
			}
			Loop;
	}
}

class LonghornTrail : actor
{
	Default
	{
		+NoInteraction;
	}
	
	States
	{
	Spawn:
		TNT1 A 0 NoDelay {
			A_SpawnItemEx("LonghornTrailSmoke", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE, 0);
			A_SpawnItemEx("BuellerPuff_Main", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE, 0);
			A_SpawnItemEx("BuellerPuff_Flash", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE, 0);
			//A_SpawnItemEx("BuellerPuff_Spark1", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE, 0);
			//A_SpawnItemEx("BuellerPuff_Spark2", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE, 0);
			//A_SpawnItemEx("HuegPuff_Shock", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE, 0);
		}
		Stop;
	}
}

class LonghornTrailSmoke : actor
{
	Default
	{
		Alpha 0.0;
		RenderStyle "Translucent";
		+NoInteraction
		+ForceXYBillboard
	}
	
	States
	{
	Spawn:
		TNT1 A 0 NoDelay A_Jump(256, "SpriteA", "SpriteB", "SpriteC", "SpriteD");
	SpriteA:
		DYMI A 0 A_Jump(256, "FadeIn");
	SpriteB:
		DYMI B 0 A_Jump(256, "FadeIn");
	SpriteC:
		DYMI C 0 A_Jump(256, "FadeIn");
	SpriteD:
		DYMI D 0 A_Jump(256, "FadeIn");
	FadeIn:
		"####" "#" 0 A_SetScale(frandom(0.0325, 0.025));
		Goto RealFadeIn;
	RealFadeIn:
		"####" "#" 1 {
			A_FadeIn(frandom(0.1, 0.05));
			A_SetScale(Scale.X + frandom(0.001, 0.002));
			Return A_JumpIf(Alpha >= 0.5, "FadeOut");
		}
		Loop;
	FadeOut:
		"####" "#" 1 {
			A_FadeOut(frandom(0.025,0.075));
			A_SetScale(Scale.X + frandom(0.001, 0.0005));
		}
		Loop;
	}
}