Renamed OrderCounter to PlayerStatistics. Simplify income to simply earned/min.

This commit is contained in:
Scott_NZ
2012-11-25 22:16:21 +13:00
parent 82fdbc4bc6
commit 9753808936
7 changed files with 153 additions and 155 deletions

View File

@@ -86,13 +86,8 @@ namespace OpenRA.Traits
public int DisplayCash; public int DisplayCash;
public int DisplayOre; public int DisplayOre;
public int IncomePerMinute; public int Earned;
int incomeCounter; public int Spent;
public double IncomeChange;
public int TotalEarned;
public int TotalSpent;
public bool CanGiveOre(int amount) public bool CanGiveOre(int amount)
{ {
@@ -102,16 +97,13 @@ namespace OpenRA.Traits
public void GiveOre(int num) public void GiveOre(int num)
{ {
Ore += num; Ore += num;
incomeCounter += num; Earned += num;
TotalEarned += num;
if (Ore > OreCapacity) if (Ore > OreCapacity)
{ {
nextSiloAdviceTime = 0; nextSiloAdviceTime = 0;
incomeCounter -= Ore - OreCapacity; Earned -= Ore - OreCapacity;
TotalEarned -= Ore - OreCapacity;
Ore = OreCapacity; Ore = OreCapacity;
} }
} }
@@ -120,7 +112,7 @@ namespace OpenRA.Traits
{ {
if (Ore < num) return false; if (Ore < num) return false;
Ore -= num; Ore -= num;
TotalSpent += num; Spent += num;
return true; return true;
} }
@@ -128,8 +120,7 @@ namespace OpenRA.Traits
public void GiveCash(int num) public void GiveCash(int num)
{ {
Cash += num; Cash += num;
incomeCounter += num; Earned += num;
TotalEarned += num;
} }
public bool TakeCash(int num) public bool TakeCash(int num)
@@ -138,7 +129,7 @@ namespace OpenRA.Traits
// Spend ore before cash // Spend ore before cash
Ore -= num; Ore -= num;
TotalSpent += num; Spent += num;
if (Ore < 0) if (Ore < 0)
{ {
Cash += Ore; Cash += Ore;
@@ -203,13 +194,6 @@ namespace OpenRA.Traits
DisplayOre -= move; DisplayOre -= move;
playCashTickDown(self); playCashTickDown(self);
} }
if (self.World.FrameNumber % 1500 == 0)
{
IncomeChange = IncomePerMinute == 0 ? 0 : (double)(incomeCounter - IncomePerMinute) / IncomePerMinute;
IncomePerMinute = incomeCounter;
incomeCounter = 0;
}
} }

View File

@@ -256,7 +256,6 @@
<Compile Include="NukePaletteEffect.cs" /> <Compile Include="NukePaletteEffect.cs" />
<Compile Include="NullLoadScreen.cs" /> <Compile Include="NullLoadScreen.cs" />
<Compile Include="OpenWidgetAtGameStart.cs" /> <Compile Include="OpenWidgetAtGameStart.cs" />
<Compile Include="Orders\OrderCounter.cs" />
<Compile Include="Orders\DeployOrderTargeter.cs" /> <Compile Include="Orders\DeployOrderTargeter.cs" />
<Compile Include="Orders\EnterBuildingOrderTargeter.cs" /> <Compile Include="Orders\EnterBuildingOrderTargeter.cs" />
<Compile Include="Orders\PlaceBuildingOrderGenerator.cs" /> <Compile Include="Orders\PlaceBuildingOrderGenerator.cs" />
@@ -271,6 +270,7 @@
<Compile Include="ParaDrop.cs" /> <Compile Include="ParaDrop.cs" />
<Compile Include="ParachuteAttachment.cs" /> <Compile Include="ParachuteAttachment.cs" />
<Compile Include="Passenger.cs" /> <Compile Include="Passenger.cs" />
<Compile Include="Player\PlayerStatistics.cs" />
<Compile Include="Player\ActorGroupProxy.cs" /> <Compile Include="Player\ActorGroupProxy.cs" />
<Compile Include="Player\AllyRepair.cs" /> <Compile Include="Player\AllyRepair.cs" />
<Compile Include="Player\ClassicProductionQueue.cs" /> <Compile Include="Player\ClassicProductionQueue.cs" />

View File

@@ -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<OrderCounter> { }
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);
}
}
}

View File

@@ -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<RevealsShroud>())
.SelectMany(a => world.FindTilesInCircle(a.Location, a.Trait<RevealsShroud>().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++;
}
}
}

View File

@@ -13,7 +13,6 @@ using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using OpenRA.Mods.RA.Buildings; using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Orders;
using OpenRA.Network; using OpenRA.Network;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Widgets; using OpenRA.Widgets;
@@ -71,7 +70,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{ {
ClearStats(); ClearStats();
statsDropDown.GetText = () => "Basic"; statsDropDown.GetText = () => "Basic";
LoadStats(BasicStats); DisplayStats(BasicStats);
} }
}, },
new StatsDropDownOption new StatsDropDownOption
@@ -82,7 +81,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{ {
ClearStats(); ClearStats();
statsDropDown.GetText = () => "Economic"; statsDropDown.GetText = () => "Economic";
LoadStats(EconomicStats); DisplayStats(EconomicStats);
} }
}, },
new StatsDropDownOption new StatsDropDownOption
@@ -93,7 +92,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{ {
ClearStats(); ClearStats();
statsDropDown.GetText = () => "Production"; statsDropDown.GetText = () => "Production";
LoadStats(ProductionStats); DisplayStats(ProductionStats);
} }
}, },
new StatsDropDownOption new StatsDropDownOption
@@ -104,7 +103,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{ {
ClearStats(); ClearStats();
statsDropDown.GetText = () => "Combat"; 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")); InitializeWidgets(widget, widget.Get("BACKGROUND"), widget.Get("PLAYER_STATS_PANEL"));
ClearStats(); ClearStats();
LoadStats(BasicStats); DisplayStats(BasicStats);
} }
void ClearStats() void ClearStats()
@@ -133,7 +132,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
combatStatsHeaders.Visible = false; combatStatsHeaders.Visible = false;
} }
void LoadStats(Func<Player, ScrollItemWidget> forEachPlayer) void DisplayStats(Func<Player, ScrollItemWidget> forEachPlayer)
{ {
var teams = players.GroupBy(p => (world.LobbyInfo.ClientWithIndex(p.ClientIndex) ?? new Session.Client()).Team).OrderBy(g => g.Key); var teams = players.GroupBy(p => (world.LobbyInfo.ClientWithIndex(p.ClientIndex) ?? new Session.Client()).Team).OrderBy(g => g.Key);
foreach (var t in teams) foreach (var t in teams)
@@ -158,16 +157,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
AddPlayerFlagAndName(template, player); AddPlayerFlagAndName(template, player);
template.Get<LabelWidget>("MAP_CONTROL").GetText = () => var stats = player.PlayerActor.Trait<PlayerStatistics>();
{ template.Get<LabelWidget>("CONTROL").GetText = () => MapControl(stats.MapControl);
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<RevealsShroud>())
.SelectMany(a => world.FindTilesInCircle(a.Location, a.Trait<RevealsShroud>().RevealRange))
.Distinct()
.Count();
return Round((double)controlled / total * 100).ToString("F1") + "%";
};
return template; return template;
} }
@@ -179,11 +170,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
AddPlayerFlagAndName(template, player); AddPlayerFlagAndName(template, player);
var production = template.Get<ObserverProductionIconsWidget>("PRODUCTION_ICONS"); template.Get<ObserverProductionIconsWidget>("PRODUCTION_ICONS").GetPlayer = () => player;
production.GetPlayer = () => player; template.Get<ObserverSupportPowerIconsWidget>("SUPPORT_POWER_ICONS").GetPlayer = () => player;
var supportPowers = template.Get<ObserverSupportPowerIconsWidget>("SUPPORT_POWER_ICONS");
supportPowers.GetPlayer = () => player;
return template; return template;
} }
@@ -196,27 +184,18 @@ namespace OpenRA.Mods.RA.Widgets.Logic
AddPlayerFlagAndName(template, player); AddPlayerFlagAndName(template, player);
var res = player.PlayerActor.Trait<PlayerResources>(); var res = player.PlayerActor.Trait<PlayerResources>();
template.Get<LabelWidget>("CASH").GetText = () => "$" + (res.DisplayCash + res.DisplayOre);
template.Get<LabelWidget>("INCOME").GetText = () => "$" + res.IncomePerMinute;
var change = template.Get<LabelWidget>("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<LabelWidget>("TOTAL_ASSETS"); template.Get<LabelWidget>("CASH").GetText = () => "$" + (res.DisplayCash + res.DisplayOre);
template.Get<LabelWidget>("EARNED_MIN").GetText = () => EarnedPerMinute(res.Earned);
template.Get<LabelWidget>("EARNED").GetText = () => "$" + res.Earned;
template.Get<LabelWidget>("SPENT").GetText = () => "$" + res.Spent;
var assets = template.Get<LabelWidget>("ASSETS");
assets.GetText = () => "$" + world.Actors assets.GetText = () => "$" + world.Actors
.Where(a => a.Owner == player && !a.IsDead() && a.Info.Traits.WithInterface<ValuedInfo>().Any()) .Where(a => a.Owner == player && !a.IsDead() && a.Info.Traits.WithInterface<ValuedInfo>().Any())
.Sum(a => a.Info.Traits.WithInterface<ValuedInfo>().First().Cost); .Sum(a => a.Info.Traits.WithInterface<ValuedInfo>().First().Cost);
template.Get<LabelWidget>("TOTAL_EARNED").GetText = () => "$" + res.TotalEarned; var harvesters = template.Get<LabelWidget>("HARVESTERS");
template.Get<LabelWidget>("TOTAL_SPENT").GetText = () => "$" + res.TotalSpent;
var harvesters = template.Get<LabelWidget>("NUMBER_HARVESTERS");
harvesters.GetText = () => world.Actors.Count(a => a.Owner == player && !a.IsDead() && a.HasTrait<Harvester>()).ToString(); harvesters.GetText = () => world.Actors.Count(a => a.Owner == player && !a.IsDead() && a.HasTrait<Harvester>()).ToString();
return template; return template;
@@ -231,7 +210,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var res = player.PlayerActor.Trait<PlayerResources>(); var res = player.PlayerActor.Trait<PlayerResources>();
template.Get<LabelWidget>("CASH").GetText = () => "$" + (res.DisplayCash + res.DisplayOre); template.Get<LabelWidget>("CASH").GetText = () => "$" + (res.DisplayCash + res.DisplayOre);
template.Get<LabelWidget>("INCOME").GetText = () => "$" + res.IncomePerMinute; template.Get<LabelWidget>("EARNED_MIN").GetText = () => EarnedPerMinute(res.Earned);
var powerRes = player.PlayerActor.Trait<PowerManager>(); var powerRes = player.PlayerActor.Trait<PowerManager>();
var power = template.Get<LabelWidget>("POWER"); var power = template.Get<LabelWidget>("POWER");
@@ -240,7 +219,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic
template.Get<LabelWidget>("KILLS").GetText = () => player.Kills.ToString(); template.Get<LabelWidget>("KILLS").GetText = () => player.Kills.ToString();
template.Get<LabelWidget>("DEATHS").GetText = () => player.Deaths.ToString(); template.Get<LabelWidget>("DEATHS").GetText = () => player.Deaths.ToString();
template.Get<LabelWidget>("ORDERS").GetText = () => OrderCounter.OrdersPerMinute(player.PlayerActor.Trait<OrderCounter>(), world).ToString("F1");
var stats = player.PlayerActor.Trait<PlayerStatistics>();
template.Get<LabelWidget>("ACTIONS_MIN").GetText = () => OrdersPerMinute(stats.OrderCount);
return template; 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) static void AddPlayerFlagAndName(ScrollItemWidget template, Player player)

View File

@@ -438,22 +438,22 @@ Container@OBSERVER_ROOT:
Height:25 Height:25
Font:Bold Font:Bold
Text:Cash Text:Cash
Label@INCOME_HEADER: Label@EARNED_MIN_HEADER:
X:325 X:325
Y:40 Y:40
Width:60 Width:60
Height:25 Height:25
Font:Bold Font:Bold
Text:Income Text:Earned/min
Label@POWER_HEADER Label@POWER_HEADER
X:405 X:425
Y:40 Y:40
Width:80 Width:80
Height:25 Height:25
Font:Bold Font:Bold
Text:Power Text:Power
Label@KILLS_HEADER: Label@KILLS_HEADER:
X:485 X:505
Y:40 Y:40
Width:40 Width:40
Height:25 Height:25
@@ -461,20 +461,20 @@ Container@OBSERVER_ROOT:
Text:Kills Text:Kills
Align:Right Align:Right
Label@DEATHS_HEADER: Label@DEATHS_HEADER:
X:545 X:565
Y:40 Y:40
Width:40 Width:40
Height:25 Height:25
Font:Bold Font:Bold
Text:Deaths Text:Deaths
Align:Right Align:Right
Label@ORDERS_HEADER: Label@ACTIONS_MIN_HEADER:
X:605 X:665
Y:40 Y:40
Width:40 Width:40
Height:25 Height:25
Font:Bold Font:Bold
Text:APM Text:Actions/min
Align:Right Align:Right
Container@ECONOMIC_STATS_HEADERS: Container@ECONOMIC_STATS_HEADERS:
X:0 X:0
@@ -496,36 +496,36 @@ Container@OBSERVER_ROOT:
Height:25 Height:25
Font:Bold Font:Bold
Text:Cash Text:Cash
Label@INCOME_HEADER: Label@EARNED_MIN_HEADER:
X:325 X:325
Y:40 Y:40
Width:120 Width:60
Height:25 Height:25
Font:Bold Font:Bold
Text:Income Text:Earned/min
Label@TOTAL_ASSETS_HEADER Label@ASSETS_HEADER
X:445 X:425
Y:40 Y:40
Width:60 Width:60
Height:25 Height:25
Font:Bold Font:Bold
Text:Assets Text:Assets
Label@TOTAL_EARNED_HEADER Label@EARNED_HEADER
X:505 X:505
Y:40 Y:40
Width:60 Width:60
Height:25 Height:25
Font:Bold Font:Bold
Text:Earned Text:Earned
Label@TOTAL_SPENT_HEADER Label@SPENT_HEADER
X:565 X:585
Y:40 Y:40
Width:60 Width:60
Height:25 Height:25
Font:Bold Font:Bold
Text:Spent Text:Spent
Label@NUMBER_HARVESTERS_HEADER Label@HARVESTERS_HEADER
X:645 X:665
Y:40 Y:40
Width:60 Width:60
Height:25 Height:25
@@ -572,13 +572,13 @@ Container@OBSERVER_ROOT:
Height:25 Height:25
Font:Bold Font:Bold
Text:Player Text:Player
Label@MAP_CONTROL_HEADER: Label@CONTROL_HEADER:
X:245 X:245
Y:40 Y:40
Width:60 Width:60
Height:25 Height:25
Font:Bold Font:Bold
Text:Map Control Text:Control
ScrollPanel@PLAYER_STATS_PANEL: ScrollPanel@PLAYER_STATS_PANEL:
X:25 X:25
Y:70 Y:70
@@ -622,30 +622,30 @@ Container@OBSERVER_ROOT:
Y:0 Y:0
Width:80 Width:80
Height:PARENT_BOTTOM Height:PARENT_BOTTOM
Label@INCOME: Label@EARNED_MIN:
X:295 X:295
Y:0 Y:0
Width:60 Width:60
Height:PARENT_BOTTOM Height:PARENT_BOTTOM
Label@POWER: Label@POWER:
X:375 X:395
Y:0 Y:0
Width:80 Width:80
Height:PARENT_BOTTOM Height:PARENT_BOTTOM
Label@KILLS: Label@KILLS:
X:455 X:475
Y:0 Y:0
Width:40 Width:40
Height:PARENT_BOTTOM Height:PARENT_BOTTOM
Align:Right Align:Right
Label@DEATHS: Label@DEATHS:
X:515 X:535
Y:0 Y:0
Width:40 Width:40
Height:PARENT_BOTTOM Height:PARENT_BOTTOM
Align:Right Align:Right
Label@ORDERS: Label@ACTIONS_MIN:
X:575 X:635
Y:0 Y:0
Width:40 Width:40
Height:PARENT_BOTTOM Height:PARENT_BOTTOM
@@ -674,33 +674,28 @@ Container@OBSERVER_ROOT:
Y:0 Y:0
Width:80 Width:80
Height:PARENT_BOTTOM Height:PARENT_BOTTOM
Label@INCOME: Label@EARNED_MIN:
X:295 X:295
Y:0 Y:0
Width:60 Width:60
Height:PARENT_BOTTOM Height:PARENT_BOTTOM
Label@INCOME_CHANGE: Label@ASSETS:
X:355 X:395
Y:0 Y:0
Width:60 Width:60
Height:PARENT_BOTTOM Height:PARENT_BOTTOM
Label@TOTAL_ASSETS: Label@EARNED:
X:415
Y:0
Width:60
Height:PARENT_BOTTOM
Label@TOTAL_EARNED:
X:475 X:475
Y:0 Y:0
Width:60 Width:60
Height:PARENT_BOTTOM Height:PARENT_BOTTOM
Label@TOTAL_SPENT: Label@SPENT:
X:535 X:555
Y:0 Y:0
Width:60 Width:60
Height:PARENT_BOTTOM Height:PARENT_BOTTOM
Label@NUMBER_HARVESTERS: Label@HARVESTERS:
X:615 X:635
Y:0 Y:0
Width:60 Width:60
Height:PARENT_BOTTOM Height:PARENT_BOTTOM
@@ -753,7 +748,7 @@ Container@OBSERVER_ROOT:
Width:160 Width:160
Height:PARENT_BOTTOM Height:PARENT_BOTTOM
Font:Bold Font:Bold
Label@MAP_CONTROL Label@CONTROL
X:215 X:215
Y:0 Y:0
Width:60 Width:60

View File

@@ -190,7 +190,7 @@ Player:
GpsWatcher: GpsWatcher:
Shroud: Shroud:
BaseAttackNotifier: BaseAttackNotifier:
OrderCounter: PlayerStatistics:
World: World:
OpenWidgetAtGameStart: OpenWidgetAtGameStart: