From 12b84a84686d1801073c9116578a6bc57d88d523 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sun, 10 Jan 2010 17:28:05 +1300 Subject: [PATCH] finished building *Infos --- OpenRa.Game/Chrome.cs | 2 +- OpenRa.Game/Game.cs | 6 +++--- OpenRa.Game/GameRules/Footprint.cs | 8 ++++---- OpenRa.Game/GameRules/Rules.cs | 4 ++-- OpenRa.Game/GameRules/TechTree.cs | 4 ++-- OpenRa.Game/GameRules/UnitInfo.cs | 4 ++-- .../Orders/PlaceBuildingOrderGenerator.cs | 4 ++-- OpenRa.Game/Orders/PowerDownOrderGenerator.cs | 2 +- OpenRa.Game/Orders/RepairOrderGenerator.cs | 2 +- OpenRa.Game/Orders/SellOrderGenerator.cs | 2 +- OpenRa.Game/Orders/UnitOrderGenerator.cs | 2 +- OpenRa.Game/Orders/UnitOrders.cs | 2 +- OpenRa.Game/Player.cs | 2 +- OpenRa.Game/Traits/APMine.cs | 11 +++++++---- OpenRa.Game/Traits/ATMine.cs | 10 ++++++---- OpenRa.Game/Traits/AcceptsOre.cs | 5 +++++ OpenRa.Game/Traits/Activities/HeliReturn.cs | 2 +- OpenRa.Game/Traits/AttackBase.cs | 4 +--- OpenRa.Game/Traits/AttackHeli.cs | 5 +++++ OpenRa.Game/Traits/AttackPlane.cs | 5 +++++ OpenRa.Game/Traits/AttackTurreted.cs | 7 +++++-- OpenRa.Game/Traits/AutoHeal.cs | 4 ++-- OpenRa.Game/Traits/AutoTarget.cs | 7 +------ OpenRa.Game/Traits/BelowUnits.cs | 4 ++-- OpenRa.Game/Traits/Buildable.cs | 9 ++------- OpenRa.Game/Traits/Building.cs | 9 +++++++-- OpenRa.Game/Traits/C4Demolition.cs | 4 ++-- OpenRa.Game/Traits/ChronoshiftDeploy.cs | 5 +++++ OpenRa.Game/Traits/ChronoshiftPaletteEffect.cs | 3 +++ OpenRa.Game/Traits/Chronosphere.cs | 6 ++---- OpenRa.Game/Traits/Cloak.cs | 5 +++++ OpenRa.Game/Traits/EngineerCapture.cs | 7 +------ OpenRa.Game/Traits/Explodes.cs | 7 +------ OpenRa.Game/Traits/Fake.cs | 12 ++---------- OpenRa.Game/Traits/GpsLaunchSite.cs | 8 ++------ OpenRa.Game/Traits/Harvester.cs | 4 +--- OpenRa.Game/Traits/Helicopter.cs | 5 ++++- OpenRa.Game/Traits/InvisibleToOthers.cs | 7 +------ OpenRa.Game/Traits/IronCurtain.cs | 17 +++-------------- OpenRa.Game/Traits/IronCurtainable.cs | 4 +--- OpenRa.Game/Traits/McvDeploy.cs | 2 +- OpenRa.Game/Traits/MineImmune.cs | 11 ++--------- OpenRa.Game/Traits/Minelayer.cs | 16 ++++------------ OpenRa.Game/Traits/Plane.cs | 3 +++ OpenRa.Game/Traits/Production.cs | 6 +++--- OpenRa.Game/Traits/StoresOre.cs | 2 +- OpenRa.Game/Traits/WaterPaletteRotation.cs | 6 ++---- OpenRa.Game/UiOverlay.cs | 2 +- 48 files changed, 121 insertions(+), 147 deletions(-) diff --git a/OpenRa.Game/Chrome.cs b/OpenRa.Game/Chrome.cs index 3033c1a2fc..51cca4e4d2 100644 --- a/OpenRa.Game/Chrome.cs +++ b/OpenRa.Game/Chrome.cs @@ -647,7 +647,7 @@ namespace OpenRa.Game DrawRightAligned( "${0}".F(info.Cost), pos + new int2(-5,5), Game.LocalPlayer.Cash + Game.LocalPlayer.Ore >= info.Cost ? Color.White : Color.Red); - var bi = info as BuildingInfo; + var bi = info as LegacyBuildingInfo; if (bi != null) DrawRightAligned("ϟ{0}".F(bi.Power), pos + new int2(-5, 20), Game.LocalPlayer.PowerProvided - Game.LocalPlayer.PowerDrained + bi.Power >= 0 diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index 271d636519..1fa4fac1ac 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -321,7 +321,7 @@ namespace OpenRa.Game public static Random SharedRandom = new Random(0); /* for things that require sync */ public static Random CosmeticRandom = new Random(); /* for things that are just fluff */ - public static bool CanPlaceBuilding(BuildingInfo building, int2 xy, Actor toIgnore, bool adjust) + public static bool CanPlaceBuilding(LegacyBuildingInfo building, int2 xy, Actor toIgnore, bool adjust) { return !Footprint.Tiles(building, xy, adjust).Any( t => !Rules.Map.IsInMap(t.X, t.Y) || Rules.Map.ContainsResource(t) || !Game.IsCellBuildable(t, @@ -329,7 +329,7 @@ namespace OpenRa.Game toIgnore)); } - public static bool IsCloseEnoughToBase(Player p, BuildingInfo bi, int2 position) + public static bool IsCloseEnoughToBase(Player p, LegacyBuildingInfo bi, int2 position) { var maxDistance = bi.Adjacent + 1; @@ -338,7 +338,7 @@ namespace OpenRa.Game heuristic = loc => { var b = Game.BuildingInfluence.GetBuildingAt(loc); - if (b != null && b.Owner == p && (b.Info as BuildingInfo).BaseNormal) return 0; + if (b != null && b.Owner == p && (b.Info as LegacyBuildingInfo).BaseNormal) return 0; if ((loc - position).Length > maxDistance) return float.PositiveInfinity; /* not quite right */ return 1; diff --git a/OpenRa.Game/GameRules/Footprint.cs b/OpenRa.Game/GameRules/Footprint.cs index 2a2311496d..3d740fd1d2 100644 --- a/OpenRa.Game/GameRules/Footprint.cs +++ b/OpenRa.Game/GameRules/Footprint.cs @@ -6,12 +6,12 @@ namespace OpenRa.Game.GameRules { static class Footprint { - public static IEnumerable Tiles( BuildingInfo buildingInfo, int2 position ) + public static IEnumerable Tiles( LegacyBuildingInfo buildingInfo, int2 position ) { return Tiles(buildingInfo, position, true); } - public static IEnumerable Tiles( BuildingInfo buildingInfo, int2 position, bool adjustForPlacement ) + public static IEnumerable Tiles( LegacyBuildingInfo buildingInfo, int2 position, bool adjustForPlacement ) { var dim = buildingInfo.Dimensions; @@ -33,7 +33,7 @@ namespace OpenRa.Game.GameRules return Tiles( building.unitInfo, a.Location, false ); } - public static IEnumerable UnpathableTiles( BuildingInfo buildingInfo, int2 position ) + public static IEnumerable UnpathableTiles( LegacyBuildingInfo buildingInfo, int2 position ) { var footprint = buildingInfo.Footprint.Where( x => !char.IsWhiteSpace( x ) ).ToArray(); foreach( var tile in TilesWhere( buildingInfo.Name, buildingInfo.Dimensions, footprint, a => a == 'x' ) ) @@ -52,7 +52,7 @@ namespace OpenRa.Game.GameRules yield return new int2( x, y ); } - public static int2 AdjustForBuildingSize( BuildingInfo unitInfo ) + public static int2 AdjustForBuildingSize( LegacyBuildingInfo unitInfo ) { var dim = unitInfo.Dimensions; return new int2( dim.X / 2, dim.Y > 1 ? ( dim.Y + 1 ) / 2 : 0 ); diff --git a/OpenRa.Game/GameRules/Rules.cs b/OpenRa.Game/GameRules/Rules.cs index fd5207b3d6..30c9781e35 100755 --- a/OpenRa.Game/GameRules/Rules.cs +++ b/OpenRa.Game/GameRules/Rules.cs @@ -65,8 +65,8 @@ namespace OpenRa.Game 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>("Building", s => new LegacyBuildingInfo(s)), + Pair.New>("Defense", s => new LegacyBuildingInfo(s)), Pair.New>("Infantry", s => new InfantryInfo(s)), Pair.New>("Vehicle", s => new VehicleInfo(s)), Pair.New>("Ship", s => new VehicleInfo(s)), diff --git a/OpenRa.Game/GameRules/TechTree.cs b/OpenRa.Game/GameRules/TechTree.cs index 354cc3a38a..8e8253f782 100755 --- a/OpenRa.Game/GameRules/TechTree.cs +++ b/OpenRa.Game/GameRules/TechTree.cs @@ -12,7 +12,7 @@ namespace OpenRa.Game.GameRules { foreach( var b in Rules.Categories[ "Building" ] ) { - var info = (BuildingInfo)Rules.UnitInfo[ b ]; + var info = (LegacyBuildingInfo)Rules.UnitInfo[ b ]; foreach( var p in info.Produces ) producesIndex[ p ].Add( info ); } @@ -21,7 +21,7 @@ namespace OpenRa.Game.GameRules public Cache> GatherBuildings( Player player ) { var ret = new Cache>( x => new List() ); - foreach( var b in Game.world.Actors.Where( x => x.Owner == player && x.Info is BuildingInfo ) ) + foreach( var b in Game.world.Actors.Where( x => x.Owner == player && x.Info is LegacyBuildingInfo ) ) ret[ b.Info.Name ].Add( b ); return ret; } diff --git a/OpenRa.Game/GameRules/UnitInfo.cs b/OpenRa.Game/GameRules/UnitInfo.cs index 8f06bf4193..e3daf1eb12 100755 --- a/OpenRa.Game/GameRules/UnitInfo.cs +++ b/OpenRa.Game/GameRules/UnitInfo.cs @@ -94,7 +94,7 @@ namespace OpenRa.Game.GameRules public VehicleInfo(string name) : base(name) { } } - public class BuildingInfo : LegacyUnitInfo + public class LegacyBuildingInfo : LegacyUnitInfo { public readonly int2 Dimensions = new int2(1, 1); public readonly string Footprint = "x"; @@ -112,6 +112,6 @@ namespace OpenRa.Game.GameRules public readonly int[] RallyPoint = { 1, 3 }; public readonly float[] SpawnOffset = null; - public BuildingInfo(string name) : base(name) { } + public LegacyBuildingInfo(string name) : base(name) { } } } diff --git a/OpenRa.Game/Orders/PlaceBuildingOrderGenerator.cs b/OpenRa.Game/Orders/PlaceBuildingOrderGenerator.cs index 5c9d2b25fc..193f5872d0 100644 --- a/OpenRa.Game/Orders/PlaceBuildingOrderGenerator.cs +++ b/OpenRa.Game/Orders/PlaceBuildingOrderGenerator.cs @@ -6,12 +6,12 @@ namespace OpenRa.Game.Orders class PlaceBuildingOrderGenerator : IOrderGenerator { readonly Actor Producer; - readonly BuildingInfo Building; + readonly LegacyBuildingInfo Building; public PlaceBuildingOrderGenerator(Actor producer, string name) { Producer = producer; - Building = (BuildingInfo)Rules.UnitInfo[ name ]; + Building = (LegacyBuildingInfo)Rules.UnitInfo[ name ]; } public IEnumerable Order(int2 xy, MouseInput mi) diff --git a/OpenRa.Game/Orders/PowerDownOrderGenerator.cs b/OpenRa.Game/Orders/PowerDownOrderGenerator.cs index 5779e81a20..5a33cbf1d0 100644 --- a/OpenRa.Game/Orders/PowerDownOrderGenerator.cs +++ b/OpenRa.Game/Orders/PowerDownOrderGenerator.cs @@ -27,7 +27,7 @@ namespace OpenRa.Game.Orders && a.traits.Contains() && a.Info.Selectable).FirstOrDefault(); - var building = underCursor != null ? underCursor.Info as BuildingInfo : null; + var building = underCursor != null ? underCursor.Info as LegacyBuildingInfo : null; if (building != null) yield return new Order("PowerDown", underCursor, null, int2.Zero, null); diff --git a/OpenRa.Game/Orders/RepairOrderGenerator.cs b/OpenRa.Game/Orders/RepairOrderGenerator.cs index bc79d65ed4..84da77c725 100644 --- a/OpenRa.Game/Orders/RepairOrderGenerator.cs +++ b/OpenRa.Game/Orders/RepairOrderGenerator.cs @@ -27,7 +27,7 @@ namespace OpenRa.Game.Orders && a.traits.Contains() && a.Info.Selectable).FirstOrDefault(); - var building = underCursor != null ? underCursor.Info as BuildingInfo : null; + var building = underCursor != null ? underCursor.Info as LegacyBuildingInfo : null; if (building != null && building.Repairable && underCursor.Health < building.Strength) yield return new Order("Repair", underCursor, null, int2.Zero, null); diff --git a/OpenRa.Game/Orders/SellOrderGenerator.cs b/OpenRa.Game/Orders/SellOrderGenerator.cs index 3576c59d1e..c46b459d55 100644 --- a/OpenRa.Game/Orders/SellOrderGenerator.cs +++ b/OpenRa.Game/Orders/SellOrderGenerator.cs @@ -27,7 +27,7 @@ namespace OpenRa.Game.Orders && a.traits.Contains() && a.Info.Selectable).FirstOrDefault(); - var building = underCursor != null ? underCursor.Info as BuildingInfo : null; + var building = underCursor != null ? underCursor.Info as LegacyBuildingInfo : null; if (building != null && !building.Unsellable) yield return new Order("Sell", underCursor, null, int2.Zero, null); diff --git a/OpenRa.Game/Orders/UnitOrderGenerator.cs b/OpenRa.Game/Orders/UnitOrderGenerator.cs index 95ad375bbb..c578db1f34 100644 --- a/OpenRa.Game/Orders/UnitOrderGenerator.cs +++ b/OpenRa.Game/Orders/UnitOrderGenerator.cs @@ -69,7 +69,7 @@ namespace OpenRa.Game.Orders else return Cursor.MoveBlocked; case "DeployMcv": - var factBuildingInfo = (BuildingInfo)Rules.UnitInfo["fact"]; + var factBuildingInfo = (LegacyBuildingInfo)Rules.UnitInfo["fact"]; if (Game.CanPlaceBuilding(factBuildingInfo, a.Location - new int2(1, 1), a, false)) return Cursor.Deploy; else diff --git a/OpenRa.Game/Orders/UnitOrders.cs b/OpenRa.Game/Orders/UnitOrders.cs index 6e11cfad3a..66646d787c 100644 --- a/OpenRa.Game/Orders/UnitOrders.cs +++ b/OpenRa.Game/Orders/UnitOrders.cs @@ -16,7 +16,7 @@ namespace OpenRa.Game.Orders Game.world.AddFrameEndTask( _ => { var queue = order.Player.PlayerActor.traits.Get(); - var building = (BuildingInfo)Rules.UnitInfo[ order.TargetString ]; + var building = (LegacyBuildingInfo)Rules.UnitInfo[ order.TargetString ]; var producing = queue.CurrentItem(Rules.UnitCategory[order.TargetString]); if( producing == null || producing.Item != order.TargetString || producing.RemainingTime != 0 ) return; diff --git a/OpenRa.Game/Player.cs b/OpenRa.Game/Player.cs index b4ff66fe75..9a162aa067 100644 --- a/OpenRa.Game/Player.cs +++ b/OpenRa.Game/Player.cs @@ -84,7 +84,7 @@ namespace OpenRa.Game { OreCapacity = Game.world.Actors .Where(a => a.Owner == this && a.traits.Contains()) - .Select(a => a.Info as BuildingInfo) + .Select(a => a.Info as LegacyBuildingInfo) .Where(b => b != null) .Sum(b => b.Storage); } diff --git a/OpenRa.Game/Traits/APMine.cs b/OpenRa.Game/Traits/APMine.cs index 41a6b3db9c..4d443321ed 100644 --- a/OpenRa.Game/Traits/APMine.cs +++ b/OpenRa.Game/Traits/APMine.cs @@ -1,10 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using OpenRa.Game.GameRules; +using System.Collections.Generic; using OpenRa.Game.Effects; + namespace OpenRa.Game.Traits { + class APMineInfo : ITraitInfo + { + public object Create(Actor self) { return new APMine(self); } + } + class APMine : ICrushable, IOccupySpace { readonly Actor self; diff --git a/OpenRa.Game/Traits/ATMine.cs b/OpenRa.Game/Traits/ATMine.cs index 9ee444195c..0a0bcda360 100644 --- a/OpenRa.Game/Traits/ATMine.cs +++ b/OpenRa.Game/Traits/ATMine.cs @@ -1,11 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using OpenRa.Game.GameRules; +using System.Collections.Generic; using OpenRa.Game.Effects; namespace OpenRa.Game.Traits { + class ATMineInfo : ITraitInfo + { + public object Create(Actor self) { return new ATMine(self); } + } + class ATMine : ICrushable, IOccupySpace { readonly Actor self; diff --git a/OpenRa.Game/Traits/AcceptsOre.cs b/OpenRa.Game/Traits/AcceptsOre.cs index 49d6bc129a..6c8c200afa 100644 --- a/OpenRa.Game/Traits/AcceptsOre.cs +++ b/OpenRa.Game/Traits/AcceptsOre.cs @@ -2,6 +2,11 @@ namespace OpenRa.Game.Traits { + class AcceptsOreInfo : ITraitInfo + { + public object Create(Actor self) { return new AcceptsOre(self); } + } + class AcceptsOre { public AcceptsOre(Actor self) diff --git a/OpenRa.Game/Traits/Activities/HeliReturn.cs b/OpenRa.Game/Traits/Activities/HeliReturn.cs index 913ab24a84..6a26fc918b 100644 --- a/OpenRa.Game/Traits/Activities/HeliReturn.cs +++ b/OpenRa.Game/Traits/Activities/HeliReturn.cs @@ -34,7 +34,7 @@ namespace OpenRa.Game.Traits.Activities if (res != null) self.traits.Get().reservation = res.Reserve(self); - var offset = (dest.Info as BuildingInfo).SpawnOffset; + var offset = (dest.Info as LegacyBuildingInfo).SpawnOffset; var offsetVec = offset != null ? new float2(offset[0], offset[1]) : float2.Zero; return Util.SequenceActivities( diff --git a/OpenRa.Game/Traits/AttackBase.cs b/OpenRa.Game/Traits/AttackBase.cs index ed8bfb08f3..4b99833445 100644 --- a/OpenRa.Game/Traits/AttackBase.cs +++ b/OpenRa.Game/Traits/AttackBase.cs @@ -8,9 +8,7 @@ namespace OpenRa.Game.Traits { class AttackBaseInfo : ITraitInfo { - - - public object Create(Actor self) { return new AttackBase(self); } + public virtual object Create(Actor self) { return new AttackBase(self); } } class AttackBase : IIssueOrder, IResolveOrder, ITick diff --git a/OpenRa.Game/Traits/AttackHeli.cs b/OpenRa.Game/Traits/AttackHeli.cs index 4749edc089..41d3fc2c51 100644 --- a/OpenRa.Game/Traits/AttackHeli.cs +++ b/OpenRa.Game/Traits/AttackHeli.cs @@ -2,6 +2,11 @@ namespace OpenRa.Game.Traits { + class AttackHeliInfo : AttackBaseInfo + { + public override object Create(Actor self) { return new AttackHeli(self); } + } + class AttackHeli : AttackFrontal { public AttackHeli(Actor self) : base(self, 20) { } diff --git a/OpenRa.Game/Traits/AttackPlane.cs b/OpenRa.Game/Traits/AttackPlane.cs index 05fad7ecb8..b4f4f9e02a 100644 --- a/OpenRa.Game/Traits/AttackPlane.cs +++ b/OpenRa.Game/Traits/AttackPlane.cs @@ -2,6 +2,11 @@ namespace OpenRa.Game.Traits { + class AttackPlaneInfo : AttackBaseInfo + { + public override object Create(Actor self) { return new AttackPlane(self); } + } + class AttackPlane : AttackFrontal { public AttackPlane(Actor self) : base(self, 20) { } diff --git a/OpenRa.Game/Traits/AttackTurreted.cs b/OpenRa.Game/Traits/AttackTurreted.cs index c574e309a8..dff7ff4001 100755 --- a/OpenRa.Game/Traits/AttackTurreted.cs +++ b/OpenRa.Game/Traits/AttackTurreted.cs @@ -3,11 +3,14 @@ using OpenRa.Game.GameRules; namespace OpenRa.Game.Traits { - class AttackTurretedInfo : AttackBaseInfo { } + class AttackTurretedInfo : AttackBaseInfo + { + public override object Create(Actor self) { return new AttackTurreted( self ); } + } class AttackTurreted : AttackBase, INotifyBuildComplete { - public AttackTurreted( Actor self ) : base(self) { self.traits.Get(); } + public AttackTurreted(Actor self) : base(self) { } public override void Tick(Actor self) { diff --git a/OpenRa.Game/Traits/AutoHeal.cs b/OpenRa.Game/Traits/AutoHeal.cs index 61018ed3cd..eb882df245 100644 --- a/OpenRa.Game/Traits/AutoHeal.cs +++ b/OpenRa.Game/Traits/AutoHeal.cs @@ -3,10 +3,10 @@ using OpenRa.Game.Traits.Activities; namespace OpenRa.Game.Traits { + class AutoHealInfo : StatelessTraitInfo { } + class AutoHeal : ITick { - public AutoHeal(Actor self) { } - void AttackTarget(Actor self, Actor target) { var attack = self.traits.WithInterface().First(); diff --git a/OpenRa.Game/Traits/AutoTarget.cs b/OpenRa.Game/Traits/AutoTarget.cs index 94e66aeeaf..0906fac297 100644 --- a/OpenRa.Game/Traits/AutoTarget.cs +++ b/OpenRa.Game/Traits/AutoTarget.cs @@ -2,15 +2,10 @@ namespace OpenRa.Game.Traits { - class AutoTargetInfo : ITraitInfo - { - public object Create(Actor self) { return new AutoTarget(self); } - } + class AutoTargetInfo : StatelessTraitInfo { } class AutoTarget : ITick, INotifyDamage { - public AutoTarget(Actor self) {} - void AttackTarget(Actor self, Actor target) { var attack = self.traits.WithInterface().First(); diff --git a/OpenRa.Game/Traits/BelowUnits.cs b/OpenRa.Game/Traits/BelowUnits.cs index 7bc4d84681..f5d82d6727 100644 --- a/OpenRa.Game/Traits/BelowUnits.cs +++ b/OpenRa.Game/Traits/BelowUnits.cs @@ -3,10 +3,10 @@ using System.Linq; namespace OpenRa.Game.Traits { + class BelowUnitsInfo : StatelessTraitInfo { } + class BelowUnits : IRenderModifier { - public BelowUnits(Actor self) { } - public IEnumerable ModifyRender(Actor self, IEnumerable r) { return r.Select(a => a.WithZOffset(-1)); diff --git a/OpenRa.Game/Traits/Buildable.cs b/OpenRa.Game/Traits/Buildable.cs index 25eec93980..273fdf1d97 100755 --- a/OpenRa.Game/Traits/Buildable.cs +++ b/OpenRa.Game/Traits/Buildable.cs @@ -5,7 +5,7 @@ using System.Text; namespace OpenRa.Game.Traits { - class BuildableInfo : ITraitInfo + class BuildableInfo : StatelessTraitInfo { public readonly int TechLevel = -1; public readonly string Tab = null; @@ -15,12 +15,7 @@ namespace OpenRa.Game.Traits public readonly string Description = ""; public readonly string LongDesc = ""; public readonly string Icon = null; - - public object Create(Actor self) { return new Buildable(self); } } - class Buildable - { - public Buildable( Actor self ) { } - } + class Buildable { } } diff --git a/OpenRa.Game/Traits/Building.cs b/OpenRa.Game/Traits/Building.cs index 1fa3538314..2e7b204008 100644 --- a/OpenRa.Game/Traits/Building.cs +++ b/OpenRa.Game/Traits/Building.cs @@ -9,10 +9,15 @@ using OpenRa.Game.Graphics; namespace OpenRa.Game.Traits { + class BuildingInfo : ITraitInfo + { + public object Create(Actor self) { return new Building(self); } + } + class Building : INotifyDamage, IResolveOrder, ITick { readonly Actor self; - public readonly BuildingInfo unitInfo; + public readonly LegacyBuildingInfo unitInfo; [Sync] bool isRepairing = false; [Sync] @@ -24,7 +29,7 @@ namespace OpenRa.Game.Traits public Building(Actor self) { this.self = self; - unitInfo = (BuildingInfo)self.Info; + unitInfo = (LegacyBuildingInfo)self.Info; self.CenterLocation = Game.CellSize * ((float2)self.Location + .5f * (float2)unitInfo.Dimensions); } diff --git a/OpenRa.Game/Traits/C4Demolition.cs b/OpenRa.Game/Traits/C4Demolition.cs index e6b75178b2..68ae518333 100644 --- a/OpenRa.Game/Traits/C4Demolition.cs +++ b/OpenRa.Game/Traits/C4Demolition.cs @@ -2,10 +2,10 @@ namespace OpenRa.Game.Traits { + class C4DemolitionInfo : StatelessTraitInfo { } + class C4Demolition : IIssueOrder, IResolveOrder { - public C4Demolition(Actor self) { } - public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) { if (mi.Button != MouseButton.Right) return null; diff --git a/OpenRa.Game/Traits/ChronoshiftDeploy.cs b/OpenRa.Game/Traits/ChronoshiftDeploy.cs index 2cc8a2a9a4..08c24000ba 100644 --- a/OpenRa.Game/Traits/ChronoshiftDeploy.cs +++ b/OpenRa.Game/Traits/ChronoshiftDeploy.cs @@ -4,6 +4,11 @@ using OpenRa.Game.Orders; namespace OpenRa.Game.Traits { + class ChronoshiftDeployInfo : ITraitInfo + { + public object Create(Actor self) { return new ChronoshiftDeploy(self); } + } + class ChronoshiftDeploy : IIssueOrder, IResolveOrder, ISpeedModifier, ITick, IPips { // Recharge logic diff --git a/OpenRa.Game/Traits/ChronoshiftPaletteEffect.cs b/OpenRa.Game/Traits/ChronoshiftPaletteEffect.cs index 36a4f0e40c..dc2ef912e2 100644 --- a/OpenRa.Game/Traits/ChronoshiftPaletteEffect.cs +++ b/OpenRa.Game/Traits/ChronoshiftPaletteEffect.cs @@ -3,6 +3,9 @@ using OpenRa.Game.Graphics; namespace OpenRa.Game.Traits { + // this is NOT bound through rules (it belongs on the world actor!) + // so no *Info required + class ChronoshiftPaletteEffect : IPaletteModifier, ITick { const int chronoEffectLength = 20; diff --git a/OpenRa.Game/Traits/Chronosphere.cs b/OpenRa.Game/Traits/Chronosphere.cs index cad8a1cf13..34f660a014 100644 --- a/OpenRa.Game/Traits/Chronosphere.cs +++ b/OpenRa.Game/Traits/Chronosphere.cs @@ -5,8 +5,6 @@ using System.Text; namespace OpenRa.Game.Traits { - class Chronosphere - { - public Chronosphere(Actor self) { } - } + class ChronosphereInfo : StatelessTraitInfo { } + class Chronosphere { } } diff --git a/OpenRa.Game/Traits/Cloak.cs b/OpenRa.Game/Traits/Cloak.cs index 5b225438d6..b782d854e1 100644 --- a/OpenRa.Game/Traits/Cloak.cs +++ b/OpenRa.Game/Traits/Cloak.cs @@ -4,6 +4,11 @@ using OpenRa.Game.Graphics; namespace OpenRa.Game.Traits { + class CloakInfo : ITraitInfo + { + public object Create(Actor self) { return new Cloak(self); } + } + class Cloak : IRenderModifier, INotifyAttack, ITick { [Sync] diff --git a/OpenRa.Game/Traits/EngineerCapture.cs b/OpenRa.Game/Traits/EngineerCapture.cs index f06873e662..efc03dc6cd 100644 --- a/OpenRa.Game/Traits/EngineerCapture.cs +++ b/OpenRa.Game/Traits/EngineerCapture.cs @@ -2,17 +2,12 @@ namespace OpenRa.Game.Traits { - class EngineerCaptureInfo : ITraitInfo - { - public object Create(Actor self) { return new EngineerCapture(self); } - } + class EngineerCaptureInfo : StatelessTraitInfo { } class EngineerCapture : IIssueOrder, IResolveOrder { public const int EngineerDamage = 300; // todo: push into rules, as a weapon - public EngineerCapture(Actor self) { } - public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) { if (mi.Button != MouseButton.Right) return null; diff --git a/OpenRa.Game/Traits/Explodes.cs b/OpenRa.Game/Traits/Explodes.cs index 712ded0e4f..2b058de917 100644 --- a/OpenRa.Game/Traits/Explodes.cs +++ b/OpenRa.Game/Traits/Explodes.cs @@ -2,15 +2,10 @@ namespace OpenRa.Game.Traits { - class ExplodesInfo : ITraitInfo - { - public object Create(Actor self) { return new Explodes(self); } - } + class ExplodesInfo : StatelessTraitInfo { } class Explodes : INotifyDamage { - public Explodes(Actor self) {} - public void Damaged(Actor self, AttackInfo e) { if (self.IsDead) diff --git a/OpenRa.Game/Traits/Fake.cs b/OpenRa.Game/Traits/Fake.cs index b62b4cfeee..9eb9127856 100644 --- a/OpenRa.Game/Traits/Fake.cs +++ b/OpenRa.Game/Traits/Fake.cs @@ -2,18 +2,10 @@ namespace OpenRa.Game.Traits { - class FakeInfo : ITraitInfo - { - public object Create(Actor self) { return new Fake(self); } - } + class FakeInfo : StatelessTraitInfo { } class Fake : ITags { - public Fake(Actor self){} - - public IEnumerable GetTags() - { - yield return TagType.Fake; - } + public IEnumerable GetTags() { yield return TagType.Fake; } } } diff --git a/OpenRa.Game/Traits/GpsLaunchSite.cs b/OpenRa.Game/Traits/GpsLaunchSite.cs index 1a7bfaa461..ed10b56620 100644 --- a/OpenRa.Game/Traits/GpsLaunchSite.cs +++ b/OpenRa.Game/Traits/GpsLaunchSite.cs @@ -2,10 +2,6 @@ namespace OpenRa.Game.Traits { - class GpsLaunchSiteInfo : ITraitInfo - { - public object Create(Actor self) { return new GpsLaunchSite(self); } - } - - class GpsLaunchSite { public GpsLaunchSite(Actor self) { } } + class GpsLaunchSiteInfo : StatelessTraitInfo { } + class GpsLaunchSite { } } diff --git a/OpenRa.Game/Traits/Harvester.cs b/OpenRa.Game/Traits/Harvester.cs index 4d038d93c9..d9f72f592f 100644 --- a/OpenRa.Game/Traits/Harvester.cs +++ b/OpenRa.Game/Traits/Harvester.cs @@ -5,7 +5,7 @@ namespace OpenRa.Game.Traits { class HarvesterInfo : ITraitInfo { - public object Create(Actor self) { return new Harvester(self); } + public object Create(Actor self) { return new Harvester(); } } class Harvester : IIssueOrder, IResolveOrder, IPips @@ -18,8 +18,6 @@ namespace OpenRa.Game.Traits public bool IsFull { get { return oreCarried + gemsCarried == Rules.General.BailCount; } } public bool IsEmpty { get { return oreCarried == 0 && gemsCarried == 0; } } - public Harvester(Actor self) { } - public void AcceptResource(bool isGem) { if (isGem) gemsCarried++; diff --git a/OpenRa.Game/Traits/Helicopter.cs b/OpenRa.Game/Traits/Helicopter.cs index 999bc6a68f..8477103c63 100644 --- a/OpenRa.Game/Traits/Helicopter.cs +++ b/OpenRa.Game/Traits/Helicopter.cs @@ -6,6 +6,9 @@ namespace OpenRa.Game.Traits { class HelicopterInfo : ITraitInfo { + public readonly int ROT = 0; + public readonly int Speed = 0; + public object Create(Actor self) { return new Helicopter(self); } } @@ -60,7 +63,7 @@ namespace OpenRa.Game.Traits if (res != null) reservation = res.Reserve(self); - var offset = (order.TargetActor.Info as BuildingInfo).SpawnOffset; + var offset = (order.TargetActor.Info as LegacyBuildingInfo).SpawnOffset; var offsetVec = offset != null ? new float2(offset[0], offset[1]) : float2.Zero; self.CancelActivity(); diff --git a/OpenRa.Game/Traits/InvisibleToOthers.cs b/OpenRa.Game/Traits/InvisibleToOthers.cs index 969dc31d68..dab24dfc59 100644 --- a/OpenRa.Game/Traits/InvisibleToOthers.cs +++ b/OpenRa.Game/Traits/InvisibleToOthers.cs @@ -2,15 +2,10 @@ namespace OpenRa.Game.Traits { - class InvisibleToOthersInfo : ITraitInfo - { - public object Create(Actor self) { return new InvisibleToOthers(self); } - } + class InvisibleToOthersInfo : StatelessTraitInfo { } class InvisibleToOthers : IRenderModifier { - public InvisibleToOthers(Actor self) { } - public IEnumerable ModifyRender(Actor self, IEnumerable r) { return Game.LocalPlayer == self.Owner diff --git a/OpenRa.Game/Traits/IronCurtain.cs b/OpenRa.Game/Traits/IronCurtain.cs index 8126493e6e..5ea72102c8 100644 --- a/OpenRa.Game/Traits/IronCurtain.cs +++ b/OpenRa.Game/Traits/IronCurtain.cs @@ -1,17 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - + namespace OpenRa.Game.Traits { - class IronCurtainInfo : ITraitInfo - { - public object Create(Actor self) { return new IronCurtain(self); } - } - - class IronCurtain - { - public IronCurtain(Actor self) {} - } + class IronCurtainInfo : StatelessTraitInfo { } + class IronCurtain { } } diff --git a/OpenRa.Game/Traits/IronCurtainable.cs b/OpenRa.Game/Traits/IronCurtainable.cs index 45344f3c34..e00474fdd1 100644 --- a/OpenRa.Game/Traits/IronCurtainable.cs +++ b/OpenRa.Game/Traits/IronCurtainable.cs @@ -5,7 +5,7 @@ namespace OpenRa.Game.Traits { class IronCurtainableInfo : ITraitInfo { - public object Create(Actor self) { return new IronCurtain(self); } + public object Create(Actor self) { return new IronCurtainable(); } } class IronCurtainable : IResolveOrder, IDamageModifier, ITick @@ -13,8 +13,6 @@ namespace OpenRa.Game.Traits [Sync] int RemainingTicks = 0; - public IronCurtainable(Actor self) { } - public void Tick(Actor self) { if (RemainingTicks > 0) diff --git a/OpenRa.Game/Traits/McvDeploy.cs b/OpenRa.Game/Traits/McvDeploy.cs index 5b5cb880b1..20221549a3 100644 --- a/OpenRa.Game/Traits/McvDeploy.cs +++ b/OpenRa.Game/Traits/McvDeploy.cs @@ -24,7 +24,7 @@ namespace OpenRa.Game.Traits { if( order.OrderString == "DeployMcv" ) { - var factBuildingInfo = (BuildingInfo)Rules.UnitInfo[ "fact" ]; + var factBuildingInfo = (LegacyBuildingInfo)Rules.UnitInfo[ "fact" ]; if( Game.CanPlaceBuilding( factBuildingInfo, self.Location - new int2( 1, 1 ), self, false ) ) { self.CancelActivity(); diff --git a/OpenRa.Game/Traits/MineImmune.cs b/OpenRa.Game/Traits/MineImmune.cs index f82acf08c4..04f488a096 100644 --- a/OpenRa.Game/Traits/MineImmune.cs +++ b/OpenRa.Game/Traits/MineImmune.cs @@ -1,13 +1,6 @@  namespace OpenRa.Game.Traits { - class MineImmuneInfo : ITraitInfo - { - public object Create(Actor self) { return new MineImmune(self); } - } - - class MineImmune - { - public MineImmune(Actor self) { } - } + class MineImmuneInfo : StatelessTraitInfo { } + class MineImmune { } } diff --git a/OpenRa.Game/Traits/Minelayer.cs b/OpenRa.Game/Traits/Minelayer.cs index 7fe567bd2b..1012998d5e 100644 --- a/OpenRa.Game/Traits/Minelayer.cs +++ b/OpenRa.Game/Traits/Minelayer.cs @@ -1,27 +1,19 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Linq; namespace OpenRa.Game.Traits { - class MinelayerInfo : ITraitInfo - { - public object Create(Actor self) { return new Minelayer(self); } - } + class MinelayerInfo : StatelessTraitInfo { } class Minelayer : IIssueOrder, IResolveOrder { - public Minelayer(Actor self) { } - public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) { var limitedAmmo = self.traits.GetOrDefault(); if (limitedAmmo != null && !limitedAmmo.HasAmmo()) return null; - + // Ensure that the cell is empty except for the minelayer - if (Game.UnitInfluence.GetUnitsAt( xy ).Any(a => a != self)) + if (Game.UnitInfluence.GetUnitsAt(xy).Any(a => a != self)) return null; if (mi.Button == MouseButton.Right && underCursor == self) diff --git a/OpenRa.Game/Traits/Plane.cs b/OpenRa.Game/Traits/Plane.cs index 17602323e3..27030b4705 100644 --- a/OpenRa.Game/Traits/Plane.cs +++ b/OpenRa.Game/Traits/Plane.cs @@ -5,6 +5,9 @@ namespace OpenRa.Game.Traits { class PlaneInfo : ITraitInfo { + public readonly int ROT = 0; + public readonly int Speed = 0; + public object Create(Actor self) { return new Plane(self); } } diff --git a/OpenRa.Game/Traits/Production.cs b/OpenRa.Game/Traits/Production.cs index fa17b7fbff..1a6a270a94 100755 --- a/OpenRa.Game/Traits/Production.cs +++ b/OpenRa.Game/Traits/Production.cs @@ -43,7 +43,7 @@ namespace OpenRa.Game.Traits newUnit.QueueActivity( new Activities.Move( rp.rallyPoint, 1 ) ); } - var bi = self.Info as BuildingInfo; + var bi = self.Info as LegacyBuildingInfo; if (bi != null && bi.SpawnOffset != null) newUnit.CenterLocation = self.CenterLocation + new float2(bi.SpawnOffset[0], bi.SpawnOffset[1]); @@ -83,12 +83,12 @@ namespace OpenRa.Game.Traits } // Cancel existing primaries - foreach (var p in (self.Info as BuildingInfo).Produces) + foreach (var p in (self.Info as LegacyBuildingInfo).Produces) { foreach (var b in Game.world.Actors.Where(x => x.traits.Contains() && x.Owner == self.Owner && x.traits.Get().IsPrimary == true - && (x.Info as BuildingInfo).Produces.Contains(p))) + && (x.Info as LegacyBuildingInfo).Produces.Contains(p))) { b.traits.Get().SetPrimaryProducer(b, false); } diff --git a/OpenRa.Game/Traits/StoresOre.cs b/OpenRa.Game/Traits/StoresOre.cs index 4fa5945e96..5630ef83c3 100644 --- a/OpenRa.Game/Traits/StoresOre.cs +++ b/OpenRa.Game/Traits/StoresOre.cs @@ -14,7 +14,7 @@ namespace OpenRa.Game.Traits public void OnSteal(Actor self, Actor thief) { // Steal half the ore the building holds - var toSteal = (self.Info as BuildingInfo).Storage/2; + var toSteal = (self.Info as LegacyBuildingInfo).Storage/2; self.Owner.TakeCash(toSteal); thief.Owner.GiveCash(toSteal); diff --git a/OpenRa.Game/Traits/WaterPaletteRotation.cs b/OpenRa.Game/Traits/WaterPaletteRotation.cs index 7c5a5eacf9..cba52f71a5 100644 --- a/OpenRa.Game/Traits/WaterPaletteRotation.cs +++ b/OpenRa.Game/Traits/WaterPaletteRotation.cs @@ -2,10 +2,8 @@ namespace OpenRa.Game.Traits { - class WaterPaletteRotationInfo : ITraitInfo - { - public object Create(Actor self) { return new WaterPaletteRotation(self); } - } + // this is NOT bound through rules (it belongs on the world actor!) + // so no *Info required class WaterPaletteRotation : ITick, IPaletteModifier { diff --git a/OpenRa.Game/UiOverlay.cs b/OpenRa.Game/UiOverlay.cs index 0dfc1272cc..7a0e4c8c29 100644 --- a/OpenRa.Game/UiOverlay.cs +++ b/OpenRa.Game/UiOverlay.cs @@ -42,7 +42,7 @@ namespace OpenRa.Game spriteRenderer.DrawSprite(unitDebug, Game.CellSize * new float2(i, j), 0); } - public void DrawBuildingGrid( BuildingInfo bi ) + public void DrawBuildingGrid( LegacyBuildingInfo bi ) { var position = Game.controller.MousePosition.ToInt2(); var isCloseEnough = Game.IsCloseEnoughToBase(Game.LocalPlayer, bi, position);