Skip to content

Commit

Permalink
Fix random map choosing same maps
Browse files Browse the repository at this point in the history
  • Loading branch information
peterekepeter committed Aug 23, 2023
1 parent bb40b8c commit c35bc34
Show file tree
Hide file tree
Showing 7 changed files with 344 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class MapListReader extends Info;
class FsMapsReader extends Info;

var int iSeek;
var String FirstMap;
Expand Down
155 changes: 95 additions & 60 deletions MVES/Classes/MV_MapList.uc
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ var config string M[16384];

var string MapListString; //Send this over the net!
var MapHistory History;
var MapListReader Reader;
var FsMapsReader Reader;

event PostBeginPlay()
{
History = new(self) class'MapHistory';
History.MapList = self;
History = new(Self) class'MapHistory';
History.MapList = Self;
}

//We scan all maps, check if they match our filters
Expand All @@ -63,7 +63,7 @@ function GlobalLoad(bool bFullscan)
Mutator.CleanRules();
Mutator.CountFilters();
if ( Mutator.ServerCodeName == '' )
Mutator.SetPropertyText("ServerCodeName",string(rand(MaxInt)) $ string(rand(MaxInt)) );
Mutator.SetPropertyText("ServerCodeName",string(rand(MaxInt))$string(rand(MaxInt)) );
CacheCodes();
iMapList = 0;

Expand All @@ -77,13 +77,13 @@ function GlobalLoad(bool bFullscan)
}
if ( Mutator.HasRandom(i) )
{
CurRules = CurRules $ ":" $ TwoDigits(i);
CurRules = CurRules$":"$TwoDigits(i);
}
}

if ( CurRules != "" )
{
MapList[iMapList] = "Random" $ CurRules $ ";";
MapList[iMapList] = "Random"$CurRules$";";
iMapList ++ ;
PrevRules = CurRules;
}
Expand Down Expand Up @@ -146,7 +146,7 @@ function GlobalLoad(bool bFullscan)
iLen = Len( TmpCodes[i]);
for ( j = FStart[i] ; j < FEnd[i] ; j ++ )
{
if ( ! (Left( Mutator.GetMapFilter(j), iLen) ~= TmpCodes[i]) ) //Check that this IS a filter for this gamemode
if (! (Left( Mutator.GetMapFilter(j), iLen) ~= TmpCodes[i]) ) //Check that this IS a filter for this gamemode
continue;
sTest = Mid( Mutator.GetMapFilter(j), iLen);
if ( Mutator.bEnableMapTags && InStr(sTest, ":") == 0 ) //Tag match
Expand Down Expand Up @@ -181,7 +181,7 @@ function GlobalLoad(bool bFullscan)
}

if ( bAddTag )
CurRules = CurRules $ GameTags[i];
CurRules = CurRules$GameTags[i];
}
if ( CurRules != "" )
{
Expand All @@ -190,11 +190,11 @@ function GlobalLoad(bool bFullscan)
Maps[ iMaps ++ ] = ClearMap;
if (CurRules == PrevRules)
{
MapList[ iMapList ] = ClearMap $ ";";
MapList[ iMapList ] = ClearMap$";";
}
else
{
MapList[ iMapList ] = ClearMap $ CurRules $ ";";
MapList[ iMapList ] = ClearMap$CurRules$";";
}
iMapList ++ ;
PrevRules = CurRules;
Expand All @@ -204,15 +204,15 @@ function GlobalLoad(bool bFullscan)
Log("[MVE] Remove old + add new maps...");
NewMaps = ":";
for (i = 0; i < iMaps; i ++ )
NewMaps = NewMaps $ Maps[i] $ ":";
NewMaps = NewMaps$Maps[i]$":";
ClearMap = ":";
j = 0;
for (i = 0; i < iM; i ++ )
{
if (InStr(NewMaps, ":" $ M[i] $ ":") != -1)
if (InStr(NewMaps, ":"$M[i]$":") != -1)
{
ClearMap = ClearMap $ M[i] $ ":";
ClearMap = ClearMap$M[i]$":";
if (i != j)
M[j] = M[i];
j ++ ;
Expand All @@ -222,7 +222,7 @@ function GlobalLoad(bool bFullscan)

for (i = 0; i < iMaps; i ++ )
{
if (InStr(ClearMap, ":" $ Maps[i] $ ":") == -1)
if (InStr(ClearMap, ":"$Maps[i]$":") == -1)
M[j ++ ] = Maps[i];
}
iM = j;
Expand All @@ -231,12 +231,12 @@ function GlobalLoad(bool bFullscan)

ClearMap = ":";
for (i = 0; i < iMapList; i ++ )
ClearMap = ClearMap $ Left(MapList[i], InStr(MapList[i], ":")) $ ":" $ i $ ":";
ClearMap = ClearMap$Left(MapList[i], InStr(MapList[i], ":"))$":"$i$":";

for (j = 0; j < ArrayCount(iNewMaps) && iM - j > 0; j ++ )
{
NewMaps = M[iM - j - 1];
k = InStr(ClearMap, ":" $ NewMaps $ ":");
k = InStr(ClearMap, ":"$NewMaps$":");
if (k == -1)
{
iNewMaps[j] = 0;
Expand All @@ -258,11 +258,11 @@ function GlobalLoad(bool bFullscan)
for ( j = FStart[i] ; j < FEnd[i] ; j ++ )
{
//Check that this IS a filter for this gamemode
if ( ! (Left( Mutator.GetMapFilter(j), iLen) ~= TmpCodes[i]) )
if (! (Left( Mutator.GetMapFilter(j), iLen) ~= TmpCodes[i]) )
{
continue;
}
MapList[iMapList] = Mid( Mutator.GetMapFilter(j), iLen) $ GameTags[i] $ ";";
MapList[iMapList] = Mid( Mutator.GetMapFilter(j), iLen)$GameTags[i]$";";
iMapList ++ ;
}
}
Expand Down Expand Up @@ -330,18 +330,18 @@ function CacheCodes()

for ( i = 0 ; i < Mutator.iGames ; i ++ )
{
tmpCode = Mutator.MutatorCode(i) $ " ";
tmpCode = Mutator.MutatorCode(i)$" ";
if ( tmpCode != " " )
{
for ( j = 0 ; j < k ; j ++ )
if ( TmpCodes[j] == tmpCode )
{
GameTags[j] = GameTags[j] $ ":" $ TwoDigits(i);
GameTags[j] = GameTags[j]$":"$TwoDigits(i);
goto END_LOOP;
}
if ( Left(tmpCode,7) ~= "premade" )
IsPremade[k] = 1;
GameTags[k] = ":" $ TwoDigits(i);
GameTags[k] = ":"$TwoDigits(i);
TmpCodes[k ++ ] = tmpCode;
}
END_LOOP:
Expand Down Expand Up @@ -418,15 +418,15 @@ function EnumerateGames()
if ( TmpGameName[j] ~= gameName )
{
// add to existing rule from RuleList
RuleList[j] = RuleList[j] $ ":" $ TwoDigits(i);
RuleList[j] = RuleList[j]$":"$TwoDigits(i);
found = True;
}
}
if (!found)
{
// add new entry into RuleList
TmpGameName[iRules] = gameName;
RuleList[iRules] = ":" $ TwoDigits(i);
RuleList[iRules] = ":"$TwoDigits(i);
iRules ++ ;
}
}
Expand Down Expand Up @@ -483,7 +483,7 @@ function bool IsValidMap( out string MapString, out string reason )
{
// found!
// normalize string for voting stage
MapString = Left(MapList[i], iLen) $ ":" $ GameIdx;
MapString = Left(MapList[i], iLen)$":"$GameIdx;
// TODO check if map on coldown
// TODO check if map in crashed state
return True;
Expand Down Expand Up @@ -548,26 +548,26 @@ function GenerateString()
local string S;

for ( i = 0 ; i < iRules ; i ++ )
MapListString = MapListString $ "RuleList[" $ string(i) $ "]=" $ RuleList[i] $ chr(13);
MapListString = MapListString$"RuleList["$string(i)$"]="$RuleList[i]$chr(13);
for ( i = 0 ; i < iGameC ; i ++ )
{
if ( GameNames[i] != "" )
{
j ++ ;
MapListString = MapListString $ "GameModeName[" $ string(i) $ "]=" $ GameNames[i] $ chr(13)
$ "RuleName[" $ string(i) $ "]=" $ RuleNames[i] $ chr(13)
$ "VotePriority[" $ string(i) $ "]=" $ string(VotePriority[i]) $ chr(13);
MapListString = MapListString$"GameModeName["$string(i)$"]="$GameNames[i]$chr(13)
$"RuleName["$string(i)$"]="$RuleNames[i]$chr(13)
$"VotePriority["$string(i)$"]="$string(VotePriority[i])$chr(13);
}
}
GameCount = j; //HACK FIX

for ( i = 0 ; i < iMapList ; i ++ )
MapListString = MapListString $ "MapList[" $ string(i) $ "]=" $ MapList[i] $ chr(13);
MapListString = MapListString$"MapList["$string(i)$"]="$MapList[i]$chr(13);

MapListString = MapListString
$ "MapCount=" $ string(iMapList) $ chr(13)
$ "RuleListCount=" $ string(iRules) $ chr(13)
$ "RuleCount=" $ string(GameCount) $ chr(13);
$"MapCount="$string(iMapList)$chr(13)
$"RuleListCount="$string(iRules)$chr(13)
$"RuleCount="$string(GameCount)$chr(13);
GenerateCode();
}
Expand All @@ -589,7 +589,7 @@ function GenerateCode()
}
i ++ ;
}
LastUpdate = class'MV_MainExtension'.static.NumberToByte(K) $ class'MV_MainExtension'.static.NumberToByte(j);
LastUpdate = class'MV_MainExtension'.static.NumberToByte(K)$class'MV_MainExtension'.static.NumberToByte(j);
}
function string GetStringSection( string StartsFrom)
Expand All @@ -611,9 +611,9 @@ function string GetStringSection( string StartsFrom)
Result = Left( Result, Len(Result) -1);

if (!bNext )
return "[START]" $ chr(13) $ Result $ "[END]" $ chr(13) $ "[NEXT]" $ chr(13);
return "[START]"$chr(13)$Result$"[END]"$chr(13)$"[NEXT]"$chr(13);
//Notify END of list, add the "[X]" on individual map entries!
return "[START]" $ chr(13) $ Result $ "[NEXT]" $ chr(13) $ "[END]" $ chr(13);
return "[START]"$chr(13)$Result$"[NEXT]"$chr(13)$"[END]"$chr(13);
}

function string RemoveExtension( string aStr)
Expand All @@ -639,15 +639,10 @@ function string RemoveExtension( string aStr)
function string TwoDigits( int i)
{
if ( i < 10 )
return "0"$ string(i);
return "0"$string(i);
return string(i);
}

final function string MapName( int i)
{
return class'MV_MainExtension'.static.ByDelimiter(MapList[i],":");
}
final function string MapGames( int i)
{
return Mid(MapList[i], InStr( MapList[i], ":") + 1);
Expand All @@ -673,34 +668,74 @@ final function bool IsEdited( int i)
return MapList[i] != default.MapList[i];
}

final function string RandomMap( int Game)
final function string RandomMap( int gameIdx, int forPlayerCount )
{
local int MaxRandom, i, iRandom;
local string GameString, Result;
GameString = ":" $ TwoDigits( Game);
MaxRandom = 1;
for ( i = 1 ; i < iMapList ; i ++ )
local MapListDecoder decoder;
local int i, j, code;
local string result;
local string options[4096];
local string bestResult;
local string levelString;
local MapVoteResult map;
local int bestScore, resultScore;
local int count, idealPlayers, delta;

decoder = new class'MapListDecoder';
count = 0;

for (i = 0; i < iMapList; i+=1)
{
if ( (InStr( MapList[i], GameString) > 0) && (Left(MapList[i], 3) != "[X]") )
decoder.L[i] = MapList[i];
while (decoder.ReadEntry(result))
{
if ( Rand(MaxRandom ++ ) == 0 )
Result = MapList[i];
while (decoder.ReadCode(code)) {
if (code == gameIdx )
{
options[count] = result;
count += 1;
continue;
}
}
}
}
if ( Result != "" )
return class'MV_MainExtension'.static.ByDelimiter(Result,":");
//All maps red?
MaxRandom = 1;
for ( i = 1 ; i < iMapList ; i ++ )

levelString = ""$decoder;
decoder.Parse(levelString, ".", levelString);
bestScore = -1000;
for (i = 0; i < 10; i += 1)
{
if ( (InStr( MapList[i], GameString) > 0) )
result = options[(Rand(count) + gameIdx * 7 + count * 13) % count];
resultScore = 0;
map = class'MapVoteResult'.static.Create(result, gameIdx);
if (result ~= "Random")
{
resultScore -= 100;
}
else if (!map.CanMapBeLoaded())
{
resultScore -= 100;
}
else if (forPlayerCount >= 0)
{
idealPlayers = map.GetAvgIdealPlayerCount();
if (idealPlayers >= 0)
{
delta = forPlayerCount - idealPlayers;
if (delta < 0)
{
delta = -delta;
}
resultScore += 32 - delta;
}
}
if (result ~= levelString) resultScore -= 10;
if (bestScore <= resultScore)
{
if ( Rand(MaxRandom ++ ) == 0 )
Result = MapList[i];
bestResult = result;
bestScore = resultScore;
}
}
return class'MV_MainExtension'.static.ByDelimiter(Result,":");
return bestResult;
}

final simulated function float GetVotePriority( int Idx)
Expand Down
Loading

0 comments on commit c35bc34

Please sign in to comment.