Skip to content

Commit

Permalink
Fix game minute in PlayerStatistics
Browse files Browse the repository at this point in the history
  • Loading branch information
teinarss committed Jul 21, 2019
1 parent ee26ad2 commit 059813f
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions OpenRA.Mods.Common/Traits/Player/PlayerStatistics.cs
Expand Up @@ -10,6 +10,7 @@
#endregion

using System.Collections.Generic;
using OpenRA.Graphics;
using OpenRA.Traits;

namespace OpenRA.Mods.Common.Traits
Expand All @@ -20,7 +21,7 @@ public class PlayerStatisticsInfo : ITraitInfo
public object Create(ActorInitializer init) { return new PlayerStatistics(init.Self); }
}

public class PlayerStatistics : ITick, IResolveOrder, INotifyCreated
public class PlayerStatistics : ITick, IResolveOrder, INotifyCreated, IWorldLoaded
{
PlayerResources resources;
PlayerExperience experience;
Expand Down Expand Up @@ -58,6 +59,7 @@ public int Experience
public int BuildingsDead;

public int ArmyValue;
int replayTimestep;

public PlayerStatistics(Actor self) { }

Expand All @@ -84,7 +86,9 @@ void UpdateArmyThisMinute()

void ITick.Tick(Actor self)
{
if (self.World.WorldTick % 1500 == 1)
var timestep = self.World.IsReplay ? replayTimestep : self.World.Timestep;

if (timestep * self.World.WorldTick % 60000 == 0)
{
UpdateEarnedThisMinute();
UpdateArmyThisMinute();
Expand Down Expand Up @@ -116,6 +120,15 @@ public void ResolveOrder(Actor self, Order order)
return;
OrderCount++;
}

public void WorldLoaded(World w, WorldRenderer wr)
{
if (w.IsReplay)
replayTimestep = w.WorldActor.Trait<MapOptions>().GameSpeed.Timestep;

UpdateEarnedThisMinute();
UpdateArmyThisMinute();
}
}

[Desc("Attach this to a unit to update observer stats.")]
Expand Down

0 comments on commit 059813f

Please sign in to comment.