//=============================================================================
// CTFNWMutator. The CTF randomizer mutator.
// This mutator simply spawns weapons in CTF games, specially designed
//	to handle RX maps without any pathnodes, basing the placement on playerstarts
//------------------------------------------------------------------------------
//	The UltimaProtos, MegaTon and Enhanced Bolt Rifle 
//	are handled specially, since they are spawned on hidden spots 
//	(Spots that have UDamage, HealthPack, Instagib, etc)
//	So, if there's no spots like this, these weapons never spawn
//	The CybotLauncher, even being a MegaWeapon, it's handled like a normal one
//	since it's almost inofensive against RX blasts
//=============================================================================
class CTFNWMutator expands Mutator config(NaliWeaponsII);

var(RandWeapons) globalconfig bool add_WRE;
var(RandWeapons) globalconfig bool add_FlameT;
var(RandWeapons) globalconfig bool add_BoltR;
var(RandWeapons) globalconfig bool add_SBoltR;
var(RandWeapons) globalconfig bool add_Graviton;
var(RandWeapons) globalconfig bool add_Freezer;
var(RandWeapons) globalconfig bool add_Vulcan;
var(RandWeapons) globalconfig bool add_TheMiner;
var(RandWeapons) globalconfig bool add_MMLauncher;
var(RandWeapons) globalconfig bool add_IRPR;
var(RandWeapons) globalconfig bool add_Cybot;
var(RandWeapons) globalconfig bool add_MegaTon;
var(RandWeapons) globalconfig bool add_UltimaProtos;
var(RandWeapons) globalconfig bool bInfiniteEBRAmmo;
var(RandWeapons) globalconfig int AddedWeaponsAmmoMulti;
var(RandWeapons) globalconfig bool add_NukeA;
var(RandWeapons) globalconfig bool add_NukeB;
var(RandWeapons) globalconfig bool add_NukeC;
var(RandWeapons) globalconfig bool add_NukeD;
var(RandWeapons) globalconfig bool add_NukeE;

function PostBeginPlay()
{
	local PlayerStart PS;
	local float FlagsHalfDistance;
	local FlagBase FB, OldFB;
	local NaliWeapons NWW;
	local Inventory I;
	local vector HitLocation, HitNormal, EndTrace, X, Y, Z;
	local Actor A;
	local bool Red_WRE, Red_FlameT, Red_Bolt, Red_Graviton, Red_Freezer, Red_Vulcan, Red_TheMiner, Red_MMLauncher, Red_IRPR, Red_Cybot;
	local bool Blue_WRE, Blue_FlameT, Blue_Bolt, Blue_Graviton, Blue_Freezer, Blue_Vulcan, Blue_TheMiner, Blue_MMLauncher, Blue_IRPR, Blue_Cybot;
	local rotator RandYaw;
	local byte Try;
	local bool SBoltRAdded, MegaTonAdded, UltimaAdded;
	local bool NukeAddedA, NukeAddedB, NukeAddedC, NukeAddedD, NukeAddedE;
	
	if (Level.Game.IsA('CTFGame'))
	{
    		ForEach AllActors(Class'PlayerStart', PS)
		{
			if (PS.TeamNumber == 0)
			{
				if (!Red_WRE && add_WRE)
				{
					Red_WRE = True;
					NWW = Spawn(Class'WRE',,, PS.Location);
					NWW.bAddedRandomlly = True;
				}
				else if (!Red_FlameT && add_FlameT)
				{
					Red_FlameT = True;
					NWW = Spawn(Class'FlameTracker',,, PS.Location);
					NWW.bAddedRandomlly = True;
				}
				else if (!Red_Bolt && add_BoltR)
				{
					Red_Bolt = True;
					NWW = Spawn(Class'BoltRifle',,, PS.Location);
					NWW.bAddedRandomlly = True;
				}
				else if (!Red_Graviton && add_Graviton)
				{
					Red_Graviton = True;
					NWW = Spawn(Class'Graviton',,, PS.Location);
					NWW.bAddedRandomlly = True;
				}
				else if (!Red_Freezer && add_Freezer)
				{
					Red_Freezer = True;
					NWW = Spawn(Class'Freezer',,, PS.Location);
					NWW.bAddedRandomlly = True;
				}
				else if (!Red_Vulcan && add_Vulcan)
				{
					Red_Vulcan = True;
					NWW = Spawn(Class'Vulcan',,, PS.Location);
					NWW.bAddedRandomlly = True;
				}
				else if (!Red_TheMiner && add_TheMiner)
				{
					Red_TheMiner = True;
					NWW = Spawn(Class'TheMiner',,, PS.Location);
					NWW.bAddedRandomlly = True;
				}
				else if (!Red_MMLauncher && add_MMLauncher)
				{
					Red_MMLauncher = True;
					NWW = Spawn(Class'MultiMissile',,, PS.Location);
					NWW.bAddedRandomlly = True;
				}
				else if (!Red_IRPR && add_IRPR)
				{
					Red_IRPR = True;
					NWW = Spawn(Class'IRPR',,, PS.Location);
					NWW.bAddedRandomlly = True;
				}
				else if (!Red_Cybot && add_Cybot)
				{
					Red_Cybot = True;
					NWW = Spawn(Class'CybotLauncher',,, PS.Location);
					NWW.bAddedRandomlly = True;
				}
			}
			else
			{
				if (!Blue_WRE && add_WRE)
				{
					Blue_WRE = True;
					NWW = Spawn(Class'WRE',,, PS.Location);
					NWW.bAddedRandomlly = True;
				}
				else if (!Blue_FlameT && add_FlameT)
				{
					Blue_FlameT = True;
					NWW = Spawn(Class'FlameTracker',,, PS.Location);
					NWW.bAddedRandomlly = True;
				}
				else if (!Blue_Bolt && add_BoltR)
				{
					Blue_Bolt = True;
					NWW = Spawn(Class'BoltRifle',,, PS.Location);
					NWW.bAddedRandomlly = True;
				}
				else if (!Blue_Graviton && add_Graviton)
				{
					Blue_Graviton = True;
					NWW = Spawn(Class'Graviton',,, PS.Location);
					NWW.bAddedRandomlly = True;
				}
				else if (!Blue_Freezer && add_Freezer)
				{
					Blue_Freezer = True;
					NWW = Spawn(Class'Freezer',,, PS.Location);
					NWW.bAddedRandomlly = True;
				}
				else if (!Blue_Vulcan && add_Vulcan)
				{
					Blue_Vulcan = True;
					NWW = Spawn(Class'Vulcan',,, PS.Location);
					NWW.bAddedRandomlly = True;
				}
				else if (!Blue_TheMiner && add_TheMiner)
				{
					Blue_TheMiner = True;
					NWW = Spawn(Class'TheMiner',,, PS.Location);
					NWW.bAddedRandomlly = True;
				}
				else if (!Blue_MMLauncher && add_MMLauncher)
				{
					Blue_MMLauncher = True;
					NWW = Spawn(Class'MultiMissile',,, PS.Location);
					NWW.bAddedRandomlly = True;
				}
				else if (!Blue_IRPR && add_IRPR)
				{
					Blue_IRPR = True;
					NWW = Spawn(Class'IRPR',,, PS.Location);
					NWW.bAddedRandomlly = True;
				}
				else if (!Blue_Cybot && add_Cybot)
				{
					Blue_Cybot = True;
					NWW = Spawn(Class'CybotLauncher',,, PS.Location);
					NWW.bAddedRandomlly = True;
				}
			}
		}

		ForEach AllActors(Class'Inventory', I)
		{
			Try = 0;

			if ((I.IsA('SuperShockRifle') || I.IsA('UT_JumpBoots')) && add_SBoltR && !SBoltRAdded)
			{
				While (Try < 20 && VSize(HitLocation - I.Location) < 120)
				{
					RandYaw = Rand(16384) * 4 * rot(0,1,0);
					GetAxes(RandYaw, X, Y, Z);
					EndTrace = I.Location + 512*X;
					A = Trace(HitLocation, HitNormal, EndTrace, I.Location, False);

					if (A == None)
						HitLocation = EndTrace;

					HitLocation = HitLocation - 60*HitNormal;

					Try++;
				}
	
				if (bInfiniteEBRAmmo)
					Spawn(Class'SuperBoltRifleInf',,, HitLocation, I.Rotation);
				else
					Spawn(Class'SuperBoltRifle',,, HitLocation, I.Rotation);

				SBoltRAdded = True;
			}
			else if ((I.IsA('UDamage') || I.IsA('HealthPack') || I.IsA('UT_Invisibility') || I.IsA('UT_ShieldBelt')) && add_MegaTon && !MegaTonAdded)
			{
				While (Try < 20 && VSize(HitLocation - I.Location) < 120)
				{
					RandYaw = Rand(16384) * 4 * rot(0,1,0);
					GetAxes(RandYaw, X, Y, Z);
					EndTrace = I.Location + 512*X;
					A = Trace(HitLocation, HitNormal, EndTrace, I.Location, False);

					if (A == None)
						HitLocation = EndTrace;

					HitLocation = HitLocation - 60*HitNormal;

					Try++;
				}
	
				Spawn(Class'MegaTon',,, HitLocation, I.Rotation);

				MegaTonAdded = True;
			}
			else if ((I.IsA('UDamage') || I.IsA('HealthPack') || I.IsA('UT_Invisibility') || I.IsA('UT_ShieldBelt')) && add_UltimaProtos && !UltimaAdded)
			{
				While (Try < 20 && VSize(HitLocation - I.Location) < 120)
				{
					RandYaw = Rand(16384) * 4 * rot(0,1,0);
					GetAxes(RandYaw, X, Y, Z);
					EndTrace = I.Location + 512*X;
					A = Trace(HitLocation, HitNormal, EndTrace, I.Location, False);

					if (A == None)
						HitLocation = EndTrace;

					HitLocation = HitLocation - 60*HitNormal;

					Try++;
				}
	
				Spawn(Class'UltimaProtos',,, HitLocation, I.Rotation);

				UltimaAdded = True;
			}
			else if ((I.IsA('UDamage') || I.IsA('HealthPack') || I.IsA('UT_Invisibility') || I.IsA('UT_ShieldBelt')) && add_NukeA && !NukeAddedA)
			{
				While (Try < 20 && VSize(HitLocation - I.Location) < 120)
				{
					RandYaw = Rand(16384) * 4 * rot(0,1,0);
					GetAxes(RandYaw, X, Y, Z);
					EndTrace = I.Location + 512*X;
					A = Trace(HitLocation, HitNormal, EndTrace, I.Location, False);

					if (A == None)
						HitLocation = EndTrace;

					HitLocation = HitLocation - 60*HitNormal;

					Try++;
				}
	
				Spawn(Class'NuclearLauncherLvlA',,, HitLocation, I.Rotation);

				NukeAddedA = True;
			}
			else if ((I.IsA('UDamage') || I.IsA('HealthPack') || I.IsA('UT_Invisibility') || I.IsA('UT_ShieldBelt')) && add_NukeB && !NukeAddedB)
			{
				While (Try < 20 && VSize(HitLocation - I.Location) < 120)
				{
					RandYaw = Rand(16384) * 4 * rot(0,1,0);
					GetAxes(RandYaw, X, Y, Z);
					EndTrace = I.Location + 512*X;
					A = Trace(HitLocation, HitNormal, EndTrace, I.Location, False);

					if (A == None)
						HitLocation = EndTrace;

					HitLocation = HitLocation - 60*HitNormal;

					Try++;
				}
	
				Spawn(Class'NuclearLauncherLvlB',,, HitLocation, I.Rotation);

				NukeAddedB = True;
			}
			else if ((I.IsA('UDamage') || I.IsA('HealthPack') || I.IsA('UT_Invisibility') || I.IsA('UT_ShieldBelt')) && add_NukeC && !NukeAddedC)
			{
				While (Try < 20 && VSize(HitLocation - I.Location) < 120)
				{
					RandYaw = Rand(16384) * 4 * rot(0,1,0);
					GetAxes(RandYaw, X, Y, Z);
					EndTrace = I.Location + 512*X;
					A = Trace(HitLocation, HitNormal, EndTrace, I.Location, False);

					if (A == None)
						HitLocation = EndTrace;

					HitLocation = HitLocation - 60*HitNormal;

					Try++;
				}
	
				Spawn(Class'NuclearLauncherLvlC',,, HitLocation, I.Rotation);

				NukeAddedC = True;
			}
			else if ((I.IsA('UDamage') || I.IsA('HealthPack') || I.IsA('UT_Invisibility') || I.IsA('UT_ShieldBelt')) && add_NukeD && !NukeAddedD)
			{
				While (Try < 20 && VSize(HitLocation - I.Location) < 120)
				{
					RandYaw = Rand(16384) * 4 * rot(0,1,0);
					GetAxes(RandYaw, X, Y, Z);
					EndTrace = I.Location + 512*X;
					A = Trace(HitLocation, HitNormal, EndTrace, I.Location, False);

					if (A == None)
						HitLocation = EndTrace;

					HitLocation = HitLocation - 60*HitNormal;

					Try++;
				}
	
				Spawn(Class'NuclearLauncherLvlD',,, HitLocation, I.Rotation);

				NukeAddedD = True;
			}
			else if ((I.IsA('UDamage') || I.IsA('HealthPack') || I.IsA('UT_Invisibility') || I.IsA('UT_ShieldBelt')) && add_NukeE && !NukeAddedE)
			{
				While (Try < 20 && VSize(HitLocation - I.Location) < 120)
				{
					RandYaw = Rand(16384) * 4 * rot(0,1,0);
					GetAxes(RandYaw, X, Y, Z);
					EndTrace = I.Location + 512*X;
					A = Trace(HitLocation, HitNormal, EndTrace, I.Location, False);

					if (A == None)
						HitLocation = EndTrace;

					HitLocation = HitLocation - 60*HitNormal;

					Try++;
				}
	
				Spawn(Class'NuclearLauncherLvlE',,, HitLocation, I.Rotation);

				NukeAddedE = True;
			}
		}
    	}

}



defaultproperties
{
	add_WRE=True
	add_FlameT=True
	add_BoltR=True
	add_SBoltR=True
	add_Graviton=True
	add_Freezer=True
	add_Vulcan=True
	add_TheMiner=True
	add_MMLauncher=True
	add_IRPR=True
	add_Cybot=True
	add_UltimaProtos=False
	add_MegaTon=False
	add_NukeA=True
	add_NukeB=True
	add_NukeC=True
	add_NukeD=False
	add_NukeE=False
	bInfiniteEBRAmmo=True
	AddedWeaponsAmmoMulti=3
}