diff --git a/OpenRA.Mods.Common/Traits/Player/PlayerStatistics.cs b/OpenRA.Mods.Common/Traits/Player/PlayerStatistics.cs index f09fc32f72..26f6b87774 100644 --- a/OpenRA.Mods.Common/Traits/Player/PlayerStatistics.cs +++ b/OpenRA.Mods.Common/Traits/Player/PlayerStatistics.cs @@ -56,6 +56,7 @@ namespace OpenRA.Mods.Common.Traits public int BuildingsDead; public int ArmyValue; + public int AssetsValue; // High resolution (every second) record of earnings, limited to the last minute readonly Queue earnedSeconds = new Queue(60); @@ -186,6 +187,9 @@ namespace OpenRA.Mods.Common.Traits [Desc("Add to army value in statistics")] public bool AddToArmyValue = false; + [Desc("Add to assets value in statistics")] + public bool AddToAssetsValue = true; + [ActorReference] [Desc("Count this actor as a different type in the spectator army display.")] public string OverrideActor = null; @@ -201,6 +205,7 @@ namespace OpenRA.Mods.Common.Traits PlayerStatistics playerStats; bool includedInArmyValue = false; + bool includedInAssetsValue = false; public UpdatesPlayerStatistics(UpdatesPlayerStatisticsInfo info, Actor self) { @@ -236,17 +241,26 @@ namespace OpenRA.Mods.Common.Traits includedInArmyValue = false; playerStats.Units[actorName].Count--; } + + if (includedInAssetsValue) + { + playerStats.AssetsValue -= cost; + includedInAssetsValue = false; + } } void INotifyCreated.Created(Actor self) { includedInArmyValue = info.AddToArmyValue; - if (includedInArmyValue) { playerStats.ArmyValue += cost; playerStats.Units[actorName].Count++; } + + includedInAssetsValue = info.AddToAssetsValue; + if (includedInAssetsValue) + playerStats.AssetsValue += cost; } void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) @@ -260,6 +274,12 @@ namespace OpenRA.Mods.Common.Traits newOwnerStats.Units[actorName].Count++; } + if (includedInAssetsValue) + { + playerStats.AssetsValue -= cost; + newOwnerStats.AssetsValue += cost; + } + playerStats = newOwnerStats; } @@ -271,6 +291,12 @@ namespace OpenRA.Mods.Common.Traits includedInArmyValue = false; playerStats.Units[actorName].Count--; } + + if (includedInAssetsValue) + { + playerStats.AssetsValue -= cost; + includedInAssetsValue = false; + } } } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverStatsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverStatsLogic.cs index d901f9abee..55496b0cff 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverStatsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverStatsLogic.cs @@ -386,11 +386,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic SetupPlayerColor(player, template, playerColor, playerGradient); - var res = player.PlayerActor.Trait(); var stats = player.PlayerActor.TraitOrDefault(); if (stats == null) return template; + var res = player.PlayerActor.Trait(); var cashText = new CachedTransform(i => "$" + i); template.Get("CASH").GetText = () => cashText.Update(res.Cash + res.Resources); @@ -404,10 +404,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic template.Get("SPENT").GetText = () => spentText.Update(res.Spent); var assetsText = new CachedTransform(i => "$" + i); - var assets = template.Get("ASSETS"); - assets.GetText = () => assetsText.Update(world.ActorsHavingTrait() - .Where(a => a.Owner == player && !a.IsDead) - .Sum(a => a.Info.TraitInfos().First().Cost)); + template.Get("ASSETS").GetText = () => assetsText.Update(stats.AssetsValue); var harvesters = template.Get("HARVESTERS"); harvesters.GetText = () => world.ActorsHavingTrait().Count(a => a.Owner == player && !a.IsDead).ToString();