Browse Source

Change how map lists work

This patch enables support of per-game mode lists
pull/2/head
Anton Tarasenko 2 years ago
parent
commit
36aed1a2d3
  1. 1
      sources/AcediaLauncherMut.uc
  2. 5
      sources/GameModes/BaseGameMode.uc
  3. 1
      sources/StartUp.uc
  4. 153
      sources/VotingHandlerAdapter.uc

1
sources/AcediaLauncherMut.uc

@ -46,7 +46,6 @@ simulated function PreBeginPlay()
} }
if (votingAdapter != none) { if (votingAdapter != none) {
votingAdapter.InjectIntoVotingHandler(); votingAdapter.InjectIntoVotingHandler();
votingAdapter.TrySetupMapList();
} }
SetupMutatorSignals(); SetupMutatorSignals();
} }

5
sources/GameModes/BaseGameMode.uc

@ -431,6 +431,11 @@ public function array<Text> GetIncludedMutators()
return StringToTextArray(validatedMutators); return StringToTextArray(validatedMutators);
} }
public function array<Text> GetIncludedMapLists()
{
return StringToTextArray(includeMaps);
}
defaultproperties defaultproperties
{ {
configName = "AcediaGameModes" configName = "AcediaGameModes"

1
sources/StartUp.uc

@ -61,6 +61,7 @@ private function InitializeServer()
_ = class'Global'.static.GetInstance(); _ = class'Global'.static.GetInstance();
_server = class'ServerGlobal'.static.GetInstance(); _server = class'ServerGlobal'.static.GetInstance();
class'ServerLevelCore'.static.CreateLevelCore(self); class'ServerLevelCore'.static.CreateLevelCore(self);
class'MapList'.static.Initialize();
for (i = 0; i < class'Packages'.default.package.length; i += 1) { for (i = 0; i < class'Packages'.default.package.length; i += 1) {
_.environment.RegisterPackage_S(class'Packages'.default.package[i]); _.environment.RegisterPackage_S(class'Packages'.default.package[i]);
} }

153
sources/VotingHandlerAdapter.uc

@ -66,6 +66,9 @@ var private NativeActorRef votingHandlerReference;
// otherwise Acedia will alter its config // otherwise Acedia will alter its config
var private array<VotingHandler.MapVoteGameConfig> backupVotingHandlerConfig; var private array<VotingHandler.MapVoteGameConfig> backupVotingHandlerConfig;
// Maps map pseudonims we've used in voting handler to real map names
var private HashTable pseudonimToMap;
// Setting value of this flag to `true` indicates that map switching just // Setting value of this flag to `true` indicates that map switching just
// occurred and we need to recover some information from the previous map. // occurred and we need to recover some information from the previous map.
var private config bool isServerTraveling; var private config bool isServerTraveling;
@ -88,7 +91,7 @@ var private const array<string> normalSynonyms;
var private const array<string> longSynonyms; var private const array<string> longSynonyms;
var private LoggerAPI.Definition fatNoXVotingHandler, fatBadGameConfigIndexVH; var private LoggerAPI.Definition fatNoXVotingHandler, fatBadGameConfigIndexVH;
var private LoggerAPI.Definition fatBadGameConfigIndexAdapter; var private LoggerAPI.Definition fatBadGameConfigIndexAdapter, warnMissingMapList;
protected function Finalizer() protected function Finalizer()
{ {
@ -103,10 +106,10 @@ protected function Finalizer()
* Backup of replaced configs is made internally, so that they can be restored * Backup of replaced configs is made internally, so that they can be restored
* on map change. * on map change.
*/ */
// TODO ADD ME!
public final function InjectIntoVotingHandler() public final function InjectIntoVotingHandler()
{ {
local int i; local int i;
local string nextGameModePrefix;
local GameMode nextGameMode; local GameMode nextGameMode;
local XVotingHandler votingHandler; local XVotingHandler votingHandler;
local array<VotingHandler.MapVoteGameConfig> newVotingHandlerConfig; local array<VotingHandler.MapVoteGameConfig> newVotingHandlerConfig;
@ -121,13 +124,17 @@ public final function InjectIntoVotingHandler()
_.logger.Auto(fatNoXVotingHandler); _.logger.Auto(fatNoXVotingHandler);
return; return;
} }
pseudonimToMap = _.collections.EmptyHashTable();
votingHandlerReference = _server.unreal.ActorRef(votingHandler); votingHandlerReference = _server.unreal.ActorRef(votingHandler);
availableGameModes = class'GameMode'.static.AvailableConfigs(); availableGameModes = class'GameMode'.static.AvailableConfigs();
for (i = 0; i < availableGameModes.length; i += 1) votingHandler.mapCount = 0;
{ votingHandler.mapList.length = 0;
for (i = 0; i < availableGameModes.length; i += 1) {
nextGameModePrefix = "GM" $ i;
nextGameMode = GameMode(class'GameMode'.static nextGameMode = GameMode(class'GameMode'.static
.GetConfigInstance(availableGameModes[i])); .GetConfigInstance(availableGameModes[i]));
newVotingHandlerConfig[i] = BuildVotingHandlerConfig(nextGameMode); newVotingHandlerConfig[i] = BuildVotingHandlerConfig(nextGameMode, nextGameModePrefix);
LoadGameModeMaps(nextGameMode, nextGameModePrefix, votingHandler);
// Setup proper game mode index // Setup proper game mode index
if (availableGameModes[i].ToString() == targetGameMode) { if (availableGameModes[i].ToString() == targetGameMode) {
votingHandler.currentGameConfig = i; votingHandler.currentGameConfig = i;
@ -140,57 +147,134 @@ public final function InjectIntoVotingHandler()
votingHandler.gameConfig = newVotingHandlerConfig; votingHandler.gameConfig = newVotingHandlerConfig;
} }
public function TrySetupMapList() { private function LoadGameModeMaps(
local Text currentConfigName; GameMode gameMode,
local MapList currentConfig; string gameModePrefix,
XVotingHandler votingHandler
) {
local int i;
local ArrayList gameModeMaps;
local Text mapNameReal, mapNamePseudonim;
local VotingHandler.MapHistoryInfo nextMapInfo;
local VotingHandler.MapVoteMapList nextRecord;
local array<VotingHandler.MapVoteMapList> newMaps;
if (currentConfigName != none) { nextRecord.bEnabled = true;
currentConfig = MapList(class'MapList'.static.GetConfigInstance(currentConfigName)); gameModeMaps = GetAllGameModeMaps(gameMode);
} for (i = 0; i < gameModeMaps.GetLength(); i += 1) {
if (currentConfig != none) { // Make a pseudonim to map connection
ReplaceHandlerMaps(XVotingHandler(votingHandlerReference.Get()), currentConfig.map); mapNameReal = gameModeMaps.GetText(i);
mapNamePseudonim = MakeMapPseudonim(mapNameReal, gameModePrefix);
pseudonimToMap.SetItem(mapNamePseudonim, mapNameReal);
// Setup `VotingHandler.MapVoteMapList` struct for next map
nextRecord.mapName = mapNamePseudonim.ToString();
if (votingHandler.history != none) {
nextMapInfo = votingHandler.history.GetMapHistory(nextRecord.mapName);
nextRecord.playCount = nextMapInfo.p;
nextRecord.sequence = nextMapInfo.s;
} else {
nextRecord.playCount = 0;
nextRecord.sequence = 0;
}
newMaps[newMaps.length] = nextRecord;
}
AppendMapsIntoHandler(votingHandler, newMaps);
}
private function Text MakeMapPseudonim(Text realName, string gameModePrefix) {
local Parser parser;
local MutableText prefix, nameBody;
local MutableText result;
result = _.text.FromStringM(gameModePrefix);
result.Append(P("-"));
parser = realName.Parse();
parser.MUntil(prefix, _.text.GetCharacter("-"));
parser.Match(P("-"));
if (parser.Ok()) {
nameBody = parser.GetRemainderM();
result.Append(nameBody);
}
else {
result.Append(realName);
}
_.memory.Free(nameBody);
_.memory.Free(prefix);
_.memory.Free(parser);
return result.IntoText();
}
private function ArrayList GetAllGameModeMaps(GameMode gameMode) {
local int i, j;
local HashTable uniqueMapSet;
local ArrayList result;
local array<Text> usedMapLists;
local MapList nextMapConfig;
local array<string> nextMapArray;
local Text nextMapName, lowerMapName;
uniqueMapSet = _.collections.EmptyHashTable(); // to quickly make sure we add each map only once
result = _.collections.EmptyArrayList();
usedMapLists = gameMode.GetIncludedMapLists();
for (i = 0; i < usedMapLists.length; i += 1) {
// Get maps from `MapList` config
nextMapConfig = MapList(class'MapList'.static.GetConfigInstance(usedMapLists[i]));
nextMapArray.length = 0;
if (nextMapConfig != none) {
nextMapArray = nextMapConfig.map;
} else { } else {
warn("currentConfig is none! Aborting!"); _.logger.Auto(warnMissingMapList).Arg(usedMapLists[i].Copy());
} }
_.memory.Free(currentConfig); _.memory.Free(nextMapConfig);
_.memory.Free(currentConfigName); // Add maps we haven't yet added from other lists
_.memory.Free(mapListFeature); for (j = 0; j < nextMapArray.length; j += 1) {
nextMapName = _.text.FromString(nextMapArray[j]);
lowerMapName = nextMapName.LowerCopy();
if (!uniqueMapSet.HasKey(lowerMapName)) {
uniqueMapSet.SetItem(lowerMapName, none);
result.AddItem(nextMapName);
}
_.memory.Free(lowerMapName);
_.memory.Free(nextMapName);
}
}
_.memory.Free(uniqueMapSet);
_.memory.FreeMany(usedMapLists);
return result;
} }
// TODO add map reps and play count from KFMapVoteHistory.ini private function AppendMapsIntoHandler(
public function ReplaceHandlerMaps(XVotingHandler votingHandler, array<string> maps) { XVotingHandler votingHandler,
local VotingHandler.MapVoteMapList nextRecord; array<VotingHandler.MapVoteMapList> newMaps
local array<VotingHandler.MapVoteMapList> recordArray; ) {
local int i; local int i;
local array<VotingHandler.MapVoteMapList> mapListCopy;
if (votingHandler == none) { if (votingHandler == none) {
warn("votingHandler is none!"); warn("votingHandler is none!");
return; return;
} }
if (maps.length == 0) { if (newMaps.length == 0) {
warn("maps.length is 0!"); warn("newMaps.length is 0!");
return; return;
} }
recordArray = votingHandler.mapList; mapListCopy = votingHandler.mapList;
warn(">>> recordArray.length =" $ recordArray.length); for (i = 0; i < newMaps.length; i += 1) {
recordArray.length = maps.length; mapListCopy[mapListCopy.length] = newMaps[i];
votingHandler.mapCount = maps.length;
nextRecord.bEnabled = true;
for (i = 0; i < maps.length; i += 1) {
nextRecord.mapName = maps[i];
recordArray[i] = nextRecord;
} }
votingHandler.mapList = recordArray; votingHandler.mapList = mapListCopy;
votingHandler.mapCount += newMaps.length;
} }
private function VotingHandler.MapVoteGameConfig BuildVotingHandlerConfig( private function VotingHandler.MapVoteGameConfig BuildVotingHandlerConfig(
GameMode gameMode) GameMode gameMode,
string gameModePrefix)
{ {
local MutableText nextColoredName; local MutableText nextColoredName;
local VotingHandler.MapVoteGameConfig result; local VotingHandler.MapVoteGameConfig result;
result.gameClass = _.text.IntoString(gameMode.GetGameTypeClass()); result.gameClass = _.text.IntoString(gameMode.GetGameTypeClass());
result.prefix = _.text.IntoString(gameMode.GetMapPrefix()); result.prefix = gameModePrefix $ "-";
nextColoredName = gameMode nextColoredName = gameMode
.GetTitle() .GetTitle()
.IntoMutableText() .IntoMutableText()
@ -404,6 +488,7 @@ defaultproperties
normalSynonyms(1) = "medium" normalSynonyms(1) = "medium"
normalSynonyms(2) = "regular" normalSynonyms(2) = "regular"
longSynonyms(0) = "long" longSynonyms(0) = "long"
warnMissingMapList = (l=LOG_Warning,m="Cannot find map list `%1`.")
fatNoXVotingHandler = (l=LOG_Fatal,m="`XVotingHandler` class is missing. Make sure your server setup supports Acedia's game modes (by used voting handler derived from `XVotingHandler`).") fatNoXVotingHandler = (l=LOG_Fatal,m="`XVotingHandler` class is missing. Make sure your server setup supports Acedia's game modes (by used voting handler derived from `XVotingHandler`).")
fatBadGameConfigIndexVH = (l=LOG_Fatal,m="`XVotingHandler`'s `currentGameConfig` variable value of %1 is out-of-bounds for `XVotingHandler.gameConfig` of length %2. Report this issue.") fatBadGameConfigIndexVH = (l=LOG_Fatal,m="`XVotingHandler`'s `currentGameConfig` variable value of %1 is out-of-bounds for `XVotingHandler.gameConfig` of length %2. Report this issue.")
fatBadGameConfigIndexAdapter = (l=LOG_Fatal,m="`XVotingHandler`'s `currentGameConfig` variable value of %1 is out-of-bounds for `VHAdapter` of length %2. Report this issue.") fatBadGameConfigIndexAdapter = (l=LOG_Fatal,m="`XVotingHandler`'s `currentGameConfig` variable value of %1 is out-of-bounds for `VHAdapter` of length %2. Report this issue.")

Loading…
Cancel
Save