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

Gameplay.MPMetaCarryable


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
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
class MPMetaCarryable extends MPCarryable;

var(MPMetaCarryable) int				maxCarryables	"The maximum number of carryables that can be carried in this metacarryable";
var(MPMetaCarryable) int				numCarryables	"The current number of carryables stored in this metacarryable";
var(MPMetaCarryable) class<MPCarryable>	carryableClass	"The class of MPCarryable stored in this metacarryable";
var(MPMetaCarryable) bool				bAutoFill		"If true, this metacarryable will fill itself up when it is introduced into the world";

// Stores instances of each carryable being carried
// Assume for now that a metacarryable never carries another metacarryable
var array<MPCarryable>	carryables;
var bool bHasHomeLocation;

function PostBeginPlay()
{
	local MPCarryable c;
	local int i;

	Super.PostBeginPlay();

	// Check to see if there should be some stored instances in this metacarryable
	// Note that this approach requires that there is a difference between a placed instance
	// in the editor (which require autofilling) and a dynamically spawned instance (which
	// must not autofill since existing instances get added)
	if (bAutoFill)
	{
		Log("Metacarryable "$self$" filling instances "$maxCarryables);
		for (i=0; i<maxCarryables && numCarryables < maxCarryables; i++)
		{
			c = spawn(carryableClass,,,Location);

			if (c == None)
			{
				Log("MetaCarryable error:  could not autofill with class "$carryableClass);
				return;
			}

			// MJ TODO:  There are cases where individual instances will returnToHome and
			// overlap each other.  Not sure what the best solution to this is (spread them out a bit?)
			c.homeLocation = Location;
			bHasHomeLocation = true;
			add(c);
		}
	}
}

function returnToHome(optional bool bSignificant)
{
	local int i;

	// Return all stored carryables
	for (i=0; i<carryables.Length; i++)
		carryables[i].returnToHome();

	// If it has a home, return it; otherwise, destroy it
	if (bHasHomeLocation)
		super.returnToHome(bSignificant);
	else
	{
		//Log("Destroying metaCarryable "$self$" in returnToHome()");
		destroy();
	}
}

function add(MPCarryable c)
{
	if (numCarryables >= maxCarryables)
	{
		Log("MetaCarryable warning:  exceeding carryable capacity on adding "$c);
		return;
	}

	// If this is the first carryable added, do some initialization
	if (carryables.Length == 0)
	{
		if (carryableClass == None)
			carryableClass = c.Class;

		if (c.carrier != None)
		{
			carrier = c.carrier;
			setOwner(c.Owner);
		}
	}
	carryables[carryables.Length] = c;
	numCarryables = numCarryables + 1;

	// Lock the carryable
	c.GotoState('Locked');
}

function pickup(Character c)
{
	local int i,j;
	local int maxPickup;

	if (carryableClass != None)
		maxPickup = carryableClass.default.maxCarried;
	else if (c.carryableReference != None)
		maxPickup = c.carryableReference.maxCarried;
	else
		maxPickup = 0;

	//Log("Metacarryable pickup "$self$", max = "$maxPickup$", len = "$carryables.Length);
	// Empty the carryable as much as possible
	for (i=0; i<carryables.Length && c.numCarryables < maxPickup; i++)
	{
		//Log("Picking up "$carryables[i]);
		if (carryables[i].attemptPickup(c))
			numCarryables--;
	}

	// Drop the remaining carryables
	// Consider composing them into denominations first; for now just drop them as singles
	for (j=0; j<numCarryables; j++)
	{
		//Log("Dropping "$carryables[i+j]);
		carryables[i+j].bCollideWorld = true;
		carryables[i+j].unifiedSetPosition(Location);
		carryables[i+j].drop(true);
	}

	// Get rid of the metacarryable
	carryables.Length = 0;
	destroy();
}

function bool canCombineWith(class<MPCarryable> targetClass)
{
	return carryableClass == targetClass;
}

function int getNumCarryables()
{
	local int i;
	local int total;

	for (i=0; i<carryables.Length; i++)
		total += carryables[i].getNumCarryables();

	Log(self$" has carryables: "$total);
	return total;
}

function int getMaxCarried()
{
	return carryableClass.default.maxCarried;
}

defaultproperties
{
	maxCarryables	= 5
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: ne 5.9.2004 15:53:18.000 - Creation time: st 23.5.2018 00:10:45.936 - Created with UnCodeX