From 409a48b22a8ca6caf60fcd2d728feaa859a40b74 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sun, 10 Jan 2010 13:06:39 +1300 Subject: [PATCH] more --- OpenRa.Game/Actor.cs | 4 ++-- OpenRa.Game/GameRules/Rules.cs | 16 ++++++++-------- OpenRa.Game/GameRules/TechTree.cs | 6 +++--- OpenRa.Game/GameRules/UnitInfo.cs | 8 ++++---- .../Orders/ChronosphereSelectOrderGenerator.cs | 2 +- OpenRa.Game/Orders/IronCurtainOrderGenerator.cs | 2 +- OpenRa.Game/Traits/AttackBase.cs | 7 +++++++ OpenRa.Game/Traits/AutoTarget.cs | 5 +++++ OpenRa.Game/Traits/Chronoshiftable.cs | 5 +++++ OpenRa.Game/Traits/Production.cs | 4 ++-- OpenRa.Game/Traits/ProductionSurround.cs | 2 +- OpenRa.Game/Traits/RenderUnitReload.cs | 5 +++++ OpenRa.Game/Traits/Repairable.cs | 5 +++++ OpenRa.Game/Traits/TraitsInterfaces.cs | 2 +- OpenRa.Game/Traits/Unit.cs | 12 +++++++++++- 15 files changed, 61 insertions(+), 24 deletions(-) diff --git a/OpenRa.Game/Actor.cs b/OpenRa.Game/Actor.cs index 76044e28a0..1493fd8625 100755 --- a/OpenRa.Game/Actor.cs +++ b/OpenRa.Game/Actor.cs @@ -12,7 +12,7 @@ namespace OpenRa.Game { [Sync] public readonly TypeDictionary traits = new TypeDictionary(); - public readonly UnitInfo Info; + public readonly LegacyUnitInfo Info; public readonly uint ActorID; [Sync] @@ -36,7 +36,7 @@ namespace OpenRa.Game public Actor( ActorInfo info, int2 location, Player owner ) { ActorID = Game.world.NextAID(); - Info = (UnitInfo)info; // temporary + Info = (LegacyUnitInfo)info; // temporary Location = location; CenterLocation = Traits.Util.CenterOfCell(Location); Owner = owner; diff --git a/OpenRa.Game/GameRules/Rules.cs b/OpenRa.Game/GameRules/Rules.cs index 46a53ee424..fd5207b3d6 100755 --- a/OpenRa.Game/GameRules/Rules.cs +++ b/OpenRa.Game/GameRules/Rules.cs @@ -13,7 +13,7 @@ namespace OpenRa.Game public static IniFile AllRules; public static Dictionary> Categories = new Dictionary>(); public static Dictionary UnitCategory; - public static InfoLoader UnitInfo; + public static InfoLoader UnitInfo; public static InfoLoader WeaponInfo; public static InfoLoader WarheadInfo; public static InfoLoader ProjectileInfo; @@ -64,13 +64,13 @@ namespace OpenRa.Game "Plane"); UnitCategory = Categories.SelectMany(x => x.Value.Select(y => new KeyValuePair(y, x.Key))).ToDictionary(x => x.Key, x => x.Value); - UnitInfo = new InfoLoader( - Pair.New>("Building", s => new BuildingInfo(s)), - Pair.New>("Defense", s => new BuildingInfo(s)), - Pair.New>("Infantry", s => new InfantryInfo(s)), - Pair.New>("Vehicle", s => new VehicleInfo(s)), - Pair.New>("Ship", s => new VehicleInfo(s)), - Pair.New>("Plane", s => new VehicleInfo(s))); + UnitInfo = new InfoLoader( + Pair.New>("Building", s => new BuildingInfo(s)), + Pair.New>("Defense", s => new BuildingInfo(s)), + Pair.New>("Infantry", s => new InfantryInfo(s)), + Pair.New>("Vehicle", s => new VehicleInfo(s)), + Pair.New>("Ship", s => new VehicleInfo(s)), + Pair.New>("Plane", s => new VehicleInfo(s))); LoadCategories( "Weapon", diff --git a/OpenRa.Game/GameRules/TechTree.cs b/OpenRa.Game/GameRules/TechTree.cs index c2cfb0c230..354cc3a38a 100755 --- a/OpenRa.Game/GameRules/TechTree.cs +++ b/OpenRa.Game/GameRules/TechTree.cs @@ -6,7 +6,7 @@ namespace OpenRa.Game.GameRules { class TechTree { - readonly Cache> producesIndex = new Cache>( x => new List() ); + readonly Cache> producesIndex = new Cache>( x => new List() ); public TechTree() { @@ -26,7 +26,7 @@ namespace OpenRa.Game.GameRules return ret; } - public bool CanBuild( UnitInfo unit, Player player, Cache> playerBuildings ) + public bool CanBuild( LegacyUnitInfo unit, Player player, Cache> playerBuildings ) { if( unit.TechLevel == -1 ) return false; @@ -59,7 +59,7 @@ namespace OpenRa.Game.GameRules .Where(x => Rules.UnitInfo[x].Owner.Contains(player.Race)); /* todo: fix for dual-race scenarios (captured buildings) */ } - public IEnumerable UnitBuiltAt( UnitInfo info ) + public IEnumerable UnitBuiltAt( LegacyUnitInfo info ) { if( info.BuiltAt.Length != 0 ) return info.BuiltAt.Select( x => Rules.UnitInfo[ x.ToLowerInvariant() ] ); diff --git a/OpenRa.Game/GameRules/UnitInfo.cs b/OpenRa.Game/GameRules/UnitInfo.cs index 1b13fa1883..8f06bf4193 100755 --- a/OpenRa.Game/GameRules/UnitInfo.cs +++ b/OpenRa.Game/GameRules/UnitInfo.cs @@ -11,7 +11,7 @@ namespace OpenRa.Game.GameRules concrete = 4, } - public class UnitInfo : ActorInfo + public class LegacyUnitInfo : ActorInfo { public readonly string Name; @@ -64,10 +64,10 @@ namespace OpenRa.Game.GameRules public readonly int[] PrimaryLocalOffset = { }; public readonly int[] SecondaryLocalOffset = { }; - public UnitInfo(string name) { Name = name; } + public LegacyUnitInfo(string name) { Name = name; } } - public class LegacyMobileInfo : UnitInfo + public class LegacyMobileInfo : LegacyUnitInfo { public readonly int Speed = 0; public readonly bool NoMovingFire = false; @@ -94,7 +94,7 @@ namespace OpenRa.Game.GameRules public VehicleInfo(string name) : base(name) { } } - public class BuildingInfo : UnitInfo + public class BuildingInfo : LegacyUnitInfo { public readonly int2 Dimensions = new int2(1, 1); public readonly string Footprint = "x"; diff --git a/OpenRa.Game/Orders/ChronosphereSelectOrderGenerator.cs b/OpenRa.Game/Orders/ChronosphereSelectOrderGenerator.cs index ec0c0f4edf..b4a013b15a 100644 --- a/OpenRa.Game/Orders/ChronosphereSelectOrderGenerator.cs +++ b/OpenRa.Game/Orders/ChronosphereSelectOrderGenerator.cs @@ -33,7 +33,7 @@ namespace OpenRa.Game.Orders && a.traits.WithInterface().Any() && a.Info.Selectable).FirstOrDefault(); - var unit = underCursor != null ? underCursor.Info as UnitInfo : null; + var unit = underCursor != null ? underCursor.Info as LegacyUnitInfo : null; if (unit != null) yield return new Order("ChronosphereSelect", underCursor, null, int2.Zero, power.Name); diff --git a/OpenRa.Game/Orders/IronCurtainOrderGenerator.cs b/OpenRa.Game/Orders/IronCurtainOrderGenerator.cs index 0a75ca1dd6..57f9870c5a 100644 --- a/OpenRa.Game/Orders/IronCurtainOrderGenerator.cs +++ b/OpenRa.Game/Orders/IronCurtainOrderGenerator.cs @@ -33,7 +33,7 @@ namespace OpenRa.Game.Orders && a.traits.Contains() && a.Info.Selectable).FirstOrDefault(); - var unit = underCursor != null ? underCursor.Info as UnitInfo : null; + var unit = underCursor != null ? underCursor.Info as LegacyUnitInfo : null; if (unit != null) yield return new Order("IronCurtain", underCursor, null, int2.Zero, power.Name); diff --git a/OpenRa.Game/Traits/AttackBase.cs b/OpenRa.Game/Traits/AttackBase.cs index 6b78edfe9c..ed8bfb08f3 100644 --- a/OpenRa.Game/Traits/AttackBase.cs +++ b/OpenRa.Game/Traits/AttackBase.cs @@ -6,6 +6,13 @@ using OpenRa.Game.Effects; namespace OpenRa.Game.Traits { + class AttackBaseInfo : ITraitInfo + { + + + public object Create(Actor self) { return new AttackBase(self); } + } + class AttackBase : IIssueOrder, IResolveOrder, ITick { [Sync] public Actor target; diff --git a/OpenRa.Game/Traits/AutoTarget.cs b/OpenRa.Game/Traits/AutoTarget.cs index bd7730d57c..94e66aeeaf 100644 --- a/OpenRa.Game/Traits/AutoTarget.cs +++ b/OpenRa.Game/Traits/AutoTarget.cs @@ -2,6 +2,11 @@ namespace OpenRa.Game.Traits { + class AutoTargetInfo : ITraitInfo + { + public object Create(Actor self) { return new AutoTarget(self); } + } + class AutoTarget : ITick, INotifyDamage { public AutoTarget(Actor self) {} diff --git a/OpenRa.Game/Traits/Chronoshiftable.cs b/OpenRa.Game/Traits/Chronoshiftable.cs index 2df077e0bb..4450d036ce 100644 --- a/OpenRa.Game/Traits/Chronoshiftable.cs +++ b/OpenRa.Game/Traits/Chronoshiftable.cs @@ -5,6 +5,11 @@ using System.Linq; namespace OpenRa.Game.Traits { + class ChronoshiftableInfo : ITraitInfo + { + public object Create(Actor self) { return new Chronoshiftable(self); } + } + class Chronoshiftable : IResolveOrder, ISpeedModifier, ITick { // Return-to-sender logic diff --git a/OpenRa.Game/Traits/Production.cs b/OpenRa.Game/Traits/Production.cs index fb83d73a85..4cebf0f320 100755 --- a/OpenRa.Game/Traits/Production.cs +++ b/OpenRa.Game/Traits/Production.cs @@ -11,7 +11,7 @@ namespace OpenRa.Game.Traits public Production( Actor self ) { } - public virtual int2? CreationLocation( Actor self, UnitInfo producee ) + public virtual int2? CreationLocation( Actor self, LegacyUnitInfo producee ) { return ( 1 / 24f * self.CenterLocation ).ToInt2(); } @@ -21,7 +21,7 @@ namespace OpenRa.Game.Traits return newUnit.Info.InitialFacing; } - public bool Produce( Actor self, UnitInfo producee ) + public bool Produce( Actor self, LegacyUnitInfo producee ) { var location = CreationLocation( self, producee ); if( location == null || Game.UnitInfluence.GetUnitsAt( location.Value ).Any() ) diff --git a/OpenRa.Game/Traits/ProductionSurround.cs b/OpenRa.Game/Traits/ProductionSurround.cs index 4fb0091697..1c2f1d8327 100644 --- a/OpenRa.Game/Traits/ProductionSurround.cs +++ b/OpenRa.Game/Traits/ProductionSurround.cs @@ -24,7 +24,7 @@ namespace OpenRa.Game.Traits return null; } - public override int2? CreationLocation(Actor self, UnitInfo producee) + public override int2? CreationLocation(Actor self, LegacyUnitInfo producee) { return FindAdjacentTile(self, producee.WaterBound ? UnitMovementType.Float : UnitMovementType.Wheel); /* hackety hack */ diff --git a/OpenRa.Game/Traits/RenderUnitReload.cs b/OpenRa.Game/Traits/RenderUnitReload.cs index 59f05a5ea7..fe0c8c2f53 100644 --- a/OpenRa.Game/Traits/RenderUnitReload.cs +++ b/OpenRa.Game/Traits/RenderUnitReload.cs @@ -2,6 +2,11 @@ namespace OpenRa.Game.Traits { + class RenderUnitReloadInfo : ITraitInfo + { + public object Create(Actor self) { return new RenderUnitReload(self); } + } + class RenderUnitReload : RenderUnit { public RenderUnitReload(Actor self) diff --git a/OpenRa.Game/Traits/Repairable.cs b/OpenRa.Game/Traits/Repairable.cs index c5c38caf84..7e75fd48ce 100644 --- a/OpenRa.Game/Traits/Repairable.cs +++ b/OpenRa.Game/Traits/Repairable.cs @@ -6,6 +6,11 @@ using OpenRa.Game.Traits.Activities; namespace OpenRa.Game.Traits { + class RepairableInfo : ITraitInfo + { + public object Create(Actor self) { return new Repairable(self); } + } + class Repairable : IIssueOrder, IResolveOrder { IDisposable reservation; diff --git a/OpenRa.Game/Traits/TraitsInterfaces.cs b/OpenRa.Game/Traits/TraitsInterfaces.cs index 7a6c05611b..440eda8a1f 100644 --- a/OpenRa.Game/Traits/TraitsInterfaces.cs +++ b/OpenRa.Game/Traits/TraitsInterfaces.cs @@ -24,7 +24,7 @@ namespace OpenRa.Game.Traits interface IProducer { - bool Produce( Actor self, UnitInfo producee ); + bool Produce( Actor self, LegacyUnitInfo producee ); void SetPrimaryProducer(Actor self, bool isPrimary); } interface IOccupySpace { IEnumerable OccupiedCells(); } diff --git a/OpenRa.Game/Traits/Unit.cs b/OpenRa.Game/Traits/Unit.cs index ebfc56cf31..c3de5d2dfe 100755 --- a/OpenRa.Game/Traits/Unit.cs +++ b/OpenRa.Game/Traits/Unit.cs @@ -1,6 +1,16 @@ - +using OpenRa.Game.GameRules; + namespace OpenRa.Game.Traits { + class UnitInfo : ITraitInfo + { + public readonly int HP = 0; + public readonly ArmorType Armor = ArmorType.none; + public readonly bool Crewed = false; // replace with trait? + + public object Create(Actor self) { return new Unit(self); } + } + class Unit : INotifyDamage { [Sync]