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

Engine.MapList


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
//=============================================================================
// MapList.
//
// contains a list of maps to cycle through
//
//=============================================================================
class MapList extends Info
	abstract;

var array<CacheManager.MapRecord> CachedMaps;
var(Maps) protected config array<string> Maps;
var protected config int MapNum;

// When Spawned, removed any list entry that are empty
event PreBeginPlay()
{
	Super.PreBeginPlay();

	class'CacheManager'.static.GetMapList( CachedMaps );
	if ( HasInvalidMaps() )
	{
		MapNum=0;
		SaveConfig();
		Log("MapList had invalid entries!");
	}
}

event PostBeginPlay()
{
	if ( Maps.Length == 0 )
		Warn(Name@"has no maps configured!");

	Super.PostBeginPlay();
}

/*
function GetAllMaps(out string s) // sjs
{
    local int i;

    s = "";
    for( i=0; i<Maps.Length; i++ )
    {
        if( Maps[i] ~= "Entry" )
            continue;
        if( Maps[i] == "" )
            continue;
        if ( s != "" )
        	s $= ",";
        s $= Maps[i];
    }
}
*/
function string GetNextMap()
{
	local MaplistRecord.MapItem Item;
	local array<MaplistRecord.MapItem> ArItem;
	local string CurrentMap;
	local int i;

	CurrentMap = GetURLMap(true);
	if ( CurrentMap == "" )
		i = MapNum;
	else
	{
		// first, try the easy way
		for ( i = 0; i < Maps.Length; i++ )
			if ( CurrentMap ~= Maps[i] )
				break;

		if ( i == Maps.Length )
		{
			// Next check entries that would be the same except for options that have been reversed
			class'MaplistRecord'.static.CreateMapItem( CurrentMap, Item );
			class'MaplistRecord'.static.CreateMapItemList(Maps, ArItem);

			for ( i=0; i<ArItem.Length; i++ )
				if ( class'MaplistRecord'.static.CompareItems(Item,ArItem[i]) )
					break;

			if ( i == ArItem.Length )
			{
//				log("No maplist entries could be found that matched current command line '"$CurrentMap$"' (strict search).  Attempting loose search...",'MaplistManager');

				// Next attempt a really slow comparison
				for ( i = 0; i < ArItem.Length; i++ )
					if ( class'MaplistRecord'.static.CompareItemsSlow(Item,ArItem[i]) )
					{
//						log("Found probable match (loose search): '"$ArItem[i].FullURL$"'",'MaplistManager');
						break;
					}

				// TODO - write a 'find best match' algo
				if ( i == ArItem.Length )
				{
//					log("No maplist entries found matching the current command line (loose search).  Attempting mapname search...",'MaplistManager');

					// Now just attempt to find map names that match
					for ( i = 0; i < ArItem.Length; i++ )
						if ( Item.MapName ~= ArItem[i].MapName )
						{
//							log("Found possible match (mapname search): '"$ArItem[i].FullURL$"'",'MaplistManager');
							break;
						}


					// If no matches were found, prevent the maplist from always looping back the first map
					if ( i == ArItem.Length )
					{
						log("No maplist entries found matching the current command line (mapname search).  Performing blind switch to index "$MapNum + 1@"of current maplist",'MaplistManager');
						return UpdateMapNum(MapNum + 1);
					}
				}
			}
		}
	}

	// search vs. w/ or w/out .unr extension
	return UpdateMapNum(i + 1);
}

function string UpdateMapNum(int NewMapNum)
{
	if ( Maps.Length == 0 )
	{
		Warn("No maps configured for game maplist! Unable to change maps!");
		return "";
	}

	while (true)
	{
		if ( NewMapNum < 0 || NewMapNum >= Maps.Length )
			NewMapNum = 0;

		if ( NewMapNum == MapNum || MapNum < 0 || MapNum >= Maps.Length )
			break;

		if ( FindCacheIndex( Maps[NewMapNum] ) != -1 )
			break;

		NewMapNum++;
	}

	MapNum = NewMapNum;

	// Notify MaplistHandler of the change in current map
	if ( Level.Game.MaplistHandler != None )
		Level.Game.MaplistHandler.MapChange(Maps[MapNum]);

	SaveConfig();
	return Maps[MapNum];
}

function int FindCacheIndex(string MapName)
{
	local int i;
	local string Tmp;

	Tmp = class'MaplistRecord'.static.GetBaseMapName(MapName);
	for ( i = 0; i < CachedMaps.Length; i++ )
		if ( CachedMaps[i].MapName ~= Tmp )
			return i;

	return -1;
}

function string GetMap( int MapIndex )
{
	if ( MapIndex < 0 || MapIndex >= Maps.Length )
		return "";

	return Maps[MapIndex];
}

function array<string> GetMaps()
{
	if ( HasInvalidMaps() )
	{
		MapNum = 0;
		SaveConfig();
	}

	return Maps;
}

static function array<string> StaticGetMaps()
{
	if ( StaticHasInvalidMaps() )
	{
		default.MapNum = 0;
		StaticSaveConfig();
	}

	return default.Maps;

}

function bool HasInvalidMaps(optional bool bReadOnly)
{
	local int i;
	local bool bInvalid;

	for ( i = Maps.Length - 1; i >= 0; i-- )
	{
		if ( Maps[i] == "" )
		{
			bInvalid = True;
			if ( !bReadOnly )
				Maps.Remove(i,1);
		}

		else if ( FindCacheIndex(Maps[i]) == -1 )
		{
			bInvalid = True;
			if ( !bReadOnly )
				Maps.Remove(i,1);
		}
	}

	return bInvalid;
}

static function bool StaticHasInvalidMaps(optional bool bReadOnly)
{
	local int i, j;
	local bool bInvalid;
	local array<CacheManager.MapRecord> Recs;
	local string URL, MapName;

	class'CacheManager'.static.GetMapList(Recs);

	for ( i = default.Maps.Length - 1; i >= 0; i-- )
	{
		if ( default.Maps[i] == "" )
		{
			bInvalid = True;
			if ( !bReadOnly )
				default.Maps.Remove(i,1);
		}

		else
		{
			URL = default.Maps[i];
			MapName = class'MaplistRecord'.static.GetBaseMapName(URL);
			for ( j = 0; j < Recs.Length; j++ )
				if ( Recs[j].MapName ~= MapName )
					break;

			if ( j == Recs.Length )
			{
				bInvalid = True;
				if ( !bReadOnly )
					default.Maps.Remove(i,1);
			}
		}
	}

	return bInvalid;
}

static function bool SetMaplist( int CurrentNum, array<string> NewMaps )
{
	if ( CurrentNum >= NewMaps.Length )
		CurrentNum = 0;

	default.MapNum = CurrentNum;
	default.Maps   = NewMaps;

	StaticSaveConfig();
	return True;
}


Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Di 5.9.2006 22:28:42.000 - Creation time: Do 14.8.2014 09:58:44.044 - Created with UnCodeX