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 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;
}
}

View File

@@ -256,7 +256,6 @@
<Compile Include="NukePaletteEffect.cs" />
<Compile Include="NullLoadScreen.cs" />
<Compile Include="OpenWidgetAtGameStart.cs" />
<Compile Include="Orders\OrderCounter.cs" />
<Compile Include="Orders\DeployOrderTargeter.cs" />
<Compile Include="Orders\EnterBuildingOrderTargeter.cs" />
<Compile Include="Orders\PlaceBuildingOrderGenerator.cs" />
@@ -271,6 +270,7 @@
<Compile Include="ParaDrop.cs" />
<Compile Include="ParachuteAttachment.cs" />
<Compile Include="Passenger.cs" />
<Compile Include="Player\PlayerStatistics.cs" />
<Compile Include="Player\ActorGroupProxy.cs" />
<Compile Include="Player\AllyRepair.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.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<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);
foreach (var t in teams)
@@ -158,16 +157,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
AddPlayerFlagAndName(template, player);
template.Get<LabelWidget>("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<RevealsShroud>())
.SelectMany(a => world.FindTilesInCircle(a.Location, a.Trait<RevealsShroud>().RevealRange))
.Distinct()
.Count();
return Round((double)controlled / total * 100).ToString("F1") + "%";
};
var stats = player.PlayerActor.Trait<PlayerStatistics>();
template.Get<LabelWidget>("CONTROL").GetText = () => MapControl(stats.MapControl);
return template;
}
@@ -179,11 +170,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
AddPlayerFlagAndName(template, player);
var production = template.Get<ObserverProductionIconsWidget>("PRODUCTION_ICONS");
production.GetPlayer = () => player;
var supportPowers = template.Get<ObserverSupportPowerIconsWidget>("SUPPORT_POWER_ICONS");
supportPowers.GetPlayer = () => player;
template.Get<ObserverProductionIconsWidget>("PRODUCTION_ICONS").GetPlayer = () => player;
template.Get<ObserverSupportPowerIconsWidget>("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<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
.Where(a => a.Owner == player && !a.IsDead() && a.Info.Traits.WithInterface<ValuedInfo>().Any())
.Sum(a => a.Info.Traits.WithInterface<ValuedInfo>().First().Cost);
template.Get<LabelWidget>("TOTAL_EARNED").GetText = () => "$" + res.TotalEarned;
template.Get<LabelWidget>("TOTAL_SPENT").GetText = () => "$" + res.TotalSpent;
var harvesters = template.Get<LabelWidget>("NUMBER_HARVESTERS");
var harvesters = template.Get<LabelWidget>("HARVESTERS");
harvesters.GetText = () => world.Actors.Count(a => a.Owner == player && !a.IsDead() && a.HasTrait<Harvester>()).ToString();
return template;
@@ -231,7 +210,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var res = player.PlayerActor.Trait<PlayerResources>();
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 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>("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;
}
@@ -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)

View File

@@ -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

View File

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