//=============================================================================
// WLockerBase.
//=============================================================================
class WLockerBase expands Decoration;

var bool bTeamOnly;
var byte LockerTeam;
var InventorySpot PMarker;
var DumbInv DBI;
var vector SpawnOffset;
var vector LightOffset;
var sound PickupSound;

var class<Weapon> LWeapon[16];
var int AbsoluteAmmo[16];
var int AmmoDifAllowed[16];
var int AmmoPickup[16];
var byte bOtherRotSet[6];

function PostBeginPlay()
{
	SpawnOffset=vect(32,0,0);
	LightOffset=vect(0,0,36);

	SetTimer(0.1, False);
}

function SetPickups()
{
local vector X, Y, Z;
local int i;
local WDumbMeshes WMesh[6];
local WDumbMeshes TeamLight;
local rotator r;


	For (i=0; i<6; i++)
	{
		if (LWeapon[i] != None)
		{
			if (LWeapon[3]!=None)
				r.Yaw = i * (65536/6);
			else if (LWeapon[2]!=None)
				r.Yaw = i * (65536/3);
			else
				r.Yaw = i * (65536/2);

			GetAxes(Rotation + r, X, Y, Z);
			if (bOtherRotSet[i] == 0)
				WMesh[i] = Spawn(Class'WDumbMeshes',,, Location + (SpawnOffset.X * X + SpawnOffset.Y * Y + SpawnOffset.Z * Z), Rotation + rot(16384,0,0));
			else			
				WMesh[i] = Spawn(Class'WDumbMeshes',,, Location + (SpawnOffset.X * X + SpawnOffset.Y * Y + SpawnOffset.Z * Z), Rotation + rot(0, 16384, -16384));
			WMesh[i].Mesh = LWeapon[i].Default.PickupViewMesh;
			WMesh[i].DrawScale = LWeapon[i].Default.PickupViewScale;
		}
	}


	GetAxes(Rotation, X, Y, Z);
	TeamLight = Spawn(Class'WDumbMeshes',,, Location + (LightOffset.X * X + LightOffset.Y * Y + LightOffset.Z * Z));
	TeamLight.Style = STY_Translucent;
	TeamLight.DrawType = DT_Sprite;
	TeamLight.DrawScale = 0.20;
	TeamLight.ScaleGlow = 0.75;

	If (bTeamOnly && Level.Game.IsA('TeamGamePlus'))
	{
		If (Level.Game.IsA('Assault'))
		{
			If (Assault(Level.Game).Attacker.TeamIndex != 0)
			{
				If (LockerTeam == 0)
					LockerTeam = 1;
				else
					LockerTeam = 0;
			}
		}

		If (LockerTeam == 0)
			TeamLight.Texture = Texture'BotPack.Translocator.TranGlow';
		else if (LockerTeam == 1)
			TeamLight.Texture = Texture'BotPack.Translocator.TranGlowB';
		else if (LockerTeam == 2)
			TeamLight.Texture = Texture'BotPack.Translocator.TranGlowG';
		else
			TeamLight.Texture = Texture'BotPack.Translocator.TranGlowY';
	}
	else
		TeamLight.Texture = Texture'BotPack.Translocator.TranGlowY';


	DBI = Spawn(Class'DumbInv',,, Location);
	DBI.bTeamOnly = bTeamOnly;
	DBI.LockerTeam = LockerTeam;

	For (i=0; i<16; i++)
	{
		if (LWeapon[i] != None)
		{

		If (AbsoluteAmmo[i] > LWeapon[i].Default.AmmoName.Default.MaxAmmo)
			AbsoluteAmmo[i] = LWeapon[i].Default.AmmoName.Default.MaxAmmo;

		DBI.LWeapon[i] = LWeapon[i];
		DBI.AbsoluteAmmo[i] = AbsoluteAmmo[i];
		DBI.AmmoDifAllowed[i] = AmmoDifAllowed[i];
		DBI.AmmoPickup[i] = AmmoPickup[i];

		}
	}

	if (PMarker != None)
	{
		PMarker.markedItem = DBI;
		DBI.MyMarker = PMarker;
	}
}


function Timer()
{
	SetPickups();
}


function Touch( actor Other )
{
	If (Other.IsA('Pawn'))
	{
		If (bTeamOnly && Level.Game.IsA('TeamGamePlus'))
		{
			If (Pawn(Other).PlayerReplicationInfo.Team == LockerTeam)
				GiveWeaponry(Pawn(Other));
		}
		else
				GiveWeaponry(Pawn(Other));
	}
}


function GiveWeaponry( pawn P)
{
local int i;
local Weapon InvK;

	For (i=0; i<16; i++)
	{
		if (LWeapon[i] != None)
		{

			If (P.FindInventoryType(LWeapon[i]) != None)
			{
				InvK = Weapon(P.FindInventoryType(LWeapon[i]));
				If( (AbsoluteAmmo[i] - InvK.AmmoType.AmmoAmount) > AmmoDifAllowed[i])
				{
					InvK.AmmoType.AmmoAmount = Min(InvK.AmmoType.AmmoAmount + AmmoPickup[i], AbsoluteAmmo[i]);
					PlaySound(PickupSound);
				}
			}
			else
			{
				InvK = Spawn(LWeapon[i]);

				InvK.RespawnTime = 0.0;
				InvK.bHeldItem = true;
				InvK.bTossedOut = false;
				InvK.GiveTo( P );
				InvK.Instigator = P;
				InvK.GiveAmmo(P);
				InvK.SetSwitchPriority(P);
				InvK.AmmoType.AmmoAmount = Min(InvK.AmmoType.AmmoAmount + AmmoPickup[i], AbsoluteAmmo[i]);
				if ( !P.bNeverSwitchOnPickup )
					InvK.WeaponSet(P);
				InvK.AmbientGlow = 0;

				PlaySound(PickupSound);
			}		
		}
	}
}


defaultproperties
{
	bStatic=False
	bStasis=False
	DrawType=DT_Mesh
	bCollideActors=True
	CollisionRadius=40.000000
	CollisionHeight=40.000000
}