Random station names! (#5548)

This commit is contained in:
Moony
2021-11-26 07:54:32 -06:00
committed by GitHub
parent 522cb3cf9c
commit f60484b15c
9 changed files with 83 additions and 10 deletions

View File

@@ -105,7 +105,7 @@ namespace Content.Client.LateJoin
new Label() new Label()
{ {
StyleClasses = { "LabelBig" }, StyleClasses = { "LabelBig" },
Text = $"NTSS {name}", Text = name,
Align = Label.AlignMode.Center, Align = Label.AlignMode.Center,
}, },
collapseButton collapseButton

View File

@@ -4,6 +4,7 @@ using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using Content.Server.Chat.Managers; using Content.Server.Chat.Managers;
using Content.Shared.CCVar; using Content.Shared.CCVar;
using Robust.Server.Maps;
using Robust.Server.Player; using Robust.Server.Player;
using Robust.Shared.Configuration; using Robust.Shared.Configuration;
using Robust.Shared.IoC; using Robust.Shared.IoC;
@@ -20,6 +21,7 @@ public class GameMapManager : IGameMapManager
[Dependency] private readonly IPlayerManager _playerManager = default!; [Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IChatManager _chatManager = default!; [Dependency] private readonly IChatManager _chatManager = default!;
[Dependency] private readonly IMapLoader _mapLoader = default!;
private GameMapPrototype _currentMap = default!; private GameMapPrototype _currentMap = default!;
private bool _currentMapForced; private bool _currentMapForced;
@@ -116,4 +118,12 @@ public class GameMapManager : IGameMapManager
{ {
return _prototypeManager.TryIndex(gameMap, out map); return _prototypeManager.TryIndex(gameMap, out map);
} }
public string GenerateMapName(GameMapPrototype gameMap)
{
if (gameMap.NameGenerator is not null && gameMap.MapNameTemplate is not null)
return gameMap.NameGenerator.FormatName(gameMap.MapNameTemplate);
else
return gameMap.MapName;
}
} }

View File

@@ -1,10 +1,10 @@
using System.Collections.Generic; using System.Collections.Generic;
using Content.Server.Maps.NameGenerators;
using Content.Shared.Roles; using Content.Shared.Roles;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
using Robust.Shared.ViewVariables;
namespace Content.Server.Maps; namespace Content.Server.Maps;
@@ -31,11 +31,23 @@ public class GameMapPrototype : IPrototype
public uint MaxPlayers { get; } = uint.MaxValue; public uint MaxPlayers { get; } = uint.MaxValue;
/// <summary> /// <summary>
/// Name of the given map. /// Name of the map to use in generic messages, like the map vote.
/// </summary> /// </summary>
[DataField("mapName", required: true)] [DataField("mapName", required: true)]
public string MapName { get; } = default!; public string MapName { get; } = default!;
/// <summary>
/// Name of the given map.
/// </summary>
[DataField("mapNameTemplate")]
public string? MapNameTemplate { get; } = default!;
/// <summary>
/// Name generator to use for the map, if any.
/// </summary>
[DataField("nameGenerator")]
public GameMapNameGenerator? NameGenerator { get; } = default!;
/// <summary> /// <summary>
/// Relative directory path to the given map, i.e. `Maps/saltern.yml` /// Relative directory path to the given map, i.e. `Maps/saltern.yml`
/// </summary> /// </summary>

View File

@@ -64,4 +64,6 @@ public interface IGameMapManager
/// <param name="gameMap">name of the map</param> /// <param name="gameMap">name of the map</param>
/// <returns>existence</returns> /// <returns>existence</returns>
bool CheckMapExists(string gameMap); bool CheckMapExists(string gameMap);
public string GenerateMapName(GameMapPrototype gameMap);
} }

View File

@@ -0,0 +1,9 @@
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Maps.NameGenerators;
[ImplicitDataDefinitionForInheritors]
public abstract class GameMapNameGenerator
{
public abstract string FormatName(string input);
}

View File

@@ -0,0 +1,26 @@
using JetBrains.Annotations;
using Robust.Shared.IoC;
using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Maps.NameGenerators;
[UsedImplicitly]
public class NanotrasenNameGenerator : GameMapNameGenerator
{
/// <summary>
/// Where the map comes from. Should be a two or three letter code, for example "VG" for Packedstation.
/// </summary>
[DataField("prefixCreator")] public string PrefixCreator = default!;
private string Prefix => "NT";
private string[] SuffixCodes => new []{ "LV", "NX", "EV", "QT", "PR" };
public override string FormatName(string input)
{
var random = IoCManager.Resolve<IRobustRandom>();
// No way in hell am I writing custom format code just to add nice names. You can live with {0}
return string.Format(input, $"{Prefix}{PrefixCreator}", $"{random.Pick(SuffixCodes)}-{random.Next(0, 999):D3}");
}
}

View File

@@ -16,6 +16,7 @@ namespace Content.Server.Station;
public class StationSystem : EntitySystem public class StationSystem : EntitySystem
{ {
[Dependency] private GameTicker _gameTicker = default!; [Dependency] private GameTicker _gameTicker = default!;
[Dependency] private IGameMapManager _gameMapManager = default!;
private uint _idCounter = 1; private uint _idCounter = 1;
private Dictionary<StationId, StationInfoData> _stationInfo = new(); private Dictionary<StationId, StationInfoData> _stationInfo = new();
@@ -101,14 +102,14 @@ public class StationSystem : EntitySystem
var jobListDict = mapPrototype.AvailableJobs.ToDictionary(x => x.Key, x => x.Value[1]); var jobListDict = mapPrototype.AvailableJobs.ToDictionary(x => x.Key, x => x.Value[1]);
var id = AllocateStationInfo(); var id = AllocateStationInfo();
_stationInfo[id] = new StationInfoData(stationName ?? mapPrototype.MapName, mapPrototype, jobListDict); _stationInfo[id] = new StationInfoData(stationName ?? _gameMapManager.GenerateMapName(mapPrototype), mapPrototype, jobListDict);
var station = EntityManager.AddComponent<StationComponent>(mapGrid); var station = EntityManager.AddComponent<StationComponent>(mapGrid);
station.Station = id; station.Station = id;
_gameTicker.UpdateJobsAvailable(); // new station means new jobs, tell any lobby-goers. _gameTicker.UpdateJobsAvailable(); // new station means new jobs, tell any lobby-goers.
Logger.InfoS("stations", Logger.InfoS("stations",
$"Setting up new {mapPrototype.ID} called {mapPrototype.MapName} on grid {mapGrid}:{gridComponent.GridIndex}"); $"Setting up new {mapPrototype.ID} called {_stationInfo[id].Name} on grid {mapGrid}:{gridComponent.GridIndex}");
return id; return id;
} }

View File

@@ -1,6 +1,10 @@
- type: gameMap - type: gameMap
id: saltern id: saltern
mapName: Saltern mapName: 'Saltern'
mapNameTemplate: '{0} Saltern {1}'
nameGenerator:
!type:NanotrasenNameGenerator
prefixCreator: '14'
mapPath: Maps/saltern.yml mapPath: Maps/saltern.yml
minPlayers: 0 minPlayers: 0
maxPlayers: 20 maxPlayers: 20
@@ -30,7 +34,11 @@
- type: gameMap - type: gameMap
id: packedstation id: packedstation
mapName: Packedstation mapName: 'Packedstation'
mapNameTemplate: '{0} Packedstation {1}'
nameGenerator:
!type:NanotrasenNameGenerator
prefixCreator: 'VG'
mapPath: Maps/packedstation.yml mapPath: Maps/packedstation.yml
minPlayers: 15 minPlayers: 15
overflowJobs: overflowJobs:
@@ -59,7 +67,11 @@
- type: gameMap - type: gameMap
id: knightship id: knightship
mapName: Knight Ship mapName: 'Knightship'
mapNameTemplate: '{0} Knightship {1}'
nameGenerator:
!type:NanotrasenNameGenerator
prefixCreator: '14'
mapPath: Maps/knightship.yml mapPath: Maps/knightship.yml
minPlayers: 0 minPlayers: 0
maxPlayers: 8 maxPlayers: 8

View File

@@ -240,6 +240,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Monstermos/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Monstermos/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Nar_0027/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Nar_0027/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Noto/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Noto/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=NTSS/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=occluder/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=occluder/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Occluders/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Occluders/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Octile/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Octile/@EntryIndexedValue">True</s:Boolean>