moved inner classes out of UnitInfo for brevity. added money-up and money-down sounds. added slow view of money changes, like real-ra.

This commit is contained in:
Chris Forbes
2009-11-29 15:26:55 +13:00
parent 9860b35030
commit da84b66424
17 changed files with 96 additions and 77 deletions

View File

@@ -91,7 +91,7 @@ namespace OpenRa.Game
Game.orderManager.FrameNumber, Game.orderManager.FrameNumber,
PerfHistory.items["render"].LastValue, PerfHistory.items["render"].LastValue,
PerfHistory.items["tick_time"].LastValue, PerfHistory.items["tick_time"].LastValue,
Game.LocalPlayer.Cash, Game.LocalPlayer.DisplayCash,
Game.LocalPlayer.GetTotalPower() Game.LocalPlayer.GetTotalPower()
), new int2(140, 5), Color.White); ), new int2(140, 5), Color.White);
@@ -100,7 +100,7 @@ namespace OpenRa.Game
chromeRenderer.DrawSprite(specialBinSprite, float2.Zero, 0); chromeRenderer.DrawSprite(specialBinSprite, float2.Zero, 0);
chromeRenderer.DrawSprite(moneyBinSprite, new float2(Game.viewport.Width - 320, 0), 0); chromeRenderer.DrawSprite(moneyBinSprite, new float2(Game.viewport.Width - 320, 0), 0);
var moneyDigits = Game.LocalPlayer.Cash.ToString(); var moneyDigits = Game.LocalPlayer.DisplayCash.ToString();
var x = Game.viewport.Width - 155; var x = Game.viewport.Width - 155;
foreach (var d in moneyDigits.Reverse()) foreach (var d in moneyDigits.Reverse())
{ {

View File

@@ -27,7 +27,7 @@ namespace OpenRa.Game
if (order.Subject != null && order.Player == Game.LocalPlayer) if (order.Subject != null && order.Player == Game.LocalPlayer)
doVoice = order.Subject; doVoice = order.Subject;
} }
if (doVoice != null && doVoice.traits.Contains<Mobile>()) if (doVoice != null && doVoice.traits.Contains<Unit>())
Game.PlaySound(Game.SovietVoices.First.GetNext() + GetVoiceSuffix(doVoice), false); Game.PlaySound(Game.SovietVoices.First.GetNext() + GetVoiceSuffix(doVoice), false);
} }
@@ -43,7 +43,7 @@ namespace OpenRa.Game
static string GetVoiceSuffix(Actor unit) static string GetVoiceSuffix(Actor unit)
{ {
var suffixes = new[] { ".r01", ".r03" }; var suffixes = new[] { ".r01", ".r03" };
return suffixes[unit.traits.Get<Traits.Mobile>().Voice]; return suffixes[unit.ActorID % suffixes.Length];
} }
float2 dragStart, dragEnd; float2 dragStart, dragEnd;
@@ -69,12 +69,12 @@ namespace OpenRa.Game
Game.SelectActorsInBox(Game.CellSize * dragStart, Game.CellSize * xy)); Game.SelectActorsInBox(Game.CellSize * dragStart, Game.CellSize * xy));
var voicedUnit = ((UnitOrderGenerator)orderGenerator).selection var voicedUnit = ((UnitOrderGenerator)orderGenerator).selection
.Select(a => a.traits.GetOrDefault<Mobile>()) .Where(a => a.traits.Contains<Unit>()
.Where(m => m != null && m.self.Owner == Game.LocalPlayer) && a.Owner == Game.LocalPlayer)
.FirstOrDefault(); .FirstOrDefault();
if (voicedUnit != null) if (voicedUnit != null)
Game.PlaySound(Game.SovietVoices.Second.GetNext() + GetVoiceSuffix(voicedUnit.self), false); Game.PlaySound(Game.SovietVoices.Second.GetNext() + GetVoiceSuffix(voicedUnit), false);
} }
dragStart = dragEnd = xy; dragStart = dragEnd = xy;
@@ -124,7 +124,7 @@ namespace OpenRa.Game
else else
return Cursor.MoveBlocked; return Cursor.MoveBlocked;
case "DeployMcv": case "DeployMcv":
var factBuildingInfo = (UnitInfo.BuildingInfo)Rules.UnitInfo[ "fact" ]; var factBuildingInfo = (BuildingInfo)Rules.UnitInfo[ "fact" ];
if( Game.CanPlaceBuilding( factBuildingInfo, a.Location - new int2( 1, 1 ), a, false ) ) if( Game.CanPlaceBuilding( factBuildingInfo, a.Location - new int2( 1, 1 ), a, false ) )
return Cursor.Deploy; return Cursor.Deploy;
else else

View File

@@ -303,7 +303,7 @@ namespace OpenRa.Game
return null; return null;
} }
public static bool CanPlaceBuilding(UnitInfo.BuildingInfo building, int2 xy, Actor toIgnore, bool adjust) public static bool CanPlaceBuilding(BuildingInfo building, int2 xy, Actor toIgnore, bool adjust)
{ {
return !Footprint.Tiles(building, xy, adjust).Any( return !Footprint.Tiles(building, xy, adjust).Any(
t => Rules.Map.ContainsResource(t) || !Game.IsCellBuildable(t, t => Rules.Map.ContainsResource(t) || !Game.IsCellBuildable(t,
@@ -311,12 +311,12 @@ namespace OpenRa.Game
toIgnore)); toIgnore));
} }
public static bool CanPlaceBuilding(UnitInfo.BuildingInfo building, int2 xy, bool adjust) public static bool CanPlaceBuilding(BuildingInfo building, int2 xy, bool adjust)
{ {
return CanPlaceBuilding(building, xy, null, adjust); return CanPlaceBuilding(building, xy, null, adjust);
} }
public static bool IsCloseEnoughToBase(Player p, UnitInfo.BuildingInfo bi, int2 position) public static bool IsCloseEnoughToBase(Player p, BuildingInfo bi, int2 position)
{ {
var maxDistance = bi.Adjacent + 2; /* real-ra is weird. this is 1 GAP. */ var maxDistance = bi.Adjacent + 2; /* real-ra is weird. this is 1 GAP. */

View File

@@ -9,12 +9,12 @@ namespace OpenRa.Game.GameRules
{ {
static class Footprint static class Footprint
{ {
public static IEnumerable<int2> Tiles( UnitInfo.BuildingInfo buildingInfo, int2 position ) public static IEnumerable<int2> Tiles( BuildingInfo buildingInfo, int2 position )
{ {
return Tiles(buildingInfo, position, true); return Tiles(buildingInfo, position, true);
} }
public static IEnumerable<int2> Tiles( UnitInfo.BuildingInfo buildingInfo, int2 position, bool adjustForPlacement ) public static IEnumerable<int2> Tiles( BuildingInfo buildingInfo, int2 position, bool adjustForPlacement )
{ {
var dim = buildingInfo.Dimensions; var dim = buildingInfo.Dimensions;
@@ -36,7 +36,7 @@ namespace OpenRa.Game.GameRules
return Tiles( building.unitInfo, a.Location, false ); return Tiles( building.unitInfo, a.Location, false );
} }
public static IEnumerable<int2> UnpathableTiles( UnitInfo.BuildingInfo buildingInfo, int2 position ) public static IEnumerable<int2> UnpathableTiles( BuildingInfo buildingInfo, int2 position )
{ {
var footprint = buildingInfo.Footprint.Where( x => !char.IsWhiteSpace( x ) ).ToArray(); var footprint = buildingInfo.Footprint.Where( x => !char.IsWhiteSpace( x ) ).ToArray();
foreach( var tile in TilesWhere( buildingInfo.Name, buildingInfo.Dimensions, footprint, a => a == 'x' ) ) foreach( var tile in TilesWhere( buildingInfo.Name, buildingInfo.Dimensions, footprint, a => a == 'x' ) )
@@ -55,7 +55,7 @@ namespace OpenRa.Game.GameRules
yield return new int2( x, y ); yield return new int2( x, y );
} }
public static int2 AdjustForBuildingSize( UnitInfo.BuildingInfo unitInfo ) public static int2 AdjustForBuildingSize( BuildingInfo unitInfo )
{ {
var dim = unitInfo.Dimensions; var dim = unitInfo.Dimensions;
return new int2( dim.X / 2, dim.Y > 1 ? ( dim.Y + 1 ) / 2 : 0 ); return new int2( dim.X / 2, dim.Y > 1 ? ( dim.Y + 1 ) / 2 : 0 );

View File

@@ -53,12 +53,12 @@ namespace OpenRa.Game
UnitCategory = Categories.SelectMany(x => x.Value.Select(y => new KeyValuePair<string, string>(y, x.Key))).ToDictionary(x => x.Key, x => x.Value); UnitCategory = Categories.SelectMany(x => x.Value.Select(y => new KeyValuePair<string, string>(y, x.Key))).ToDictionary(x => x.Key, x => x.Value);
UnitInfo = new InfoLoader<UnitInfo>( UnitInfo = new InfoLoader<UnitInfo>(
Pair.New<string, Func<string, UnitInfo>>("Building", s => new UnitInfo.BuildingInfo(s)), Pair.New<string, Func<string, UnitInfo>>("Building", s => new BuildingInfo(s)),
Pair.New<string, Func<string, UnitInfo>>("Defense", s => new UnitInfo.BuildingInfo(s)), Pair.New<string, Func<string, UnitInfo>>("Defense", s => new BuildingInfo(s)),
Pair.New<string, Func<string, UnitInfo>>("Infantry", s => new UnitInfo.InfantryInfo(s)), Pair.New<string, Func<string, UnitInfo>>("Infantry", s => new InfantryInfo(s)),
Pair.New<string, Func<string, UnitInfo>>("Vehicle", s => new UnitInfo.VehicleInfo(s)), Pair.New<string, Func<string, UnitInfo>>("Vehicle", s => new VehicleInfo(s)),
Pair.New<string, Func<string, UnitInfo>>("Ship", s => new UnitInfo.VehicleInfo(s)), Pair.New<string, Func<string, UnitInfo>>("Ship", s => new VehicleInfo(s)),
Pair.New<string, Func<string, UnitInfo>>("Plane", s => new UnitInfo.VehicleInfo(s))); Pair.New<string, Func<string, UnitInfo>>("Plane", s => new VehicleInfo(s)));
LoadCategories( LoadCategories(
"Weapon", "Weapon",

View File

@@ -14,7 +14,7 @@ namespace OpenRa.Game.GameRules
{ {
foreach( var b in Rules.Categories[ "Building" ] ) foreach( var b in Rules.Categories[ "Building" ] )
{ {
var info = (UnitInfo.BuildingInfo)Rules.UnitInfo[ b ]; var info = (BuildingInfo)Rules.UnitInfo[ b ];
foreach( var p in info.Produces ) foreach( var p in info.Produces )
producesIndex[ p ].Add( info ); producesIndex[ p ].Add( info );
} }
@@ -23,7 +23,7 @@ namespace OpenRa.Game.GameRules
public Cache<string, List<Actor>> GatherBuildings( Player player ) public Cache<string, List<Actor>> GatherBuildings( Player player )
{ {
var ret = new Cache<string, List<Actor>>( x => new List<Actor>() ); var ret = new Cache<string, List<Actor>>( x => new List<Actor>() );
foreach( var b in Game.world.Actors.Where( x => x.Owner == player && x.unitInfo is UnitInfo.BuildingInfo ) ) foreach( var b in Game.world.Actors.Where( x => x.Owner == player && x.unitInfo is BuildingInfo ) )
ret[ b.unitInfo.Name ].Add( b ); ret[ b.unitInfo.Name ].Add( b );
return ret; return ret;
} }

View File

@@ -56,54 +56,54 @@ namespace OpenRa.Game.GameRules
public readonly int InitialFacing = 128; public readonly int InitialFacing = 128;
public UnitInfo(string name) { Name = name; } public UnitInfo(string name) { Name = name; }
}
public class MobileInfo : UnitInfo public class MobileInfo : UnitInfo
{ {
public readonly int Passengers = 0; public readonly int Passengers = 0;
public readonly int Speed = 0; public readonly int Speed = 0;
public readonly bool NoMovingFire = false; public readonly bool NoMovingFire = false;
public MobileInfo(string name) : base(name) { } public MobileInfo(string name) : base(name) { }
} }
public class InfantryInfo : MobileInfo public class InfantryInfo : MobileInfo
{ {
public readonly bool Crushable = true; // also on VehicleInfo, but with a different default public readonly bool Crushable = true; // also on VehicleInfo, but with a different default
public readonly bool C4 = false; public readonly bool C4 = false;
public readonly bool FraidyCat = false; public readonly bool FraidyCat = false;
public readonly bool Infiltrate = false; public readonly bool Infiltrate = false;
public readonly bool IsCanine = false; public readonly bool IsCanine = false;
public readonly int SquadSize = 1; public readonly int SquadSize = 1;
public InfantryInfo(string name) : base(name) { } public InfantryInfo(string name) : base(name) { }
} }
public class VehicleInfo : MobileInfo public class VehicleInfo : MobileInfo
{ {
public readonly bool Crushable = false; public readonly bool Crushable = false;
public readonly bool Tracked = false; public readonly bool Tracked = false;
public VehicleInfo(string name) : base(name) { } public VehicleInfo(string name) : base(name) { }
} }
public class BuildingInfo : UnitInfo public class BuildingInfo : UnitInfo
{ {
public readonly int2 Dimensions = new int2( 1, 1 ); public readonly int2 Dimensions = new int2(1, 1);
public readonly string Footprint = "x"; public readonly string Footprint = "x";
public readonly string[] Produces = { }; public readonly string[] Produces = { };
public readonly bool BaseNormal = true; public readonly bool BaseNormal = true;
public readonly int Adjacent = 1; public readonly int Adjacent = 1;
public readonly bool Bib = false; public readonly bool Bib = false;
public readonly bool Capturable = false; public readonly bool Capturable = false;
public readonly int Power = 0; public readonly int Power = 0;
public readonly bool Powered = false; public readonly bool Powered = false;
public readonly bool Repairable = true; public readonly bool Repairable = true;
public readonly int Storage = 0; public readonly int Storage = 0;
public readonly bool Unsellable = false; public readonly bool Unsellable = false;
public readonly int[] RallyPoint = { 1, 3 }; public readonly int[] RallyPoint = { 1, 3 };
public BuildingInfo(string name) : base(name) { } public BuildingInfo(string name) : base(name) { }
}
} }
} }

View File

@@ -9,12 +9,12 @@ namespace OpenRa.Game
class PlaceBuilding : IOrderGenerator class PlaceBuilding : IOrderGenerator
{ {
public readonly Player Owner; public readonly Player Owner;
public readonly UnitInfo.BuildingInfo Building; public readonly BuildingInfo Building;
public PlaceBuilding(Player owner, string name) public PlaceBuilding(Player owner, string name)
{ {
Owner = owner; Owner = owner;
Building = (UnitInfo.BuildingInfo)Rules.UnitInfo[ name ]; Building = (BuildingInfo)Rules.UnitInfo[ name ];
} }
public IEnumerable<Order> Order(int2 xy, bool lmb) public IEnumerable<Order> Order(int2 xy, bool lmb)

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System;
namespace OpenRa.Game namespace OpenRa.Game
{ {
@@ -10,6 +11,7 @@ namespace OpenRa.Game
public Race Race; public Race Race;
public readonly int Index; public readonly int Index;
public int Cash; public int Cash;
public int DisplayCash;
int powerProvided; int powerProvided;
int powerDrained; int powerDrained;
@@ -20,6 +22,7 @@ namespace OpenRa.Game
this.PlayerName = playerName; this.PlayerName = playerName;
this.Race = race; this.Race = race;
this.Cash = 10000; this.Cash = 10000;
this.DisplayCash = 0;
this.powerProvided = this.powerDrained = 0; this.powerProvided = this.powerDrained = 0;
foreach( var cat in Rules.Categories.Keys ) foreach( var cat in Rules.Categories.Keys )
@@ -56,11 +59,29 @@ namespace OpenRa.Game
return true; return true;
} }
const int displayCashDeltaPerFrame = 50;
public void Tick() public void Tick()
{ {
foreach( var p in production ) foreach( var p in production )
if( p.Value != null ) if( p.Value != null )
p.Value.Tick( this ); p.Value.Tick( this );
if (this == Game.LocalPlayer)
{
if (DisplayCash < Cash)
{
DisplayCash += Math.Min(displayCashDeltaPerFrame,
Cash - DisplayCash);
Game.PlaySound("cashup1.aud", false);
}
else if (DisplayCash > Cash)
{
DisplayCash -= Math.Min(displayCashDeltaPerFrame,
DisplayCash - Cash);
Game.PlaySound("cashdn1.aud", false);
}
}
} }
// Key: Production category. Categories are: Building, Infantry, Vehicle, Ship, Plane (and one per super, if they're done in here) // Key: Production category. Categories are: Building, Infantry, Vehicle, Ship, Plane (and one per super, if they're done in here)

View File

@@ -180,7 +180,7 @@ namespace OpenRa.Game.Traits.Activities
var oldFraction = moveFraction; var oldFraction = moveFraction;
var oldTotal = moveFractionTotal; var oldTotal = moveFractionTotal;
moveFraction += ( self.unitInfo as UnitInfo.MobileInfo ).Speed; moveFraction += ( self.unitInfo as MobileInfo ).Speed;
UpdateCenterLocation( self, mobile ); UpdateCenterLocation( self, mobile );
if( moveFraction >= moveFractionTotal ) if( moveFraction >= moveFractionTotal )
{ {

View File

@@ -8,11 +8,11 @@ namespace OpenRa.Game.Traits
{ {
class Building : ITick, INotifyBuildComplete class Building : ITick, INotifyBuildComplete
{ {
public readonly UnitInfo.BuildingInfo unitInfo; public readonly BuildingInfo unitInfo;
public Building(Actor self) public Building(Actor self)
{ {
unitInfo = (UnitInfo.BuildingInfo)self.unitInfo; unitInfo = (BuildingInfo)self.unitInfo;
} }
bool first = true; bool first = true;

View File

@@ -52,7 +52,7 @@ namespace OpenRa.Game.Traits
self.unitInfo.ROT); self.unitInfo.ROT);
// .6f going the wrong way; .8f going sideways, 1f going forward. // .6f going the wrong way; .8f going sideways, 1f going forward.
var rawSpeed = .2f * (self.unitInfo as UnitInfo.VehicleInfo).Speed; var rawSpeed = .2f * (self.unitInfo as VehicleInfo).Speed;
var angle = (unit.Facing - desiredFacing) / 128f * Math.PI; var angle = (unit.Facing - desiredFacing) / 128f * Math.PI;
var scale = .4f + .6f * (float)Math.Cos(angle); var scale = .4f + .6f * (float)Math.Cos(angle);

View File

@@ -22,7 +22,7 @@ namespace OpenRa.Game.Traits
public InfantrySquad(Actor self) public InfantrySquad(Actor self)
{ {
var ii = (UnitInfo.InfantryInfo)self.unitInfo; var ii = (InfantryInfo)self.unitInfo;
for (int i = 0; i < ii.SquadSize; i++) for (int i = 0; i < ii.SquadSize; i++)
elements.Add(new Soldier(self.unitInfo.Name, elements.Add(new Soldier(self.unitInfo.Name,
self.CenterLocation.ToInt2() + elementOffsets[ii.SquadSize][i])); self.CenterLocation.ToInt2() + elementOffsets[ii.SquadSize][i]));
@@ -72,7 +72,7 @@ namespace OpenRa.Game.Traits
anim.PlayFetchIndex("stand", anim.PlayFetchIndex("stand",
() => Util.QuantizeFacing(facing, anim.CurrentSequence.Length)); () => Util.QuantizeFacing(facing, anim.CurrentSequence.Length));
location = initialLocation; location = initialLocation;
speed = ((UnitInfo.InfantryInfo)Rules.UnitInfo[name]).Speed / 2; speed = ((InfantryInfo)Rules.UnitInfo[name]).Speed / 2;
} }
public void Tick( int2 desiredLocation, Actor self ) public void Tick( int2 desiredLocation, Actor self )

View File

@@ -22,7 +22,7 @@ namespace OpenRa.Game.Traits
{ {
if( order.OrderString == "DeployMcv" ) if( order.OrderString == "DeployMcv" )
{ {
var factBuildingInfo = (UnitInfo.BuildingInfo)Rules.UnitInfo[ "fact" ]; var factBuildingInfo = (BuildingInfo)Rules.UnitInfo[ "fact" ];
if( Game.CanPlaceBuilding( factBuildingInfo, self.Location - new int2( 1, 1 ), self, false ) ) if( Game.CanPlaceBuilding( factBuildingInfo, self.Location - new int2( 1, 1 ), self, false ) )
{ {
self.CancelActivity(); self.CancelActivity();

View File

@@ -16,8 +16,6 @@ namespace OpenRa.Game.Traits
public int2 fromCell { get { return __fromCell; } set { Game.UnitInfluence.Remove( this ); __fromCell = value; Game.UnitInfluence.Add( this ); } } public int2 fromCell { get { return __fromCell; } set { Game.UnitInfluence.Remove( this ); __fromCell = value; Game.UnitInfluence.Add( this ); } }
public int2 toCell { get { return self.Location; } set { Game.UnitInfluence.Remove( this ); self.Location = value; Game.UnitInfluence.Add( this ); } } public int2 toCell { get { return self.Location; } set { Game.UnitInfluence.Remove( this ); self.Location = value; Game.UnitInfluence.Add( this ); } }
public int Voice = Game.CosmeticRandom.Next(2);
public Mobile(Actor self) public Mobile(Actor self)
{ {
this.self = self; this.self = self;
@@ -62,7 +60,7 @@ namespace OpenRa.Game.Traits
case "Infantry": case "Infantry":
return UnitMovementType.Foot; return UnitMovementType.Foot;
case "Vehicle": case "Vehicle":
return ( self.unitInfo as UnitInfo.VehicleInfo ).Tracked ? UnitMovementType.Track : UnitMovementType.Wheel; return ( self.unitInfo as VehicleInfo ).Tracked ? UnitMovementType.Track : UnitMovementType.Wheel;
case "Ship": case "Ship":
return UnitMovementType.Float; return UnitMovementType.Float;
case "Plane": case "Plane":

View File

@@ -43,7 +43,7 @@ namespace OpenRa.Game
spriteRenderer.DrawSprite(unitDebug, Game.CellSize * new float2(i, j), 0); spriteRenderer.DrawSprite(unitDebug, Game.CellSize * new float2(i, j), 0);
} }
public void DrawBuildingGrid( UnitInfo.BuildingInfo bi ) public void DrawBuildingGrid( BuildingInfo bi )
{ {
var position = Game.controller.MousePosition.ToInt2(); var position = Game.controller.MousePosition.ToInt2();
var isCloseEnough = Game.IsCloseEnoughToBase(Game.LocalPlayer, bi, position); var isCloseEnough = Game.IsCloseEnoughToBase(Game.LocalPlayer, bi, position);

View File

@@ -28,7 +28,7 @@ namespace OpenRa.Game
{ {
Game.world.AddFrameEndTask( _ => Game.world.AddFrameEndTask( _ =>
{ {
var building = (UnitInfo.BuildingInfo)Rules.UnitInfo[ order.TargetString ]; var building = (BuildingInfo)Rules.UnitInfo[ order.TargetString ];
var producing = order.Player.Producing(Rules.UnitCategory[order.TargetString]); var producing = order.Player.Producing(Rules.UnitCategory[order.TargetString]);
if( producing == null || producing.Item != order.TargetString || producing.RemainingTime != 0 ) if( producing == null || producing.Item != order.TargetString || producing.RemainingTime != 0 )
return; return;