Skip to content

Commit

Permalink
Random station names! (#5548)
Browse files Browse the repository at this point in the history
  • Loading branch information
moonheart08 authored Nov 26, 2021
1 parent 522cb3c commit f60484b
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Content.Client/LateJoin/LateJoinGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private void RebuildUI()
new Label()
{
StyleClasses = { "LabelBig" },
Text = $"NTSS {name}",
Text = name,
Align = Label.AlignMode.Center,
},
collapseButton
Expand Down
12 changes: 11 additions & 1 deletion Content.Server/Maps/GameMapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using Content.Server.Chat.Managers;
using Content.Shared.CCVar;
using Robust.Server.Maps;
using Robust.Server.Player;
using Robust.Shared.Configuration;
using Robust.Shared.IoC;
Expand All @@ -20,6 +21,7 @@ public class GameMapManager : IGameMapManager
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IChatManager _chatManager = default!;
[Dependency] private readonly IMapLoader _mapLoader = default!;

private GameMapPrototype _currentMap = default!;
private bool _currentMapForced;
Expand Down Expand Up @@ -116,4 +118,12 @@ private bool TryLookupMap(string gameMap, [NotNullWhen(true)] out GameMapPrototy
{
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;
}
}
16 changes: 14 additions & 2 deletions Content.Server/Maps/GameMapPrototype.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Collections.Generic;
using Content.Server.Maps.NameGenerators;
using Content.Shared.Roles;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
using Robust.Shared.ViewVariables;

namespace Content.Server.Maps;

Expand All @@ -31,11 +31,23 @@ public class GameMapPrototype : IPrototype
public uint MaxPlayers { get; } = uint.MaxValue;

/// <summary>
/// Name of the given map.
/// Name of the map to use in generic messages, like the map vote.
/// </summary>
[DataField("mapName", required: true)]
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>
/// Relative directory path to the given map, i.e. `Maps/saltern.yml`
/// </summary>
Expand Down
4 changes: 3 additions & 1 deletion Content.Server/Maps/IGameMapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,6 @@ public interface IGameMapManager
/// <param name="gameMap">name of the map</param>
/// <returns>existence</returns>
bool CheckMapExists(string gameMap);
}

public string GenerateMapName(GameMapPrototype gameMap);
}
9 changes: 9 additions & 0 deletions Content.Server/Maps/NameGenerators/GameMapNameGenerator.cs
Original file line number Diff line number Diff line change
@@ -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);
}
26 changes: 26 additions & 0 deletions Content.Server/Maps/NameGenerators/NanotrasenNameGenerator.cs
Original file line number Diff line number Diff line change
@@ -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}");
}
}
5 changes: 3 additions & 2 deletions Content.Server/Station/StationSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Content.Server.Station;
public class StationSystem : EntitySystem
{
[Dependency] private GameTicker _gameTicker = default!;
[Dependency] private IGameMapManager _gameMapManager = default!;
private uint _idCounter = 1;

private Dictionary<StationId, StationInfoData> _stationInfo = new();
Expand Down Expand Up @@ -101,14 +102,14 @@ public StationId InitialSetupStationGrid(EntityUid mapGrid, GameMapPrototype map
var jobListDict = mapPrototype.AvailableJobs.ToDictionary(x => x.Key, x => x.Value[1]);
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);
station.Station = id;

_gameTicker.UpdateJobsAvailable(); // new station means new jobs, tell any lobby-goers.

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;
}
Expand Down
18 changes: 15 additions & 3 deletions Resources/Prototypes/Maps/game.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
- type: gameMap
id: saltern
mapName: Saltern
mapName: 'Saltern'
mapNameTemplate: '{0} Saltern {1}'
nameGenerator:
!type:NanotrasenNameGenerator
prefixCreator: '14'
mapPath: Maps/saltern.yml
minPlayers: 0
maxPlayers: 20
Expand Down Expand Up @@ -30,7 +34,11 @@

- type: gameMap
id: packedstation
mapName: Packedstation
mapName: 'Packedstation'
mapNameTemplate: '{0} Packedstation {1}'
nameGenerator:
!type:NanotrasenNameGenerator
prefixCreator: 'VG'
mapPath: Maps/packedstation.yml
minPlayers: 15
overflowJobs:
Expand Down Expand Up @@ -59,7 +67,11 @@

- type: gameMap
id: knightship
mapName: Knight Ship
mapName: 'Knightship'
mapNameTemplate: '{0} Knightship {1}'
nameGenerator:
!type:NanotrasenNameGenerator
prefixCreator: '14'
mapPath: Maps/knightship.yml
minPlayers: 0
maxPlayers: 8
Expand Down
1 change: 1 addition & 0 deletions SpaceStation14.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@
<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/=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/=Occluders/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Octile/@EntryIndexedValue">True</s:Boolean>
Expand Down

0 comments on commit f60484b

Please sign in to comment.