diff --git a/OpenRA.Mods.Common/AI/AttackOrFleeFuzzy.cs b/OpenRA.Mods.Common/AI/AttackOrFleeFuzzy.cs index a102996dbb..2a0553fab6 100644 --- a/OpenRA.Mods.Common/AI/AttackOrFleeFuzzy.cs +++ b/OpenRA.Mods.Common/AI/AttackOrFleeFuzzy.cs @@ -208,7 +208,7 @@ namespace OpenRA.Mods.Common.AI protected float RelativeSpeed(IEnumerable own, IEnumerable enemy) { - return RelativeValue(own, enemy, 100, Average, (Actor a) => a.Trait().Info.Speed); + return RelativeValue(own, enemy, 100, Average, (Actor a) => a.Info.Traits.Get().Speed); } protected static float RelativeValue(IEnumerable own, IEnumerable enemy, float normalizeByValue, diff --git a/OpenRA.Mods.Common/Activities/Air/HeliReturn.cs b/OpenRA.Mods.Common/Activities/Air/HeliReturn.cs index 24a0c7896d..27cb96e534 100644 --- a/OpenRA.Mods.Common/Activities/Air/HeliReturn.cs +++ b/OpenRA.Mods.Common/Activities/Air/HeliReturn.cs @@ -17,20 +17,16 @@ namespace OpenRA.Mods.Common.Activities { public class HeliReturn : Activity { - readonly AircraftInfo aircraftInfo; readonly Helicopter heli; - readonly HelicopterInfo heliInfo; public HeliReturn(Actor self) { - aircraftInfo = self.Info.Traits.Get(); heli = self.Trait(); - heliInfo = self.Info.Traits.Get(); } - public static Actor ChooseHelipad(Actor self) + public Actor ChooseHelipad(Actor self) { - var rearmBuildings = self.Info.Traits.Get().RearmBuildings; + var rearmBuildings = heli.Info.RearmBuildings; return self.World.Actors.Where(a => a.Owner == self.Owner).FirstOrDefault( a => rearmBuildings.Contains(a.Info.Name) && !Reservable.IsReserved(a)); } @@ -41,11 +37,11 @@ namespace OpenRA.Mods.Common.Activities return NextActivity; var dest = ChooseHelipad(self); - var initialFacing = aircraftInfo.InitialFacing; + var initialFacing = heli.Info.InitialFacing; if (dest == null) { - var rearmBuildings = heliInfo.RearmBuildings; + var rearmBuildings = heli.Info.RearmBuildings; var nearestHpad = self.World.ActorsWithTrait() .Where(a => a.Actor.Owner == self.Owner && rearmBuildings.Contains(a.Actor.Info.Name)) .Select(a => a.Actor) diff --git a/OpenRA.Mods.Common/Activities/DeliverResources.cs b/OpenRA.Mods.Common/Activities/DeliverResources.cs index 5983ba1190..bffbddee68 100644 --- a/OpenRA.Mods.Common/Activities/DeliverResources.cs +++ b/OpenRA.Mods.Common/Activities/DeliverResources.cs @@ -21,7 +21,6 @@ namespace OpenRA.Mods.Common.Activities readonly IMove movement; readonly Harvester harv; - readonly HarvesterInfo harvInfo; bool isDocking; int chosenTicks; @@ -30,7 +29,6 @@ namespace OpenRA.Mods.Common.Activities { movement = self.Trait(); harv = self.Trait(); - harvInfo = self.Info.Traits.Get(); } public override Activity Tick(Actor self) @@ -57,7 +55,7 @@ namespace OpenRA.Mods.Common.Activities // No refineries exist; check again after delay defined in Harvester. if (harv.LinkedProc == null) - return Util.SequenceActivities(new Wait(harvInfo.SearchForDeliveryBuildingDelay), this); + return Util.SequenceActivities(new Wait(harv.Info.SearchForDeliveryBuildingDelay), this); var proc = harv.LinkedProc; var iao = proc.Trait(); diff --git a/OpenRA.Mods.Common/Activities/SpriteHarvesterDockSequence.cs b/OpenRA.Mods.Common/Activities/SpriteHarvesterDockSequence.cs index 89da5f73bf..ddf4773e3f 100644 --- a/OpenRA.Mods.Common/Activities/SpriteHarvesterDockSequence.cs +++ b/OpenRA.Mods.Common/Activities/SpriteHarvesterDockSequence.cs @@ -16,13 +16,13 @@ namespace OpenRA.Mods.Common.Activities public class SpriteHarvesterDockSequence : HarvesterDockSequence { readonly WithSpriteBody wsb; - readonly WithDockingAnimation wda; + readonly WithDockingAnimationInfo wda; public SpriteHarvesterDockSequence(Actor self, Actor refinery, int dockAngle, bool isDragRequired, WVec dragOffset, int dragLength) : base(self, refinery, dockAngle, isDragRequired, dragOffset, dragLength) { wsb = self.Trait(); - wda = self.Trait(); + wda = self.Info.Traits.Get(); } public override Activity OnStateDock(Actor self) @@ -30,14 +30,14 @@ namespace OpenRA.Mods.Common.Activities foreach (var trait in self.TraitsImplementing()) trait.Docked(); - wsb.PlayCustomAnimation(self, wda.Info.DockSequence, () => wsb.PlayCustomAnimationRepeating(self, wda.Info.DockLoopSequence)); + wsb.PlayCustomAnimation(self, wda.DockSequence, () => wsb.PlayCustomAnimationRepeating(self, wda.DockLoopSequence)); dockingState = State.Loop; return this; } public override Activity OnStateUndock(Actor self) { - wsb.PlayCustomAnimationBackwards(self, wda.Info.DockSequence, + wsb.PlayCustomAnimationBackwards(self, wda.DockSequence, () => { dockingState = State.Complete; diff --git a/OpenRA.Mods.Common/Scripting/Global/ReinforcementsGlobal.cs b/OpenRA.Mods.Common/Scripting/Global/ReinforcementsGlobal.cs index 9472e0315f..c8bf726376 100644 --- a/OpenRA.Mods.Common/Scripting/Global/ReinforcementsGlobal.cs +++ b/OpenRA.Mods.Common/Scripting/Global/ReinforcementsGlobal.cs @@ -137,10 +137,10 @@ namespace OpenRA.Mods.Common.Scripting } else { - var heli = transport.TraitOrDefault(); + var heli = transport.Info.Traits.GetOrDefault(); if (heli != null) { - transport.QueueActivity(new Turn(transport, heli.Info.InitialFacing)); + transport.QueueActivity(new Turn(transport, heli.InitialFacing)); transport.QueueActivity(new HeliLand(transport, true)); transport.QueueActivity(new Wait(15)); } diff --git a/OpenRA.Mods.Common/Traits/Buildings/Bridge.cs b/OpenRA.Mods.Common/Traits/Buildings/Bridge.cs index d3318755c9..23df972704 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/Bridge.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/Bridge.cs @@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits class Bridge : IRender, INotifyDamageStateChanged { - readonly Building building; + readonly BuildingInfo building; readonly Bridge[] neighbours = new Bridge[2]; readonly BridgeHut[] huts = new BridgeHut[2]; // Huts before this / first & after this / last readonly Health health; @@ -93,7 +93,7 @@ namespace OpenRA.Mods.Common.Traits this.info = info; type = self.Info.Name; isDangling = new Lazy(() => huts[0] == huts[1] && (neighbours[0] == null || neighbours[1] == null)); - building = self.Trait(); + building = self.Info.Traits.Get(); } public Bridge Neighbour(int direction) { return neighbours[direction]; } @@ -173,7 +173,7 @@ namespace OpenRA.Mods.Common.Traits IRenderable[] TemplateRenderables(WorldRenderer wr, PaletteReference palette, ushort template) { - var offset = FootprintUtils.CenterOffset(self.World, building.Info).Y + 1024; + var offset = FootprintUtils.CenterOffset(self.World, building).Y + 1024; return footprint.Select(c => (IRenderable)(new SpriteRenderable( wr.Theater.TileSprite(new TerrainTile(template, c.Value)), diff --git a/OpenRA.Mods.Common/Traits/Buildings/BuildingInfluence.cs b/OpenRA.Mods.Common/Traits/Buildings/BuildingInfluence.cs index e4419943c2..b15743b5eb 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/BuildingInfluence.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/BuildingInfluence.cs @@ -31,22 +31,22 @@ namespace OpenRA.Mods.Common.Traits world.ActorAdded += a => { - var b = a.TraitOrDefault(); + var b = a.Info.Traits.GetOrDefault(); if (b == null) return; - foreach (var u in FootprintUtils.Tiles(map.Rules, a.Info.Name, b.Info, a.Location)) + foreach (var u in FootprintUtils.Tiles(map.Rules, a.Info.Name, b, a.Location)) if (influence.Contains(u) && influence[u] == null) influence[u] = a; }; world.ActorRemoved += a => { - var b = a.TraitOrDefault(); + var b = a.Info.Traits.GetOrDefault(); if (b == null) return; - foreach (var u in FootprintUtils.Tiles(map.Rules, a.Info.Name, b.Info, a.Location)) + foreach (var u in FootprintUtils.Tiles(map.Rules, a.Info.Name, b, a.Location)) if (influence.Contains(u) && influence[u] == a) influence[u] = null; }; diff --git a/OpenRA.Mods.Common/Traits/Capturable.cs b/OpenRA.Mods.Common/Traits/Capturable.cs index 85f5af6fb6..c45634b2ac 100644 --- a/OpenRA.Mods.Common/Traits/Capturable.cs +++ b/OpenRA.Mods.Common/Traits/Capturable.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits public bool CanBeTargetedBy(Actor captor, Player owner) { - var c = captor.TraitOrDefault(); + var c = captor.Info.Traits.GetOrDefault(); if (c == null) return false; @@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits if (playerRelationship == Stance.Neutral && !AllowNeutral) return false; - if (!c.Info.CaptureTypes.Contains(Type)) + if (!c.CaptureTypes.Contains(Type)) return false; return true; diff --git a/OpenRA.Mods.Common/Traits/CombatDebugOverlay.cs b/OpenRA.Mods.Common/Traits/CombatDebugOverlay.cs index d02d943d1d..22d8333ba6 100644 --- a/OpenRA.Mods.Common/Traits/CombatDebugOverlay.cs +++ b/OpenRA.Mods.Common/Traits/CombatDebugOverlay.cs @@ -26,15 +26,15 @@ namespace OpenRA.Mods.Common.Traits { readonly DeveloperMode devMode; + readonly HealthInfo healthInfo; Lazy attack; Lazy coords; - Lazy health; public CombatDebugOverlay(Actor self) { + healthInfo = self.Info.Traits.GetOrDefault(); attack = Exts.Lazy(() => self.TraitOrDefault()); coords = Exts.Lazy(() => self.Trait()); - health = Exts.Lazy(() => self.TraitOrDefault()); var localPlayer = self.World.LocalPlayer; devMode = localPlayer != null ? localPlayer.PlayerActor.Trait() : null; @@ -45,8 +45,8 @@ namespace OpenRA.Mods.Common.Traits if (devMode == null || !devMode.ShowCombatGeometry) return; - if (health.Value != null) - wr.DrawRangeCircle(self.CenterPosition, health.Value.Info.Radius, Color.Red); + if (healthInfo != null) + wr.DrawRangeCircle(self.CenterPosition, healthInfo.Radius, Color.Red); // No armaments to draw if (attack.Value == null) @@ -96,11 +96,11 @@ namespace OpenRA.Mods.Common.Traits if (devMode == null || !devMode.ShowCombatGeometry || e.Damage == 0) return; - var health = self.TraitOrDefault(); - if (health == null) + if (healthInfo == null) return; - var damageText = "{0} ({1}%)".F(-e.Damage, e.Damage * 100 / health.MaxHP); + var maxHP = healthInfo.HP > 0 ? healthInfo.HP : 1; + var damageText = "{0} ({1}%)".F(-e.Damage, e.Damage * 100 / maxHP); self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, e.Attacker.Owner.Color.RGB, damageText, 30))); } diff --git a/OpenRA.Mods.Common/Traits/ExternalCapturable.cs b/OpenRA.Mods.Common/Traits/ExternalCapturable.cs index f046deaecd..fa85fb4194 100644 --- a/OpenRA.Mods.Common/Traits/ExternalCapturable.cs +++ b/OpenRA.Mods.Common/Traits/ExternalCapturable.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits public bool CanBeTargetedBy(Actor captor, Player owner) { - var c = captor.TraitOrDefault(); + var c = captor.Info.Traits.GetOrDefault(); if (c == null) return false; @@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Traits if (playerRelationship == Stance.Neutral && !AllowNeutral) return false; - if (!c.Info.CaptureTypes.Contains(Type)) + if (!c.CaptureTypes.Contains(Type)) return false; return true; diff --git a/OpenRA.Mods.Common/Traits/Harvester.cs b/OpenRA.Mods.Common/Traits/Harvester.cs index dbb356706f..ffaf79a2f6 100644 --- a/OpenRA.Mods.Common/Traits/Harvester.cs +++ b/OpenRA.Mods.Common/Traits/Harvester.cs @@ -67,7 +67,7 @@ namespace OpenRA.Mods.Common.Traits IExplodeModifier, IOrderVoice, ISpeedModifier, ISync, INotifyCreated, INotifyResourceClaimLost, INotifyIdle, INotifyBlockingMove, INotifyBuildComplete { - readonly HarvesterInfo info; + public readonly HarvesterInfo Info; readonly Mobile mobile; Dictionary contents = new Dictionary(); bool idleSmart = true; @@ -92,20 +92,20 @@ namespace OpenRA.Mods.Common.Traits public Harvester(Actor self, HarvesterInfo info) { - this.info = info; + Info = info; mobile = self.Trait(); self.QueueActivity(new CallFunc(() => ChooseNewProc(self, null))); } public void Created(Actor self) { - if (info.SearchOnCreation) + if (Info.SearchOnCreation) self.QueueActivity(new FindResources(self)); } public void BuildingComplete(Actor self) { - if (info.SearchOnCreation) + if (Info.SearchOnCreation) self.QueueActivity(new FindResources(self)); } @@ -151,8 +151,8 @@ namespace OpenRA.Mods.Common.Traits bool IsAcceptableProcType(Actor proc) { - return info.DeliveryBuildings.Count == 0 || - info.DeliveryBuildings.Contains(proc.Info.Name); + return Info.DeliveryBuildings.Count == 0 || + Info.DeliveryBuildings.Contains(proc.Info.Name); } public Actor ClosestProc(Actor self, Actor ignore) @@ -192,9 +192,9 @@ namespace OpenRA.Mods.Common.Traits return null; } - public bool IsFull { get { return contents.Values.Sum() == info.Capacity; } } + public bool IsFull { get { return contents.Values.Sum() == Info.Capacity; } } public bool IsEmpty { get { return contents.Values.Sum() == 0; } } - public int Fullness { get { return contents.Values.Sum() * 100 / info.Capacity; } } + public int Fullness { get { return contents.Values.Sum() * 100 / Info.Capacity; } } public void AcceptResource(ResourceType type) { @@ -212,7 +212,7 @@ namespace OpenRA.Mods.Common.Traits if (self.Location == deliveryLoc) { // Get out of the way: - var unblockCell = LastHarvestedCell ?? (deliveryLoc + info.UnblockCell); + var unblockCell = LastHarvestedCell ?? (deliveryLoc + Info.UnblockCell); var moveTo = mobile.NearestMoveableCell(unblockCell, 1, 5); self.QueueActivity(mobile.MoveTo(moveTo, 1)); self.SetTargetLine(Target.FromCell(self.World, moveTo), Color.Gray, false); @@ -287,7 +287,7 @@ namespace OpenRA.Mods.Common.Traits if (--contents[type] == 0) contents.Remove(type); - currentUnloadTicks = info.UnloadTicksPerBale; + currentUnloadTicks = Info.UnloadTicksPerBale; } return contents.Count == 0; @@ -318,10 +318,10 @@ namespace OpenRA.Mods.Common.Traits public string VoicePhraseForOrder(Actor self, Order order) { if (order.OrderString == "Harvest") - return info.HarvestVoice; + return Info.HarvestVoice; if (order.OrderString == "Deliver" && !IsEmpty) - return info.DeliverVoice; + return Info.DeliverVoice; return null; } @@ -421,7 +421,7 @@ namespace OpenRA.Mods.Common.Traits PipType GetPipAt(int i) { - var n = i * info.Capacity / info.PipCount; + var n = i * Info.Capacity / Info.PipCount; foreach (var rt in contents) if (n < rt.Value) @@ -434,7 +434,7 @@ namespace OpenRA.Mods.Common.Traits public IEnumerable GetPips(Actor self) { - var numPips = info.PipCount; + var numPips = Info.PipCount; for (var i = 0; i < numPips; i++) yield return GetPipAt(i); @@ -444,7 +444,7 @@ namespace OpenRA.Mods.Common.Traits public int GetSpeedModifier() { - return 100 - (100 - info.FullyLoadedSpeed) * contents.Values.Sum() / info.Capacity; + return 100 - (100 - Info.FullyLoadedSpeed) * contents.Values.Sum() / Info.Capacity; } class HarvestOrderTargeter : IOrderTargeter diff --git a/OpenRA.Mods.Common/Traits/ProximityCaptor.cs b/OpenRA.Mods.Common/Traits/ProximityCaptor.cs index 8e8cafb294..92f39b3487 100644 --- a/OpenRA.Mods.Common/Traits/ProximityCaptor.cs +++ b/OpenRA.Mods.Common/Traits/ProximityCaptor.cs @@ -15,22 +15,11 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { [Desc("Actor can capture ProximityCapturable actors.")] - public class ProximityCaptorInfo : ITraitInfo + public class ProximityCaptorInfo : TraitInfo { [FieldLoader.Require] public readonly HashSet Types = new HashSet(); - public object Create(ActorInitializer init) { return new ProximityCaptor(this); } } - public class ProximityCaptor - { - public readonly ProximityCaptorInfo Info; - - public ProximityCaptor(ProximityCaptorInfo info) { Info = info; } - - public bool HasAny(IEnumerable typesList) - { - return Info.Types.Overlaps(typesList); - } - } + public class ProximityCaptor { } } diff --git a/OpenRA.Mods.Common/Traits/ProximityCapturable.cs b/OpenRA.Mods.Common/Traits/ProximityCapturable.cs index 96ce392d61..eed7608fe2 100644 --- a/OpenRA.Mods.Common/Traits/ProximityCapturable.cs +++ b/OpenRA.Mods.Common/Traits/ProximityCapturable.cs @@ -105,8 +105,8 @@ namespace OpenRA.Mods.Common.Traits bool CanBeCapturedBy(Actor a) { - var pc = a.TraitOrDefault(); - return pc != null && pc.HasAny(Info.CaptorTypes); + var pc = a.Info.Traits.GetOrDefault(); + return pc != null && pc.Types.Overlaps(Info.CaptorTypes); } IEnumerable UnitsInRange() diff --git a/OpenRA.Mods.Common/Traits/Render/WithDockingAnimation.cs b/OpenRA.Mods.Common/Traits/Render/WithDockingAnimation.cs index 252b4a53d2..d77bd3b5ee 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithDockingAnimation.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithDockingAnimation.cs @@ -12,24 +12,14 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { - public class WithDockingAnimationInfo : ITraitInfo, Requires, Requires + public class WithDockingAnimationInfo : TraitInfo, Requires, Requires { [Desc("Displayed when docking to refinery.")] [SequenceReference] public readonly string DockSequence = "dock"; [Desc("Looped while unloading at refinery.")] [SequenceReference] public readonly string DockLoopSequence = "dock-loop"; - - public object Create(ActorInitializer init) { return new WithDockingAnimation(init, this); } } - public class WithDockingAnimation - { - public readonly WithDockingAnimationInfo Info; - - public WithDockingAnimation(ActorInitializer init, WithDockingAnimationInfo info) - { - Info = info; - } - } + public class WithDockingAnimation { } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/LoadIngamePlayerOrObserverUILogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/LoadIngamePlayerOrObserverUILogic.cs index 660f676516..012bb9a144 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/LoadIngamePlayerOrObserverUILogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/LoadIngamePlayerOrObserverUILogic.cs @@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { var playerWidgets = Game.LoadWidget(world, "PLAYER_WIDGETS", playerRoot, new WidgetArgs()); var sidebarTicker = playerWidgets.Get("SIDEBAR_TICKER"); - var objectives = world.LocalPlayer.PlayerActor.TraitOrDefault(); + var objectives = world.LocalPlayer.PlayerActor.Info.Traits.GetOrDefault(); sidebarTicker.OnTick = () => { @@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (world.LocalPlayer.WinState != WinState.Undefined && !loadingObserverWidgets) { loadingObserverWidgets = true; - Game.RunAfterDelay(objectives != null ? objectives.Info.GameOverDelay : 0, () => + Game.RunAfterDelay(objectives != null ? objectives.GameOverDelay : 0, () => { playerRoot.RemoveChildren(); Game.LoadWidget(world, "OBSERVER_WIDGETS", playerRoot, new WidgetArgs()); diff --git a/OpenRA.Mods.D2k/Traits/Carryall.cs b/OpenRA.Mods.D2k/Traits/Carryall.cs index c4324a3607..07a6663e0b 100644 --- a/OpenRA.Mods.D2k/Traits/Carryall.cs +++ b/OpenRA.Mods.D2k/Traits/Carryall.cs @@ -50,7 +50,8 @@ namespace OpenRA.Mods.D2k.Traits IsBusy = false; IsCarrying = false; - carryHeight = self.Trait().Info.LandAltitude; + var helicopter = self.Info.Traits.GetOrDefault(); + carryHeight = helicopter != null ? helicopter.LandAltitude : WDist.Zero; } public void OnBecomingIdle(Actor self)