Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

SpawnWithLockerWeapons.SpawnWithLockerWeapons


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
/******************************************************************************
SpawnWithLockerWeapons

Creation date: 2009-02-07 13:19
Last change: $Id$
Copyright (c) 2009, Wormbo
******************************************************************************/

class SpawnWithLockerWeapons extends Mutator;


struct TBestLocker {
	var Actor Start;
	var WeaponLocker Locker;
};

var bool bInitialized;
var array<TBestLocker> BestLockers;
var array<WeaponLocker> AllLockers;
var array<UnrealPawn> SpawnedPlayers;

function Initialize()
{
	local int i;
	local WeaponLocker Locker;
	
	bInitialized = True;
	
	// find all lockers for faster access
	foreach AllActors(class'WeaponLocker', Locker) {
		if (Locker.IsInState('LockerPickup'))
			AllLockers[i++] = Locker;
	}
	AllLockers.Length = i; // just making sure
}

function ModifyPlayer(Pawn Other)
{
	local int i;
	local WeaponLocker BestLocker;
	local Weapon Copy;
	
	if (!bInitialized)
		Initialize();
	
	Super.ModifyPlayer(Other);
	
	if (UnrealPawn(Other) != None) {
		// check if we processed this player already
		for (i = SpawnedPlayers.Length - 1; i >= 0; --i) {
			if (SpawnedPlayers[i] == None || SpawnedPlayers[i].Health <= 0)
				SpawnedPlayers.Remove(i, 1);
			else if (SpawnedPlayers[i] == Other)
				return;
		}
		SpawnedPlayers[SpawnedPlayers.Length] = UnrealPawn(Other);
		
		BestLocker = GetBestLocker(Other.LastStartSpot);
		if (BestLocker != None) {
			for (i = 0; i < BestLocker.Weapons.Length; ++i) {
				BestLocker.InventoryType = BestLocker.Weapons[i].WeaponClass;
				Copy =  Weapon(Other.FindInventoryType(BestLocker.Weapons[i].WeaponClass));
				if (Copy != None) {
					Copy.FillToInitialAmmo();
				}
				else if (Level.Game.PickupQuery(Other, BestLocker)) {
					Copy = Weapon(BestLocker.SpawnCopy(Other));
					if (Copy != None) {
						Copy.PickupFunction(Other);
						if (BestLocker.Weapons[i].ExtraAmmo > 0)
							Copy.AddAmmo(BestLocker.Weapons[i].ExtraAmmo, 0);
					}
				}
			}
		}
	}
}


function WeaponLocker GetBestLocker(Actor Start)
{
	local int i;
	local WeaponLocker BestLocker;
	local float Dist, BestDist;
	
	if (AllLockers.Length == 0 || Start == None)
		return None; // no lockers on map
	
	// check if best locker already known
	for (i = 0; i < BestLockers.Length; ++i) {
		if (BestLockers[i].Start == Start)
			return BestLockers[i].Locker; // previously known best locker
	}
	
	// look for closest locker
	for (i = 0; i < AllLockers.Length; ++i) {
		if (AllLockers[i] != None && !AllLockers[i].IsInState('Disabled')) {
			Dist = VSize(Start.Location - AllLockers[i].Location);
			if (BestLocker == None || BestDist > Dist) {
				BestLocker = AllLockers[i];
				BestDist = Dist;
			}
		}
	}
	
	// cache result
	BestLockers.Insert(0, 1);
	BestLockers[0].Locker = BestLocker;
	BestLockers[0].Start = Start;
	
	return BestLocker;
}



//=============================================================================
// Default values
//=============================================================================

defaultproperties
{
	FriendlyName = "Spawn with locker weapons"
	Description  = "Spawning players are automatically equiped with all weapons from the nearest weapon locker."
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Sa 7.2.2009 15:35:26.000 - Creation time: Sa 23.8.2014 09:19:00.002 - Created with UnCodeX