From 88186f2106cb7fb85461c49ac659a582597ef364 Mon Sep 17 00:00:00 2001 From: Rane <60792108+Elijahrane@users.noreply.github.com> Date: Tue, 1 Nov 2022 21:17:35 -0400 Subject: [PATCH] Map pool cvar (#12313) * it just works * nuke votable * whoops --- Content.Client/Entry/EntryPoint.cs | 1 + Content.Server/Maps/GameMapManager.cs | 18 +++++++++++++-- Content.Server/Maps/GameMapPoolPrototype.cs | 22 +++++++++++++++++++ .../Maps/GameMapPrototype.MapSelection.cs | 6 ----- Content.Shared/CCVar/CCVars.cs | 6 +++++ Resources/Prototypes/Maps/Pools/default.yml | 13 +++++++++++ Resources/Prototypes/Maps/centcomm.yml | 1 - Resources/Prototypes/Maps/cluster.yml | 1 - Resources/Prototypes/Maps/dart.yml | 3 +-- Resources/Prototypes/Maps/infiltrator.yml | 1 - Resources/Prototypes/Maps/omega.yml | 1 - Resources/Prototypes/Maps/pirate.yml | 1 - Resources/Prototypes/Maps/test.yml | 1 - 13 files changed, 59 insertions(+), 16 deletions(-) create mode 100644 Content.Server/Maps/GameMapPoolPrototype.cs create mode 100644 Resources/Prototypes/Maps/Pools/default.yml diff --git a/Content.Client/Entry/EntryPoint.cs b/Content.Client/Entry/EntryPoint.cs index d902dea498..3db214fe48 100644 --- a/Content.Client/Entry/EntryPoint.cs +++ b/Content.Client/Entry/EntryPoint.cs @@ -115,6 +115,7 @@ namespace Content.Client.Entry _prototypeManager.RegisterIgnore("htnCompound"); _prototypeManager.RegisterIgnore("htnPrimitive"); _prototypeManager.RegisterIgnore("gameMap"); + _prototypeManager.RegisterIgnore("gameMapPool"); _prototypeManager.RegisterIgnore("faction"); _prototypeManager.RegisterIgnore("lobbyBackground"); _prototypeManager.RegisterIgnore("advertisementsPack"); diff --git a/Content.Server/Maps/GameMapManager.cs b/Content.Server/Maps/GameMapManager.cs index c780306f6a..28c9413e7f 100644 --- a/Content.Server/Maps/GameMapManager.cs +++ b/Content.Server/Maps/GameMapManager.cs @@ -68,7 +68,22 @@ public sealed class GameMapManager : IGameMapManager public IEnumerable AllVotableMaps() { - return _prototypeManager.EnumeratePrototypes().Where(x => x.Votable); + if (_prototypeManager.TryIndex(_configurationManager.GetCVar(CCVars.GameMapPool), out var pool)) + { + foreach (var map in pool.Maps) + { + if (!_prototypeManager.TryIndex(map, out var mapProto)) + { + Logger.Error("Couldn't index map " + map + " in pool " + pool.ID); + continue; + } + + yield return mapProto; + } + } else + { + throw new Exception("Could not index map pool prototype " + _configurationManager.GetCVar(CCVars.GameMapPool) + "!"); + } } public IEnumerable AllMaps() @@ -170,7 +185,6 @@ public sealed class GameMapManager : IGameMapManager { Logger.InfoS("mapsel", string.Join(", ", _previousMaps)); var eligible = CurrentlyEligibleMaps() - .Where(x => x.Votable) .Select(x => (proto: x, weight: GetMapQueuePriority(x.ID))) .OrderByDescending(x => x.weight).ToArray(); Logger.InfoS("mapsel", string.Join(", ", eligible.Select(x => (x.proto.ID, x.weight)))); diff --git a/Content.Server/Maps/GameMapPoolPrototype.cs b/Content.Server/Maps/GameMapPoolPrototype.cs new file mode 100644 index 0000000000..2d20084a57 --- /dev/null +++ b/Content.Server/Maps/GameMapPoolPrototype.cs @@ -0,0 +1,22 @@ +using JetBrains.Annotations; +using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set; + +namespace Content.Server.Maps; + +/// +/// Prototype that holds a pool of maps that can be indexed based on the map pool CCVar. +/// +[Prototype("gameMapPool"), PublicAPI] +public sealed class GameMapPoolPrototype : IPrototype +{ + /// + [IdDataField] + public string ID { get; } = default!; + + /// + /// Which maps are in this pool. + /// + [DataField("maps", customTypeSerializer:typeof(PrototypeIdHashSetSerializer), required: true)] + public readonly HashSet Maps = new(0); +} diff --git a/Content.Server/Maps/GameMapPrototype.MapSelection.cs b/Content.Server/Maps/GameMapPrototype.MapSelection.cs index 6ef6644dbe..53ace8e5f4 100644 --- a/Content.Server/Maps/GameMapPrototype.MapSelection.cs +++ b/Content.Server/Maps/GameMapPrototype.MapSelection.cs @@ -8,12 +8,6 @@ public sealed partial class GameMapPrototype [DataField("fallback")] public bool Fallback { get; } - /// - /// Controls if the map can be voted for. - /// - [DataField("votable")] - public bool Votable { get; } = true; - /// /// Minimum players for the given map. /// diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index a83eb7b422..8c01c04d34 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -184,6 +184,12 @@ namespace Content.Shared.CCVar public static readonly CVarDef GameMap = CVarDef.Create("game.map", "Saltern", CVar.SERVERONLY); + /// + /// Prototype to use for map pool. + /// + public static readonly CVarDef + GameMapPool = CVarDef.Create("game.map_pool", "DefaultMapPool", CVar.SERVERONLY); + /// /// Controls if the game should obey map criteria or not. Overriden if a map vote or similar occurs. /// diff --git a/Resources/Prototypes/Maps/Pools/default.yml b/Resources/Prototypes/Maps/Pools/default.yml new file mode 100644 index 0000000000..7b675e8989 --- /dev/null +++ b/Resources/Prototypes/Maps/Pools/default.yml @@ -0,0 +1,13 @@ +- type: gameMapPool + id: DefaultMapPool + maps: + - Bagel + - Box + - Cluster + - Kettle + - Lighthouse + - Marathon + - Omega + - Origin + - Pillar + - Saltern diff --git a/Resources/Prototypes/Maps/centcomm.yml b/Resources/Prototypes/Maps/centcomm.yml index 24ac369221..ebdb10f3e4 100644 --- a/Resources/Prototypes/Maps/centcomm.yml +++ b/Resources/Prototypes/Maps/centcomm.yml @@ -3,7 +3,6 @@ mapName: 'Central Command' mapPath: /Maps/centcomm.yml minPlayers: 10 - votable: false stations: centcomm: mapNameTemplate: '{0} Central Command {1}' diff --git a/Resources/Prototypes/Maps/cluster.yml b/Resources/Prototypes/Maps/cluster.yml index b15feca083..a7ad7c07c4 100644 --- a/Resources/Prototypes/Maps/cluster.yml +++ b/Resources/Prototypes/Maps/cluster.yml @@ -4,7 +4,6 @@ mapPath: /Maps/cluster.yml minPlayers: 0 maxPlayers: 35 - votable: true stations: Cluster: mapNameTemplate: '{0} Cluster Station {1}' diff --git a/Resources/Prototypes/Maps/dart.yml b/Resources/Prototypes/Maps/dart.yml index 46981a75e3..0135bbc4b1 100644 --- a/Resources/Prototypes/Maps/dart.yml +++ b/Resources/Prototypes/Maps/dart.yml @@ -3,7 +3,6 @@ mapName: 'Dart ERT' mapPath: /Maps/dart.yml minPlayers: 0 - votable: false stations: Dart: mapNameTemplate: '{0} Dart ERT {1}' @@ -16,4 +15,4 @@ ERTEngineer: [ 0, 1 ] ERTSecurity: [ 0, 1 ] ERTMedical: [ 0, 1 ] - ERTJanitor: [ 0, 1 ] \ No newline at end of file + ERTJanitor: [ 0, 1 ] diff --git a/Resources/Prototypes/Maps/infiltrator.yml b/Resources/Prototypes/Maps/infiltrator.yml index c00d333169..d0c45ddf69 100644 --- a/Resources/Prototypes/Maps/infiltrator.yml +++ b/Resources/Prototypes/Maps/infiltrator.yml @@ -3,7 +3,6 @@ mapName: 'Syndicate Infiltrator' mapPath: /Maps/infiltrator.yml minPlayers: 0 - votable: false stations: Station: #TODO: Mapper, add a BecomesStation component to the primary grid of the map. mapNameTemplate: '{0} Infiltrator {1}' diff --git a/Resources/Prototypes/Maps/omega.yml b/Resources/Prototypes/Maps/omega.yml index 524b092f6e..6265ff91f2 100644 --- a/Resources/Prototypes/Maps/omega.yml +++ b/Resources/Prototypes/Maps/omega.yml @@ -4,7 +4,6 @@ mapPath: /Maps/omega.yml minPlayers: 0 maxPlayers: 35 - votable: true stations: Omega: mapNameTemplate: '{0} Omega Station {1}' diff --git a/Resources/Prototypes/Maps/pirate.yml b/Resources/Prototypes/Maps/pirate.yml index 1a0d318e3c..05e7d4c5e1 100644 --- a/Resources/Prototypes/Maps/pirate.yml +++ b/Resources/Prototypes/Maps/pirate.yml @@ -3,7 +3,6 @@ mapName: 'Pirate Ship' mapPath: /Maps/pirate.yml minPlayers: 0 - votable: false stations: Station: #TODO: Mapper, add a BecomesStation component to the primary grid of the map. mapNameTemplate: '{0} Pirate {1}' diff --git a/Resources/Prototypes/Maps/test.yml b/Resources/Prototypes/Maps/test.yml index b61c5be1cd..31b6593120 100644 --- a/Resources/Prototypes/Maps/test.yml +++ b/Resources/Prototypes/Maps/test.yml @@ -3,7 +3,6 @@ mapName: Empty mapPath: /Maps/Test/empty.yml minPlayers: 0 - votable: false stations: Empty: mapNameTemplate: "Empty"