Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation
previous class next class | frames no frames

# Gameplay.MPAreaTrigger

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
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239

    class MPAreaTrigger extends TriggerRadius;

    var IMPAreaTriggerable		listener;
    var float					triggerFrequency;
    var (EffectEvents) Name		playerInAreaEffectEvent			"The name of an effect event that loops on players in the area";

    struct characterPresence
    {
    	var Character character;
    	var float markerTime;
    };

    var array<characterPresence>	charList;

    function PostBeginPlay()
    {
    	local Character c;

    	Super.PostBeginPlay();
    	SetTimer(triggerFrequency, true);

    	// Evaluate everyone within radius and add them
    	ForEach TouchingActors(class'Character', c)
    	{
    		addCharacter(c);
    	}
    }

    simulated function Touch(Actor Other)
    {
    	local Character c;

    	if (listener == None)
    		return;

    	listener.OnAreaEnteredByActor(Other);

    	c = Character(Other);
    	if (c == None || c.team() == None || c.health <= 0)
    		return;

    	addCharacter(c);
    	super.Touch(Other);

    	c.TriggerEffectEvent(playerInAreaEffectEvent);

    	if (listener != None)
    		listener.OnAreaEntered(c);
    }

    simulated function UnTouch(Actor Other)
    {
    	local Character c;
    	local int i;

    	if (listener == None)
    		return;

    	listener.OnAreaExitedByActor(Other);

    	c = Character(Other);
    	if (c == None || c.team() == None)
    		return;

    	removeCharacter(c);
    	super.UnTouch(Other);

    	// Superclass doesn't remove from touching, so do it manually
    	for (i = 0; i < Touching.Length; ++i)
    	{
    		if (Touching[i] == Other)
    		{
    			Touching.Remove(i, 1);
    			break;
    		}
    	}

    	c.UnTriggerEffectEvent(playerInAreaEffectEvent);
    	listener.OnAreaExited(c);
    }

    function addCharacter(Character c)
    {
    	local characterPresence cp;
    	local int i;

    	// For some reason Touch is being called multiple times, so make sure not to add it
    	// more than once
    	for (i=0; i<charList.Length; i++)
    	{
    		if (charList[i].character == c)
    			return;
    	}

    	cp.character = c;
    	cp.markerTime = Level.TimeSeconds;

    	charList[charList.Length] = cp;
    	//Log(self$" adding "$c);
    }

    function removeCharacter(Character c)
    {
    	local int i;

    	for (i=0; i<charList.Length; i++)
    	{
    		if (charList[i].character == c)
    		{
    			charList.remove(i, 1);
    			//Log(self$" removing "$c);
    		}
    	}
    }

    function bool containsCharacter(Character c)
    {
    	local int i;

    	for (i=0; i<charList.Length; i++)
    	{
    		if (charList[i].character == c && c.health > 0)
    			return true;
    	}

    	return false;
    }

    function float getCharacterMarkerTime(Character c)
    {
    	local int i;

    	for (i=0; i<charList.Length; i++)
    	{
    		if (charList[i].character == c)
    			return charList[i].markerTime;
    	}

    	return 0;
    }

    function bool enoughTimeElapsedSinceMarkerTime(Character c, float time, optional bool resetMarkerTimeWhenTrue)
    {
    	local int i;

    	for (i=0; i<charList.Length; i++)
    	{
    		if (charList[i].character == c)
    		{
    			if (Level.TimeSeconds - charList[i].markerTime > time)
    			{
    				if (resetMarkerTimeWhenTrue)
    					charList[i].markerTime = Level.TimeSeconds;
    				return true;
    			}
    			return false;
    		}
    	}

    	return false;
    }

    function Timer()
    {
    	if (listener == None)
    	{
    		// This will be the case if the listener has been destroyed, for example as a result of filtering.
    		// Get rid of the area trigger.
    		SetTimer(0, false);
    		destroy();
    	}
    	else
    		listener.OnAreaTick();
    }

    function setTriggerFrequency(float f)
    {
    	triggerFrequency = f;
    	SetTimer(triggerFrequency, true);
    }

    function int numPlayers(optional TeamInfo searchTeam)
    {
    	local Character Other;
    	local int n, i;

    	// Note that this does *not* count neutral characters
    	for (i=0; i<charList.Length; i++)
    	{
    		Other = charList[i].character;
    		if (Other.team() != None && (searchTeam == None || Other.team() == searchTeam))
    			n++;
    	}
    	return n;
    }

    // Look at all characters inside this trigger.  If there are only characters from a single
    // team, return what that team is.  Otherwise, return None.  Also return None if there's
    // nobody in the trigger.  Consider includeCharacter but don't consider excludeCharacter.
    function TeamInfo onlyRemainingTeam(optional Character includeCharacter, optional Character excludeCharacter)
    {
    	local TeamInfo searchTeam;
    	local Character Other;
    	local int i;

    	if (includeCharacter != None)
    		searchTeam = includeCharacter.team();

    	for (i=0; i<charList.Length; i++)
    	{
    		Other = charList[i].character;

    		//Log("AreaTrigger contains "$Other$" but will exclude "$excludeCharacter);
    		if (Other != excludeCharacter && Other.health > 0)
    		{
    			// Init searchTeam
    			if (searchTeam == None)
    				searchTeam = Other.team();

    			//Log("AreaTrigger comparing "$searchTeam$" to "$Other.team()$" for character "$Other);
    			if (searchTeam != Other.team())
    			{
    				//Log("AreaTrigger found no only remaining team");
    				return None;
    			}
    		}
    	}
    	//Log("AreaTrigger found only remaining team = "$searchTeam);
    	return searchTeam;
    }

    defaultproperties
    {
    	CollisionHeight = 1000
    	CollisionRadius = 1000
    	triggerFrequency = 1
    	playerInAreaEffectEvent		= InArea
    	bCanDeadTriggerExit = true
    }

Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation
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.791 - Created with UnCodeX