From 975380893670185e728689c73784d4cbd5e1adc6 Mon Sep 17 00:00:00 2001 From: Scott_NZ Date: Sun, 25 Nov 2012 22:16:21 +1300 Subject: [PATCH] Renamed OrderCounter to PlayerStatistics. Simplify income to simply earned/min. --- OpenRA.Game/Traits/Player/PlayerResources.cs | 30 ++------ OpenRA.Mods.RA/OpenRA.Mods.RA.csproj | 2 +- OpenRA.Mods.RA/Orders/OrderCounter.cs | 48 ------------ OpenRA.Mods.RA/Player/PlayerStatistics.cs | 76 +++++++++++++++++++ .../Widgets/Logic/ObserverStatsLogic.cs | 75 ++++++++---------- mods/ra/chrome/ingame.yaml | 75 +++++++++--------- mods/ra/rules/system.yaml | 2 +- 7 files changed, 153 insertions(+), 155 deletions(-) delete mode 100644 OpenRA.Mods.RA/Orders/OrderCounter.cs create mode 100644 OpenRA.Mods.RA/Player/PlayerStatistics.cs diff --git a/OpenRA.Game/Traits/Player/PlayerResources.cs b/OpenRA.Game/Traits/Player/PlayerResources.cs index d80efe4335..9f0261e4d9 100644 --- a/OpenRA.Game/Traits/Player/PlayerResources.cs +++ b/OpenRA.Game/Traits/Player/PlayerResources.cs @@ -86,13 +86,8 @@ namespace OpenRA.Traits public int DisplayCash; public int DisplayOre; - public int IncomePerMinute; - int incomeCounter; - - public double IncomeChange; - - public int TotalEarned; - public int TotalSpent; + public int Earned; + public int Spent; public bool CanGiveOre(int amount) { @@ -102,16 +97,13 @@ namespace OpenRA.Traits public void GiveOre(int num) { Ore += num; - incomeCounter += num; - TotalEarned += num; + Earned += num; if (Ore > OreCapacity) { nextSiloAdviceTime = 0; - incomeCounter -= Ore - OreCapacity; - TotalEarned -= Ore - OreCapacity; - + Earned -= Ore - OreCapacity; Ore = OreCapacity; } } @@ -120,7 +112,7 @@ namespace OpenRA.Traits { if (Ore < num) return false; Ore -= num; - TotalSpent += num; + Spent += num; return true; } @@ -128,8 +120,7 @@ namespace OpenRA.Traits public void GiveCash(int num) { Cash += num; - incomeCounter += num; - TotalEarned += num; + Earned += num; } public bool TakeCash(int num) @@ -138,7 +129,7 @@ namespace OpenRA.Traits // Spend ore before cash Ore -= num; - TotalSpent += num; + Spent += num; if (Ore < 0) { Cash += Ore; @@ -203,13 +194,6 @@ namespace OpenRA.Traits DisplayOre -= move; playCashTickDown(self); } - - if (self.World.FrameNumber % 1500 == 0) - { - IncomeChange = IncomePerMinute == 0 ? 0 : (double)(incomeCounter - IncomePerMinute) / IncomePerMinute; - IncomePerMinute = incomeCounter; - incomeCounter = 0; - } } diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 3297f9d4fc..cf1c60aa84 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -256,7 +256,6 @@ - @@ -271,6 +270,7 @@ + diff --git a/OpenRA.Mods.RA/Orders/OrderCounter.cs b/OpenRA.Mods.RA/Orders/OrderCounter.cs deleted file mode 100644 index 89d8b20b10..0000000000 --- a/OpenRA.Mods.RA/Orders/OrderCounter.cs +++ /dev/null @@ -1,48 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) - * This file is part of OpenRA, which is free software. It is made - * available to you under the terms of the GNU General Public License - * as published by the Free Software Foundation. For more information, - * see COPYING. - */ -#endregion - -using OpenRA.Traits; - -namespace OpenRA.Mods.RA.Orders -{ - public class OrderCounterInfo : TraitInfo { } - - public class OrderCounter : IResolveOrder - { - public int Orders; - - public void ResolveOrder(Actor self, Order order) - { - switch (order.OrderString) - { - case "Chat": - case "TeamChat": - case "HandshakeResponse": - case "PauseRequest": - case "PauseGame": - case "StartGame": - case "Disconnected": - case "ServerError": - case "SyncInfo": - return; - } - if (order.OrderString.StartsWith("Dev")) - { - return; - } - Orders++; - } - - public static double OrdersPerMinute(OrderCounter counter, World world) - { - return world.FrameNumber == 0 ? 0 : counter.Orders / (world.FrameNumber / 1500.0); - } - } -} diff --git a/OpenRA.Mods.RA/Player/PlayerStatistics.cs b/OpenRA.Mods.RA/Player/PlayerStatistics.cs new file mode 100644 index 0000000000..6309c7e8ee --- /dev/null +++ b/OpenRA.Mods.RA/Player/PlayerStatistics.cs @@ -0,0 +1,76 @@ +#region Copyright & License Information +/* + * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System.Linq; +using OpenRA.Traits; + +namespace OpenRA.Mods.RA +{ + public class PlayerStatisticsInfo : ITraitInfo + { + public object Create(ActorInitializer init) { return new PlayerStatistics(init.self); } + } + + public class PlayerStatistics : ITick, IResolveOrder + { + World world; + Player player; + + public PlayerStatistics(Actor self) + { + world = self.World; + player = self.Owner; + } + + public double MapControl; + + void UpdateMapControl() + { + var total = (double)world.Map.Bounds.Width * world.Map.Bounds.Height; + MapControl = world.Actors + .Where(a => !a.IsDead() && a.IsInWorld && a.Owner == player && a.HasTrait()) + .SelectMany(a => world.FindTilesInCircle(a.Location, a.Trait().RevealRange)) + .Distinct() + .Count() / total; + } + + public void Tick(Actor self) + { + if (self.World.FrameNumber % 250 == 1) + { + UpdateMapControl(); + } + } + + public int OrderCount; + + public void ResolveOrder(Actor self, Order order) + { + switch (order.OrderString) + { + case "Chat": + case "TeamChat": + case "HandshakeResponse": + case "PauseRequest": + case "PauseGame": + case "StartGame": + case "Disconnected": + case "ServerError": + case "SyncInfo": + return; + } + if (order.OrderString.StartsWith("Dev")) + { + return; + } + OrderCount++; + } + } +} diff --git a/OpenRA.Mods.RA/Widgets/Logic/ObserverStatsLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/ObserverStatsLogic.cs index f2f7d3eb91..a9cc43eb23 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/ObserverStatsLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/ObserverStatsLogic.cs @@ -13,7 +13,6 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; using OpenRA.Mods.RA.Buildings; -using OpenRA.Mods.RA.Orders; using OpenRA.Network; using OpenRA.Traits; using OpenRA.Widgets; @@ -71,7 +70,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic { ClearStats(); statsDropDown.GetText = () => "Basic"; - LoadStats(BasicStats); + DisplayStats(BasicStats); } }, new StatsDropDownOption @@ -82,7 +81,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic { ClearStats(); statsDropDown.GetText = () => "Economic"; - LoadStats(EconomicStats); + DisplayStats(EconomicStats); } }, new StatsDropDownOption @@ -93,7 +92,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic { ClearStats(); statsDropDown.GetText = () => "Production"; - LoadStats(ProductionStats); + DisplayStats(ProductionStats); } }, new StatsDropDownOption @@ -104,7 +103,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic { ClearStats(); statsDropDown.GetText = () => "Combat"; - LoadStats(CombatStats); + DisplayStats(CombatStats); } } }; @@ -121,7 +120,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic InitializeWidgets(widget, widget.Get("BACKGROUND"), widget.Get("PLAYER_STATS_PANEL")); ClearStats(); - LoadStats(BasicStats); + DisplayStats(BasicStats); } void ClearStats() @@ -133,7 +132,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic combatStatsHeaders.Visible = false; } - void LoadStats(Func forEachPlayer) + void DisplayStats(Func forEachPlayer) { var teams = players.GroupBy(p => (world.LobbyInfo.ClientWithIndex(p.ClientIndex) ?? new Session.Client()).Team).OrderBy(g => g.Key); foreach (var t in teams) @@ -158,16 +157,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic AddPlayerFlagAndName(template, player); - template.Get("MAP_CONTROL").GetText = () => - { - var total = world.Map.Bounds.Width * world.Map.Bounds.Height; - var controlled = world.Actors - .Where(a => !a.IsDead() && a.IsInWorld && a.Owner == player && a.HasTrait()) - .SelectMany(a => world.FindTilesInCircle(a.Location, a.Trait().RevealRange)) - .Distinct() - .Count(); - return Round((double)controlled / total * 100).ToString("F1") + "%"; - }; + var stats = player.PlayerActor.Trait(); + template.Get("CONTROL").GetText = () => MapControl(stats.MapControl); return template; } @@ -179,11 +170,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic AddPlayerFlagAndName(template, player); - var production = template.Get("PRODUCTION_ICONS"); - production.GetPlayer = () => player; - - var supportPowers = template.Get("SUPPORT_POWER_ICONS"); - supportPowers.GetPlayer = () => player; + template.Get("PRODUCTION_ICONS").GetPlayer = () => player; + template.Get("SUPPORT_POWER_ICONS").GetPlayer = () => player; return template; } @@ -196,27 +184,18 @@ namespace OpenRA.Mods.RA.Widgets.Logic AddPlayerFlagAndName(template, player); var res = player.PlayerActor.Trait(); - template.Get("CASH").GetText = () => "$" + (res.DisplayCash + res.DisplayOre); - template.Get("INCOME").GetText = () => "$" + res.IncomePerMinute; - var change = template.Get("INCOME_CHANGE"); - change.GetText = () => Round(res.IncomeChange * 100) + "%"; - change.GetColor = () => - { - var c = Round(res.IncomeChange * 100); - if (c < 0) return Color.Red; - if (c > 0) return Color.LimeGreen; - return Color.White; - }; - var assets = template.Get("TOTAL_ASSETS"); + template.Get("CASH").GetText = () => "$" + (res.DisplayCash + res.DisplayOre); + template.Get("EARNED_MIN").GetText = () => EarnedPerMinute(res.Earned); + template.Get("EARNED").GetText = () => "$" + res.Earned; + template.Get("SPENT").GetText = () => "$" + res.Spent; + + var assets = template.Get("ASSETS"); assets.GetText = () => "$" + world.Actors .Where(a => a.Owner == player && !a.IsDead() && a.Info.Traits.WithInterface().Any()) .Sum(a => a.Info.Traits.WithInterface().First().Cost); - template.Get("TOTAL_EARNED").GetText = () => "$" + res.TotalEarned; - template.Get("TOTAL_SPENT").GetText = () => "$" + res.TotalSpent; - - var harvesters = template.Get("NUMBER_HARVESTERS"); + var harvesters = template.Get("HARVESTERS"); harvesters.GetText = () => world.Actors.Count(a => a.Owner == player && !a.IsDead() && a.HasTrait()).ToString(); return template; @@ -231,7 +210,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic var res = player.PlayerActor.Trait(); template.Get("CASH").GetText = () => "$" + (res.DisplayCash + res.DisplayOre); - template.Get("INCOME").GetText = () => "$" + res.IncomePerMinute; + template.Get("EARNED_MIN").GetText = () => EarnedPerMinute(res.Earned); var powerRes = player.PlayerActor.Trait(); var power = template.Get("POWER"); @@ -240,7 +219,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic template.Get("KILLS").GetText = () => player.Kills.ToString(); template.Get("DEATHS").GetText = () => player.Deaths.ToString(); - template.Get("ORDERS").GetText = () => OrderCounter.OrdersPerMinute(player.PlayerActor.Trait(), world).ToString("F1"); + + var stats = player.PlayerActor.Trait(); + template.Get("ACTIONS_MIN").GetText = () => OrdersPerMinute(stats.OrderCount); return template; } @@ -257,9 +238,19 @@ namespace OpenRA.Mods.RA.Widgets.Logic }); } - static double Round(double value) + string MapControl(double control) { - return Math.Round(value, 1, MidpointRounding.AwayFromZero); + return (control * 100).ToString("F1") + "%"; + } + + string OrdersPerMinute(double orders) + { + return (world.FrameNumber == 0 ? 0 : orders / (world.FrameNumber / 1500.0)).ToString("F1"); + } + + string EarnedPerMinute(double earned) + { + return "$" + (world.FrameNumber == 0 ? 0 : earned / (world.FrameNumber / 1500.0)).ToString("F2"); } static void AddPlayerFlagAndName(ScrollItemWidget template, Player player) diff --git a/mods/ra/chrome/ingame.yaml b/mods/ra/chrome/ingame.yaml index 8c07e27480..88f072964f 100644 --- a/mods/ra/chrome/ingame.yaml +++ b/mods/ra/chrome/ingame.yaml @@ -438,22 +438,22 @@ Container@OBSERVER_ROOT: Height:25 Font:Bold Text:Cash - Label@INCOME_HEADER: + Label@EARNED_MIN_HEADER: X:325 Y:40 Width:60 Height:25 Font:Bold - Text:Income + Text:Earned/min Label@POWER_HEADER - X:405 + X:425 Y:40 Width:80 Height:25 Font:Bold Text:Power Label@KILLS_HEADER: - X:485 + X:505 Y:40 Width:40 Height:25 @@ -461,20 +461,20 @@ Container@OBSERVER_ROOT: Text:Kills Align:Right Label@DEATHS_HEADER: - X:545 + X:565 Y:40 Width:40 Height:25 Font:Bold Text:Deaths Align:Right - Label@ORDERS_HEADER: - X:605 + Label@ACTIONS_MIN_HEADER: + X:665 Y:40 Width:40 Height:25 Font:Bold - Text:APM + Text:Actions/min Align:Right Container@ECONOMIC_STATS_HEADERS: X:0 @@ -496,36 +496,36 @@ Container@OBSERVER_ROOT: Height:25 Font:Bold Text:Cash - Label@INCOME_HEADER: + Label@EARNED_MIN_HEADER: X:325 Y:40 - Width:120 + Width:60 Height:25 Font:Bold - Text:Income - Label@TOTAL_ASSETS_HEADER - X:445 + Text:Earned/min + Label@ASSETS_HEADER + X:425 Y:40 Width:60 Height:25 Font:Bold Text:Assets - Label@TOTAL_EARNED_HEADER + Label@EARNED_HEADER X:505 Y:40 Width:60 Height:25 Font:Bold Text:Earned - Label@TOTAL_SPENT_HEADER - X:565 + Label@SPENT_HEADER + X:585 Y:40 Width:60 Height:25 Font:Bold Text:Spent - Label@NUMBER_HARVESTERS_HEADER - X:645 + Label@HARVESTERS_HEADER + X:665 Y:40 Width:60 Height:25 @@ -572,13 +572,13 @@ Container@OBSERVER_ROOT: Height:25 Font:Bold Text:Player - Label@MAP_CONTROL_HEADER: + Label@CONTROL_HEADER: X:245 Y:40 Width:60 Height:25 Font:Bold - Text:Map Control + Text:Control ScrollPanel@PLAYER_STATS_PANEL: X:25 Y:70 @@ -622,30 +622,30 @@ Container@OBSERVER_ROOT: Y:0 Width:80 Height:PARENT_BOTTOM - Label@INCOME: + Label@EARNED_MIN: X:295 Y:0 Width:60 Height:PARENT_BOTTOM Label@POWER: - X:375 + X:395 Y:0 Width:80 Height:PARENT_BOTTOM Label@KILLS: - X:455 + X:475 Y:0 Width:40 Height:PARENT_BOTTOM Align:Right Label@DEATHS: - X:515 + X:535 Y:0 Width:40 Height:PARENT_BOTTOM Align:Right - Label@ORDERS: - X:575 + Label@ACTIONS_MIN: + X:635 Y:0 Width:40 Height:PARENT_BOTTOM @@ -674,33 +674,28 @@ Container@OBSERVER_ROOT: Y:0 Width:80 Height:PARENT_BOTTOM - Label@INCOME: + Label@EARNED_MIN: X:295 Y:0 Width:60 Height:PARENT_BOTTOM - Label@INCOME_CHANGE: - X:355 + Label@ASSETS: + X:395 Y:0 Width:60 Height:PARENT_BOTTOM - Label@TOTAL_ASSETS: - X:415 - Y:0 - Width:60 - Height:PARENT_BOTTOM - Label@TOTAL_EARNED: + Label@EARNED: X:475 Y:0 Width:60 Height:PARENT_BOTTOM - Label@TOTAL_SPENT: - X:535 + Label@SPENT: + X:555 Y:0 Width:60 Height:PARENT_BOTTOM - Label@NUMBER_HARVESTERS: - X:615 + Label@HARVESTERS: + X:635 Y:0 Width:60 Height:PARENT_BOTTOM @@ -753,7 +748,7 @@ Container@OBSERVER_ROOT: Width:160 Height:PARENT_BOTTOM Font:Bold - Label@MAP_CONTROL + Label@CONTROL X:215 Y:0 Width:60 diff --git a/mods/ra/rules/system.yaml b/mods/ra/rules/system.yaml index c449756dda..d3245ddd48 100644 --- a/mods/ra/rules/system.yaml +++ b/mods/ra/rules/system.yaml @@ -190,7 +190,7 @@ Player: GpsWatcher: Shroud: BaseAttackNotifier: - OrderCounter: + PlayerStatistics: World: OpenWidgetAtGameStart: