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

Gameplay.Utility


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
// Utility class with useful stuff!

class Utility extends Core.Object;// config(Utility);

struct LevelData
{
    var /*config*/ string name;                     // level name "MP-Fort"
    var /*config*/ string title;                    // level title (can be untitled)
    var /*config*/ int checksum;                    // level checksum (used to detect level changes)
    var /*config*/ array<string> gameTypes;         // supported game types in this level ["CTF", "Fuel", "DeathMatch"]
};

var /*config*/ array<LevelData> levels;             // cached list of data for levels

struct GameData
{
    var /*config*/ string name;                     // name of game type "CTF"
    var /*config*/ string className;                // name of game info class "GameClasses.ModeCTF"
};

var /*config*/ array<GameData> gameTypes;           // cached list of game types supported in list of levels

struct LevelsForGameType
{
    var string gameType;                            // game type name "CTF"
    var array<LevelData> levels;                    // list of level names that support this game type
};

var /*config*/ array<LevelsForGameType> gameTypeLevels;

var bool initialized;                   // temporary: so we only scan levels once to extract the required data (slow)


static function load()
{
    // load cached level data
    
    ResetConfig();
}

static function smartRefresh()
{
    // refresh cached data only if we need to
    
    if (!default.initialized)
    {
        refresh();
        default.initialized = true;
    }
}

static function refresh()
{
    // scan levels and extract important information
                       
    local int i, j, k, index;
    local bool match;
    local string gameType;
    local string gameClass;
    local array<string> files;
    local array<LevelSummary> data;
    
    scanLevels(files, data);

    default.levels.length = files.length;

    for (i=0; i<files.length; i++)
    {
        default.levels[i].name = files[i];
        default.levels[i].title = data[i].title;
        default.levels[i].checksum = 0;                 // todo: store checksum in level summary!
        
		for (j=0; j<data[i].SupportedModes.length; j++)
		{
			if (data[i].supportedModes[j]!=None)
			{
			    // add game type to the list of supported game types for this level if it is unique (duplicates in source array)
			
			    gameType = data[i].supportedModes[j].default.acronym;
			    gameClass = string(data[i].supportedModes[j]);
			    
			    match = false;
			    
			    for (k=0; k<default.levels[i].gameTypes.length; k++)
			    {
					if (default.levels[i].gameTypes[k] == gameType)
					{
				        match = true;
						break;
					}
			    }
			    
			    if (!match)
				{
                    default.levels[i].gameTypes[default.levels[i].gameTypes.length] = gameType;
				}

                // and if this is a new game type then add it to the global list

                match = false;

                for (k=0; k<default.gameTypes.length; k++)
                {
                    if (gameType==default.gameTypes[k].name)
                    {
                        match = true;
                        break;
                    }
                }
                
                if (!match)
                {
                    index = default.gameTypes.length;
                    default.gameTypes.length = index + 1;
                    default.gameTypes[index].name = gameType;
                    default.gameTypes[index].className = gameClass;
                }
            }
		}
    }

    // generate the list of levels for each game type
    
    default.gameTypeLevels.length = default.gameTypes.length;
    
    for (i=0; i<default.gameTypes.length; i++)
    {
        default.gameTypeLevels[i].gameType = default.gameTypes[i].name;
        
        // find set of levels that support this game type
        
        for (j=0; j<default.levels.length; j++)
        {
            for (k=0; k<default.levels[j].gameTypes.length; k++)
            {
                gameType = default.levels[j].gameTypes[k];
                
                if (gameType==default.gameTypes[i].name)
                {
                    // level supports this game type
                    default.gameTypeLevels[i].levels[default.gameTypeLevels[i].levels.length] = default.levels[j];
                }
            }    
        }
    }
}

static function save()
{
    // save cached level data
    
    StaticSaveConfig();
}

static function getGameTypeList(out array<GameData> gameTypeNames)
{
    gameTypeNames = default.gameTypes;
}

static function getLevelList(out array<string> levelNames, optional bool bPreferTitles)
{
    local int i;
    
    for (i=0; i<default.levels.length; i++)
	{
		if (bPreferTitles && default.levels[i].title != "Untitled")
			levelNames[i] = default.levels[i].title;
		else
	        levelNames[i] = default.levels[i].name;
	}
}

static function getLevelListForGameType(string gameType, out array<string> levels, optional bool bPreferTitles)
{
    local int i, j;
	local array<string> levelList;
	local string mapTitle, mapFilename;
	
	if (gameType=="")
	    getLevelList(levels, bPreferTitles);

    for (i=0; i<default.gameTypeLevels.length; i++)
    {
        if (gameType==default.gameTypeLevels[i].gameType)
        {
			for (j=0; j<default.gameTypeLevels[i].levels.Length; j++)
			{
				mapTitle = default.gameTypeLevels[i].levels[j].title;
				mapFilename = default.gameTypeLevels[i].levels[j].name;

				if (bPreferTitles && mapTitle != "Untitled")
					levelList[levelList.Length] = mapTitle;
				else
					levelList[levelList.Length] = mapFilename;
			}
			levels = levelList;
            break;
        }
    }
}

static function string getGameTypeFromGameClassName(string gameClass)
{
    local int i;

    for (i=0; i<default.gameTypes.length; i++)
    {
        if (gameClass==default.gameTypes[i].className)
            return default.gameTypes[i].name;
    }
}

static function getMutatorList(Engine.LevelInfo level, out array<string> mutators)
{
    local string nextMutator;
    local string nextDescription;

	level.GetNextIntDesc("Engine.Mutator", 0, nextMutator, nextDescription);     // todo: Gameplay.Mutator

	mutators.length = 0;
	
	while (nextMutator!="")
	{	
		mutators[mutators.Length] = nextMutator;

		level.GetNextIntDesc("Engine.Mutator", mutators.length, nextMutator, nextDescription);
	}
	
	// TODO: mutator list is not correct
}

// internal functions

private static function scanLevels(out array<String> files, out array<LevelSummary> levels)
{
	local int i;
	local LevelSummary level;
	local string firstlevel, nextlevel, testlevel, loadlevel;

	// get list of level filenames matching MP-*
	
	firstlevel = class'Actor'.static.GetMapName("MP-", "", 0);
	nextlevel = firstlevel;

	while (!(firstlevel ~= testlevel))
	{
		if (Right(nextlevel, 4) ~= ".tvm")
			loadlevel = Left(nextlevel, Len(nextlevel) - 4);
		else
			loadlevel = nextlevel;

		nextlevel = class'Actor'.static.GetMapName("MP-", nextlevel, 1);
		testlevel = nextlevel;

		if (loadlevel != "")
			files[files.length] = loadlevel;
	}

	// Now load the actual LevelSummaries (potentially slow)
	
	for (i=0; i<files.length; i++)
	{
		level = LevelSummary(DynamicLoadObject(files[i]$".LevelSummary", class'LevelSummary'));

		if (level==None)
			continue;

		levels[levels.length] = level;
	}

    assert(files.length==levels.length);
}
            

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