Refactor GameSpeed setting

*Remove internal GameSpeed defaults
 Enforce setting values explicitly all the time
 Require definition of a DefaultSpeed

*Remove Global.Timestep default

*Remove the hacky Timestep/OrderLatency setting via LobbyInfo

*Fix shellmaps ignoring mod-defined gamespeeds

*Make DateTimeGlobal use the MapOptions gamespeed
This commit is contained in:
reaperrr
2021-04-02 14:11:45 +02:00
committed by Paul Chote
parent fe129956bb
commit 1a9dfc0893
22 changed files with 214 additions and 205 deletions

View File

@@ -112,7 +112,7 @@ namespace OpenRA.Mods.Common.Traits
var randomFactor = world.LocalRandom.Next(0, baseBuilder.Info.StructureProductionRandomBonusDelay);
// Needs to be at least 4 * OrderLatency because otherwise the AI frequently duplicates build orders (i.e. makes the same build decision twice)
waitTicks = active ? 4 * world.LobbyInfo.GlobalSettings.OrderLatency + baseBuilder.Info.StructureProductionActiveDelay + randomFactor
waitTicks = active ? 4 * world.OrderLatency + baseBuilder.Info.StructureProductionActiveDelay + randomFactor
: baseBuilder.Info.StructureProductionInactiveDelay + randomFactor;
}

View File

@@ -58,7 +58,6 @@ namespace OpenRA.Mods.Common.Traits
int lastIncome;
int lastIncomeTick;
int ticks;
int replayTimestep;
bool armyGraphDisabled;
bool incomeGraphDisabled;
@@ -81,7 +80,7 @@ namespace OpenRA.Mods.Common.Traits
{
ticks++;
var timestep = self.World.IsReplay ? replayTimestep : self.World.Timestep;
var timestep = self.World.Timestep;
if (ticks * timestep >= 30000)
{
ticks = 0;
@@ -124,9 +123,6 @@ namespace OpenRA.Mods.Common.Traits
public void WorldLoaded(World w, WorldRenderer wr)
{
if (w.IsReplay)
replayTimestep = w.WorldActor.Trait<MapOptions>().GameSpeed.Timestep;
if (!armyGraphDisabled)
ArmySamples.Add(ArmyValue);

View File

@@ -93,6 +93,7 @@ namespace OpenRA.Mods.Common.Traits
public class TimeLimitManager : INotifyTimeLimit, ITick, IWorldLoaded
{
readonly TimeLimitManagerInfo info;
readonly int ticksPerSecond;
MapOptions mapOptions;
LabelWidget countdownLabel;
CachedTransform<int, string> countdown;
@@ -105,13 +106,14 @@ namespace OpenRA.Mods.Common.Traits
{
this.info = info;
Notification = info.Notification;
ticksPerSecond = 1000 / self.World.Timestep;
var tl = self.World.LobbyInfo.GlobalSettings.OptionOrDefault("timelimit", info.TimeLimitDefault.ToString());
if (!int.TryParse(tl, out TimeLimit))
TimeLimit = info.TimeLimitDefault;
// Convert from minutes to ticks
TimeLimit *= 60 * (1000 / self.World.Timestep);
TimeLimit *= 60 * ticksPerSecond;
}
void IWorldLoaded.WorldLoaded(World w, OpenRA.Graphics.WorldRenderer wr)
@@ -124,7 +126,7 @@ namespace OpenRA.Mods.Common.Traits
if (countdownLabel != null)
{
countdown = new CachedTransform<int, string>(t =>
info.CountdownText.F(WidgetUtils.FormatTime(t, true, w.IsReplay ? mapOptions.GameSpeed.Timestep : w.Timestep)));
info.CountdownText.F(WidgetUtils.FormatTime(t, true, w.Timestep)));
countdownLabel.GetText = () => countdown.Update(ticksRemaining);
}
}
@@ -134,7 +136,6 @@ namespace OpenRA.Mods.Common.Traits
if (TimeLimit <= 0)
return;
var ticksPerSecond = 1000 / (self.World.IsReplay ? mapOptions.GameSpeed.Timestep : self.World.Timestep);
ticksRemaining = TimeLimit - self.World.WorldTick;
if (ticksRemaining == 0)

View File

@@ -60,8 +60,8 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Description of the game speed option in the lobby.")]
public readonly string GameSpeedDropdownDescription = "Change the rate at which time passes";
[Desc("Default game speed.")]
public readonly string GameSpeed = "default";
[Desc("Default game speed (leave empty to use the default defined in mod.yaml).")]
public readonly string GameSpeed = null;
[Desc("Prevent the game speed from being changed in the lobby.")]
public readonly bool GameSpeedDropdownLocked = false;
@@ -84,18 +84,18 @@ namespace OpenRA.Mods.Common.Traits
yield return new LobbyOption("techlevel", TechLevelDropdownLabel, TechLevelDropdownDescription, TechLevelDropdownVisible, TechLevelDropdownDisplayOrder,
techLevels, TechLevel, TechLevelDropdownLocked);
var gameSpeeds = Game.ModData.Manifest.Get<GameSpeeds>().Speeds
.ToDictionary(s => s.Key, s => s.Value.Name);
var gameSpeeds = Game.ModData.Manifest.Get<GameSpeeds>();
var speeds = gameSpeeds.Speeds.ToDictionary(s => s.Key, s => s.Value.Name);
// NOTE: The server hardcodes special-case logic for this option id
// NOTE: This is just exposing the UI, the backend logic for this option is hardcoded in World
yield return new LobbyOption("gamespeed", GameSpeedDropdownLabel, GameSpeedDropdownDescription, GameSpeedDropdownVisible, GameSpeedDropdownDisplayOrder,
gameSpeeds, GameSpeed, GameSpeedDropdownLocked);
speeds, GameSpeed ?? gameSpeeds.DefaultSpeed, GameSpeedDropdownLocked);
}
void IRulesetLoaded<ActorInfo>.RulesetLoaded(Ruleset rules, ActorInfo info)
{
var gameSpeeds = Game.ModData.Manifest.Get<GameSpeeds>().Speeds;
if (!gameSpeeds.ContainsKey(GameSpeed))
if (GameSpeed != null && !gameSpeeds.ContainsKey(GameSpeed))
throw new YamlException("Invalid default game speed '{0}'.".F(GameSpeed));
}
@@ -108,7 +108,6 @@ namespace OpenRA.Mods.Common.Traits
public bool ShortGame { get; private set; }
public string TechLevel { get; private set; }
public GameSpeed GameSpeed { get; private set; }
public MapOptions(MapOptionsInfo info)
{
@@ -122,11 +121,6 @@ namespace OpenRA.Mods.Common.Traits
TechLevel = self.World.LobbyInfo.GlobalSettings
.OptionOrDefault("techlevel", info.TechLevel);
var speed = self.World.LobbyInfo.GlobalSettings
.OptionOrDefault("gamespeed", info.GameSpeed);
GameSpeed = Game.ModData.Manifest.Get<GameSpeeds>().Speeds[speed];
}
}
}