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

Engine.OnlineRecentPlayersList


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
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
/**
 * Copyright 1998-2011 Epic Games, Inc. All Rights Reserved.
 */

/**
 * This class holds a list of players met online that the players on this PC/console
 * encountered. It does not persist the list. Both parties and individuals are tracked
 * with the individuals containing all party members. Note that it only holds the
 * unique ids of the players.
 */
class OnlineRecentPlayersList extends Object
	config(Engine);

/** The set of players that players on this PC/console have recently encountered */
var array<UniqueNetId> RecentPlayers;

/** Holds a set of players that made up a party */
struct RecentParty
{
	/** The player that was the party leader */
	var UniqueNetid PartyLeader;
	/** The list of players that comprise the party (should include the leader) */
	var array<UniqueNetId> PartyMembers;
};

/** The list of recent parties that the players on this PC/console has encountered */
var array<RecentParty> RecentParties;

/** Holds the information about the last party that a player on this pc/console was in */
var RecentParty LastParty;

/** The size of the recent player list to allow before losing the oldest entries */
var config int MaxRecentPlayers;

/** The size of the recent party list to allow before losing the oldest entries */
var config int MaxRecentParties;

/** The position in the array that new players should be added at */
var int RecentPlayersAddIndex;

/** The position in the array that new parties should be added at */
var int RecentPartiesAddIndex;

/** The set of people that the player/PC/console are currently playing with/against */
struct CurrentPlayerMet
{
	/** The team the player is on */
	var int TeamNum;
	/** The skill rating of the player */
	var int Skill;
	/** The unique net id for the player */
	var UniqueNetId NetId;
};

/** Holds the list of current players (the set of players currently in a session */
var private array<CurrentPlayerMet> CurrentPlayers;

/**
 * Adds a player to the recent players list
 *
 * @param NewPlayer the player being added
 */
function AddPlayerToRecentPlayers(UniqueNetId NewPlayer)
{
	local int FindIndex;

	// Search the list of players for this one and only add if not present
	FindIndex = RecentPlayers.Find('Uid',NewPlayer.Uid);
	if (FindIndex == INDEX_NONE)
	{
		// Wrap back to the oldest entry if we've hit our max
		if (RecentPlayersAddIndex >= MaxRecentPlayers)
		{
			RecentPlayersAddIndex = 0;
		}
		// Make sure the array has space
		if (RecentPlayersAddIndex + 1 >= RecentPlayers.Length)
		{
			RecentPlayers.Length = RecentPlayersAddIndex + 1;
		}
		RecentPlayers[RecentPlayersAddIndex] = NewPlayer;
		// Move to the next available slot. This will wrap to zero if it grows too large
		RecentPlayersAddIndex++;
	}
}

/** Clears the recent players list and resets the add index */
function ClearRecentPlayers()
{
	RecentPlayersAddIndex = 0;
	RecentPlayers.Length = 0;
}

/**
 * Adds a player to the recent players list
 *
 * @param PartyLeader the player being added
 * @param PartyMembers the members of the party
 */
function AddPartyToRecentParties(UniqueNetId PartyLeader,const out array<UniqueNetId> PartyMembers)
{
	local int FindIndex;

	// Search the list of parties for the leader and only add if not present
	FindIndex = RecentParties.Find('PartyLeader',PartyLeader);
	if (FindIndex == INDEX_NONE)
	{
		// Wrap back to the oldest entry if we've hit our max
		if (RecentPartiesAddIndex >= MaxRecentParties)
		{
			RecentPartiesAddIndex = 0;
		}
		// Make sure the array has space
		if (RecentPartiesAddIndex + 1 >= RecentParties.Length)
		{
			RecentParties.Length = RecentPartiesAddIndex + 1;
		}
		RecentParties[RecentPartiesAddIndex].PartyLeader = PartyLeader;
		RecentParties[RecentPartiesAddIndex].PartyMembers = PartyMembers;
		// Move to the next available slot. This will wrap to zero if it grows too large
		RecentPartiesAddIndex++;
	}
}

/** Clears the recent parties list and resets the add index */
function ClearRecentParties()
{
	RecentPartiesAddIndex = 0;
	RecentParties.Length = 0;
}

/**
 * Builds a single list of players from the recent parties list
 *
 * @param Players the array getting the data copied into it
 */
function GetPlayersFromRecentParties(out array<UniqueNetId> Players)
{
	local int PartyIndex;
	local int MemberIndex;
	local int AddMemberAt;

	Players.Length = 0;
	AddMemberAt = 0;
	// Look at each registered party and add them for showing
	for (PartyIndex = 0; PartyIndex < RecentParties.Length; PartyIndex++)
	{
		for (MemberIndex = 0; MemberIndex < RecentParties[PartyIndex].PartyMembers.Length; MemberIndex++)
		{
			Players.Length = AddMemberAt + 1;
			Players[AddMemberAt] = RecentParties[PartyIndex].PartyMembers[MemberIndex];
		}
	}
}

/**
 * Builds a single list of players from the current players list
 *
 * @param Players the array getting the data copied into it
 */
function GetPlayersFromCurrentPlayers(out array<UniqueNetId> Players)
{
	local int PlayerIndex;

	Players.Length = 0;
	// Look at each registered party and add them for showing
	for (PlayerIndex = 0; PlayerIndex < CurrentPlayers.Length; PlayerIndex++)
	{
		Players.AddItem(CurrentPlayers[PlayerIndex].NetId);
	}
}

/**
 * Finds the player indicated and returns their skill rating
 *
 * @param Player the player to search for
 *
 * @return the skill for the specified player
 */
function int GetSkillForCurrentPlayer(UniqueNetId Player)
{
	local int PlayerIndex;

	// Search for the specified player and return their skill
	for (PlayerIndex = 0; PlayerIndex < CurrentPlayers.Length; PlayerIndex++)
	{
		if (CurrentPlayers[PlayerIndex].NetId == Player)
		{
			return CurrentPlayers[PlayerIndex].Skill;
		}
	}
	return 0;
}

/**
 * Finds the player indicated and returns their team that was assigned
 *
 * @param Player the player to search for
 *
 * @return the team number for the specified player
 */
function int GetTeamForCurrentPlayer(UniqueNetId Player)
{
	local int PlayerIndex;

	// Search for the specified player and return their team number
	for (PlayerIndex = 0; PlayerIndex < CurrentPlayers.Length; PlayerIndex++)
	{
		if (CurrentPlayers[PlayerIndex].NetId == Player)
		{
			return CurrentPlayers[PlayerIndex].TeamNum;
		}
	}
	return 255;
}

/**
 * Adds a player to the recent players list
 *
 * @param PartyLeader the player being added
 * @param PartyMembers the members of the party
 */
function SetLastParty(UniqueNetId PartyLeader,const out array<UniqueNetId> PartyMembers)
{
	LastParty.PartyLeader = PartyLeader;
	LastParty.PartyMembers = PartyMembers;
}

/**
 * Helper function for showing the recent players list
 *
 * @param LocalUserNum the controller number of the associated user
 * @param Title the title to use for the UI
 * @param Description the text to show at the top of the UI
 *
 * @return TRUE if it was able to show the UI, FALSE if it failed
 */
function bool ShowRecentPlayerList(byte LocalUserNum,string Title,string Description)
{
	local OnlineSubsystem OnlineSub;

	OnlineSub = class'GameEngine'.static.GetOnlineSubsystem();
	if (OnlineSub != None &&
		OnlineSub.PlayerInterfaceEx != None)
	{
		// Use the custom UI list to display them
		return OnlineSub.PlayerInterfaceEx.ShowCustomPlayersUI(LocalUserNum,RecentPlayers,Title,Description);
	}
	return false;
}

/**
 * Builds a single player list out of the various parties encountered and shows
 *
 * @param LocalUserNum the controller number of the associated user
 * @param Title the title to use for the UI
 * @param Description the text to show at the top of the UI
 *
 * @return TRUE if it was able to show the UI, FALSE if it failed
 */
function bool ShowRecentPartiesPlayerList(byte LocalUserNum,string Title,string Description)
{
	local OnlineSubsystem OnlineSub;
	local array<UniqueNetId> Players;

	OnlineSub = class'GameEngine'.static.GetOnlineSubsystem();
	if (OnlineSub != None &&
		OnlineSub.PlayerInterfaceEx != None)
	{
		GetPlayersFromRecentParties(Players);
		// Use the custom UI list to display them
		return OnlineSub.PlayerInterfaceEx.ShowCustomPlayersUI(LocalUserNum,Players,Title,Description);
	}
	return false;
}

/**
 * Shows the last party that you were in as a player list
 *
 * @param LocalUserNum the controller number of the associated user
 * @param Title the title to use for the UI
 * @param Description the text to show at the top of the UI
 *
 * @return TRUE if it was able to show the UI, FALSE if it failed
 */
function bool ShowLastPartyPlayerList(byte LocalUserNum,string Title,string Description)
{
	local OnlineSubsystem OnlineSub;

	OnlineSub = class'GameEngine'.static.GetOnlineSubsystem();
	if (OnlineSub != None &&
		OnlineSub.PlayerInterfaceEx != None)
	{
		// Use the custom UI list to display them
		return OnlineSub.PlayerInterfaceEx.ShowCustomPlayersUI(LocalUserNum,LastParty.PartyMembers,Title,Description);
	}
	return false;
}

/**
 * Builds a single player list out of the players in the current players list
 *
 * @param LocalUserNum the controller number of the associated user
 * @param Title the title to use for the UI
 * @param Description the text to show at the top of the UI
 *
 * @return TRUE if it was able to show the UI, FALSE if it failed
 */
function bool ShowCurrentPlayersList(byte LocalUserNum,string Title,string Description)
{
	local OnlineSubsystem OnlineSub;
	local array<UniqueNetId> Players;

	OnlineSub = class'GameEngine'.static.GetOnlineSubsystem();
	if (OnlineSub != None &&
		OnlineSub.PlayerInterfaceEx != None)
	{
		GetPlayersFromCurrentPlayers(Players);
		// Use the custom UI list to display them
		return OnlineSub.PlayerInterfaceEx.ShowCustomPlayersUI(LocalUserNum,Players,Title,Description);
	}
	return false;
}

`if(`notdefined(FINAL_RELEASE))
/** Log list of players for debugging */
function DumpPlayersList(const out array<CurrentPlayerMet> Players)
{
	local OnlineSubsystem OnlineSub;
	local int PlayerIdx;
	local UniqueNetId NetId;

	OnlineSub = class'GameEngine'.static.GetOnlineSubsystem();
	if (OnlineSub != None)
	{
		for (PlayerIdx=0; PlayerIdx<Players.Length; PlayerIdx++)
		{
			NetId = Players[PlayerIdx].NetId;
			`Log("DumpPlayersList: "
				$" PlayerIdx="$PlayerIdx
				$" UniqueId="$OnlineSub.UniqueNetIdToString(NetId)
				,,'DevOnline');
		}
	}
}
`endif

/**
 * Sets the current player list to the data specified
 *
 * @param Players the list of players to copy
 */
function SetCurrentPlayersList(const array<CurrentPlayerMet> Players)
{
`if(`notdefined(FINAL_RELEASE))
	DumpPlayersList(Players);
`endif
	CurrentPlayers = Players;
}

/** @return the number of players in the current player session */
function int GetCurrentPlayersListCount()
{
	return CurrentPlayers.Length;
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: to 6-1-2011 07:10:46.000 - Creation time: ti 22-3-2011 19:57:08.883 - Created with UnCodeX