diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index 30b91880a9..52feda0cbe 100755 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -22,13 +22,13 @@ namespace OpenRA public class Actor { [Sync] - public readonly TypeDictionary traits = new TypeDictionary(); + readonly TypeDictionary traits = new TypeDictionary(); public readonly ActorInfo Info; public readonly World World; public readonly uint ActorID; - public int2 Location { get { return traits.Get().TopLeft; } } + public int2 Location { get { return Trait().TopLeft; } } [Sync] public Player Owner; @@ -51,10 +51,10 @@ namespace OpenRA Info = Rules.Info[name.ToLowerInvariant()]; foreach (var trait in Info.TraitsInConstructOrder()) - traits.Add(trait.Create(init)); + AddTrait(trait.Create(init)); } - if( CenterLocation == float2.Zero && traits.Contains() ) + if( CenterLocation == float2.Zero && HasTrait() ) CenterLocation = Traits.Util.CenterOfCell(Location); Size = Lazy.New(() => @@ -64,7 +64,7 @@ namespace OpenRA return new float2(si.Bounds[0], si.Bounds[1]); // auto size from render - var firstSprite = traits.WithInterface().SelectMany(x => x.Render(this)).FirstOrDefault(); + var firstSprite = TraitsImplementing().SelectMany(x => x.Render(this)).FirstOrDefault(); if (firstSprite.Sprite == null) return float2.Zero; return firstSprite.Sprite.size; }); @@ -83,7 +83,7 @@ namespace OpenRA if (currentActivity is Idle) { if (!wasIdle) - foreach (var ni in traits.WithInterface()) + foreach (var ni in TraitsImplementing()) ni.Idle(this); break; @@ -102,8 +102,8 @@ namespace OpenRA public IEnumerable Render() { - var mods = traits.WithInterface(); - var sprites = traits.WithInterface().SelectMany(x => x.Render(this)); + var mods = TraitsImplementing(); + var sprites = TraitsImplementing().SelectMany(x => x.Render(this)); return mods.Aggregate(sprites, (m, p) => p.ModifyRender(this, m)); } @@ -120,7 +120,7 @@ namespace OpenRA .OrderByDescending(a => a.Info.Traits.Contains() ? a.Info.Traits.Get().Priority : int.MinValue) .FirstOrDefault(); - return traits.WithInterface() + return TraitsImplementing() .Select( x => x.IssueOrder( this, xy, mi, underCursor ) ) .FirstOrDefault( x => x != null ); } @@ -137,7 +137,7 @@ namespace OpenRA if (useAltitude) { - var move = traits.GetOrDefault(); + var move = TraitOrDefault(); if (move != null) loc -= new float2(0, move.Altitude); } @@ -188,5 +188,30 @@ namespace OpenRA { return "{0} {1}{2}".F( Info.Name, ActorID, IsInWorld ? "" : " (not in world)" ); } + + public T Trait() + { + return traits.Get(); + } + + public T TraitOrDefault() + { + return traits.GetOrDefault(); + } + + public IEnumerable TraitsImplementing() + { + return traits.WithInterface(); + } + + public bool HasTrait() + { + return traits.Contains(); + } + + public void AddTrait( object t ) + { + traits.Add( t ); + } } } diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 99c9a6b70c..fd61b714e5 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -384,7 +384,7 @@ namespace OpenRA LoadMap(map); world.Queries = new World.AllQueries(world); - foreach (var gs in world.WorldActor.traits.WithInterface()) + foreach (var gs in world.WorldActor.TraitsImplementing()) gs.GameStarted(world); orderManager.StartGame(); } @@ -398,7 +398,7 @@ namespace OpenRA world.Queries = new World.AllQueries(world); - foreach (var gs in world.WorldActor.traits.WithInterface()) + foreach (var gs in world.WorldActor.TraitsImplementing()) gs.GameStarted(world); viewport.GoToStartLocation(world.LocalPlayer); diff --git a/OpenRA.Game/Graphics/TerrainRenderer.cs b/OpenRA.Game/Graphics/TerrainRenderer.cs index 63289a0cd6..3d1128e4fe 100644 --- a/OpenRA.Game/Graphics/TerrainRenderer.cs +++ b/OpenRA.Game/Graphics/TerrainRenderer.cs @@ -98,7 +98,7 @@ namespace OpenRA.Graphics new Range(indicesPerRow * firstRow, indicesPerRow * lastRow), PrimitiveType.TriangleList, Game.Renderer.SpriteShader)); - foreach (var r in world.WorldActor.traits.WithInterface()) + foreach (var r in world.WorldActor.TraitsImplementing()) r.Render(); } } diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index ca484f47bf..95f73449d2 100644 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -76,7 +76,7 @@ namespace OpenRA.Graphics public void RefreshPalette() { Game.world.WorldRenderer.palette.Update( - Game.world.WorldActor.traits.WithInterface()); + Game.world.WorldActor.TraitsImplementing()); } public void Tick() diff --git a/OpenRA.Game/Network/UnitOrders.cs b/OpenRA.Game/Network/UnitOrders.cs index aba47aeba1..9beb38336a 100755 --- a/OpenRA.Game/Network/UnitOrders.cs +++ b/OpenRA.Game/Network/UnitOrders.cs @@ -70,7 +70,7 @@ namespace OpenRA.Network order.Player.Stances[targetPlayer] = (Stance)order.TargetLocation.Y; if (targetPlayer == world.LocalPlayer) - world.WorldActor.traits.Get().UpdatePlayerStance(world, order.Player, oldStance, order.Player.Stances[targetPlayer]); + world.WorldActor.Trait().UpdatePlayerStance(world, order.Player, oldStance, order.Player.Stances[targetPlayer]); Game.Debug("{0} has set diplomatic stance vs {1} to {2}".F( order.Player.PlayerName, targetPlayer.PlayerName, order.Player.Stances[targetPlayer])); @@ -79,7 +79,7 @@ namespace OpenRA.Network default: { if( !order.IsImmediate ) - foreach (var t in order.Subject.traits.WithInterface()) + foreach (var t in order.Subject.TraitsImplementing()) t.ResolveOrder(order.Subject, order); break; } diff --git a/OpenRA.Game/Orders/PlaceBuildingOrderGenerator.cs b/OpenRA.Game/Orders/PlaceBuildingOrderGenerator.cs index 1371b297c8..d99dffe0e9 100644 --- a/OpenRA.Game/Orders/PlaceBuildingOrderGenerator.cs +++ b/OpenRA.Game/Orders/PlaceBuildingOrderGenerator.cs @@ -56,7 +56,7 @@ namespace OpenRA.Orders public void Tick( World world ) { - var producing = Producer.traits.Get().CurrentItem( Rules.Info[ Building ].Category ); + var producing = Producer.Trait().CurrentItem( Rules.Info[ Building ].Category ); if (producing == null || producing.Item != Building || producing.RemainingTime != 0) world.CancelInputMode(); } diff --git a/OpenRA.Game/Orders/UnitOrderGenerator.cs b/OpenRA.Game/Orders/UnitOrderGenerator.cs index 5ee4a21b07..a9620505e0 100644 --- a/OpenRA.Game/Orders/UnitOrderGenerator.cs +++ b/OpenRA.Game/Orders/UnitOrderGenerator.cs @@ -38,21 +38,21 @@ namespace OpenRA.Orders public void RenderBeforeWorld(World world) { foreach (var a in world.Selection.Actors) - foreach (var t in a.traits.WithInterface()) + foreach (var t in a.TraitsImplementing()) t.RenderBeforeWorld(a); } public void RenderAfterWorld( World world ) { foreach (var a in world.Selection.Actors) - foreach (var t in a.traits.WithInterface()) + foreach (var t in a.TraitsImplementing()) t.RenderAfterWorld(a); } public string GetCursor( World world, int2 xy, MouseInput mi ) { var c = Order(world, xy, mi) - .Select(o => o.Subject.traits.WithInterface() + .Select(o => o.Subject.TraitsImplementing() .Select(pc => pc.CursorForOrder(o.Subject, o)).FirstOrDefault(a => a != null)) .FirstOrDefault(a => a != null); diff --git a/OpenRA.Game/PathFinder.cs b/OpenRA.Game/PathFinder.cs index 86f7737c28..64450889c8 100644 --- a/OpenRA.Game/PathFinder.cs +++ b/OpenRA.Game/PathFinder.cs @@ -69,7 +69,7 @@ namespace OpenRA { using( new PerfSample( "find_unit_path_multiple_src" ) ) { - var mobile = self.traits.Get(); + var mobile = self.Trait(); var tilesInRange = world.FindTilesInCircle(target, range) .Where( t => mobile.CanEnterCell(t)); @@ -86,7 +86,7 @@ namespace OpenRA return q => p != q && ((p - q).LengthSquared < dist * dist) && - (world.WorldActor.traits.Get().GetUnitsAt(q).Any(a => a.Group != self.Group)); + (world.WorldActor.Trait().GetUnitsAt(q).Any(a => a.Group != self.Group)); } public List FindPath( PathSearch search ) diff --git a/OpenRA.Game/PathSearch.cs b/OpenRA.Game/PathSearch.cs index 108809a757..72fcb55cd5 100755 --- a/OpenRA.Game/PathSearch.cs +++ b/OpenRA.Game/PathSearch.cs @@ -33,7 +33,7 @@ namespace OpenRA this.self = self; world = self.World; cellInfo = InitCellInfo(); - mobile = self.traits.Get(); + mobile = self.Trait(); queue = new PriorityQueue(); } diff --git a/OpenRA.Game/Selection.cs b/OpenRA.Game/Selection.cs index 31afd7772a..d2edf39087 100644 --- a/OpenRA.Game/Selection.cs +++ b/OpenRA.Game/Selection.cs @@ -21,7 +21,7 @@ namespace OpenRA public void Add(World w, Actor a) { actors.Add(a); - foreach (var ns in w.WorldActor.traits.WithInterface()) + foreach (var ns in w.WorldActor.TraitsImplementing()) ns.SelectionChanged(); } @@ -44,7 +44,7 @@ namespace OpenRA var voicedUnit = actors.FirstOrDefault(a => a.Owner == world.LocalPlayer && a.HasVoice()); Sound.PlayVoice("Select", voicedUnit); - foreach (var ns in world.WorldActor.traits.WithInterface()) + foreach (var ns in world.WorldActor.TraitsImplementing()) ns.SelectionChanged(); } diff --git a/OpenRA.Game/ShroudRenderer.cs b/OpenRA.Game/ShroudRenderer.cs index c3a43a9d05..08a2faccc7 100644 --- a/OpenRA.Game/ShroudRenderer.cs +++ b/OpenRA.Game/ShroudRenderer.cs @@ -28,7 +28,7 @@ namespace OpenRA public ShroudRenderer(Player owner, Map map) { - this.shroud = owner.World.WorldActor.traits.Get(); + this.shroud = owner.World.WorldActor.Trait(); this.map = map; sprites = new Sprite[map.MapSize.X, map.MapSize.Y]; diff --git a/OpenRA.Game/Traits/Activities/Move.cs b/OpenRA.Game/Traits/Activities/Move.cs index 166111021c..9292fd06d9 100755 --- a/OpenRA.Game/Traits/Activities/Move.cs +++ b/OpenRA.Game/Traits/Activities/Move.cs @@ -90,7 +90,7 @@ namespace OpenRA.Traits.Activities public IActivity Tick( Actor self ) { - var mobile = self.traits.Get(); + var mobile = self.Trait(); if( move != null ) { @@ -165,10 +165,10 @@ namespace OpenRA.Traits.Activities void NudgeBlocker(Actor self, int2 nextCell) { - var blocker = self.World.WorldActor.traits.Get().GetUnitsAt(nextCell).FirstOrDefault(); + var blocker = self.World.WorldActor.Trait().GetUnitsAt(nextCell).FirstOrDefault(); if (blocker == null) return; - var nudge = blocker.traits.GetOrDefault(); + var nudge = blocker.TraitOrDefault(); if (nudge != null) nudge.OnNudge(blocker, self); } diff --git a/OpenRA.Game/Traits/Activities/Sell.cs b/OpenRA.Game/Traits/Activities/Sell.cs index e74ed5f376..1b7c8719cf 100644 --- a/OpenRA.Game/Traits/Activities/Sell.cs +++ b/OpenRA.Game/Traits/Activities/Sell.cs @@ -23,12 +23,12 @@ namespace OpenRA.Traits.Activities var csv = self.Info.Traits.GetOrDefault(); var cost = csv != null ? csv.Value : self.Info.Traits.Get().Cost; - var health = self.traits.GetOrDefault(); + var health = self.TraitOrDefault(); var refundFraction = self.Info.Traits.Get().RefundPercent * (health == null ? 1f : health.HPFraction); - self.Owner.PlayerActor.traits.Get().GiveCash((int)(refundFraction * cost)); + self.Owner.PlayerActor.Trait().GiveCash((int)(refundFraction * cost)); - foreach (var ns in self.traits.WithInterface()) + foreach (var ns in self.TraitsImplementing()) ns.Sold(self); self.World.AddFrameEndTask( _ => self.World.Remove( self ) ); } @@ -37,10 +37,10 @@ namespace OpenRA.Traits.Activities { if( !started ) { - framesRemaining = self.traits.Get().anim.HasSequence("make") - ? self.traits.Get().anim.GetSequence( "make" ).Length : 0; + framesRemaining = self.Trait().anim.HasSequence("make") + ? self.Trait().anim.GetSequence( "make" ).Length : 0; - foreach( var ns in self.traits.WithInterface() ) + foreach( var ns in self.TraitsImplementing() ) ns.Selling( self ); started = true; diff --git a/OpenRA.Game/Traits/Activities/Turn.cs b/OpenRA.Game/Traits/Activities/Turn.cs index d3a4076170..50e91b5e78 100755 --- a/OpenRA.Game/Traits/Activities/Turn.cs +++ b/OpenRA.Game/Traits/Activities/Turn.cs @@ -24,7 +24,7 @@ namespace OpenRA.Traits.Activities public IActivity Tick( Actor self ) { - var facing = self.traits.Get(); + var facing = self.Trait(); if( desiredFacing == facing.Facing ) return NextActivity; @@ -35,7 +35,7 @@ namespace OpenRA.Traits.Activities public void Cancel( Actor self ) { - desiredFacing = self.traits.Get().Facing; + desiredFacing = self.Trait().Facing; NextActivity = null; } } diff --git a/OpenRA.Game/Traits/Building.cs b/OpenRA.Game/Traits/Building.cs index c10e4ba2b4..0a8a292b64 100644 --- a/OpenRA.Game/Traits/Building.cs +++ b/OpenRA.Game/Traits/Building.cs @@ -47,7 +47,7 @@ namespace OpenRA.Traits public bool Disabled { - get { return self.traits.WithInterface().Any(t => t.Disabled); } + get { return self.TraitsImplementing().Any(t => t.Disabled); } } public Building(ActorInitializer init) @@ -61,14 +61,14 @@ namespace OpenRA.Traits public int GetPowerUsage() { - var modifier = self.traits - .WithInterface() + var modifier = self + .TraitsImplementing() .Select(t => t.GetPowerModifier()) .Product(); if (Info.Power > 0) { - var health = self.traits.GetOrDefault(); + var health = self.TraitOrDefault(); var healthFraction = (health == null) ? 1f : health.HPFraction; return (int)(modifier * healthFraction * Info.Power); } @@ -80,7 +80,7 @@ namespace OpenRA.Traits { if (e.DamageState == DamageState.Dead) { - self.World.WorldActor.traits.Get().AddEffect(10, self.CenterLocation, 1); + self.World.WorldActor.Trait().AddEffect(10, self.CenterLocation, 1); Sound.Play(Info.DestroyedSound, self.CenterLocation); } } diff --git a/OpenRA.Game/Traits/Health.cs b/OpenRA.Game/Traits/Health.cs index 570ad7ff11..dda3a2cd08 100644 --- a/OpenRA.Game/Traits/Health.cs +++ b/OpenRA.Game/Traits/Health.cs @@ -82,7 +82,7 @@ namespace OpenRA.Traits var oldState = this.DamageState; /* apply the damage modifiers, if we have any. */ - var modifier = (float)self.traits.WithInterface() + var modifier = (float)self.TraitsImplementing() .Select(t => t.GetDamageModifier(warhead)).Product(); damage = (int)(damage * modifier); @@ -103,7 +103,7 @@ namespace OpenRA.Traits if (hp > MaxHP) hp = MaxHP; - foreach (var nd in self.traits.WithInterface()) + foreach (var nd in self.TraitsImplementing()) nd.Damaged(self, new AttackInfo { Attacker = attacker, @@ -140,26 +140,26 @@ namespace OpenRA.Traits { public static bool IsDead(this Actor self) { - var health = self.traits.GetOrDefault(); + var health = self.TraitOrDefault(); return (health == null) ? true : health.IsDead; } public static DamageState GetDamageState(this Actor self) { - var health = self.traits.GetOrDefault(); + var health = self.TraitOrDefault(); return (health == null) ? DamageState.Undamaged : health.DamageState; } public static void InflictDamage(this Actor self, Actor attacker, int damage, WarheadInfo warhead) { - var health = self.traits.GetOrDefault(); + var health = self.TraitOrDefault(); if (health == null) return; health.InflictDamage(self, attacker, damage, warhead); } public static void Kill(this Actor self, Actor attacker) { - var health = self.traits.GetOrDefault(); + var health = self.TraitOrDefault(); if (health == null) return; health.InflictDamage(self, attacker, health.HP, null); } diff --git a/OpenRA.Game/Traits/Mobile.cs b/OpenRA.Game/Traits/Mobile.cs index 992268f612..b621236909 100644 --- a/OpenRA.Game/Traits/Mobile.cs +++ b/OpenRA.Game/Traits/Mobile.cs @@ -79,10 +79,10 @@ namespace OpenRA.Traits this.self = init.self; this.Info = info; - shroud = self.World.WorldActor.traits.Get(); - uim = self.World.WorldActor.traits.Get(); - bim = self.World.WorldActor.traits.Get(); - canShareCell = self.traits.Contains(); + shroud = self.World.WorldActor.Trait(); + uim = self.World.WorldActor.Trait(); + bim = self.World.WorldActor.Trait(); + canShareCell = self.HasTrait(); if (init.Contains()) { @@ -149,7 +149,7 @@ namespace OpenRA.Traits self.World.AddFrameEndTask(w => { w.Add(new MoveFlash(self.World, order.TargetLocation)); - var line = self.traits.GetOrDefault(); + var line = self.TraitOrDefault(); if (line != null) line.SetTarget(self, Target.FromOrder(order), Color.Green); }); @@ -203,7 +203,7 @@ namespace OpenRA.Traits if (Info.Crushes == null) return false; - var crushable = building.traits.WithInterface(); + var crushable = building.TraitsImplementing(); if (crushable.Count() == 0) return false; @@ -215,11 +215,11 @@ namespace OpenRA.Traits if (checkTransientActors && uim.AnyUnitsAt(cell)) { var actors = uim.GetUnitsAt(cell).Where(a => a != self && a != ignoreActor).ToArray(); - var nonshareable = canShareCell ? actors : actors.Where(a => !a.traits.Contains()).ToArray(); + var nonshareable = canShareCell ? actors : actors.Where(a => !a.HasTrait()).ToArray(); if (canShareCell) { - var shareable = actors.Where(a => a.traits.Contains()); + var shareable = actors.Where(a => a.HasTrait()); // only allow 5 in a cell if (shareable.Count() >= 5) @@ -230,8 +230,8 @@ namespace OpenRA.Traits if (Info.Crushes == null && nonshareable.Length > 0) return false; - if (nonshareable.Length > 0 && nonshareable.Any(a => !(a.traits.Contains() && - a.traits.WithInterface().Any(b => b.CrushClasses.Intersect(Info.Crushes).Any())))) + if (nonshareable.Length > 0 && nonshareable.Any(a => !(a.HasTrait() && + a.TraitsImplementing().Any(b => b.CrushClasses.Intersect(Info.Crushes).Any())))) return false; } @@ -241,10 +241,10 @@ namespace OpenRA.Traits public virtual void FinishedMoving(Actor self) { - var crushable = uim.GetUnitsAt(toCell).Where(a => a != self && a.traits.Contains()); + var crushable = uim.GetUnitsAt(toCell).Where(a => a != self && a.HasTrait()); foreach (var a in crushable) { - var crushActions = a.traits.WithInterface().Where(b => b.CrushClasses.Intersect(Info.Crushes).Any()); + var crushActions = a.TraitsImplementing().Where(b => b.CrushClasses.Intersect(Info.Crushes).Any()); foreach (var b in crushActions) b.OnCrush(self); } @@ -263,8 +263,8 @@ namespace OpenRA.Traits { var type = self.World.GetTerrainType(cell); - var modifier = self.traits - .WithInterface() + var modifier = self + .TraitsImplementing() .Select(t => t.GetSpeedModifier()) .Product(); return Info.Speed * TerrainSpeed[type] * modifier; @@ -323,7 +323,7 @@ namespace OpenRA.Traits if (self.Owner == self.World.LocalPlayer) self.World.AddFrameEndTask(w => { - var line = self.traits.GetOrDefault(); + var line = self.TraitOrDefault(); if (line != null) line.SetTargetSilently(self, Target.FromCell(moveTo.Value), Color.Green); }); diff --git a/OpenRA.Game/Traits/Player/DeveloperMode.cs b/OpenRA.Game/Traits/Player/DeveloperMode.cs index b1a4f21fa7..77817e53fd 100644 --- a/OpenRA.Game/Traits/Player/DeveloperMode.cs +++ b/OpenRA.Game/Traits/Player/DeveloperMode.cs @@ -58,7 +58,7 @@ namespace OpenRA.Traits } case "DevGiveCash": { - self.traits.Get().GiveCash(Info.Cash); + self.Trait().GiveCash(Info.Cash); break; } case "DevShroud": diff --git a/OpenRA.Game/Traits/Player/PlaceBuilding.cs b/OpenRA.Game/Traits/Player/PlaceBuilding.cs index 0fa1c01d8e..20cbc25784 100644 --- a/OpenRA.Game/Traits/Player/PlaceBuilding.cs +++ b/OpenRA.Game/Traits/Player/PlaceBuilding.cs @@ -27,7 +27,7 @@ namespace OpenRA.Traits { var prevItems = GetNumBuildables(self.Owner); - var queue = self.traits.Get(); + var queue = self.Trait(); var unit = Rules.Info[order.TargetString]; var producing = queue.CurrentItem(unit.Category); @@ -86,7 +86,7 @@ namespace OpenRA.Traits .FirstOrDefault(); if( producer.Actor != null ) - producer.Actor.traits.WithInterface().First().PlayCustomAnim( producer.Actor, "build" ); + producer.Actor.TraitsImplementing().First().PlayCustomAnim( producer.Actor, "build" ); } static int GetNumBuildables(Player p) diff --git a/OpenRA.Game/Traits/Player/PlayerResources.cs b/OpenRA.Game/Traits/Player/PlayerResources.cs index 36864475ca..9dedb34e57 100644 --- a/OpenRA.Game/Traits/Player/PlayerResources.cs +++ b/OpenRA.Game/Traits/Player/PlayerResources.cs @@ -57,7 +57,7 @@ namespace OpenRA.Traits void TickOre(Actor self) { OreCapacity = self.World.Queries.OwnedBy[Owner].WithTrait() - .Sum(a => a.Actor.traits.WithInterface().Sum(b => b.Capacity)); + .Sum(a => a.Actor.TraitsImplementing().Sum(b => b.Capacity)); if (Ore > OreCapacity) Ore = OreCapacity; diff --git a/OpenRA.Game/Traits/Player/ProductionQueue.cs b/OpenRA.Game/Traits/Player/ProductionQueue.cs index 87779f5d5c..50fd350379 100644 --- a/OpenRA.Game/Traits/Player/ProductionQueue.cs +++ b/OpenRA.Game/Traits/Player/ProductionQueue.cs @@ -37,7 +37,7 @@ namespace OpenRA.Traits { while( p.Value.Count > 0 && !Rules.TechTree.BuildableItems( self.Owner, p.Key ).Contains( p.Value[ 0 ].Item ) ) { - self.Owner.PlayerActor.traits.Get().GiveCash(p.Value[0].TotalCost - p.Value[0].RemainingCost); // refund what's been paid so far. + self.Owner.PlayerActor.Trait().GiveCash(p.Value[0].TotalCost - p.Value[0].RemainingCost); // refund what's been paid so far. FinishProduction(p.Key); } if( p.Value.Count > 0 ) @@ -101,7 +101,7 @@ namespace OpenRA.Traits if (unit == null || ! unit.Traits.Contains()) return 0; - if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.traits.Get().FastBuild) return 0; + if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.Trait().FastBuild) return 0; var ui = unit.Traits.Get(); var time = ui.Cost * self.Owner.PlayerActor.Info.Traits.Get().BuildSpeed /* todo: country-specific build speed bonus */ @@ -139,7 +139,7 @@ namespace OpenRA.Traits else if( lastIndex == 0 ) { var item = queue[0]; - self.Owner.PlayerActor.traits.Get().GiveCash(item.TotalCost - item.RemainingCost); // refund what's been paid so far. + self.Owner.PlayerActor.Trait().GiveCash(item.TotalCost - item.RemainingCost); // refund what's been paid so far. FinishProduction(category); } } @@ -158,7 +158,7 @@ namespace OpenRA.Traits static bool IsDisabledBuilding(Actor a) { - var building = a.traits.GetOrDefault(); + var building = a.TraitOrDefault(); return building != null && building.Disabled; } @@ -227,7 +227,7 @@ namespace OpenRA.Traits if (Paused) return; - if (player.PlayerActor.traits.Get().GetPowerState() != PowerState.Normal) + if (player.PlayerActor.Trait().GetPowerState() != PowerState.Normal) { if (--slowdown <= 0) slowdown = player.PlayerActor.Info.Traits.Get().LowPowerSlowdown; @@ -236,7 +236,7 @@ namespace OpenRA.Traits } var costThisFrame = RemainingCost / RemainingTime; - if (costThisFrame != 0 && !player.PlayerActor.traits.Get().TakeCash(costThisFrame)) return; + if (costThisFrame != 0 && !player.PlayerActor.Trait().TakeCash(costThisFrame)) return; RemainingCost -= costThisFrame; RemainingTime -= 1; if (RemainingTime > 0) return; diff --git a/OpenRA.Game/Traits/Player/TechTreeCache.cs b/OpenRA.Game/Traits/Player/TechTreeCache.cs index 18a5143f1e..cccd86084e 100755 --- a/OpenRA.Game/Traits/Player/TechTreeCache.cs +++ b/OpenRA.Game/Traits/Player/TechTreeCache.cs @@ -36,7 +36,7 @@ namespace OpenRA.Traits { var effectivePrereq = prerequisites.Where( a => a.Traits.Get().Owner.Contains( owner.Country.Race ) ); var nowHasPrerequisites = effectivePrereq.Any() && - effectivePrereq.All( a => buildings[ a.Name ].Any( b => !b.traits.Get().Disabled ) ); + effectivePrereq.All( a => buildings[ a.Name ].Any( b => !b.Trait().Disabled ) ); if( nowHasPrerequisites && !hasPrerequisites ) watcher.Available(); diff --git a/OpenRA.Game/Traits/PrimaryBuilding.cs b/OpenRA.Game/Traits/PrimaryBuilding.cs index a86688c1eb..e24a70a292 100644 --- a/OpenRA.Game/Traits/PrimaryBuilding.cs +++ b/OpenRA.Game/Traits/PrimaryBuilding.cs @@ -70,7 +70,7 @@ namespace OpenRA.Traits { public static bool IsPrimaryBuilding(this Actor a) { - var pb = a.traits.GetOrDefault(); + var pb = a.TraitOrDefault(); return pb != null && pb.IsPrimary; } } diff --git a/OpenRA.Game/Traits/Production.cs b/OpenRA.Game/Traits/Production.cs index 378187d27e..29acb9a795 100755 --- a/OpenRA.Game/Traits/Production.cs +++ b/OpenRA.Game/Traits/Production.cs @@ -40,8 +40,8 @@ namespace OpenRA.Traits public void DoProduction(Actor self, Actor newUnit, int2 exit, float2 spawn) { - var move = newUnit.traits.Get(); - var facing = newUnit.traits.GetOrDefault(); + var move = newUnit.Trait(); + var facing = newUnit.TraitOrDefault(); // Set the physical position of the unit as the exit cell move.SetPosition(newUnit,exit); @@ -58,7 +58,7 @@ namespace OpenRA.Traits // For the target line var target = exit; - var rp = self.traits.GetOrDefault(); + var rp = self.TraitOrDefault(); if (rp != null) { target = rp.rallyPoint; @@ -70,13 +70,13 @@ namespace OpenRA.Traits { self.World.AddFrameEndTask(w => { - var line = newUnit.traits.GetOrDefault(); + var line = newUnit.TraitOrDefault(); if (line != null) line.SetTargetSilently(newUnit, Target.FromCell(target), Color.Green); }); } - foreach (var t in self.traits.WithInterface()) + foreach (var t in self.TraitsImplementing()) t.UnitProduced(self, newUnit, exit); Log.Write("debug", "{0} #{1} produced by {2} #{3}", newUnit.Info.Name, newUnit.ActorID, self.Info.Name, self.ActorID); @@ -91,7 +91,7 @@ namespace OpenRA.Traits // Todo: remove assumption on Mobile; // required for 3-arg CanEnterCell - var mobile = newUnit.traits.Get(); + var mobile = newUnit.Trait(); // Pick a spawn/exit point pair // Todo: Reorder in a synced random way diff --git a/OpenRA.Game/Traits/ProvidesRadar.cs b/OpenRA.Game/Traits/ProvidesRadar.cs index 265d01189b..10f1336e7d 100644 --- a/OpenRA.Game/Traits/ProvidesRadar.cs +++ b/OpenRA.Game/Traits/ProvidesRadar.cs @@ -23,7 +23,7 @@ namespace OpenRA.Traits bool UpdateActive(Actor self) { // Check if powered - var b = self.traits.Get(); + var b = self.Trait(); if (b.Disabled) return false; var isJammed = self.World.Queries.WithTrait().Any(a => self.Owner != a.Actor.Owner diff --git a/OpenRA.Game/Traits/RepairableBuilding.cs b/OpenRA.Game/Traits/RepairableBuilding.cs index 5e2b2533ea..ec87dc444c 100644 --- a/OpenRA.Game/Traits/RepairableBuilding.cs +++ b/OpenRA.Game/Traits/RepairableBuilding.cs @@ -35,7 +35,7 @@ namespace OpenRA.Traits RepairableBuildingInfo Info; public RepairableBuilding(Actor self, RepairableBuildingInfo info) { - Health = self.traits.Get(); + Health = self.Trait(); Info = info; } @@ -60,7 +60,7 @@ namespace OpenRA.Traits var costPerHp = (Info.RepairPercent * buildingValue) / Health.MaxHP; var hpToRepair = Math.Min(Info.RepairStep, Health.MaxHP - Health.HP); var cost = (int)Math.Ceiling(costPerHp * hpToRepair); - if (!self.Owner.PlayerActor.traits.Get().TakeCash(cost)) + if (!self.Owner.PlayerActor.Trait().TakeCash(cost)) { remainingTicks = 1; return; diff --git a/OpenRA.Game/Traits/RevealsShroud.cs b/OpenRA.Game/Traits/RevealsShroud.cs index 259158c854..a817ba2767 100644 --- a/OpenRA.Game/Traits/RevealsShroud.cs +++ b/OpenRA.Game/Traits/RevealsShroud.cs @@ -31,7 +31,7 @@ namespace OpenRA.Traits if (!self.IsIdle && previousLocation != self.Location) { previousLocation = self.Location; - self.World.WorldActor.traits.Get().UpdateActor(self); + self.World.WorldActor.Trait().UpdateActor(self); } } diff --git a/OpenRA.Game/Traits/Selectable.cs b/OpenRA.Game/Traits/Selectable.cs index af021b22b3..c203bb09b1 100644 --- a/OpenRA.Game/Traits/Selectable.cs +++ b/OpenRA.Game/Traits/Selectable.cs @@ -61,7 +61,7 @@ namespace OpenRA.Traits void DrawHealthBar(Actor self, float2 xy, float2 Xy) { - var health = self.traits.GetOrDefault(); + var health = self.TraitOrDefault(); if (self.IsDead() || health == null) return; @@ -107,7 +107,7 @@ namespace OpenRA.Traits var pipxyBase = basePosition + new float2(-12, -7); // Correct for the offset in the shp file var pipxyOffset = new float2(0, 0); // Correct for offset due to multiple columns/rows - foreach (var pips in self.traits.WithInterface()) + foreach (var pips in self.TraitsImplementing()) { foreach (var pip in pips.GetPips(self)) { @@ -135,7 +135,7 @@ namespace OpenRA.Traits var tagxyBase = basePosition + new float2(-16, 2); // Correct for the offset in the shp file var tagxyOffset = new float2(0, 0); // Correct for offset due to multiple rows - foreach (var tags in self.traits.WithInterface()) + foreach (var tags in self.TraitsImplementing()) { foreach (var tag in tags.GetTags()) { @@ -154,9 +154,9 @@ namespace OpenRA.Traits void DrawUnitPath(Actor self) { - if (!Game.world.LocalPlayer.PlayerActor.traits.Get().PathDebug) return; + if (!Game.world.LocalPlayer.PlayerActor.Trait().PathDebug) return; - var mobile = self.traits.GetOrDefault(); + var mobile = self.TraitOrDefault(); if (mobile != null) { var alt = new float2(0, -mobile.Altitude); diff --git a/OpenRA.Game/Traits/SupportPower.cs b/OpenRA.Game/Traits/SupportPower.cs index 2b543a2b3e..73de5147c1 100644 --- a/OpenRA.Game/Traits/SupportPower.cs +++ b/OpenRA.Game/Traits/SupportPower.cs @@ -56,7 +56,7 @@ namespace OpenRA.Traits RemainingTime = TotalTime; Owner = self.Owner; - self.traits.Get().Add( Info.Prerequisites.Select( a => Rules.Info[ a.ToLowerInvariant() ] ).ToList(), this ); + self.Trait().Add( Info.Prerequisites.Select( a => Rules.Info[ a.ToLowerInvariant() ] ).ToList(), this ); } public void Tick(Actor self) @@ -69,7 +69,7 @@ namespace OpenRA.Traits if (IsAvailable && (!Info.RequiresPower || IsPowered())) { - if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.traits.Get().FastCharge) RemainingTime = 0; + if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.Trait().FastCharge) RemainingTime = 0; if (RemainingTime > 0) --RemainingTime; if (!notifiedCharging) { @@ -96,10 +96,10 @@ namespace OpenRA.Traits .Where(a => Rules.Info[a].Traits.Get().Owner.Contains(Owner.Country.Race)); if (Info.Prerequisites.Count() == 0) - return Owner.PlayerActor.traits.Get().GetPowerState() == PowerState.Normal; + return Owner.PlayerActor.Trait().GetPowerState() == PowerState.Normal; return effectivePrereq.Any() && - effectivePrereq.All(a => buildings[a].Any(b => !b.traits.Get().Disabled)); + effectivePrereq.All(a => buildings[a].Any(b => !b.Trait().Disabled)); } public void FinishActivate() diff --git a/OpenRA.Game/Traits/Turreted.cs b/OpenRA.Game/Traits/Turreted.cs index 0012ffb6c2..5e05518fb3 100644 --- a/OpenRA.Game/Traits/Turreted.cs +++ b/OpenRA.Game/Traits/Turreted.cs @@ -30,7 +30,7 @@ namespace OpenRA.Traits { this.info = info; turretFacing = info.InitialFacing; - facing = self.traits.GetOrDefault(); + facing = self.TraitOrDefault(); } public void Tick( Actor self ) diff --git a/OpenRA.Game/Traits/World/BibLayer.cs b/OpenRA.Game/Traits/World/BibLayer.cs index 65d51e3428..90789124d9 100644 --- a/OpenRA.Game/Traits/World/BibLayer.cs +++ b/OpenRA.Game/Traits/World/BibLayer.cs @@ -1,17 +1,17 @@ -#region Copyright & License Information -/* - * Copyright 2007-2010 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 LICENSE. - */ -#endregion - -using System; -using System.Drawing; -using System.Linq; -using OpenRA.FileFormats; +#region Copyright & License Information +/* + * Copyright 2007-2010 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 LICENSE. + */ +#endregion + +using System; +using System.Drawing; +using System.Linq; +using OpenRA.FileFormats; using OpenRA.Graphics; namespace OpenRA.Traits @@ -37,9 +37,9 @@ namespace OpenRA.Traits bibSprites = info.BibTypes.Select(x => SpriteSheetBuilder.LoadAllSprites(x)).ToArray(); self.World.ActorAdded += - a => { if (a.traits.Contains()) DoBib(a,true); }; + a => { if (a.HasTrait()) DoBib(a,true); }; self.World.ActorRemoved += - a => { if (a.traits.Contains()) DoBib(a,false); }; + a => { if (a.HasTrait()) DoBib(a,false); }; } public void WorldLoaded(World w) @@ -56,7 +56,7 @@ namespace OpenRA.Traits int bib = Array.IndexOf(info.BibWidths,size); if (bib < 0) - { + { Log.Write("debug", "Cannot bib {0}-wide building {1}", size, b.Info.Name); return; } @@ -72,23 +72,23 @@ namespace OpenRA.Traits } public void Render() - { - var cliprect = Game.viewport.ShroudBounds().HasValue - ? Rectangle.Intersect(Game.viewport.ShroudBounds().Value, world.Map.Bounds) : world.Map.Bounds; - - var minx = cliprect.Left; - var maxx = cliprect.Right; - - var miny = cliprect.Top; - var maxy = cliprect.Bottom; - - for (int x = minx; x < maxx; x++) + { + var cliprect = Game.viewport.ShroudBounds().HasValue + ? Rectangle.Intersect(Game.viewport.ShroudBounds().Value, world.Map.Bounds) : world.Map.Bounds; + + var minx = cliprect.Left; + var maxx = cliprect.Right; + + var miny = cliprect.Top; + var maxy = cliprect.Bottom; + + for (int x = minx; x < maxx; x++) for (int y = miny; y < maxy; y++) { var t = new int2(x, y); - if (world.LocalPlayer != null && !world.LocalPlayer.Shroud.IsExplored(t) || tiles[x,y].type == 0) continue; - - Game.Renderer.SpriteRenderer.DrawSprite(bibSprites[tiles[x, y].type - 1][tiles[x, y].image], + if (world.LocalPlayer != null && !world.LocalPlayer.Shroud.IsExplored(t) || tiles[x,y].type == 0) continue; + + Game.Renderer.SpriteRenderer.DrawSprite(bibSprites[tiles[x, y].type - 1][tiles[x, y].image], Game.CellSize * t, "terrain"); } } diff --git a/OpenRA.Game/Traits/World/BuildingInfluence.cs b/OpenRA.Game/Traits/World/BuildingInfluence.cs index 699d445e3d..9085cd435b 100644 --- a/OpenRA.Game/Traits/World/BuildingInfluence.cs +++ b/OpenRA.Game/Traits/World/BuildingInfluence.cs @@ -32,11 +32,11 @@ namespace OpenRA.Traits influence = new Actor[map.MapSize.X, map.MapSize.Y]; world.ActorAdded += - a => { if (a.traits.Contains()) - ChangeInfluence(a, a.traits.Get(), true); }; + a => { if (a.HasTrait()) + ChangeInfluence(a, a.Trait(), true); }; world.ActorRemoved += - a => { if (a.traits.Contains()) - ChangeInfluence(a, a.traits.Get(), false); }; + a => { if (a.HasTrait()) + ChangeInfluence(a, a.Trait(), false); }; } void ChangeInfluence( Actor a, Building building, bool isAdd ) diff --git a/OpenRA.Game/Traits/World/ResourceLayer.cs b/OpenRA.Game/Traits/World/ResourceLayer.cs index 74ce36d165..041afe9198 100644 --- a/OpenRA.Game/Traits/World/ResourceLayer.cs +++ b/OpenRA.Game/Traits/World/ResourceLayer.cs @@ -55,7 +55,7 @@ namespace OpenRA.Traits this.world = w; content = new CellContents[w.Map.MapSize.X, w.Map.MapSize.Y]; - resourceTypes = w.WorldActor.traits.WithInterface().ToArray(); + resourceTypes = w.WorldActor.TraitsImplementing().ToArray(); foreach (var rt in resourceTypes) rt.info.Sprites = rt.info.SpriteNames.Select(a => SpriteSheetBuilder.LoadAllSprites(a)).ToArray(); diff --git a/OpenRA.Game/Traits/World/Shroud.cs b/OpenRA.Game/Traits/World/Shroud.cs index 4d2a563c34..d82cdabeb5 100644 --- a/OpenRA.Game/Traits/World/Shroud.cs +++ b/OpenRA.Game/Traits/World/Shroud.cs @@ -64,7 +64,7 @@ namespace OpenRA.Traits void AddActor(Actor a) { - if (!a.traits.Contains()) + if (!a.HasTrait()) return; if (a.Owner == null || a.Owner.World.LocalPlayer == null @@ -78,7 +78,7 @@ namespace OpenRA.Traits var v = new ActorVisibility { - range = a.traits.Get().RevealRange, + range = a.Trait().RevealRange, vis = GetVisOrigins(a).ToArray() }; @@ -129,7 +129,7 @@ namespace OpenRA.Traits } else { - var mobile = a.traits.GetOrDefault(); + var mobile = a.TraitOrDefault(); if (mobile != null) return new[] { mobile.fromCell, mobile.toCell }; else diff --git a/OpenRA.Game/Traits/World/UnitInfluence.cs b/OpenRA.Game/Traits/World/UnitInfluence.cs index 16922cd431..a5d7fee06a 100644 --- a/OpenRA.Game/Traits/World/UnitInfluence.cs +++ b/OpenRA.Game/Traits/World/UnitInfluence.cs @@ -34,7 +34,7 @@ namespace OpenRA.Traits for (int j = 0; j < world.Map.MapSize.Y; j++) influence[ i, j ] = new List(); - world.ActorRemoved += a => Remove( a, a.traits.GetOrDefault() ); + world.ActorRemoved += a => Remove( a, a.TraitOrDefault() ); } public void Tick( Actor self ) @@ -49,7 +49,7 @@ namespace OpenRA.Traits for( int y = 0 ; y < self.World.Map.MapSize.Y ; y++ ) if( influence[ x, y ] != null ) foreach (var a in influence[ x, y ]) - if (!a.traits.Get().OccupiedCells().Contains( new int2( x, y ) ) ) + if (!a.Trait().OccupiedCells().Contains( new int2( x, y ) ) ) throw new InvalidOperationException( "UIM: Sanity check failed A" ); foreach( var t in self.World.Queries.WithTraitMultiple() ) diff --git a/OpenRA.Game/UiOverlay.cs b/OpenRA.Game/UiOverlay.cs index 00ead4e76f..52246c7f72 100644 --- a/OpenRA.Game/UiOverlay.cs +++ b/OpenRA.Game/UiOverlay.cs @@ -44,7 +44,7 @@ namespace OpenRA { if (Game.Settings.UnitDebug) { - var uim = world.WorldActor.traits.Get(); + var uim = world.WorldActor.Trait(); for (var i = world.Map.Bounds.Left; i < world.Map.Bounds.Right; i++) for (var j = world.Map.Bounds.Top; j < world.Map.Bounds.Bottom; j++) @@ -68,7 +68,7 @@ namespace OpenRA } else { - var res = world.WorldActor.traits.Get(); + var res = world.WorldActor.Trait(); var isCloseEnough = world.IsCloseEnoughToBase(world.LocalPlayer, name, bi, topLeft); foreach (var t in Footprint.Tiles(name, bi, topLeft)) Game.Renderer.SpriteRenderer.DrawSprite((isCloseEnough && world.IsCellBuildable(t, bi.WaterBound) && res.GetResource(t) == null) diff --git a/OpenRA.Game/Widgets/Delegates/DeveloperModeDelegate.cs b/OpenRA.Game/Widgets/Delegates/DeveloperModeDelegate.cs index 8fac1110e3..36c0d22931 100644 --- a/OpenRA.Game/Widgets/Delegates/DeveloperModeDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/DeveloperModeDelegate.cs @@ -41,7 +41,7 @@ namespace OpenRA.Widgets.Delegates }; devmodeBG.GetWidget("SETTINGS_CHECKBOX_SHROUD").Checked = - () => Game.world.LocalPlayer.PlayerActor.traits.Get().DisableShroud; + () => Game.world.LocalPlayer.PlayerActor.Trait().DisableShroud; devmodeBG.GetWidget("SETTINGS_CHECKBOX_SHROUD").OnMouseDown = mi => { Game.IssueOrder(new Order("DevShroud", Game.world.LocalPlayer.PlayerActor)); @@ -57,7 +57,7 @@ namespace OpenRA.Widgets.Delegates }; devmodeBG.GetWidget("SETTINGS_CHECKBOX_PATHDEBUG").Checked = - () => Game.world.LocalPlayer.PlayerActor.traits.Get().PathDebug; + () => Game.world.LocalPlayer.PlayerActor.Trait().PathDebug; devmodeBG.GetWidget("SETTINGS_CHECKBOX_PATHDEBUG").OnMouseDown = mi => { Game.IssueOrder(new Order("DevPathDebug", Game.world.LocalPlayer.PlayerActor)); @@ -71,7 +71,7 @@ namespace OpenRA.Widgets.Delegates }; devmodeBG.GetWidget("SETTINGS_BUILD_SPEED").Checked = - () => Game.world.LocalPlayer.PlayerActor.traits.Get().FastBuild; + () => Game.world.LocalPlayer.PlayerActor.Trait().FastBuild; devmodeBG.GetWidget("SETTINGS_BUILD_SPEED").OnMouseDown = mi => { Game.IssueOrder(new Order("DevFastBuild", Game.world.LocalPlayer.PlayerActor)); @@ -79,7 +79,7 @@ namespace OpenRA.Widgets.Delegates }; devmodeBG.GetWidget("SETTINGS_CHARGE_TIME").Checked = - () => Game.world.LocalPlayer.PlayerActor.traits.Get().FastCharge; + () => Game.world.LocalPlayer.PlayerActor.Trait().FastCharge; devmodeBG.GetWidget("SETTINGS_CHARGE_TIME").OnMouseDown = mi => { Game.IssueOrder(new Order("DevFastCharge", Game.world.LocalPlayer.PlayerActor)); diff --git a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs index 26f90b97fe..3f46f87b2e 100644 --- a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs @@ -96,7 +96,7 @@ namespace OpenRA.Widgets var done = false; foreach (var o in orders) { - foreach (var v in o.Subject.traits.WithInterface()) + foreach (var v in o.Subject.TraitsImplementing()) { if (Sound.PlayVoice(v.VoicePhraseForOrder(o.Subject, o), o.Subject)) { @@ -174,7 +174,7 @@ namespace OpenRA.Widgets IEnumerable SelectActorsInBox(World world, float2 a, float2 b) { return world.FindUnits(a, b) - .Where( x => x.traits.Contains() && x.IsVisible() ) + .Where( x => x.HasTrait() && x.IsVisible() ) .GroupBy(x => (x.Owner == world.LocalPlayer) ? x.Info.Traits.Get().Priority : 0) .OrderByDescending(g => g.Key) .Select( g => g.AsEnumerable() ) diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index b875d586d7..d525707150 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -116,7 +116,7 @@ namespace OpenRA Timer.Time( "worldActor: {0}" ); - foreach (var wlh in WorldActor.traits.WithInterface()) + foreach (var wlh in WorldActor.TraitsImplementing()) wlh.WorldLoaded(this); PathFinder = new PathFinder(this); @@ -235,8 +235,8 @@ namespace OpenRA return ret; ret = new CachedView>( set, - x => x.traits.Contains(), - x => new TraitPair { Actor = x, Trait = x.traits.Get() } ); + x => x.HasTrait(), + x => new TraitPair { Actor = x, Trait = x.Trait() } ); hasTrait.Add( ret ); return ret; } @@ -248,8 +248,8 @@ namespace OpenRA return ret; ret = new CachedView>( world.actors, - x => x.traits.Contains(), - x => x.traits.WithInterface().Select( t => new TraitPair { Actor = x, Trait = t } ) ); + x => x.HasTrait(), + x => x.TraitsImplementing().Select( t => new TraitPair { Actor = x, Trait = t } ) ); hasTrait.Add( ret ); return ret; } diff --git a/OpenRA.Game/WorldUtils.cs b/OpenRA.Game/WorldUtils.cs index 558f49623d..3c7db25eec 100755 --- a/OpenRA.Game/WorldUtils.cs +++ b/OpenRA.Game/WorldUtils.cs @@ -28,8 +28,8 @@ namespace OpenRA public static bool IsCellBuildable(this World world, int2 a, bool waterBound, Actor toIgnore) { - if (world.WorldActor.traits.Get().GetBuildingAt(a) != null) return false; - if (world.WorldActor.traits.Get().GetUnitsAt(a).Any(b => b != toIgnore)) return false; + if (world.WorldActor.Trait().GetBuildingAt(a) != null) return false; + if (world.WorldActor.Trait().GetUnitsAt(a).Any(b => b != toIgnore)) return false; if (waterBound) return world.Map.IsInMap(a.X,a.Y) && GetTerrainInfo(world,a).IsWater; @@ -47,7 +47,7 @@ namespace OpenRA { var u = float2.Min(a, b).ToInt2(); var v = float2.Max(a, b).ToInt2(); - return world.WorldActor.traits.Get().ActorsInBox(u,v); + return world.WorldActor.Trait().ActorsInBox(u,v); } public static IEnumerable FindUnitsInCircle(this World world, float2 a, float r) @@ -95,7 +95,7 @@ namespace OpenRA public static bool CanPlaceBuilding(this World world, string name, BuildingInfo building, int2 topLeft, Actor toIgnore) { - var res = world.WorldActor.traits.Get(); + var res = world.WorldActor.Trait(); return Footprint.Tiles(name, building, topLeft).All( t => world.Map.IsInMap(t.X, t.Y) && res.GetResource(t) == null && world.IsCellBuildable(t, building.WaterBound, toIgnore)); @@ -106,11 +106,11 @@ namespace OpenRA if (a.World.LocalPlayer != null && a.World.LocalPlayer.Shroud.Disabled) return true; - var shroud = a.World.WorldActor.traits.Get(); + var shroud = a.World.WorldActor.Trait(); if (!Shroud.GetVisOrigins(a).Any(o => a.World.Map.IsInMap(o) && shroud.exploredCells[o.X, o.Y])) // covered by shroud return false; - if (a.traits.WithInterface().Any(t => !t.IsVisible(a))) + if (a.TraitsImplementing().Any(t => !t.IsVisible(a))) return false; return true; @@ -131,7 +131,7 @@ namespace OpenRA { for( int x = scanStart.X ; x < scanEnd.X ; x++ ) { - var at = world.WorldActor.traits.Get().GetBuildingAt( new int2( x, y ) ); + var at = world.WorldActor.Trait().GetBuildingAt( new int2( x, y ) ); if( at != null && at.Owner.Stances[ p ] == Stance.Ally && at.Info.Traits.Get().BaseNormal ) nearnessCandidates.Add( new int2( x, y ) ); } diff --git a/OpenRA.Mods.Cnc/DeadBuildingState.cs b/OpenRA.Mods.Cnc/DeadBuildingState.cs index e42118565a..242d1428fb 100644 --- a/OpenRA.Mods.Cnc/DeadBuildingState.cs +++ b/OpenRA.Mods.Cnc/DeadBuildingState.cs @@ -27,8 +27,8 @@ namespace OpenRA.Mods.Cnc public DeadBuildingState(Actor self, DeadBuildingStateInfo info) { this.info = info; - rs = self.traits.Get(); - self.traits.Get().RemoveOnDeath = !rs.anim.HasSequence("dead"); + rs = self.Trait(); + self.Trait().RemoveOnDeath = !rs.anim.HasSequence("dead"); } public void Damaged(Actor self, AttackInfo e) diff --git a/OpenRA.Mods.Cnc/PoisonedByTiberium.cs b/OpenRA.Mods.Cnc/PoisonedByTiberium.cs index 690b88a788..8b983ca380 100644 --- a/OpenRA.Mods.Cnc/PoisonedByTiberium.cs +++ b/OpenRA.Mods.Cnc/PoisonedByTiberium.cs @@ -35,7 +35,7 @@ namespace OpenRA.Mods.Cnc { if (--poisonTicks <= 0) { - var rl = self.World.WorldActor.traits.Get(); + var rl = self.World.WorldActor.Trait(); var r = rl.GetResource(self.Location); if (r != null && info.Resources.Contains(r.info.Name)) diff --git a/OpenRA.Mods.Cnc/ProductionAirdrop.cs b/OpenRA.Mods.Cnc/ProductionAirdrop.cs index 3dd5cb5d69..86848c7636 100644 --- a/OpenRA.Mods.Cnc/ProductionAirdrop.cs +++ b/OpenRA.Mods.Cnc/ProductionAirdrop.cs @@ -51,7 +51,7 @@ namespace OpenRA.Mods.Cnc new AltitudeInit( Rules.Info["c17"].Traits.Get().CruiseAltitude ), }); - var cargo = a.traits.Get(); + var cargo = a.Trait(); var newUnit = self.World.CreateActor(false, producee.Name, new TypeDictionary { new OwnerInit( self.Owner ), diff --git a/OpenRA.Mods.Cnc/TiberiumRefineryDockAction.cs b/OpenRA.Mods.Cnc/TiberiumRefineryDockAction.cs index ce0d45e2aa..ffaee86dde 100644 --- a/OpenRA.Mods.Cnc/TiberiumRefineryDockAction.cs +++ b/OpenRA.Mods.Cnc/TiberiumRefineryDockAction.cs @@ -1,18 +1,18 @@ -#region Copyright & License Information -/* - * Copyright 2007-2010 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 LICENSE. - */ -#endregion - -using System.Drawing; -using OpenRA.Mods.RA; -using OpenRA.Mods.RA.Activities; -using OpenRA.Mods.RA.Render; -using OpenRA.Traits; +#region Copyright & License Information +/* + * Copyright 2007-2010 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 LICENSE. + */ +#endregion + +using System.Drawing; +using OpenRA.Mods.RA; +using OpenRA.Mods.RA.Activities; +using OpenRA.Mods.RA.Render; +using OpenRA.Traits; using OpenRA.Traits.Activities; namespace OpenRA.Mods.Cnc @@ -27,7 +27,7 @@ namespace OpenRA.Mods.Cnc { float2 startDock = harv.CenterLocation; float2 endDock = self.CenterLocation + new float2(-15,8); - var harvester = harv.traits.Get(); + var harvester = harv.Trait(); harv.QueueActivity( new Turn(112) ); harv.QueueActivity( new CallFunc( () => @@ -35,7 +35,7 @@ namespace OpenRA.Mods.Cnc if (!preventDock) { dockedHarv = harv; - self.traits.Get().PlayCustomAnim(self, "active"); + self.Trait().PlayCustomAnim(self, "active"); harv.QueueActivity( new Drag(startDock, endDock, 12) ); harv.QueueActivity( new CallFunc( () => @@ -51,16 +51,16 @@ namespace OpenRA.Mods.Cnc harv.QueueActivity( new CallFunc( () => harvester.Visible = true, false ) ); harv.QueueActivity( new Drag(endDock, startDock, 12) ); harv.QueueActivity( new CallFunc( () => dockedHarv = null, false ) ); - if (harvester.LastHarvestedCell != int2.Zero) + if (harvester.LastHarvestedCell != int2.Zero) { - harv.QueueActivity( new Move(harvester.LastHarvestedCell, 5) ); - if (harv.Owner == self.World.LocalPlayer) - self.World.AddFrameEndTask( w => - { - var line = harv.traits.GetOrDefault(); - if (line != null) - line.SetTargetSilently(harv, Target.FromCell(harvester.LastHarvestedCell), Color.Green); - }); + harv.QueueActivity( new Move(harvester.LastHarvestedCell, 5) ); + if (harv.Owner == self.World.LocalPlayer) + self.World.AddFrameEndTask( w => + { + var line = harv.TraitOrDefault(); + if (line != null) + line.SetTargetSilently(harv, Target.FromCell(harvester.LastHarvestedCell), Color.Green); + }); } } harv.QueueActivity( new Harvest() ); @@ -74,7 +74,7 @@ namespace OpenRA.Mods.Cnc return; // invisible harvester makes ceiling cat cry - harv.traits.Get().Visible = true; + harv.Trait().Visible = true; } public void Selling (Actor self) { CancelDock(self, dockedHarv); } diff --git a/OpenRA.Mods.RA/Activities/Attack.cs b/OpenRA.Mods.RA/Activities/Attack.cs index c0ca817702..638c0ca44e 100755 --- a/OpenRA.Mods.RA/Activities/Attack.cs +++ b/OpenRA.Mods.RA/Activities/Attack.cs @@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA.Activities public IActivity Tick( Actor self ) { - var facing = self.traits.Get(); + var facing = self.Trait(); if (!Target.IsValid) return NextActivity; @@ -40,7 +40,7 @@ namespace OpenRA.Mods.RA.Activities return new Move( Target, Range ) { NextActivity = this }; var desiredFacing = Util.GetFacing((targetCell - self.Location).ToFloat2(), 0); - var renderUnit = self.traits.GetOrDefault(); + var renderUnit = self.TraitOrDefault(); var numDirs = (renderUnit != null) ? renderUnit.anim.CurrentSequence.Facings : 8; @@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA.Activities return new Turn( desiredFacing ) { NextActivity = this }; } - var attack = self.traits.Get(); + var attack = self.Trait(); attack.target = Target; attack.DoAttack(self); return this; diff --git a/OpenRA.Mods.RA/Activities/CaptureBuilding.cs b/OpenRA.Mods.RA/Activities/CaptureBuilding.cs index c1e80425bb..41c81cb392 100644 --- a/OpenRA.Mods.RA/Activities/CaptureBuilding.cs +++ b/OpenRA.Mods.RA/Activities/CaptureBuilding.cs @@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA.Activities target.Owner = self.Owner; w.Add(target); - foreach (var t in target.traits.WithInterface()) + foreach (var t in target.TraitsImplementing()) t.OnCapture(target, self, oldOwner, self.Owner); w.Remove(self); diff --git a/OpenRA.Mods.RA/Activities/DeliverOre.cs b/OpenRA.Mods.RA/Activities/DeliverOre.cs index 9a3f7e4392..4c438a90e9 100755 --- a/OpenRA.Mods.RA/Activities/DeliverOre.cs +++ b/OpenRA.Mods.RA/Activities/DeliverOre.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Activities if( NextActivity != null ) return NextActivity; - var harv = self.traits.Get(); + var harv = self.Trait(); if (harv.LinkedProc == null) harv.ChooseNewProc(self, null); @@ -36,14 +36,14 @@ namespace OpenRA.Mods.RA.Activities var proc = harv.LinkedProc; - if( self.Location != proc.Location + proc.traits.Get().DeliverOffset ) + if( self.Location != proc.Location + proc.Trait().DeliverOffset ) { - return new Move(proc.Location + proc.traits.Get().DeliverOffset, 0) { NextActivity = this }; + return new Move(proc.Location + proc.Trait().DeliverOffset, 0) { NextActivity = this }; } else if (!isDocking) { isDocking = true; - proc.traits.Get().OnDock(self, this); + proc.Trait().OnDock(self, this); } return new Wait(10) { NextActivity = this }; } diff --git a/OpenRA.Mods.RA/Activities/EnterTransport.cs b/OpenRA.Mods.RA/Activities/EnterTransport.cs index a6460f53c7..eb66d1ac8b 100644 --- a/OpenRA.Mods.RA/Activities/EnterTransport.cs +++ b/OpenRA.Mods.RA/Activities/EnterTransport.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA.Activities if (isCanceled) return NextActivity; if (transport == null || !transport.IsInWorld) return NextActivity; - var cargo = transport.traits.Get(); + var cargo = transport.Trait(); if (cargo.IsFull(transport)) return NextActivity; diff --git a/OpenRA.Mods.RA/Activities/Fly.cs b/OpenRA.Mods.RA/Activities/Fly.cs index be91060222..b8ef96e660 100644 --- a/OpenRA.Mods.RA/Activities/Fly.cs +++ b/OpenRA.Mods.RA/Activities/Fly.cs @@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA.Activities if (d.LengthSquared < 50) /* close enough */ return NextActivity; - var aircraft = self.traits.Get(); + var aircraft = self.Trait(); var desiredFacing = Util.GetFacing(d, aircraft.Facing); if (aircraft.Altitude == cruiseAltitude) @@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA.Activities { public static void Fly(Actor self, int desiredAltitude ) { - var aircraft = self.traits.Get(); + var aircraft = self.Trait(); var speed = .2f * aircraft.MovementSpeedForCell(self, self.Location); var angle = aircraft.Facing / 128f * Math.PI; self.CenterLocation += speed * -float2.FromAngle((float)angle); diff --git a/OpenRA.Mods.RA/Activities/FlyAttack.cs b/OpenRA.Mods.RA/Activities/FlyAttack.cs index dd618714aa..fc64f4656e 100644 --- a/OpenRA.Mods.RA/Activities/FlyAttack.cs +++ b/OpenRA.Mods.RA/Activities/FlyAttack.cs @@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA.Activities if (!Target.IsValid) return NextActivity; - var limitedAmmo = self.traits.GetOrDefault(); + var limitedAmmo = self.TraitOrDefault(); if (limitedAmmo != null && !limitedAmmo.HasAmmo()) return NextActivity; diff --git a/OpenRA.Mods.RA/Activities/Harvest.cs b/OpenRA.Mods.RA/Activities/Harvest.cs index 6d260a166c..de9ad50459 100755 --- a/OpenRA.Mods.RA/Activities/Harvest.cs +++ b/OpenRA.Mods.RA/Activities/Harvest.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.RA.Activities if( isHarvesting ) return this; if( NextActivity != null ) return NextActivity; - var harv = self.traits.Get(); + var harv = self.Trait(); harv.LastHarvestedCell = self.Location; if( harv.IsFull ) @@ -42,10 +42,10 @@ namespace OpenRA.Mods.RA.Activities bool HarvestThisTile(Actor self) { - var harv = self.traits.Get(); - var renderUnit = self.traits.Get(); /* better have one of these! */ + var harv = self.Trait(); + var renderUnit = self.Trait(); /* better have one of these! */ - var resource = self.World.WorldActor.traits.Get().Harvest(self.Location); + var resource = self.World.WorldActor.Trait().Harvest(self.Location); if (resource == null) return false; @@ -60,7 +60,7 @@ namespace OpenRA.Mods.RA.Activities void FindMoreResource(Actor self) { - var res = self.World.WorldActor.traits.Get(); + var res = self.World.WorldActor.Trait(); var harv = self.Info.Traits.Get(); self.QueueActivity(new Move( diff --git a/OpenRA.Mods.RA/Activities/HeliAttack.cs b/OpenRA.Mods.RA/Activities/HeliAttack.cs index a7c4948b47..f2c0216fb5 100644 --- a/OpenRA.Mods.RA/Activities/HeliAttack.cs +++ b/OpenRA.Mods.RA/Activities/HeliAttack.cs @@ -26,14 +26,14 @@ namespace OpenRA.Mods.RA.Activities if (!target.IsValid) return NextActivity; - var limitedAmmo = self.traits.GetOrDefault(); + var limitedAmmo = self.TraitOrDefault(); if (limitedAmmo != null && !limitedAmmo.HasAmmo()) { self.QueueActivity(new HeliReturn()); return NextActivity; } - var aircraft = self.traits.Get(); + var aircraft = self.Trait(); var info = self.Info.Traits.Get(); if (aircraft.Altitude != info.CruiseAltitude) { @@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA.Activities return this; } - var range = self.traits.Get().GetMaximumRange() - 1; + var range = self.Trait().GetMaximumRange() - 1; var dist = target.CenterLocation - self.CenterLocation; var desiredFacing = Util.GetFacing(dist, aircraft.Facing); @@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA.Activities if (!float2.WithinEpsilon(float2.Zero, dist, range * Game.CellSize)) self.CenterLocation += (rawSpeed / dist.Length) * dist; - + return this; } diff --git a/OpenRA.Mods.RA/Activities/HeliFly.cs b/OpenRA.Mods.RA/Activities/HeliFly.cs index c906d79a56..37c532c160 100644 --- a/OpenRA.Mods.RA/Activities/HeliFly.cs +++ b/OpenRA.Mods.RA/Activities/HeliFly.cs @@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA.Activities return NextActivity; var info = self.Info.Traits.Get(); - var aircraft = self.traits.Get(); + var aircraft = self.Trait(); if (aircraft.Altitude != info.CruiseAltitude) { diff --git a/OpenRA.Mods.RA/Activities/HeliLand.cs b/OpenRA.Mods.RA/Activities/HeliLand.cs index eb214c8ceb..b0d7ecf2c8 100644 --- a/OpenRA.Mods.RA/Activities/HeliLand.cs +++ b/OpenRA.Mods.RA/Activities/HeliLand.cs @@ -23,7 +23,7 @@ namespace OpenRA.Mods.RA.Activities public IActivity Tick(Actor self) { if (isCanceled) return NextActivity; - var aircraft = self.traits.Get(); + var aircraft = self.Trait(); if (aircraft.Altitude == 0) return NextActivity; diff --git a/OpenRA.Mods.RA/Activities/HeliReturn.cs b/OpenRA.Mods.RA/Activities/HeliReturn.cs index ea283eb8a9..2362a1a111 100644 --- a/OpenRA.Mods.RA/Activities/HeliReturn.cs +++ b/OpenRA.Mods.RA/Activities/HeliReturn.cs @@ -40,11 +40,11 @@ namespace OpenRA.Mods.RA.Activities new HeliLand(true), NextActivity); - var res = dest.traits.GetOrDefault(); + var res = dest.TraitOrDefault(); if (res != null) - self.traits.Get().reservation = res.Reserve(self); + self.Trait().reservation = res.Reserve(self); - var pi = dest.traits.Get(); + var pi = dest.Trait(); var offset = pi != null ? pi.Spawns.First().First : float2.Zero; return Util.SequenceActivities( diff --git a/OpenRA.Mods.RA/Activities/Infiltrate.cs b/OpenRA.Mods.RA/Activities/Infiltrate.cs index 18d5c83fc7..df1551054a 100644 --- a/OpenRA.Mods.RA/Activities/Infiltrate.cs +++ b/OpenRA.Mods.RA/Activities/Infiltrate.cs @@ -23,7 +23,7 @@ namespace OpenRA.Mods.RA.Activities if (target == null || target.IsDead()) return NextActivity; if (target.Owner == self.Owner) return NextActivity; - foreach (var t in target.traits.WithInterface()) + foreach (var t in target.TraitsImplementing()) t.OnInfiltrate(target, self); self.World.AddFrameEndTask(w => w.Remove(self)); diff --git a/OpenRA.Mods.RA/Activities/Land.cs b/OpenRA.Mods.RA/Activities/Land.cs index 406882be72..757cef3c2f 100644 --- a/OpenRA.Mods.RA/Activities/Land.cs +++ b/OpenRA.Mods.RA/Activities/Land.cs @@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA.Activities if (d.LengthSquared < 50) /* close enough */ return NextActivity; - var aircraft = self.traits.Get(); + var aircraft = self.Trait(); if (aircraft.Altitude > 0) --aircraft.Altitude; diff --git a/OpenRA.Mods.RA/Activities/LayMines.cs b/OpenRA.Mods.RA/Activities/LayMines.cs index 15489aa91d..20f5f7e0b8 100644 --- a/OpenRA.Mods.RA/Activities/LayMines.cs +++ b/OpenRA.Mods.RA/Activities/LayMines.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Activities { if (canceled) return NextActivity; - var limitedAmmo = self.traits.GetOrDefault(); + var limitedAmmo = self.TraitOrDefault(); if (!limitedAmmo.HasAmmo()) { // rearm & repair at fix, then back out here to refill the minefield some more @@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA.Activities { NextActivity = new Rearm() { NextActivity = new Repair(rearmTarget) { NextActivity = this } } }; } - var ml = self.traits.Get(); + var ml = self.Trait(); if (ml.minefield.Contains(self.Location) && ShouldLayMine(self, self.Location)) { @@ -64,13 +64,13 @@ namespace OpenRA.Mods.RA.Activities bool ShouldLayMine(Actor self, int2 p) { // if there is no unit (other than me) here, we want to place a mine here - return !self.World.WorldActor.traits.Get() + return !self.World.WorldActor.Trait() .GetUnitsAt(p).Any(a => a != self); } void LayMine(Actor self) { - var limitedAmmo = self.traits.GetOrDefault(); + var limitedAmmo = self.TraitOrDefault(); if (limitedAmmo != null) limitedAmmo.Attacking(self); self.World.AddFrameEndTask( diff --git a/OpenRA.Mods.RA/Activities/Leap.cs b/OpenRA.Mods.RA/Activities/Leap.cs index c73929b7f0..1d51627377 100644 --- a/OpenRA.Mods.RA/Activities/Leap.cs +++ b/OpenRA.Mods.RA/Activities/Leap.cs @@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA.Activities this.target = target; initialLocation = self.CenterLocation; - self.traits.Get().Attacking(self); + self.Trait().Attacking(self); Sound.Play("dogg5p.aud", self.CenterLocation); } @@ -44,7 +44,7 @@ namespace OpenRA.Mods.RA.Activities if (t >= 1f) { - self.traits.WithInterface().FirstOrDefault() + self.TraitsImplementing().FirstOrDefault() .SetPosition(self, Util.CellContaining(target.CenterLocation)); if (target.IsActor) diff --git a/OpenRA.Mods.RA/Activities/Rearm.cs b/OpenRA.Mods.RA/Activities/Rearm.cs index 18088f8f82..b78821f858 100644 --- a/OpenRA.Mods.RA/Activities/Rearm.cs +++ b/OpenRA.Mods.RA/Activities/Rearm.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.RA.Activities public IActivity Tick(Actor self) { if (isCanceled) return NextActivity; - var limitedAmmo = self.traits.GetOrDefault(); + var limitedAmmo = self.TraitOrDefault(); if (limitedAmmo == null) return NextActivity; if (--remainingTicks == 0) @@ -33,10 +33,10 @@ namespace OpenRA.Mods.RA.Activities if (!limitedAmmo.GiveAmmo()) return NextActivity; var hostBuilding = self.World.FindUnits(self.CenterLocation, self.CenterLocation) - .FirstOrDefault(a => a.traits.Contains()); + .FirstOrDefault(a => a.HasTrait()); if (hostBuilding != null) - hostBuilding.traits.Get().PlayCustomAnim(hostBuilding, "active"); + hostBuilding.Trait().PlayCustomAnim(hostBuilding, "active"); remainingTicks = ticksPerPip; } diff --git a/OpenRA.Mods.RA/Activities/Repair.cs b/OpenRA.Mods.RA/Activities/Repair.cs index f7f8b604d5..bedd94dbba 100644 --- a/OpenRA.Mods.RA/Activities/Repair.cs +++ b/OpenRA.Mods.RA/Activities/Repair.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA.Activities if (isCanceled) return NextActivity; if (remainingTicks == 0) { - var health = self.traits.GetOrDefault(); + var health = self.TraitOrDefault(); if (health == null) return NextActivity; var unitCost = self.Info.Traits.Get().Cost; @@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA.Activities var costPerHp = (repairsUnits.URepairPercent * unitCost) / health.MaxHP; var hpToRepair = Math.Min(host.Info.Traits.Get().URepairStep, health.MaxHP - health.HP); var cost = (int)Math.Ceiling(costPerHp * hpToRepair); - if (!self.Owner.PlayerActor.traits.Get().TakeCash(cost)) + if (!self.Owner.PlayerActor.Trait().TakeCash(cost)) { remainingTicks = 1; return this; @@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA.Activities return NextActivity; if (host != null) - host.traits.Get() + host.Trait() .PlayCustomAnim(host, "active"); remainingTicks = (int)(repairsUnits.RepairRate * 60 * 25); diff --git a/OpenRA.Mods.RA/Activities/RepairBuilding.cs b/OpenRA.Mods.RA/Activities/RepairBuilding.cs index a9afb462f7..2aeed5d556 100644 --- a/OpenRA.Mods.RA/Activities/RepairBuilding.cs +++ b/OpenRA.Mods.RA/Activities/RepairBuilding.cs @@ -23,7 +23,7 @@ namespace OpenRA.Mods.RA.Activities public IActivity Tick(Actor self) { if (target == null || target.IsDead()) return NextActivity; - var health = target.traits.Get(); + var health = target.Trait(); if (health.DamageState == DamageState.Undamaged) return NextActivity; diff --git a/OpenRA.Mods.RA/Activities/ReturnToBase.cs b/OpenRA.Mods.RA/Activities/ReturnToBase.cs index 23aaf81990..1526616410 100644 --- a/OpenRA.Mods.RA/Activities/ReturnToBase.cs +++ b/OpenRA.Mods.RA/Activities/ReturnToBase.cs @@ -40,16 +40,16 @@ namespace OpenRA.Mods.RA.Activities dest = ChooseAirfield(self); } - var res = dest.traits.GetOrDefault(); + var res = dest.TraitOrDefault(); if (res != null) { - var plane = self.traits.Get(); + var plane = self.Trait(); plane.UnReserve(); plane.reservation = res.Reserve(self); } var landPos = dest.CenterLocation; - var aircraft = self.traits.Get(); + var aircraft = self.Trait(); var speed = .2f * aircraft.MovementSpeedForCell(self, self.Location); diff --git a/OpenRA.Mods.RA/Activities/Teleport.cs b/OpenRA.Mods.RA/Activities/Teleport.cs index cb834a0cac..1f57788ffa 100755 --- a/OpenRA.Mods.RA/Activities/Teleport.cs +++ b/OpenRA.Mods.RA/Activities/Teleport.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Activities public IActivity Tick(Actor self) { - self.traits.WithInterface().FirstOrDefault().SetPosition(self, destination); + self.TraitsImplementing().FirstOrDefault().SetPosition(self, destination); return NextActivity; } diff --git a/OpenRA.Mods.RA/Activities/Transform.cs b/OpenRA.Mods.RA/Activities/Transform.cs index 1c49508675..5cffb5a020 100644 --- a/OpenRA.Mods.RA/Activities/Transform.cs +++ b/OpenRA.Mods.RA/Activities/Transform.cs @@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA.Activities this.offset = offset; this.sounds = sounds; this.facing = facing; - rb = self.traits.GetOrDefault(); + rb = self.TraitOrDefault(); } public IActivity NextActivity { get; set; } @@ -59,8 +59,8 @@ namespace OpenRA.Mods.RA.Activities new OwnerInit( self.Owner ), new FacingInit( facing ), }; - if (self.traits.Contains()) - init.Add( new HealthInit( self.traits.Get().HPFraction )); + if (self.HasTrait()) + init.Add( new HealthInit( self.Trait().HPFraction )); var a = w.CreateActor( actor, init ); diff --git a/OpenRA.Mods.RA/Activities/UnloadCargo.cs b/OpenRA.Mods.RA/Activities/UnloadCargo.cs index 616822ebb9..b089d6f3c7 100644 --- a/OpenRA.Mods.RA/Activities/UnloadCargo.cs +++ b/OpenRA.Mods.RA/Activities/UnloadCargo.cs @@ -24,10 +24,10 @@ namespace OpenRA.Mods.RA.Activities int2? ChooseExitTile(Actor self, Actor cargo) { // is anyone still hogging this tile? - if (self.World.WorldActor.traits.Get().GetUnitsAt(self.Location).Count() > 1) + if (self.World.WorldActor.Trait().GetUnitsAt(self.Location).Count() > 1) return null; - var mobile = cargo.traits.Get(); + var mobile = cargo.Trait(); for (var i = -1; i < 2; i++) for (var j = -1; j < 2; j++) @@ -44,7 +44,7 @@ namespace OpenRA.Mods.RA.Activities // if we're a thing that can turn, turn to the // right facing for the unload animation - var facing = self.traits.GetOrDefault(); + var facing = self.TraitOrDefault(); var unloadFacing = self.Info.Traits.Get().UnloadFacing; if (facing != null && facing.Facing != unloadFacing) return new Turn(unloadFacing) { NextActivity = this }; @@ -52,11 +52,11 @@ namespace OpenRA.Mods.RA.Activities // todo: handle the BS of open/close sequences, which are inconsistent, // for reasons that probably make good sense to the westwood guys. - var cargo = self.traits.Get(); + var cargo = self.Trait(); if (cargo.IsEmpty(self)) return NextActivity; - var ru = self.traits.GetOrDefault(); + var ru = self.TraitOrDefault(); if (ru != null) ru.PlayCustomAnimation(self, "unload", null); @@ -69,12 +69,12 @@ namespace OpenRA.Mods.RA.Activities self.World.AddFrameEndTask(w => { w.Add(actor); - actor.traits.WithInterface().FirstOrDefault().SetPosition(actor, self.Location); + actor.TraitsImplementing().FirstOrDefault().SetPosition(actor, self.Location); actor.CancelActivity(); actor.QueueActivity(new Move(exitTile.Value, 0)); if (actor.Owner == self.World.LocalPlayer) { - var line = actor.traits.GetOrDefault(); + var line = actor.TraitOrDefault(); if (line != null) line.SetTargetSilently(self, Target.FromCell(exitTile.Value), Color.Green); } diff --git a/OpenRA.Mods.RA/Aircraft.cs b/OpenRA.Mods.RA/Aircraft.cs index 8b977031d5..12fd648570 100755 --- a/OpenRA.Mods.RA/Aircraft.cs +++ b/OpenRA.Mods.RA/Aircraft.cs @@ -84,8 +84,8 @@ namespace OpenRA.Mods.RA public float MovementSpeedForCell(Actor self, int2 cell) { - var modifier = self.traits - .WithInterface() + var modifier = self + .TraitsImplementing() .Select(t => t.GetSpeedModifier()) .Product(); return Info.Speed * modifier; diff --git a/OpenRA.Mods.RA/AppearsOnRadar.cs b/OpenRA.Mods.RA/AppearsOnRadar.cs index 2feeb38a9a..45492063b5 100755 --- a/OpenRA.Mods.RA/AppearsOnRadar.cs +++ b/OpenRA.Mods.RA/AppearsOnRadar.cs @@ -23,13 +23,13 @@ namespace OpenRA.Mods.RA public IEnumerable RadarSignatureCells(Actor self) { if (Space == null) - Space = self.traits.Get(); + Space = self.Trait(); return Space.OccupiedCells(); } public Color RadarSignatureColor(Actor self) { - var mod = self.traits.WithInterface().FirstOrDefault(); + var mod = self.TraitsImplementing().FirstOrDefault(); if (mod != null) return mod.RadarColorOverride(self); diff --git a/OpenRA.Mods.RA/AttackBase.cs b/OpenRA.Mods.RA/AttackBase.cs index 1e29706024..09ca6e1a78 100644 --- a/OpenRA.Mods.RA/AttackBase.cs +++ b/OpenRA.Mods.RA/AttackBase.cs @@ -64,7 +64,7 @@ namespace OpenRA.Mods.RA { if (!target.IsValid) return false; if (Weapons.All(w => w.IsReloading)) return false; - if (self.traits.WithInterface().Any(d => d.Disabled)) return false; + if (self.TraitsImplementing().Any(d => d.Disabled)) return false; return true; } @@ -102,8 +102,8 @@ namespace OpenRA.Mods.RA { if( !CanAttack( self ) ) return; - var move = self.traits.GetOrDefault(); - var facing = self.traits.GetOrDefault(); + var move = self.TraitOrDefault(); + var facing = self.TraitOrDefault(); foreach (var w in Weapons) if (CheckFire(self, move, facing, w)) w.FiredShot(); @@ -113,7 +113,7 @@ namespace OpenRA.Mods.RA { if (w.FireDelay > 0) return false; - var limitedAmmo = self.traits.GetOrDefault(); + var limitedAmmo = self.TraitOrDefault(); if (limitedAmmo != null && !limitedAmmo.HasAmmo()) return false; @@ -123,7 +123,7 @@ namespace OpenRA.Mods.RA if (!w.IsValidAgainst(target)) return false; var barrel = w.Barrels[w.Burst % w.Barrels.Length]; - var destMove = target.IsActor ? target.Actor.traits.GetOrDefault() : null; + var destMove = target.IsActor ? target.Actor.TraitOrDefault() : null; var args = new ProjectileArgs { @@ -140,7 +140,7 @@ namespace OpenRA.Mods.RA destAltitude = destMove != null ? destMove.Altitude : 0, facing = barrel.Facing + - (self.traits.Contains() ? self.traits.Get().turretFacing : + (self.HasTrait() ? self.Trait().turretFacing : facing != null ? facing.Facing : Util.GetFacing(target.CenterLocation - self.CenterLocation, 0)), }; @@ -157,7 +157,7 @@ namespace OpenRA.Mods.RA } }); - foreach (var na in self.traits.WithInterface()) + foreach (var na in self.TraitsImplementing()) na.Attacking(self); return true; @@ -219,7 +219,7 @@ namespace OpenRA.Mods.RA if (order.TargetActor != null) w.Add(new FlashTarget(order.TargetActor)); - var line = self.traits.GetOrDefault(); + var line = self.TraitOrDefault(); if (line != null) if (order.TargetActor != null) line.SetTarget(self, Target.FromOrder(order), Color.Red); else line.SetTarget(self, Target.FromOrder(order), Color.Red); diff --git a/OpenRA.Mods.RA/AttackFrontal.cs b/OpenRA.Mods.RA/AttackFrontal.cs index fe67c54bb9..997cc3b2d2 100644 --- a/OpenRA.Mods.RA/AttackFrontal.cs +++ b/OpenRA.Mods.RA/AttackFrontal.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA if (!target.IsValid) return; - var facing = self.traits.Get().Facing; + var facing = self.Trait().Facing; var facingToTarget = Util.GetFacing(target.CenterLocation - self.CenterLocation, facing); if (Math.Abs(facingToTarget - facing) % 256 < FacingTolerance) diff --git a/OpenRA.Mods.RA/AttackLeap.cs b/OpenRA.Mods.RA/AttackLeap.cs index fda15067a5..9639b68135 100644 --- a/OpenRA.Mods.RA/AttackLeap.cs +++ b/OpenRA.Mods.RA/AttackLeap.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA if (!target.IsValid) return; if (self.GetCurrentActivity() is Leap) return; - var weapon = self.traits.Get().Weapons[0].Info; + var weapon = self.Trait().Weapons[0].Info; if (weapon.Range * Game.CellSize * weapon.Range * Game.CellSize < (target.CenterLocation - self.CenterLocation).LengthSquared) return; diff --git a/OpenRA.Mods.RA/AttackOmni.cs b/OpenRA.Mods.RA/AttackOmni.cs index bf6fffa11c..c98a3e29c0 100644 --- a/OpenRA.Mods.RA/AttackOmni.cs +++ b/OpenRA.Mods.RA/AttackOmni.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA protected override bool CanAttack( Actor self ) { - var isBuilding = ( self.traits.Contains() && !buildComplete ); + var isBuilding = ( self.HasTrait() && !buildComplete ); return base.CanAttack( self ) && !isBuilding; } diff --git a/OpenRA.Mods.RA/AttackTesla.cs b/OpenRA.Mods.RA/AttackTesla.cs index 76715843ba..96c4ca40a2 100644 --- a/OpenRA.Mods.RA/AttackTesla.cs +++ b/OpenRA.Mods.RA/AttackTesla.cs @@ -68,7 +68,7 @@ namespace OpenRA.Mods.RA if (target.Actor != previousTarget) { previousTarget = target.Actor; - self.traits.Get().PlayCharge(self); + self.Trait().PlayCharge(self); } } } diff --git a/OpenRA.Mods.RA/AttackTurreted.cs b/OpenRA.Mods.RA/AttackTurreted.cs index 336f3fbe46..a0f3d1200c 100644 --- a/OpenRA.Mods.RA/AttackTurreted.cs +++ b/OpenRA.Mods.RA/AttackTurreted.cs @@ -25,11 +25,11 @@ namespace OpenRA.Mods.RA protected override bool CanAttack( Actor self ) { - if( self.traits.Contains() && !buildComplete ) + if( self.HasTrait() && !buildComplete ) return false; if (!target.IsValid) return false; - var turreted = self.traits.Get(); + var turreted = self.Trait(); turreted.desiredFacing = Util.GetFacing( target.CenterLocation - self.CenterLocation, turreted.turretFacing ); if( turreted.desiredFacing != turreted.turretFacing ) return false; @@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA protected override void QueueAttack( Actor self, Order order ) { - if (self.traits.Contains() && self.traits.Get().Disabled) + if (self.HasTrait() && self.Trait().Disabled) return; const int RangeTolerance = 1; /* how far inside our maximum range we should try to sit */ @@ -56,7 +56,7 @@ namespace OpenRA.Mods.RA target = Target.FromOrder(order); - if (self.traits.Contains()) + if (self.HasTrait()) self.QueueActivity( new Follow( target, Math.Max( 0, (int)weapon.Info.Range - RangeTolerance ) ) ); } diff --git a/OpenRA.Mods.RA/AutoHeal.cs b/OpenRA.Mods.RA/AutoHeal.cs index 184a580a55..e3a5cf5686 100644 --- a/OpenRA.Mods.RA/AutoHeal.cs +++ b/OpenRA.Mods.RA/AutoHeal.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.RA { void AttackTarget(Actor self, Actor target) { - var attack = self.traits.Get(); + var attack = self.Trait(); if (target != null) attack.ResolveOrder(self, new Order("Attack", self, target)); else @@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA bool NeedsNewTarget(Actor self) { - var attack = self.traits.Get(); + var attack = self.Trait(); var range = attack.GetMaximumRange(); if (!attack.target.IsValid) @@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA public void Tick(Actor self) { - var attack = self.traits.Get(); + var attack = self.Trait(); var range = attack.GetMaximumRange(); if (NeedsNewTarget(self)) @@ -57,12 +57,12 @@ namespace OpenRA.Mods.RA Actor ChooseTarget(Actor self, float range) { var inRange = self.World.FindUnitsInCircle(self.CenterLocation, Game.CellSize * range); - var attack = self.traits.Get(); + var attack = self.Trait(); return inRange .Where(a => a != self && self.Owner.Stances[a.Owner] == Stance.Ally) .Where(a => !a.IsDead()) - .Where(a => a.traits.Contains() && a.GetDamageState() > DamageState.Undamaged) + .Where(a => a.HasTrait() && a.GetDamageState() > DamageState.Undamaged) .Where(a => attack.HasAnyValidWeapons(Target.FromActor(a))) .OrderBy(a => (a.Location - self.Location).LengthSquared) .FirstOrDefault(); diff --git a/OpenRA.Mods.RA/AutoTarget.cs b/OpenRA.Mods.RA/AutoTarget.cs index 0039aea067..a2011449aa 100644 --- a/OpenRA.Mods.RA/AutoTarget.cs +++ b/OpenRA.Mods.RA/AutoTarget.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA void AttackTarget(Actor self, Actor target) { - var attack = self.traits.Get(); + var attack = self.Trait(); if (target != null) attack.ResolveOrder(self, new Order("Attack", self, target)); } @@ -37,7 +37,7 @@ namespace OpenRA.Mods.RA if (--nextScanTime <= 0) { - var attack = self.traits.Get(); + var attack = self.Trait(); var range = attack.GetMaximumRange(); if (!attack.target.IsValid || @@ -53,12 +53,12 @@ namespace OpenRA.Mods.RA Actor ChooseTarget(Actor self, float range) { var inRange = self.World.FindUnitsInCircle(self.CenterLocation, Game.CellSize * range); - var attack = self.traits.Get(); + var attack = self.Trait(); return inRange .Where(a => a.Owner != null && self.Owner.Stances[ a.Owner ] == Stance.Enemy) .Where(a => attack.HasAnyValidWeapons(Target.FromActor(a))) - .Where(a => !a.traits.Contains() || !a.traits.Get().Cloaked) + .Where(a => !a.HasTrait() || !a.Trait().Cloaked) .OrderBy(a => (a.Location - self.Location).LengthSquared) .FirstOrDefault(); } @@ -68,7 +68,7 @@ namespace OpenRA.Mods.RA if (!self.IsIdle) return; // not a lot we can do about things we can't hurt... although maybe we should automatically run away? - var attack = self.traits.Get(); + var attack = self.Trait(); if (!attack.HasAnyValidWeapons(Target.FromActor(e.Attacker))) return; // don't retaliate against own units force-firing on us. it's usually not what the player wanted. diff --git a/OpenRA.Mods.RA/Bridge.cs b/OpenRA.Mods.RA/Bridge.cs index f62ac7fe7a..c548555cd9 100644 --- a/OpenRA.Mods.RA/Bridge.cs +++ b/OpenRA.Mods.RA/Bridge.cs @@ -80,7 +80,7 @@ namespace OpenRA.Mods.RA public Bridge(Actor self, BridgeInfo info) { this.self = self; - Health = self.traits.Get(); + Health = self.Trait(); Health.RemoveOnDeath = false; this.Info = info; this.Type = self.Info.Name; @@ -144,11 +144,11 @@ namespace OpenRA.Mods.RA void KillUnitsOnBridge() { - var uim = self.World.WorldActor.traits.Get(); + var uim = self.World.WorldActor.Trait(); foreach (var c in TileSprites[currentTemplate].Keys) foreach (var a in uim.GetUnitsAt(c)) - if (a.traits.Contains() && !a.traits.Get().CanEnterCell(c)) + if (a.HasTrait() && !a.Trait().CanEnterCell(c)) a.Kill(self); } diff --git a/OpenRA.Mods.RA/BridgeLayer.cs b/OpenRA.Mods.RA/BridgeLayer.cs index 5c1334a4f4..79322dcc99 100644 --- a/OpenRA.Mods.RA/BridgeLayer.cs +++ b/OpenRA.Mods.RA/BridgeLayer.cs @@ -61,7 +61,7 @@ namespace OpenRA.Mods.RA ConvertBridgeToActor(w, i, j); // Link adjacent (long)-bridges so that artwork is updated correctly - foreach (var b in w.Actors.SelectMany(a => a.traits.WithInterface())) + foreach (var b in w.Actors.SelectMany(a => a.TraitsImplementing())) b.LinkNeighbouringBridges(w,this); } @@ -86,7 +86,7 @@ namespace OpenRA.Mods.RA new LocationInit( new int2(ni, nj) ), new OwnerInit( w.WorldActor.Owner ), new HealthInit( BridgeTypes[tile].Second ), - }).traits.Get(); + }).Trait(); Dictionary subTiles = new Dictionary(); diff --git a/OpenRA.Mods.RA/Burns.cs b/OpenRA.Mods.RA/Burns.cs index 6f40fc58db..fd8bb12987 100644 --- a/OpenRA.Mods.RA/Burns.cs +++ b/OpenRA.Mods.RA/Burns.cs @@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA var anim = new Animation("fire", () => 0); anim.PlayRepeating(self.Info.Traits.Get().Anim); - self.traits.Get().anims.Add("fire", + self.Trait().anims.Add("fire", new RenderSimple.AnimationWithOffset(anim, () => new float2(0, -3), null)); } diff --git a/OpenRA.Mods.RA/C4Demolition.cs b/OpenRA.Mods.RA/C4Demolition.cs index c0909c67c0..2f20246588 100644 --- a/OpenRA.Mods.RA/C4Demolition.cs +++ b/OpenRA.Mods.RA/C4Demolition.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA if (mi.Button != MouseButton.Right) return null; if (underCursor == null) return null; if (underCursor.Owner == self.Owner && !mi.Modifiers.HasModifier(Modifiers.Ctrl)) return null; - if (!underCursor.traits.Contains()) return null; + if (!underCursor.HasTrait()) return null; return new Order("C4", self, underCursor); } @@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA self.World.AddFrameEndTask(w => { w.Add(new FlashTarget(order.TargetActor)); - var line = self.traits.GetOrDefault(); + var line = self.TraitOrDefault(); if (line != null) line.SetTarget(self, Target.FromOrder(order), Color.Red); }); diff --git a/OpenRA.Mods.RA/Cargo.cs b/OpenRA.Mods.RA/Cargo.cs index 22cd55eb82..752f6fe5e6 100644 --- a/OpenRA.Mods.RA/Cargo.cs +++ b/OpenRA.Mods.RA/Cargo.cs @@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA return false; // Cannot unload mid-air - var move = self.traits.GetOrDefault(); + var move = self.TraitOrDefault(); if (move != null && move.Altitude > 0) return false; @@ -106,7 +106,7 @@ namespace OpenRA.Mods.RA static PipType GetPipForPassenger(Actor a) { - return a.traits.Get().ColorOfCargoPip( a ); + return a.Trait().ColorOfCargoPip( a ); } public void Load(Actor self, Actor a) diff --git a/OpenRA.Mods.RA/CarpetBomb.cs b/OpenRA.Mods.RA/CarpetBomb.cs index 7fe1ada802..10469a2aad 100644 --- a/OpenRA.Mods.RA/CarpetBomb.cs +++ b/OpenRA.Mods.RA/CarpetBomb.cs @@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA if ((self.Location - Target).LengthSquared > info.Range * info.Range) return; - var limitedAmmo = self.traits.GetOrDefault(); + var limitedAmmo = self.TraitOrDefault(); if (limitedAmmo != null && !limitedAmmo.HasAmmo()) return; @@ -45,11 +45,11 @@ namespace OpenRA.Mods.RA var args = new ProjectileArgs { - srcAltitude = self.traits.Get().Altitude, + srcAltitude = self.Trait().Altitude, destAltitude = 0, src = self.CenterLocation.ToInt2(), dest = self.CenterLocation.ToInt2(), - facing = self.traits.Get().Facing, + facing = self.Trait().Facing, firedBy = self, weapon = weapon }; diff --git a/OpenRA.Mods.RA/ChronoshiftDeploy.cs b/OpenRA.Mods.RA/ChronoshiftDeploy.cs index c95d8f7041..9db2c130bb 100644 --- a/OpenRA.Mods.RA/ChronoshiftDeploy.cs +++ b/OpenRA.Mods.RA/ChronoshiftDeploy.cs @@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA return; } - var movement = self.traits.GetOrDefault(); + var movement = self.TraitOrDefault(); if (order.OrderString == "ChronoshiftSelf" && movement.CanEnterCell(order.TargetLocation)) { if (self.Owner == self.World.LocalPlayer) diff --git a/OpenRA.Mods.RA/Chronoshiftable.cs b/OpenRA.Mods.RA/Chronoshiftable.cs index 0d7ce17c0a..046f0bb3fa 100755 --- a/OpenRA.Mods.RA/Chronoshiftable.cs +++ b/OpenRA.Mods.RA/Chronoshiftable.cs @@ -47,9 +47,9 @@ namespace OpenRA.Mods.RA chronoshiftReturnTicks = duration; // Kill cargo - if (killCargo && self.traits.Contains()) + if (killCargo && self.HasTrait()) { - var cargo = self.traits.Get(); + var cargo = self.Trait(); while (!cargo.IsEmpty(self)) { chronosphere.Owner.Kills++; diff --git a/OpenRA.Mods.RA/Combat.cs b/OpenRA.Mods.RA/Combat.cs index a919d2237f..a816cf1c24 100755 --- a/OpenRA.Mods.RA/Combat.cs +++ b/OpenRA.Mods.RA/Combat.cs @@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA if (warhead.SmudgeType != null) { - var smudgeLayer = world.WorldActor.traits.WithInterface() + var smudgeLayer = world.WorldActor.TraitsImplementing() .FirstOrDefault(x => x.Info.Type == warhead.SmudgeType); if (smudgeLayer == null) throw new NotImplementedException("Unknown smudge type `{0}`".F(warhead.SmudgeType)); @@ -68,10 +68,10 @@ namespace OpenRA.Mods.RA } if (warhead.Ore) - world.WorldActor.traits.Get().Destroy(targetTile); + world.WorldActor.Trait().Destroy(targetTile); - var firepowerModifier = args.firedBy.traits - .WithInterface() + var firepowerModifier = args.firedBy + .TraitsImplementing() .Select(a => a.GetFirepowerModifier()) .Product(); @@ -184,10 +184,10 @@ namespace OpenRA.Mods.RA var abInfo = self.Info.Traits.GetOrDefault(); if (abInfo == null || abInfo.Recoil == 0) return float2.Zero; - var rut = self.traits.GetOrDefault(); + var rut = self.TraitOrDefault(); if (rut == null) return float2.Zero; - var facing = self.traits.Get().turretFacing; + var facing = self.Trait().turretFacing; var localRecoil = new float2(0, recoil * abInfo.Recoil); // vector in turret-space. return Util.RotateVectorByFacing(localRecoil, facing, .7f); @@ -196,7 +196,7 @@ namespace OpenRA.Mods.RA { if(facing == null) return turret.ScreenSpacePosition; /* things that don't have a rotating base don't need the turrets repositioned */ - var ru = self.traits.GetOrDefault(); + var ru = self.TraitOrDefault(); var numDirs = (ru != null) ? ru.anim.CurrentSequence.Facings : 8; var bodyFacing = facing.Facing; var quantizedFacing = Util.QuantizeFacing(bodyFacing, numDirs) * (256 / numDirs); @@ -209,7 +209,7 @@ namespace OpenRA.Mods.RA // gets the screen-space position of a barrel. public static float2 GetBarrelPosition(Actor self, IFacing facing, Turret turret, Barrel barrel) { - var turreted = self.traits.GetOrDefault(); + var turreted = self.TraitOrDefault(); if (turreted == null && facing == null) return float2.Zero; diff --git a/OpenRA.Mods.RA/Crate.cs b/OpenRA.Mods.RA/Crate.cs index 6fb2a660ef..cbad36c3bd 100644 --- a/OpenRA.Mods.RA/Crate.cs +++ b/OpenRA.Mods.RA/Crate.cs @@ -54,12 +54,12 @@ namespace OpenRA.Mods.RA this.Info = info; - self.World.WorldActor.traits.Get().Add(self, this); + self.World.WorldActor.Trait().Add(self, this); } public void OnCrush(Actor crusher) { - var shares = self.traits.WithInterface().Select( + var shares = self.TraitsImplementing().Select( a => Pair.New(a, a.GetSelectionShares(crusher))); var totalShares = shares.Sum(a => a.Second); var n = self.World.SharedRandom.Next(totalShares); @@ -94,7 +94,7 @@ namespace OpenRA.Mods.RA public void SetPosition(Actor self, int2 cell) { - var uim = self.World.WorldActor.traits.Get(); + var uim = self.World.WorldActor.Trait(); uim.Remove(self, this); @@ -102,8 +102,8 @@ namespace OpenRA.Mods.RA self.CenterLocation = Util.CenterOfCell(cell); var seq = self.World.GetTerrainInfo(cell).IsWater ? "water" : "idle"; - if (seq != self.traits.Get().anim.CurrentSequence.Name) - self.traits.Get().anim.PlayRepeating(seq); + if (seq != self.Trait().anim.CurrentSequence.Name) + self.Trait().anim.PlayRepeating(seq); uim.Add(self, this); } diff --git a/OpenRA.Mods.RA/CrateDrop.cs b/OpenRA.Mods.RA/CrateDrop.cs index f85ff5cd54..190fd98daa 100644 --- a/OpenRA.Mods.RA/CrateDrop.cs +++ b/OpenRA.Mods.RA/CrateDrop.cs @@ -63,8 +63,8 @@ namespace OpenRA.Mods.RA if (!(inWater ? info.ValidWater : info.ValidGround).Contains(terrainType)) continue; // Don't drop on any actors - if (self.World.WorldActor.traits.Get().GetBuildingAt(p) != null) continue; - if (self.World.WorldActor.traits.Get().GetUnitsAt(p).Any()) continue; + if (self.World.WorldActor.Trait().GetBuildingAt(p) != null) continue; + if (self.World.WorldActor.Trait().GetUnitsAt(p).Any()) continue; self.World.AddFrameEndTask(w => { @@ -81,8 +81,8 @@ namespace OpenRA.Mods.RA }); plane.CancelActivity(); plane.QueueActivity(new FlyCircle(p)); - plane.traits.Get().SetLZ(p, null); - plane.traits.Get().Load(plane, crate); + plane.Trait().SetLZ(p, null); + plane.Trait().Load(plane, crate); }); return; } diff --git a/OpenRA.Mods.RA/CrateSpawner.cs b/OpenRA.Mods.RA/CrateSpawner.cs index ec312a78e2..0da56602b8 100644 --- a/OpenRA.Mods.RA/CrateSpawner.cs +++ b/OpenRA.Mods.RA/CrateSpawner.cs @@ -1,19 +1,19 @@ -#region Copyright & License Information -/* - * Copyright 2007-2010 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 LICENSE. - */ +#region Copyright & License Information +/* + * Copyright 2007-2010 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 LICENSE. + */ #endregion using System; using System.Collections.Generic; -using System.Linq; -using OpenRA.Traits; -using OpenRA.FileFormats; - +using System.Linq; +using OpenRA.Traits; +using OpenRA.FileFormats; + namespace OpenRA.Mods.RA { public class CrateSpawnerInfo : TraitInfo @@ -62,14 +62,14 @@ namespace OpenRA.Mods.RA if (!(inWater ? info.ValidWater : info.ValidGround).Contains(terrainType)) continue; // Don't spawn on any actors - if (self.World.WorldActor.traits.Get().GetBuildingAt(p) != null) continue; - if (self.World.WorldActor.traits.Get().GetUnitsAt(p).Any()) continue; + if (self.World.WorldActor.Trait().GetBuildingAt(p) != null) continue; + if (self.World.WorldActor.Trait().GetUnitsAt(p).Any()) continue; self.World.AddFrameEndTask( - w => crates.Add(w.CreateActor("crate", new TypeDictionary - { - new LocationInit( p ), - new OwnerInit( self.World.WorldActor.Owner ), + w => crates.Add(w.CreateActor("crate", new TypeDictionary + { + new LocationInit( p ), + new OwnerInit( self.World.WorldActor.Owner ), }))); return; } diff --git a/OpenRA.Mods.RA/Crates/CloakCrateAction.cs b/OpenRA.Mods.RA/Crates/CloakCrateAction.cs index dadc6ed329..c295578b83 100644 --- a/OpenRA.Mods.RA/Crates/CloakCrateAction.cs +++ b/OpenRA.Mods.RA/Crates/CloakCrateAction.cs @@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA.Crates public override int GetSelectionShares(Actor collector) { - return collector.traits.Contains() + return collector.HasTrait() ? 0 : base.GetSelectionShares(collector); } @@ -44,7 +44,7 @@ namespace OpenRA.Mods.RA.Crates collector.World.AddFrameEndTask(w => { w.Remove(collector); - collector.traits.Add(cloak); + collector.AddTrait(cloak); w.Add(collector); }); diff --git a/OpenRA.Mods.RA/Crates/GiveCashCrateAction.cs b/OpenRA.Mods.RA/Crates/GiveCashCrateAction.cs index d92502519d..0a0216766b 100644 --- a/OpenRA.Mods.RA/Crates/GiveCashCrateAction.cs +++ b/OpenRA.Mods.RA/Crates/GiveCashCrateAction.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA collector.World.AddFrameEndTask(w => { var amount = (info as GiveCashCrateActionInfo).Amount; - collector.Owner.PlayerActor.traits.Get().GiveCash(amount); + collector.Owner.PlayerActor.Trait().GiveCash(amount); }); base.Activate(collector); } diff --git a/OpenRA.Mods.RA/Crates/GiveUnitCrateAction.cs b/OpenRA.Mods.RA/Crates/GiveUnitCrateAction.cs index 53bad5b965..c4b6906539 100644 --- a/OpenRA.Mods.RA/Crates/GiveUnitCrateAction.cs +++ b/OpenRA.Mods.RA/Crates/GiveUnitCrateAction.cs @@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA.Crates int2? ChooseEmptyCellNear(Actor a) { // hack: use `a`'s movement capability. - var move = a.traits.Get(); + var move = a.Trait(); var loc = a.Location; for (var i = -1; i < 2; i++) diff --git a/OpenRA.Mods.RA/Crates/LevelUpCrateAction.cs b/OpenRA.Mods.RA/Crates/LevelUpCrateAction.cs index e7e715fc2c..5322062366 100644 --- a/OpenRA.Mods.RA/Crates/LevelUpCrateAction.cs +++ b/OpenRA.Mods.RA/Crates/LevelUpCrateAction.cs @@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA { collector.World.AddFrameEndTask(w => { - var gainsExperience = collector.traits.GetOrDefault(); + var gainsExperience = collector.TraitOrDefault(); if (gainsExperience != null) gainsExperience.GiveOneLevel(); }); diff --git a/OpenRA.Mods.RA/Crates/ResetRadarCrateAction.cs b/OpenRA.Mods.RA/Crates/ResetRadarCrateAction.cs index 0f25aacef6..edc3785fb4 100644 --- a/OpenRA.Mods.RA/Crates/ResetRadarCrateAction.cs +++ b/OpenRA.Mods.RA/Crates/ResetRadarCrateAction.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA { base.Activate(collector); if (collector.Owner == collector.World.LocalPlayer) - collector.World.WorldActor.traits.Get().ResetExploration(); + collector.World.WorldActor.Trait().ResetExploration(); } } } diff --git a/OpenRA.Mods.RA/Crates/SupportPowerCrateAction.cs b/OpenRA.Mods.RA/Crates/SupportPowerCrateAction.cs index 3194012f77..1934382dcc 100644 --- a/OpenRA.Mods.RA/Crates/SupportPowerCrateAction.cs +++ b/OpenRA.Mods.RA/Crates/SupportPowerCrateAction.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Crates public override void Activate(Actor collector) { - var p = collector.Owner.PlayerActor.traits.WithInterface() + var p = collector.Owner.PlayerActor.TraitsImplementing() .FirstOrDefault(sp => sp.GetType().Name == (info as SupportPowerCrateActionInfo).Power); if (p != null) p.Give(1); diff --git a/OpenRA.Mods.RA/DefaultShellmapScript.cs b/OpenRA.Mods.RA/DefaultShellmapScript.cs index 035ade18c9..2a7962fc20 100644 --- a/OpenRA.Mods.RA/DefaultShellmapScript.cs +++ b/OpenRA.Mods.RA/DefaultShellmapScript.cs @@ -1,19 +1,19 @@ -#region Copyright & License Information -/* - * Copyright 2007-2010 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 LICENSE. - */ -#endregion - -using System.Collections.Generic; -using System.Linq; -using OpenRA.Traits; - +#region Copyright & License Information +/* + * Copyright 2007-2010 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 LICENSE. + */ +#endregion + +using System.Collections.Generic; +using System.Linq; +using OpenRA.Traits; + namespace OpenRA.Mods.RA -{ +{ class DefaultShellmapScriptInfo : TraitInfo { } class DefaultShellmapScript: ILoadWorldHook, ITick @@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA // Sound.PlayMusic("hell226m.aud"); goodguy = w.players.Values.Where(x => x.InternalName == "GoodGuy").FirstOrDefault(); greece = w.players.Values.Where(x => x.InternalName == "Greece").FirstOrDefault(); - MapActors = w.WorldActor.traits.Get().MapActors; + MapActors = w.WorldActor.Trait().MapActors; goodguy.Stances[greece] = Stance.Enemy; @@ -37,18 +37,18 @@ namespace OpenRA.Mods.RA int ticks = 0; public void Tick(Actor self) - { - if (ticks == 250) - { - MapActors["pdox"].traits.Get().Teleport(MapActors["ca1"], new int2(90, 70)); - MapActors["pdox"].traits.Get().Teleport(MapActors["ca2"], new int2(92, 71)); + { + if (ticks == 250) + { + MapActors["pdox"].Trait().Teleport(MapActors["ca1"], new int2(90, 70)); + MapActors["pdox"].Trait().Teleport(MapActors["ca2"], new int2(92, 71)); } if (ticks == 100) - MapActors["mslo1"].traits.Get().Attack(new int2(96,53)); + MapActors["mslo1"].Trait().Attack(new int2(96,53)); if (ticks == 110) - MapActors["mslo2"].traits.Get().Attack(new int2(92,53)); + MapActors["mslo2"].Trait().Attack(new int2(92,53)); if (ticks == 120) - MapActors["mslo3"].traits.Get().Attack(new int2(94,50)); + MapActors["mslo3"].Trait().Attack(new int2(94,50)); ticks++; } diff --git a/OpenRA.Mods.RA/DemoTruck.cs b/OpenRA.Mods.RA/DemoTruck.cs index 5c5f7ae6d3..8266cff3e1 100644 --- a/OpenRA.Mods.RA/DemoTruck.cs +++ b/OpenRA.Mods.RA/DemoTruck.cs @@ -33,7 +33,7 @@ namespace OpenRA.Mods.RA public void Detonate(Actor self, Actor detonatedBy) { - var move = self.traits.GetOrDefault(); + var move = self.TraitOrDefault(); var info = self.Info.Traits.Get(); var altitude = move != null ? move.Altitude : 0; diff --git a/OpenRA.Mods.RA/DetectCloaked.cs b/OpenRA.Mods.RA/DetectCloaked.cs index 96f2af8ddb..44d7a66f41 100644 --- a/OpenRA.Mods.RA/DetectCloaked.cs +++ b/OpenRA.Mods.RA/DetectCloaked.cs @@ -34,13 +34,13 @@ namespace OpenRA.Mods.RA ticks = info.Interval; var toDecloak = self.World.FindUnitsInCircle(self.CenterLocation, info.Range * Game.CellSize) - .Where(a => a.traits.Contains()); + .Where(a => a.HasTrait()); if (!info.AffectOwnUnits) toDecloak = toDecloak.Where(a => self.Owner.Stances[a.Owner] != Stance.Ally); foreach (var a in toDecloak) - a.traits.Get().Decloak((int)(25 * info.DecloakTime)); + a.Trait().Decloak((int)(25 * info.DecloakTime)); } } } diff --git a/OpenRA.Mods.RA/Effects/Bullet.cs b/OpenRA.Mods.RA/Effects/Bullet.cs index 5db7b02610..0cf0563774 100755 --- a/OpenRA.Mods.RA/Effects/Bullet.cs +++ b/OpenRA.Mods.RA/Effects/Bullet.cs @@ -111,8 +111,8 @@ namespace OpenRA.Mods.RA.Effects var pos = float2.Lerp(Args.src, Args.dest, at); var cell = Traits.Util.CellContaining(pos); - if (world.WorldActor.traits.Get().GetUnitsAt(cell).Any( - a => a.traits.Contains())) + if (world.WorldActor.Trait().GetUnitsAt(cell).Any( + a => a.HasTrait())) { Args.dest = pos.ToInt2(); Explode(world); diff --git a/OpenRA.Mods.RA/Effects/Corpse.cs b/OpenRA.Mods.RA/Effects/Corpse.cs index 70daed8fa4..665e9b1968 100644 --- a/OpenRA.Mods.RA/Effects/Corpse.cs +++ b/OpenRA.Mods.RA/Effects/Corpse.cs @@ -23,7 +23,7 @@ namespace OpenRA.Mods.RA.Effects public Corpse(Actor fromActor, int death) { - anim = new Animation(fromActor.traits.GetOrDefault().GetImage(fromActor)); + anim = new Animation(fromActor.TraitOrDefault().GetImage(fromActor)); anim.PlayThen("die{0}".F(death + 1), () => fromActor.World.AddFrameEndTask(w => w.Remove(this))); diff --git a/OpenRA.Mods.RA/Effects/InvulnEffect.cs b/OpenRA.Mods.RA/Effects/InvulnEffect.cs index e65926fe96..5565b5752e 100644 --- a/OpenRA.Mods.RA/Effects/InvulnEffect.cs +++ b/OpenRA.Mods.RA/Effects/InvulnEffect.cs @@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA.Effects public InvulnEffect(Actor a) { this.a = a; - this.b = a.traits.Get(); + this.b = a.Trait(); } public void Tick( World world ) diff --git a/OpenRA.Mods.RA/Effects/Missile.cs b/OpenRA.Mods.RA/Effects/Missile.cs index ea21cb8d20..fdd849b08e 100755 --- a/OpenRA.Mods.RA/Effects/Missile.cs +++ b/OpenRA.Mods.RA/Effects/Missile.cs @@ -76,8 +76,8 @@ namespace OpenRA.Mods.RA.Effects var targetPosition = Args.target.CenterLocation + offset; var targetAltitude = 0; - if (Args.target.IsActor && Args.target.Actor.traits.Contains()) - targetAltitude = Args.target.Actor.traits.Get().Altitude; + if (Args.target.IsActor && Args.target.Actor.HasTrait()) + targetAltitude = Args.target.Actor.Trait().Altitude; Altitude += Math.Sign(targetAltitude - Altitude); Facing = Traits.Util.TickFacing(Facing, @@ -107,8 +107,8 @@ namespace OpenRA.Mods.RA.Effects { var cell = Traits.Util.CellContaining(Pos); - if (world.WorldActor.traits.Get().GetUnitsAt(cell).Any( - a => a.traits.Contains())) + if (world.WorldActor.Trait().GetUnitsAt(cell).Any( + a => a.HasTrait())) Explode(world); } } diff --git a/OpenRA.Mods.RA/Effects/NukeLaunch.cs b/OpenRA.Mods.RA/Effects/NukeLaunch.cs index bbbf87ec70..b3f2251db4 100755 --- a/OpenRA.Mods.RA/Effects/NukeLaunch.cs +++ b/OpenRA.Mods.RA/Effects/NukeLaunch.cs @@ -77,7 +77,7 @@ namespace OpenRA.Mods.RA.Effects { world.AddFrameEndTask(w => w.Remove(this)); Combat.DoExplosion(silo.Owner.PlayerActor, weapon, pos, 0); - world.WorldActor.traits.Get().AddEffect(20, pos, 5); + world.WorldActor.Trait().AddEffect(20, pos, 5); } public IEnumerable Render() diff --git a/OpenRA.Mods.RA/Effects/Parachute.cs b/OpenRA.Mods.RA/Effects/Parachute.cs index 19b1bc6f9f..1ec90f2f8c 100644 --- a/OpenRA.Mods.RA/Effects/Parachute.cs +++ b/OpenRA.Mods.RA/Effects/Parachute.cs @@ -59,7 +59,7 @@ namespace OpenRA.Mods.RA.Effects var loc = Traits.Util.CellContaining(location); cargo.CancelActivity(); - var mobile = cargo.traits.GetOrDefault(); + var mobile = cargo.TraitOrDefault(); if (mobile != null) mobile.SetPosition(cargo, loc); @@ -67,8 +67,8 @@ namespace OpenRA.Mods.RA.Effects { cargo.CenterLocation = Traits.Util.CenterOfCell(loc); - if (cargo.traits.Contains()) - world.WorldActor.traits.Get().Add(cargo, cargo.traits.Get()); + if (cargo.HasTrait()) + world.WorldActor.Trait().Add(cargo, cargo.Trait()); } w.Add(cargo); }); diff --git a/OpenRA.Mods.RA/EmitInfantryOnSell.cs b/OpenRA.Mods.RA/EmitInfantryOnSell.cs index 11d3fe041b..7d9eb8c197 100644 --- a/OpenRA.Mods.RA/EmitInfantryOnSell.cs +++ b/OpenRA.Mods.RA/EmitInfantryOnSell.cs @@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA var valued = self.Info.Traits.GetOrDefault(); var cost = csv != null ? csv.Value : (valued != null ? valued.Cost : 0); - var health = self.traits.GetOrDefault(); + var health = self.TraitOrDefault(); var hpFraction = (health == null) ? 1f : health.HPFraction; var dudesValue = (int)(hpFraction * info.ValueFraction * cost); var eligibleLocations = Footprint.Tiles(self).ToList(); diff --git a/OpenRA.Mods.RA/EngineerCapture.cs b/OpenRA.Mods.RA/EngineerCapture.cs index 5adbce0da8..704343e47f 100644 --- a/OpenRA.Mods.RA/EngineerCapture.cs +++ b/OpenRA.Mods.RA/EngineerCapture.cs @@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA if (mi.Button != MouseButton.Right) return null; if (underCursor == null) return null; if (self.Owner.Stances[underCursor.Owner] == Stance.Ally) return null; - if (!underCursor.traits.Contains() || !underCursor.Info.Traits.Get().Capturable) return null; + if (!underCursor.HasTrait() || !underCursor.Info.Traits.Get().Capturable) return null; return new Order("CaptureBuilding", self, underCursor); } @@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA self.World.AddFrameEndTask(w => { w.Add(new FlashTarget(order.TargetActor)); - var line = self.traits.GetOrDefault(); + var line = self.TraitOrDefault(); if (line != null) line.SetTarget(self, Target.FromOrder(order), Color.Red); }); diff --git a/OpenRA.Mods.RA/EngineerRepair.cs b/OpenRA.Mods.RA/EngineerRepair.cs index 54392851c0..24fdbc2e36 100644 --- a/OpenRA.Mods.RA/EngineerRepair.cs +++ b/OpenRA.Mods.RA/EngineerRepair.cs @@ -6,12 +6,12 @@ * as published by the Free Software Foundation. For more information, * see LICENSE. */ -#endregion - -using System.Drawing; -using OpenRA.Effects; -using OpenRA.Mods.RA.Activities; -using OpenRA.Traits; +#endregion + +using System.Drawing; +using OpenRA.Effects; +using OpenRA.Mods.RA.Activities; +using OpenRA.Traits; using OpenRA.Traits.Activities; namespace OpenRA.Mods.RA @@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA bool CanRepair(Actor self, Actor a) { - if (!a.traits.Contains()) return false; + if (!a.HasTrait()) return false; return (self.Owner.Stances[a.Owner] == Stance.Ally); } @@ -57,7 +57,7 @@ namespace OpenRA.Mods.RA self.World.AddFrameEndTask(w => { w.Add(new FlashTarget(order.TargetActor)); - var line = self.traits.GetOrDefault(); + var line = self.TraitOrDefault(); if (line != null) line.SetTarget(self, Target.FromOrder(order), Color.Yellow); }); diff --git a/OpenRA.Mods.RA/Explodes.cs b/OpenRA.Mods.RA/Explodes.cs index 89e0cdce2d..f6589aa735 100644 --- a/OpenRA.Mods.RA/Explodes.cs +++ b/OpenRA.Mods.RA/Explodes.cs @@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA var weapon = ChooseWeaponForExplosion(self); if (weapon != null) { - var move = self.traits.GetOrDefault(); + var move = self.TraitOrDefault(); var altitude = move != null ? move.Altitude : 0; Combat.DoExplosion(e.Attacker, weapon, self.CenterLocation, altitude); } @@ -39,7 +39,7 @@ namespace OpenRA.Mods.RA string ChooseWeaponForExplosion(Actor self) { - var shouldExplode = self.traits.WithInterface().All(a => a.ShouldExplode(self)); + var shouldExplode = self.TraitsImplementing().All(a => a.ShouldExplode(self)); var info = self.Info.Traits.Get(); return shouldExplode ? info.Weapon : info.EmptyWeapon; diff --git a/OpenRA.Mods.RA/GivesExperience.cs b/OpenRA.Mods.RA/GivesExperience.cs index 0f80ff9075..2d82e375b0 100644 --- a/OpenRA.Mods.RA/GivesExperience.cs +++ b/OpenRA.Mods.RA/GivesExperience.cs @@ -1,15 +1,15 @@ -#region Copyright & License Information -/* - * Copyright 2007-2010 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 LICENSE. - */ +#region Copyright & License Information +/* + * Copyright 2007-2010 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 LICENSE. + */ #endregion -using OpenRA.Traits; - +using OpenRA.Traits; + namespace OpenRA.Mods.RA { class GivesExperienceInfo : TraitInfo { public readonly int Experience = -1; } @@ -22,16 +22,16 @@ namespace OpenRA.Mods.RA { // Prevent TK from giving exp if (e.Attacker == null || e.Attacker.Owner.Stances[ self.Owner ] == Stance.Ally ) - return; - + return; + var info = self.Info.Traits.Get(); - var valued = self.Info.Traits.GetOrDefault(); - - var exp = info.Experience >= 0 - ? info.Experience + var valued = self.Info.Traits.GetOrDefault(); + + var exp = info.Experience >= 0 + ? info.Experience : valued != null ? valued.Cost : 0; - - var killer = e.Attacker.traits.GetOrDefault(); + + var killer = e.Attacker.TraitOrDefault(); if (killer != null) killer.GiveExperience(exp); } diff --git a/OpenRA.Mods.RA/Harvester.cs b/OpenRA.Mods.RA/Harvester.cs index 64e9cb3ab6..0ac5d11ac6 100644 --- a/OpenRA.Mods.RA/Harvester.cs +++ b/OpenRA.Mods.RA/Harvester.cs @@ -55,22 +55,22 @@ namespace OpenRA.Mods.RA { LinkedProc = ClosestProc(self, ignore); if (LinkedProc != null) - LinkedProc.traits.WithInterface().FirstOrDefault().LinkHarvester(LinkedProc,self); + LinkedProc.TraitsImplementing().FirstOrDefault().LinkHarvester(LinkedProc,self); } Actor ClosestProc(Actor self, Actor ignore) { var refs = self.World.Queries.OwnedBy[self.Owner] - .Where(x => x != ignore && x.traits.Contains()) + .Where(x => x != ignore && x.HasTrait()) .ToList(); var path = self.World.PathFinder.FindPath(PathSearch.FromPoints(self, - refs.Select(r => r.Location + r.traits.Get().DeliverOffset), + refs.Select(r => r.Location + r.Trait().DeliverOffset), self.Location, false)); path.Reverse(); if (path.Count != 0) - return refs.FirstOrDefault(x => x.Location + x.traits.Get().DeliverOffset == path[0]); + return refs.FirstOrDefault(x => x.Location + x.Trait().DeliverOffset == path[0]); else return null; } @@ -86,7 +86,7 @@ namespace OpenRA.Mods.RA public void Deliver(Actor self, Actor proc) { - proc.traits.Get().GiveOre(contents.Sum(kv => kv.Key.ValuePerUnit * kv.Value)); + proc.Trait().GiveOre(contents.Sum(kv => kv.Key.ValuePerUnit * kv.Value)); contents.Clear(); } @@ -96,11 +96,11 @@ namespace OpenRA.Mods.RA if (underCursor != null && underCursor.Owner == self.Owner - && underCursor.traits.Contains()) + && underCursor.HasTrait()) { return new Order("Deliver", self, underCursor); } - var res = self.World.WorldActor.traits.Get().GetResource(xy); + var res = self.World.WorldActor.Trait().GetResource(xy); var info = self.Info.Traits.Get(); if (underCursor == null && res != null && info.Resources.Contains(res.info.Name) && !IsFull) @@ -129,7 +129,7 @@ namespace OpenRA.Mods.RA self.World.AddFrameEndTask(w => { w.Add(new MoveFlash(self.World, order.TargetLocation)); - var line = self.traits.GetOrDefault(); + var line = self.TraitOrDefault(); if (line != null) line.SetTarget(self, Target.FromOrder(order), Color.Red); }); @@ -143,9 +143,9 @@ namespace OpenRA.Mods.RA if (order.TargetActor != LinkedProc) { if (LinkedProc != null) - LinkedProc.traits.WithInterface().FirstOrDefault().UnlinkHarvester(LinkedProc,self); + LinkedProc.TraitsImplementing().FirstOrDefault().UnlinkHarvester(LinkedProc,self); LinkedProc = order.TargetActor; - LinkedProc.traits.WithInterface().FirstOrDefault().LinkHarvester(LinkedProc,self); + LinkedProc.TraitsImplementing().FirstOrDefault().LinkHarvester(LinkedProc,self); } if (IsEmpty) @@ -155,7 +155,7 @@ namespace OpenRA.Mods.RA self.World.AddFrameEndTask(w => { w.Add(new FlashTarget(order.TargetActor)); - var line = self.traits.GetOrDefault(); + var line = self.TraitOrDefault(); if (line != null) line.SetTarget(self, Target.FromOrder(order), Color.Green); }); @@ -169,7 +169,7 @@ namespace OpenRA.Mods.RA { if (e.DamageState == DamageState.Dead) if (LinkedProc != null) - LinkedProc.traits.WithInterface().FirstOrDefault().UnlinkHarvester(LinkedProc,self); + LinkedProc.TraitsImplementing().FirstOrDefault().UnlinkHarvester(LinkedProc,self); } public void LinkProc(Actor self, Actor proc) diff --git a/OpenRA.Mods.RA/Helicopter.cs b/OpenRA.Mods.RA/Helicopter.cs index d22087fda4..3b63a868b1 100644 --- a/OpenRA.Mods.RA/Helicopter.cs +++ b/OpenRA.Mods.RA/Helicopter.cs @@ -44,7 +44,7 @@ namespace OpenRA.Mods.RA if (mi.Button == MouseButton.Left) return null; if (underCursor == null) - if (self.traits.GetOrDefault().CanEnterCell(xy)) + if (self.TraitOrDefault().CanEnterCell(xy)) return new Order("Move", self, xy); if (AircraftCanEnter(self, underCursor) @@ -82,7 +82,7 @@ namespace OpenRA.Mods.RA self.World.AddFrameEndTask(w => { w.Add(new MoveFlash(self.World, order.TargetLocation)); - var line = self.traits.GetOrDefault(); + var line = self.TraitOrDefault(); if (line != null) line.SetTarget(self, Target.FromOrder(order), Color.Green); }); @@ -100,18 +100,18 @@ namespace OpenRA.Mods.RA if (order.OrderString == "Enter") { if (Reservable.IsReserved(order.TargetActor)) return; - var res = order.TargetActor.traits.GetOrDefault(); + var res = order.TargetActor.TraitOrDefault(); if (res != null) reservation = res.Reserve(self); - var pi = order.TargetActor.traits.Get(); + var pi = order.TargetActor.Trait(); var offset = pi != null ? pi.Spawns.First().First : float2.Zero; if (self.Owner == self.World.LocalPlayer) self.World.AddFrameEndTask(w => { w.Add(new FlashTarget(order.TargetActor)); - var line = self.traits.GetOrDefault(); + var line = self.TraitOrDefault(); if (line != null) line.SetTarget(self, Target.FromOrder(order), Color.Green); }); @@ -128,16 +128,16 @@ namespace OpenRA.Mods.RA int offsetTicks = 0; public void Tick(Actor self) { - var aircraft = self.traits.Get(); + var aircraft = self.Trait(); if (aircraft.Altitude <= 0) return; var rawSpeed = .2f * aircraft.MovementSpeedForCell(self, self.Location); var otherHelis = self.World.FindUnitsInCircle(self.CenterLocation, Info.IdealSeparation) - .Where(a => a.traits.Contains()); + .Where(a => a.HasTrait()); var f = otherHelis - .Select(h => self.traits.Get().GetRepulseForce(self, h)) + .Select(h => self.Trait().GetRepulseForce(self, h)) .Aggregate(float2.Zero, (a, b) => a + b); self.CenterLocation += rawSpeed * f; diff --git a/OpenRA.Mods.RA/Husk.cs b/OpenRA.Mods.RA/Husk.cs index f0d5cbddd4..ebbfaa5a23 100644 --- a/OpenRA.Mods.RA/Husk.cs +++ b/OpenRA.Mods.RA/Husk.cs @@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA this.self = init.self; this.location = init.Get(); this.Facing = init.Contains() ? init.Get() : 128; - self.World.WorldActor.traits.Get().Add(self, this); + self.World.WorldActor.Trait().Add(self, this); } public int2 TopLeft { get { return location; } } diff --git a/OpenRA.Mods.RA/InfiltrateForSonarPulse.cs b/OpenRA.Mods.RA/InfiltrateForSonarPulse.cs index 6a64c82c6f..6f7ad32bd9 100644 --- a/OpenRA.Mods.RA/InfiltrateForSonarPulse.cs +++ b/OpenRA.Mods.RA/InfiltrateForSonarPulse.cs @@ -18,7 +18,7 @@ namespace OpenRA.Mods.RA { public void OnInfiltrate(Actor self, Actor spy) { - spy.Owner.PlayerActor.traits.Get().Give(1.0f); + spy.Owner.PlayerActor.Trait().Give(1.0f); } } } diff --git a/OpenRA.Mods.RA/LeavesHusk.cs b/OpenRA.Mods.RA/LeavesHusk.cs index d162cb727b..3c286aca65 100644 --- a/OpenRA.Mods.RA/LeavesHusk.cs +++ b/OpenRA.Mods.RA/LeavesHusk.cs @@ -32,12 +32,12 @@ namespace OpenRA.Mods.RA { new LocationInit( self.Location ), new OwnerInit( self.Owner ), - new FacingInit( self.traits.Get().Facing ), + new FacingInit( self.Trait().Facing ), }); - var turreted = self.traits.GetOrDefault(); + var turreted = self.TraitOrDefault(); if (turreted != null) - foreach (var p in husk.traits.WithInterface()) + foreach (var p in husk.TraitsImplementing()) p.InitialFacing = turreted.turretFacing; }); } diff --git a/OpenRA.Mods.RA/Mine.cs b/OpenRA.Mods.RA/Mine.cs index 63ca6588b8..37c981e23a 100644 --- a/OpenRA.Mods.RA/Mine.cs +++ b/OpenRA.Mods.RA/Mine.cs @@ -36,12 +36,12 @@ namespace OpenRA.Mods.RA this.self = init.self; this.info = info; this.location = init.Get(); - self.World.WorldActor.traits.Get().Add(self, this); + self.World.WorldActor.Trait().Add(self, this); } public void OnCrush(Actor crusher) { - if (crusher.traits.Contains() && crusher.Owner == self.Owner) + if (crusher.HasTrait() && crusher.Owner == self.Owner) return; var info = self.Info.Traits.Get(); diff --git a/OpenRA.Mods.RA/Minelayer.cs b/OpenRA.Mods.RA/Minelayer.cs index b6e669efc7..73882a7a23 100644 --- a/OpenRA.Mods.RA/Minelayer.cs +++ b/OpenRA.Mods.RA/Minelayer.cs @@ -59,7 +59,7 @@ namespace OpenRA.Mods.RA if (self.Owner == self.World.LocalPlayer) self.World.CancelInputMode(); - var movement = self.traits.Get(); + var movement = self.Trait(); minefield = GetMinefieldCells(minefieldStart, order.TargetLocation, self.Info.Traits.Get().MinefieldDepth) @@ -122,8 +122,8 @@ namespace OpenRA.Mods.RA int2 lastMousePos; public void RenderAfterWorld(World world) { - var ml = minelayer.traits.Get(); - var movement = minelayer.traits.Get(); + var ml = minelayer.Trait(); + var movement = minelayer.Trait(); var minefield = GetMinefieldCells(ml.minefieldStart, lastMousePos, minelayer.Info.Traits.Get().MinefieldDepth) .Where(p => movement.CanEnterCell(p)).ToArray(); diff --git a/OpenRA.Mods.RA/Modifiers/FrozenUnderFog.cs b/OpenRA.Mods.RA/Modifiers/FrozenUnderFog.cs index f734af4f9d..c74bce105f 100644 --- a/OpenRA.Mods.RA/Modifiers/FrozenUnderFog.cs +++ b/OpenRA.Mods.RA/Modifiers/FrozenUnderFog.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA public FrozenUnderFog(Actor self) { - shroud = self.World.WorldActor.traits.Get(); + shroud = self.World.WorldActor.Trait(); } public bool IsVisible(Actor self) diff --git a/OpenRA.Mods.RA/Modifiers/HiddenUnderFog.cs b/OpenRA.Mods.RA/Modifiers/HiddenUnderFog.cs index 358cc2697c..e99f929a91 100644 --- a/OpenRA.Mods.RA/Modifiers/HiddenUnderFog.cs +++ b/OpenRA.Mods.RA/Modifiers/HiddenUnderFog.cs @@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA public HiddenUnderFog(Actor self) { - shroud = self.World.WorldActor.traits.Get(); + shroud = self.World.WorldActor.Trait(); } public bool IsVisible(Actor self) diff --git a/OpenRA.Mods.RA/Orders/PowerDownOrderGenerator.cs b/OpenRA.Mods.RA/Orders/PowerDownOrderGenerator.cs index b4a90dd7eb..a747a12986 100755 --- a/OpenRA.Mods.RA/Orders/PowerDownOrderGenerator.cs +++ b/OpenRA.Mods.RA/Orders/PowerDownOrderGenerator.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Orders { var underCursor = world.FindUnitsAtMouse(mi.Location) .Where(a => a.Owner == world.LocalPlayer - && a.traits.Contains()) + && a.HasTrait()) .FirstOrDefault(); if (underCursor != null) diff --git a/OpenRA.Mods.RA/Orders/RepairOrderGenerator.cs b/OpenRA.Mods.RA/Orders/RepairOrderGenerator.cs index d22a5449ec..8df31eb6bd 100644 --- a/OpenRA.Mods.RA/Orders/RepairOrderGenerator.cs +++ b/OpenRA.Mods.RA/Orders/RepairOrderGenerator.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Orders if (mi.Button == MouseButton.Left) { var underCursor = world.FindUnitsAtMouse(mi.Location) - .Where(a => a.Owner == world.LocalPlayer && a.traits.Contains()).FirstOrDefault(); + .Where(a => a.Owner == world.LocalPlayer && a.HasTrait()).FirstOrDefault(); if (underCursor == null) yield break; diff --git a/OpenRA.Mods.RA/Orders/SellOrderGenerator.cs b/OpenRA.Mods.RA/Orders/SellOrderGenerator.cs index eeb601a886..ec0c167da8 100755 --- a/OpenRA.Mods.RA/Orders/SellOrderGenerator.cs +++ b/OpenRA.Mods.RA/Orders/SellOrderGenerator.cs @@ -30,8 +30,8 @@ namespace OpenRA.Mods.RA.Orders { var underCursor = world.FindUnitsAtMouse(mi.Location) .Where(a => a.Owner == world.LocalPlayer - && a.traits.Contains() - && a.traits.Contains()).FirstOrDefault(); + && a.HasTrait() + && a.HasTrait()).FirstOrDefault(); var building = underCursor != null ? underCursor.Info.Traits.Get() : null; diff --git a/OpenRA.Mods.RA/Orders/SetChronoTankDestination.cs b/OpenRA.Mods.RA/Orders/SetChronoTankDestination.cs index 670048a77a..66c0346d99 100644 --- a/OpenRA.Mods.RA/Orders/SetChronoTankDestination.cs +++ b/OpenRA.Mods.RA/Orders/SetChronoTankDestination.cs @@ -48,7 +48,7 @@ namespace OpenRA.Mods.RA.Orders if (!world.LocalPlayer.Shroud.IsExplored(xy)) return "move-blocked"; - var movement = self.traits.GetOrDefault(); + var movement = self.TraitOrDefault(); return (movement.CanEnterCell(xy)) ? "chrono-target" : "move-blocked"; } } diff --git a/OpenRA.Mods.RA/OreRefinery.cs b/OpenRA.Mods.RA/OreRefinery.cs index 5e6ef0c827..1283ca0ad7 100644 --- a/OpenRA.Mods.RA/OreRefinery.cs +++ b/OpenRA.Mods.RA/OreRefinery.cs @@ -44,7 +44,7 @@ namespace OpenRA.Mods.RA { this.self = self; Info = info; - Player = self.Owner.PlayerActor.traits.Get (); + Player = self.Owner.PlayerActor.Trait (); LinkedHarv = new List (); } @@ -94,13 +94,13 @@ namespace OpenRA.Mods.RA { if (e.DamageState == DamageState.Dead) foreach (var harv in LinkedHarv) - harv.traits.Get ().UnlinkProc(harv, self); + harv.Trait ().UnlinkProc(harv, self); } public int2 DeliverOffset {get{ return Info.DockOffset; }} public void OnDock (Actor harv, DeliverResources dockOrder) { - self.traits.Get().OnDock(self, harv, dockOrder); + self.Trait().OnDock(self, harv, dockOrder); } public void OnCapture (Actor self, Actor captor, Player oldOwner, Player newOwner) @@ -109,7 +109,7 @@ namespace OpenRA.Mods.RA foreach (var harv in LinkedHarv) { if (harv.Owner == self.Owner) - harv.traits.Get().UnlinkProc (harv, self); + harv.Trait().UnlinkProc (harv, self); } } @@ -117,7 +117,7 @@ namespace OpenRA.Mods.RA public void Sold (Actor self) { foreach (var harv in LinkedHarv) - harv.traits.Get().UnlinkProc (harv, self); + harv.Trait().UnlinkProc (harv, self); } public IEnumerable GetPips (Actor self) diff --git a/OpenRA.Mods.RA/OreRefineryDockAction.cs b/OpenRA.Mods.RA/OreRefineryDockAction.cs index d847dc190d..d25275399a 100644 --- a/OpenRA.Mods.RA/OreRefineryDockAction.cs +++ b/OpenRA.Mods.RA/OreRefineryDockAction.cs @@ -1,17 +1,17 @@ -#region Copyright & License Information -/* - * Copyright 2007-2010 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 LICENSE. - */ -#endregion - -using OpenRA.Mods.RA.Activities; -using OpenRA.Mods.RA.Render; -using OpenRA.Traits; -using OpenRA.Traits.Activities; +#region Copyright & License Information +/* + * Copyright 2007-2010 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 LICENSE. + */ +#endregion + +using OpenRA.Mods.RA.Activities; +using OpenRA.Mods.RA.Render; +using OpenRA.Traits; +using OpenRA.Traits.Activities; using System.Drawing; namespace OpenRA.Mods.RA @@ -24,31 +24,31 @@ namespace OpenRA.Mods.RA Actor dockedHarv = null; public void OnDock(Actor self, Actor harv, DeliverResources dockOrder) { - var harvester = harv.traits.Get(); + var harvester = harv.Trait(); - if (harv.traits.Get().Facing != 64) + if (harv.Trait().Facing != 64) harv.QueueActivity (new Turn (64)); harv.QueueActivity (new CallFunc (() => { dockedHarv = harv; - var renderUnit = harv.traits.Get (); + var renderUnit = harv.Trait (); if (renderUnit.anim.CurrentSequence.Name != "empty") renderUnit.PlayCustomAnimation (harv, "empty", () => { harvester.Deliver(harv, self); harv.QueueActivity( new CallFunc( () => dockedHarv = null, false ) ); - if (harvester.LastHarvestedCell != int2.Zero) + if (harvester.LastHarvestedCell != int2.Zero) { - harv.QueueActivity( new Move(harvester.LastHarvestedCell, 5) ); - if (harv.Owner == self.World.LocalPlayer) - self.World.AddFrameEndTask( w => - { - var line = harv.traits.GetOrDefault(); - if (line != null) - line.SetTargetSilently(harv, Target.FromCell(harvester.LastHarvestedCell), Color.Green); - }); + harv.QueueActivity( new Move(harvester.LastHarvestedCell, 5) ); + if (harv.Owner == self.World.LocalPlayer) + self.World.AddFrameEndTask( w => + { + var line = harv.TraitOrDefault(); + if (line != null) + line.SetTargetSilently(harv, Target.FromCell(harvester.LastHarvestedCell), Color.Green); + }); } harv.QueueActivity( new Harvest() ); }); diff --git a/OpenRA.Mods.RA/ParaDrop.cs b/OpenRA.Mods.RA/ParaDrop.cs index c310e34bec..aa1f37ef48 100644 --- a/OpenRA.Mods.RA/ParaDrop.cs +++ b/OpenRA.Mods.RA/ParaDrop.cs @@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA if ((self.Location - lz).LengthSquared <= r * r && !droppedAt.Contains(self.Location)) { - var cargo = self.traits.Get(); + var cargo = self.Trait(); if (cargo.IsEmpty(self)) FinishedDropping(self); else @@ -55,9 +55,9 @@ namespace OpenRA.Mods.RA droppedAt.Add(self.Location); var a = cargo.Unload(self); - var rs = a.traits.Get(); + var rs = a.Trait(); - var aircraft = self.traits.Get(); + var aircraft = self.Trait(); self.World.AddFrameEndTask(w => w.Add( new Parachute(self.Owner, rs.anim.Name, Util.CenterOfCell(Util.CellContaining(self.CenterLocation)), @@ -70,7 +70,7 @@ namespace OpenRA.Mods.RA bool IsSuitableCell(Actor actorToDrop, int2 p) { - return actorToDrop.traits.Get().CanEnterCell(p); + return actorToDrop.Trait().CanEnterCell(p); } void FinishedDropping(Actor self) diff --git a/OpenRA.Mods.RA/Passenger.cs b/OpenRA.Mods.RA/Passenger.cs index 88197a0575..61441a8508 100644 --- a/OpenRA.Mods.RA/Passenger.cs +++ b/OpenRA.Mods.RA/Passenger.cs @@ -33,7 +33,7 @@ namespace OpenRA.Mods.RA if (underCursor == null || underCursor.Owner != self.Owner) return null; - var cargo = underCursor.traits.GetOrDefault(); + var cargo = underCursor.TraitOrDefault(); if (cargo == null) return null; @@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA bool CanEnter(Actor self, Actor a) { - var cargo = a.traits.GetOrDefault(); + var cargo = a.TraitOrDefault(); return (cargo != null && !cargo.IsFull(a)); } @@ -74,7 +74,7 @@ namespace OpenRA.Mods.RA self.World.AddFrameEndTask(w => { w.Add(new FlashTarget(order.TargetActor)); - var line = self.traits.GetOrDefault(); + var line = self.TraitOrDefault(); if (line != null) line.SetTarget(self, Target.FromOrder(order), Color.Green); }); diff --git a/OpenRA.Mods.RA/Plane.cs b/OpenRA.Mods.RA/Plane.cs index 942a826065..c9b8215085 100644 --- a/OpenRA.Mods.RA/Plane.cs +++ b/OpenRA.Mods.RA/Plane.cs @@ -34,11 +34,11 @@ namespace OpenRA.Mods.RA if (firstTick) { firstTick = false; - if (self.traits.Get().Altitude == 0) + if (self.Trait().Altitude == 0) { /* not spawning in the air, so try to assoc. with our afld. this is a hack. */ var res = self.World.FindUnits(self.CenterLocation, self.CenterLocation) - .Select( a => a.traits.GetOrDefault() ).FirstOrDefault( a => a != null ); + .Select( a => a.TraitOrDefault() ).FirstOrDefault( a => a != null ); if (res != null) reservation = res.Reserve(self); @@ -93,7 +93,7 @@ namespace OpenRA.Mods.RA self.World.AddFrameEndTask(w => { w.Add(new MoveFlash(self.World, order.TargetLocation)); - var line = self.traits.GetOrDefault(); + var line = self.TraitOrDefault(); if (line != null) line.SetTarget(self, Target.FromOrder(order), Color.Green); }); @@ -114,7 +114,7 @@ namespace OpenRA.Mods.RA self.World.AddFrameEndTask(w => { w.Add(new FlashTarget(order.TargetActor)); - var line = self.traits.GetOrDefault(); + var line = self.TraitOrDefault(); if (line != null) line.SetTarget(self, Target.FromOrder(order), Color.Green); }); diff --git a/OpenRA.Mods.RA/Render/RenderBuilding.cs b/OpenRA.Mods.RA/Render/RenderBuilding.cs index 942d44c839..f51f008f32 100644 --- a/OpenRA.Mods.RA/Render/RenderBuilding.cs +++ b/OpenRA.Mods.RA/Render/RenderBuilding.cs @@ -39,7 +39,7 @@ namespace OpenRA.Mods.RA.Render void Complete( Actor self ) { anim.PlayRepeating( GetPrefix(self) + "idle" ); - foreach( var x in self.traits.WithInterface() ) + foreach( var x in self.TraitsImplementing() ) x.BuildingComplete( self ); } diff --git a/OpenRA.Mods.RA/Render/RenderBuildingOre.cs b/OpenRA.Mods.RA/Render/RenderBuildingOre.cs index b60dfc371a..4560471a2c 100755 --- a/OpenRA.Mods.RA/Render/RenderBuildingOre.cs +++ b/OpenRA.Mods.RA/Render/RenderBuildingOre.cs @@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA.Render public void BuildingComplete( Actor self ) { anim.PlayFetchIndex( "idle", - () => (int)( 4.9 * self.Owner.PlayerActor.traits.Get().GetSiloFullness() ) ); + () => (int)( 4.9 * self.Owner.PlayerActor.Trait().GetSiloFullness() ) ); } } } diff --git a/OpenRA.Mods.RA/Render/RenderBuildingTurreted.cs b/OpenRA.Mods.RA/Render/RenderBuildingTurreted.cs index 065b61f487..162f0f270e 100644 --- a/OpenRA.Mods.RA/Render/RenderBuildingTurreted.cs +++ b/OpenRA.Mods.RA/Render/RenderBuildingTurreted.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.RA.Render class RenderBuildingTurreted : RenderBuilding, INotifyBuildComplete { public RenderBuildingTurreted(Actor self) - : base(self, () => self.traits.Get().turretFacing) + : base(self, () => self.Trait().turretFacing) { } diff --git a/OpenRA.Mods.RA/Render/RenderBuildingWall.cs b/OpenRA.Mods.RA/Render/RenderBuildingWall.cs index 57a6a73236..7b3ee221ef 100644 --- a/OpenRA.Mods.RA/Render/RenderBuildingWall.cs +++ b/OpenRA.Mods.RA/Render/RenderBuildingWall.cs @@ -69,7 +69,7 @@ namespace OpenRA.Mods.RA.Render foreach (var w in adjWalls) { - w.traits.Get().AddAdjacentWall(w.Location, self.Location); + w.Trait().AddAdjacentWall(w.Location, self.Location); AddAdjacentWall(self.Location, w.Location); } hasTicked = true; diff --git a/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs b/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs index 3f1b8774cd..bc49d08c14 100644 --- a/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs +++ b/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs @@ -34,18 +34,18 @@ namespace OpenRA.Mods.RA.Render public RenderWarFactory(Actor self) { - roof = new Animation(self.traits.Get().GetImage(self)); + roof = new Animation(self.Trait().GetImage(self)); } public void BuildingComplete( Actor self ) { roof.Play( GetPrefix(self) + "idle-top" ); - self.traits.Get().anims.Add( "roof", new RenderSimple.AnimationWithOffset( roof ) { ZOffset = 2 } ); + self.Trait().anims.Add( "roof", new RenderSimple.AnimationWithOffset( roof ) { ZOffset = 2 } ); } public void Tick(Actor self) { - if (isOpen && !self.World.WorldActor.traits.Get() + if (isOpen && !self.World.WorldActor.Trait() .GetUnitsAt(openExit).Any()) { isOpen = false; @@ -70,7 +70,7 @@ namespace OpenRA.Mods.RA.Render public void Selling( Actor self ) { - self.traits.Get().anims.Remove( "roof" ); + self.Trait().anims.Remove( "roof" ); } public void Sold( Actor self ) { } diff --git a/OpenRA.Mods.RA/Render/RenderInfantry.cs b/OpenRA.Mods.RA/Render/RenderInfantry.cs index cae8cdf86c..3a7405e529 100644 --- a/OpenRA.Mods.RA/Render/RenderInfantry.cs +++ b/OpenRA.Mods.RA/Render/RenderInfantry.cs @@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA.Render public class RenderInfantry : RenderSimple, INotifyAttack, INotifyDamage { public RenderInfantry(Actor self) - : base(self, () => self.traits.Get().Facing) + : base(self, () => self.Trait().Facing) { anim.Play("stand"); } @@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA.Render if (!(self.GetCurrentActivity() is Move) && !(self.GetCurrentActivity() is Drag)) // A bit of a hack return false; - var mobile = self.traits.Get(); + var mobile = self.Trait(); if (float2.WithinEpsilon(self.CenterLocation, Util.CenterOfCell(mobile.toCell), 2)) return false; var seq = IsProne(self) ? "crawl" : "run"; @@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA.Render bool inAttack = false; bool IsProne(Actor self) { - var takeCover = self.traits.GetOrDefault(); + var takeCover = self.TraitOrDefault(); return takeCover != null && takeCover.IsProne; } diff --git a/OpenRA.Mods.RA/Render/RenderUnit.cs b/OpenRA.Mods.RA/Render/RenderUnit.cs index 0e400c329f..6bbd6f9dc1 100644 --- a/OpenRA.Mods.RA/Render/RenderUnit.cs +++ b/OpenRA.Mods.RA/Render/RenderUnit.cs @@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA.Render public class RenderUnit : RenderSimple, INotifyDamage { public RenderUnit(Actor self) - : base(self, () => self.traits.Contains() ? self.traits.Get().Facing : 0) + : base(self, () => self.HasTrait() ? self.Trait().Facing : 0) { anim.Play("idle"); anims.Add( "smoke", new AnimationWithOffset( new Animation( "smoke_m" ), null, () => !isSmoking ) ); diff --git a/OpenRA.Mods.RA/Render/RenderUnitReload.cs b/OpenRA.Mods.RA/Render/RenderUnitReload.cs index b29bb742e0..cbc764af64 100755 --- a/OpenRA.Mods.RA/Render/RenderUnitReload.cs +++ b/OpenRA.Mods.RA/Render/RenderUnitReload.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Render { var isAttacking = self.GetCurrentActivity() is Attack; - var attack = self.traits.GetOrDefault(); + var attack = self.TraitOrDefault(); if (attack != null) anim.ReplaceAnim((attack.IsReloading() ? "empty-" : "") diff --git a/OpenRA.Mods.RA/Render/RenderUnitRotor.cs b/OpenRA.Mods.RA/Render/RenderUnitRotor.cs index 7996a5740a..8eb6471d19 100755 --- a/OpenRA.Mods.RA/Render/RenderUnitRotor.cs +++ b/OpenRA.Mods.RA/Render/RenderUnitRotor.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA.Render public RenderUnitRotor( Actor self ) : base(self) { - var facing = self.traits.Get(); + var facing = self.Trait(); var info = self.Info.Traits.Get(); rotorAnim = new Animation(GetImage(self)); @@ -52,7 +52,7 @@ namespace OpenRA.Mods.RA.Render { base.Tick(self); - var isFlying = self.traits.Get().Altitude > 0; + var isFlying = self.Trait().Altitude > 0; if (isFlying ^ (rotorAnim.CurrentSequence.Name != "rotor")) return; diff --git a/OpenRA.Mods.RA/Render/RenderUnitSpinner.cs b/OpenRA.Mods.RA/Render/RenderUnitSpinner.cs index 2db18fa898..7b04b874a3 100755 --- a/OpenRA.Mods.RA/Render/RenderUnitSpinner.cs +++ b/OpenRA.Mods.RA/Render/RenderUnitSpinner.cs @@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA.Render spinnerAnim.PlayRepeating("spinner"); anims.Add("spinner", new AnimationWithOffset( spinnerAnim, - () => Combat.GetTurretPosition( self, self.traits.Get(), new Turret(info.Offset)), + () => Combat.GetTurretPosition( self, self.Trait(), new Turret(info.Offset)), null ) { ZOffset = 1 } ); } } diff --git a/OpenRA.Mods.RA/Render/RenderUnitTurreted.cs b/OpenRA.Mods.RA/Render/RenderUnitTurreted.cs index ed85f92088..2cc70d4530 100755 --- a/OpenRA.Mods.RA/Render/RenderUnitTurreted.cs +++ b/OpenRA.Mods.RA/Render/RenderUnitTurreted.cs @@ -23,9 +23,9 @@ namespace OpenRA.Mods.RA.Render public RenderUnitTurreted(Actor self) : base(self) { - var facing = self.traits.Get(); - var turreted = self.traits.Get(); - var attack = self.traits.GetOrDefault(); + var facing = self.Trait(); + var turreted = self.Trait(); + var attack = self.TraitOrDefault(); var attackInfo = self.Info.Traits.Get(); var turretAnim = new Animation(GetImage(self), () => turreted.turretFacing ); diff --git a/OpenRA.Mods.RA/RenderRangeCircle.cs b/OpenRA.Mods.RA/RenderRangeCircle.cs index a1dcf92179..fd70672da5 100644 --- a/OpenRA.Mods.RA/RenderRangeCircle.cs +++ b/OpenRA.Mods.RA/RenderRangeCircle.cs @@ -23,7 +23,7 @@ namespace OpenRA.Mods.RA self.World.WorldRenderer.DrawRangeCircle( Color.FromArgb(128, Color.Yellow), - self.CenterLocation, (int)self.traits.Get().GetMaximumRange()); + self.CenterLocation, (int)self.Trait().GetMaximumRange()); } } } diff --git a/OpenRA.Mods.RA/Repairable.cs b/OpenRA.Mods.RA/Repairable.cs index c324271d01..994c2b9f8a 100644 --- a/OpenRA.Mods.RA/Repairable.cs +++ b/OpenRA.Mods.RA/Repairable.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA Health Health; public Repairable(Actor self) { - Health = self.traits.Get(); + Health = self.Trait(); } public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) @@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA bool CanRepair(Actor self) { - var li = self.traits.GetOrDefault(); + var li = self.TraitOrDefault(); return (Health.DamageState > DamageState.Undamaged || (li != null && !li.FullAmmo()) ); } @@ -67,13 +67,13 @@ namespace OpenRA.Mods.RA if (!CanRepair(self)) return; - var rp = order.TargetActor.traits.GetOrDefault(); + var rp = order.TargetActor.TraitOrDefault(); if (self.Owner == self.World.LocalPlayer) self.World.AddFrameEndTask(w => { w.Add(new FlashTarget(order.TargetActor)); - var line = self.traits.GetOrDefault(); + var line = self.TraitOrDefault(); if (line != null) line.SetTarget(self, Target.FromOrder(order), Color.Green); }); diff --git a/OpenRA.Mods.RA/RepairableNear.cs b/OpenRA.Mods.RA/RepairableNear.cs index 254fd3dff6..7aaa16de2f 100644 --- a/OpenRA.Mods.RA/RepairableNear.cs +++ b/OpenRA.Mods.RA/RepairableNear.cs @@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA if (self.Owner == self.World.LocalPlayer) self.World.AddFrameEndTask( w => { - var line = self.traits.GetOrDefault(); + var line = self.TraitOrDefault(); if (line != null) line.SetTargetSilently(self, Target.FromActor(order.TargetActor), Color.Green); }); diff --git a/OpenRA.Mods.RA/RequiresPower.cs b/OpenRA.Mods.RA/RequiresPower.cs index 141924c920..f60d06a278 100644 --- a/OpenRA.Mods.RA/RequiresPower.cs +++ b/OpenRA.Mods.RA/RequiresPower.cs @@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA public bool Disabled { - get { return (self.Owner.PlayerActor.traits.Get().GetPowerState() != PowerState.Normal); } + get { return (self.Owner.PlayerActor.Trait().GetPowerState() != PowerState.Normal); } } } } diff --git a/OpenRA.Mods.RA/Reservable.cs b/OpenRA.Mods.RA/Reservable.cs index 526fa1329b..8e90f13962 100644 --- a/OpenRA.Mods.RA/Reservable.cs +++ b/OpenRA.Mods.RA/Reservable.cs @@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA public static bool IsReserved(Actor a) { - var res = a.traits.GetOrDefault(); + var res = a.TraitOrDefault(); return res != null && res.reservedFor != null; } } diff --git a/OpenRA.Mods.RA/ReservableProduction.cs b/OpenRA.Mods.RA/ReservableProduction.cs index a1b80a2f62..8be9bd9af6 100644 --- a/OpenRA.Mods.RA/ReservableProduction.cs +++ b/OpenRA.Mods.RA/ReservableProduction.cs @@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA { var exit = self.Location + s.Second; var spawn = self.CenterLocation + s.First; - if (!self.World.WorldActor.traits.Get().GetUnitsAt( exit ).Any()) + if (!self.World.WorldActor.Trait().GetUnitsAt( exit ).Any()) { var newUnit = self.World.CreateActor( producee.Name, new TypeDictionary { @@ -45,13 +45,13 @@ namespace OpenRA.Mods.RA }); newUnit.CenterLocation = spawn; - var rp = self.traits.GetOrDefault(); + var rp = self.TraitOrDefault(); if( rp != null ) { newUnit.QueueActivity( new Activities.HeliFly( Util.CenterOfCell(rp.rallyPoint)) ); } - foreach (var t in self.traits.WithInterface()) + foreach (var t in self.TraitsImplementing()) t.UnitProduced(self, newUnit, exit); Log.Write("debug", "{0} #{1} produced by {2} #{3}", newUnit.Info.Name, newUnit.ActorID, self.Info.Name, self.ActorID); diff --git a/OpenRA.Mods.RA/ReturnOnIdle.cs b/OpenRA.Mods.RA/ReturnOnIdle.cs index e5e0ce91f3..102e9a1f4b 100644 --- a/OpenRA.Mods.RA/ReturnOnIdle.cs +++ b/OpenRA.Mods.RA/ReturnOnIdle.cs @@ -21,7 +21,7 @@ namespace OpenRA.Mods.RA { public void Idle(Actor self) { - var altitude = self.traits.Get().Altitude; + var altitude = self.Trait().Altitude; if (altitude == 0) return; // we're on the ground, let's stay there. var airfield = ReturnToBase.ChooseAirfield(self); diff --git a/OpenRA.Mods.RA/SeedsResource.cs b/OpenRA.Mods.RA/SeedsResource.cs index 2e5352d907..d683693787 100644 --- a/OpenRA.Mods.RA/SeedsResource.cs +++ b/OpenRA.Mods.RA/SeedsResource.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.RA { public readonly int Interval = 75; public readonly string ResourceType = "Ore"; - public readonly int MaxRange = 100; + public readonly int MaxRange = 100; public readonly int AnimationInterval = 750; } @@ -34,14 +34,14 @@ namespace OpenRA.Mods.RA if (--ticks <= 0) { var info = self.Info.Traits.Get(); - var resourceType = self.World.WorldActor.traits - .WithInterface() + var resourceType = self.World.WorldActor + .TraitsImplementing() .FirstOrDefault(t => t.info.Name == info.ResourceType); if (resourceType == null) throw new InvalidOperationException("No such resource type `{0}`".F(info.ResourceType)); - var resLayer = self.World.WorldActor.traits.Get(); + var resLayer = self.World.WorldActor.Trait(); var cell = RandomWalk(self.Location, self.World.SharedRandom) .Take(info.MaxRange) @@ -59,7 +59,7 @@ namespace OpenRA.Mods.RA if (--animationTicks <= 0) { var info = self.Info.Traits.Get(); - self.traits.Get().PlayCustomAnim(self, "active"); + self.Trait().PlayCustomAnim(self, "active"); animationTicks = info.AnimationInterval; } } diff --git a/OpenRA.Mods.RA/SelfHealing.cs b/OpenRA.Mods.RA/SelfHealing.cs index d781a0d054..9a32734b6f 100644 --- a/OpenRA.Mods.RA/SelfHealing.cs +++ b/OpenRA.Mods.RA/SelfHealing.cs @@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA return; var info = self.Info.Traits.Get(); - if (self.traits.Get().HPFraction >= info.HealIfBelow) + if (self.Trait().HPFraction >= info.HealIfBelow) return; if (--ticks <= 0) diff --git a/OpenRA.Mods.RA/SpawnDefaultUnits.cs b/OpenRA.Mods.RA/SpawnDefaultUnits.cs index 60ce4bc846..5a67abf55f 100644 --- a/OpenRA.Mods.RA/SpawnDefaultUnits.cs +++ b/OpenRA.Mods.RA/SpawnDefaultUnits.cs @@ -48,7 +48,7 @@ namespace OpenRA.Mods.RA }); if (p == p.World.LocalPlayer || p.Stances[p.World.LocalPlayer] == Stance.Ally) - p.World.WorldActor.traits.Get().Explore(p.World, sp, + p.World.WorldActor.Trait().Explore(p.World, sp, p.World.WorldActor.Info.Traits.Get().InitialExploreRange); } diff --git a/OpenRA.Mods.RA/Spy.cs b/OpenRA.Mods.RA/Spy.cs index 3066715255..30e21fc1e3 100644 --- a/OpenRA.Mods.RA/Spy.cs +++ b/OpenRA.Mods.RA/Spy.cs @@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA if (mi.Button != MouseButton.Right) return null; if (underCursor == null) return null; if (underCursor.Owner == self.Owner) return null; - if (!underCursor.traits.Contains()) return null; + if (!underCursor.HasTrait()) return null; return new Order("Infiltrate", self, underCursor); } @@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA if (self.Owner == self.World.LocalPlayer) self.World.AddFrameEndTask( w => { - var line = self.traits.GetOrDefault(); + var line = self.TraitOrDefault(); if (line != null) line.SetTargetSilently(self, Target.FromActor(order.TargetActor), Color.Green); }); diff --git a/OpenRA.Mods.RA/StoresOre.cs b/OpenRA.Mods.RA/StoresOre.cs index 533aeb6562..6df3da3979 100644 --- a/OpenRA.Mods.RA/StoresOre.cs +++ b/OpenRA.Mods.RA/StoresOre.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA PlayerResources Player; public StoresOre(Actor self, StoresOreInfo info) { - Player = self.Owner.PlayerActor.traits.Get(); + Player = self.Owner.PlayerActor.Trait(); Info = info; } @@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA { var ore = Stored(self); Player.TakeOre(ore); - Player = newOwner.PlayerActor.traits.Get(); + Player = newOwner.PlayerActor.Trait(); Player.GiveOre(ore); } diff --git a/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs b/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs index 8b1ee06809..2b8bdef8b6 100755 --- a/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs +++ b/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs @@ -59,7 +59,7 @@ namespace OpenRA.Mods.RA new FacingInit( Util.GetFacing(order.TargetLocation - startPos, 0) ), new AltitudeInit( Rules.Info[info.UnitType].Traits.Get().CruiseAltitude ), }); - a.traits.Get().SetTarget(order.TargetLocation); + a.Trait().SetTarget(order.TargetLocation); a.CancelActivity(); a.QueueActivity(new Fly(order.TargetLocation)); diff --git a/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs b/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs index f8e2abf877..c735982aee 100755 --- a/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs +++ b/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs @@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA self.World.CancelInputMode(); // Ensure the target cell is valid for the unit - var movement = order.TargetActor.traits.GetOrDefault(); + var movement = order.TargetActor.TraitOrDefault(); if (!movement.CanEnterCell(order.TargetLocation)) return; @@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA .WithTrait() .Select(x => x.Actor).FirstOrDefault(); - chronosphere.traits.Get().Teleport(order.TargetActor, order.TargetLocation); + chronosphere.Trait().Teleport(order.TargetActor, order.TargetLocation); FinishActivate(); } @@ -71,8 +71,8 @@ namespace OpenRA.Mods.RA if (mi.Button == MouseButton.Left) { var underCursor = world.FindUnitsAtMouse(mi.Location) - .Where(a => a.Owner != null && a.traits.Contains() - && a.traits.Contains()).FirstOrDefault(); + .Where(a => a.Owner != null && a.HasTrait() + && a.HasTrait()).FirstOrDefault(); if (underCursor != null) yield return new Order("ChronosphereSelect", world.LocalPlayer.PlayerActor, underCursor); @@ -146,7 +146,7 @@ namespace OpenRA.Mods.RA if (!world.LocalPlayer.Shroud.IsExplored(xy)) return "move-blocked"; - var movement = self.traits.GetOrDefault(); + var movement = self.TraitOrDefault(); return (movement.CanEnterCell(xy)) ? "chrono-target" : "move-blocked"; } } @@ -171,7 +171,7 @@ namespace OpenRA.Mods.RA public void Teleport(Actor targetActor, int2 targetLocation) { var info = self.Info.Traits.Get(); - bool success = targetActor.traits.Get().Activate(targetActor, targetLocation, info.Duration * 25, info.KillCargo, self); + bool success = targetActor.Trait().Activate(targetActor, targetLocation, info.Duration * 25, info.KillCargo, self); if (success) { @@ -182,7 +182,7 @@ namespace OpenRA.Mods.RA foreach (var a in self.World.Queries.WithTrait()) a.Trait.Enable(); - self.traits.Get().PlayCustomAnim(self, "active"); + self.Trait().PlayCustomAnim(self, "active"); } } } diff --git a/OpenRA.Mods.RA/SupportPowers/GpsPower.cs b/OpenRA.Mods.RA/SupportPowers/GpsPower.cs index 6f3c34c748..0bd0066918 100755 --- a/OpenRA.Mods.RA/SupportPowers/GpsPower.cs +++ b/OpenRA.Mods.RA/SupportPowers/GpsPower.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA protected override void OnFinishCharging() { var launchSite = Owner.World.Queries.OwnedBy[Owner] - .FirstOrDefault(a => a.traits.Contains()); + .FirstOrDefault(a => a.HasTrait()); if (launchSite == null) return; diff --git a/OpenRA.Mods.RA/SupportPowers/IronCurtainPower.cs b/OpenRA.Mods.RA/SupportPowers/IronCurtainPower.cs index 753bbd235e..1f991d2ae2 100755 --- a/OpenRA.Mods.RA/SupportPowers/IronCurtainPower.cs +++ b/OpenRA.Mods.RA/SupportPowers/IronCurtainPower.cs @@ -46,11 +46,11 @@ namespace OpenRA.Mods.RA .Where(a => a.Actor.Owner != null) .FirstOrDefault().Actor; if (curtain != null) - curtain.traits.Get().PlayCustomAnim(curtain, "active"); + curtain.Trait().PlayCustomAnim(curtain, "active"); Sound.Play("ironcur9.aud", order.TargetActor.CenterLocation); - order.TargetActor.traits.Get().Activate(order.TargetActor, + order.TargetActor.Trait().Activate(order.TargetActor, (int)((Info as IronCurtainPowerInfo).Duration * 25 * 60)); FinishActivate(); @@ -75,8 +75,8 @@ namespace OpenRA.Mods.RA { var underCursor = world.FindUnitsAtMouse(mi.Location) .Where(a => a.Owner != null - && a.traits.Contains() - && a.traits.Contains()).FirstOrDefault(); + && a.HasTrait() + && a.HasTrait()).FirstOrDefault(); if (underCursor != null) yield return new Order("IronCurtain", underCursor.Owner.PlayerActor, underCursor); diff --git a/OpenRA.Mods.RA/SupportPowers/NukePower.cs b/OpenRA.Mods.RA/SupportPowers/NukePower.cs index f9dcc007d4..1cc72d7ae4 100755 --- a/OpenRA.Mods.RA/SupportPowers/NukePower.cs +++ b/OpenRA.Mods.RA/SupportPowers/NukePower.cs @@ -38,16 +38,16 @@ namespace OpenRA.Mods.RA if (order.OrderString == "NuclearMissile") { var silo = self.World.Queries.OwnedBy[self.Owner] - .Where(a => a.traits.Contains()) + .Where(a => a.HasTrait()) .FirstOrDefault(); if (silo != null) - silo.traits.Get().PlayCustomAnim(silo, "active"); + silo.Trait().PlayCustomAnim(silo, "active"); // Play to everyone but the current player if (Owner != Owner.World.LocalPlayer) Sound.Play(Info.LaunchSound); - silo.traits.Get().Attack(order.TargetLocation); + silo.Trait().Attack(order.TargetLocation); self.World.CancelInputMode(); FinishActivate(); @@ -78,7 +78,7 @@ namespace OpenRA.Mods.RA public void Attack(int2 targetLocation) { - self.traits.Get().PlayCustomAnim(self, "active"); + self.Trait().PlayCustomAnim(self, "active"); self.World.AddFrameEndTask(w => { diff --git a/OpenRA.Mods.RA/SupportPowers/ParatroopersPower.cs b/OpenRA.Mods.RA/SupportPowers/ParatroopersPower.cs index a4a206fbb2..3b3a67e636 100755 --- a/OpenRA.Mods.RA/SupportPowers/ParatroopersPower.cs +++ b/OpenRA.Mods.RA/SupportPowers/ParatroopersPower.cs @@ -75,9 +75,9 @@ namespace OpenRA.Mods.RA a.CancelActivity(); a.QueueActivity(new FlyCircle(p)); - a.traits.Get().SetLZ(p, flare); + a.Trait().SetLZ(p, flare); - var cargo = a.traits.Get(); + var cargo = a.Trait(); foreach (var i in items) cargo.Load(a, owner.World.CreateActor(false, i.ToLowerInvariant(), new TypeDictionary { new OwnerInit( a.Owner ) })); }); diff --git a/OpenRA.Mods.RA/ThrowsParticles.cs b/OpenRA.Mods.RA/ThrowsParticles.cs index 2b0564265b..2e7827c405 100644 --- a/OpenRA.Mods.RA/ThrowsParticles.cs +++ b/OpenRA.Mods.RA/ThrowsParticles.cs @@ -48,9 +48,9 @@ namespace OpenRA.Mods.RA if (info != null) { alt = 0; - var ifacing = self.traits.Get(); + var ifacing = self.Trait(); pos = Combat.GetTurretPosition(self, ifacing, new Turret(info.Offset)); - var ru = self.traits.Get(); + var ru = self.Trait(); v = Game.CosmeticRandom.Gauss2D(1) * info.Spread.RelOffset(); dfacing = Game.CosmeticRandom.Gauss1D(2) * info.ROT; diff --git a/OpenRA.Mods.RA/Transforms.cs b/OpenRA.Mods.RA/Transforms.cs index 22170ef364..a4da5c65d7 100644 --- a/OpenRA.Mods.RA/Transforms.cs +++ b/OpenRA.Mods.RA/Transforms.cs @@ -68,7 +68,7 @@ namespace OpenRA.Mods.RA } self.CancelActivity(); - if (self.traits.Contains()) + if (self.HasTrait()) self.QueueActivity(new Turn(Info.Facing)); self.QueueActivity(new Transform(self, Info.IntoActor, Info.Offset, Info.Facing, Info.TransformSounds)); diff --git a/OpenRA.Mods.RA/Wall.cs b/OpenRA.Mods.RA/Wall.cs index 11bfac451f..8a228e7254 100644 --- a/OpenRA.Mods.RA/Wall.cs +++ b/OpenRA.Mods.RA/Wall.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA { this.self = self; this.info = info; - self.World.WorldActor.traits.Get().Add(self, self.traits.Get()); + self.World.WorldActor.Trait().Add(self, self.Trait()); } public IEnumerable CrushClasses { get { return info.CrushClasses; } } diff --git a/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs b/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs index 014f4685fa..be8204a1c6 100755 --- a/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs +++ b/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs @@ -200,7 +200,7 @@ namespace OpenRA.Mods.RA.Widgets .OrderBy(a => a.Traits.Get().BuildPaletteOrder) .ToArray(); - var queue = world.LocalPlayer.PlayerActor.traits.Get(); + var queue = world.LocalPlayer.PlayerActor.Trait(); var overlayBits = new List>(); numActualRows = Math.Max((allBuildables.Length + Columns - 1) / Columns, Rows); @@ -338,7 +338,7 @@ namespace OpenRA.Mods.RA.Widgets { var player = world.LocalPlayer; var unit = Rules.Info[item]; - var queue = player.PlayerActor.traits.Get(); + var queue = player.PlayerActor.Trait(); var eva = world.WorldActor.Info.Traits.Get(); var producing = queue.AllItems(unit.Category).FirstOrDefault( a => a.Item == item ); @@ -408,7 +408,7 @@ namespace OpenRA.Mods.RA.Widgets var y = paletteOrigin.Y + 9; tabs.Clear(); - var queue = world.LocalPlayer.PlayerActor.traits.Get(); + var queue = world.LocalPlayer.PlayerActor.Trait(); foreach (var q in tabImageNames) { @@ -471,7 +471,7 @@ namespace OpenRA.Mods.RA.Widgets buildable.Description + ((buildable.Hotkey != null)? " ({0})".F(buildable.Hotkey.ToUpper()) : ""), p.ToInt2() + new int2(5, 5), Color.White); - var resources = pl.PlayerActor.traits.Get(); + var resources = pl.PlayerActor.Trait(); DrawRightAligned("${0}".F(buildable.Cost), pos + new int2(-5, 5), (resources.DisplayCash + resources.DisplayOre >= buildable.Cost ? Color.White : Color.Red )); diff --git a/OpenRA.Mods.RA/Widgets/MoneyBinWidget.cs b/OpenRA.Mods.RA/Widgets/MoneyBinWidget.cs index 528561586e..891062e519 100755 --- a/OpenRA.Mods.RA/Widgets/MoneyBinWidget.cs +++ b/OpenRA.Mods.RA/Widgets/MoneyBinWidget.cs @@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA.Widgets public override void DrawInner(World world) { - var playerResources = world.LocalPlayer.PlayerActor.traits.Get(); + var playerResources = world.LocalPlayer.PlayerActor.Trait(); var digitCollection = "digits-" + world.LocalPlayer.Country.Race; var chromeCollection = "chrome-" + world.LocalPlayer.Country.Race; @@ -74,7 +74,7 @@ namespace OpenRA.Mods.RA.Widgets } public override bool HandleInputInner(MouseInput mi) - { + { if (mi.Event == MouseInputEvent.Down) { var action = buttons.Where(a => a.First.Contains(mi.Location.ToPoint())) diff --git a/OpenRA.Mods.RA/Widgets/PowerBinWidget.cs b/OpenRA.Mods.RA/Widgets/PowerBinWidget.cs index c99c0763b3..155641ab89 100755 --- a/OpenRA.Mods.RA/Widgets/PowerBinWidget.cs +++ b/OpenRA.Mods.RA/Widgets/PowerBinWidget.cs @@ -6,11 +6,11 @@ * as published by the Free Software Foundation. For more information, * see LICENSE. */ -#endregion - -using System; +#endregion + +using System; using System.Drawing; -using OpenRA.Graphics; +using OpenRA.Graphics; using OpenRA.Traits; using OpenRA.Widgets; @@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Widgets { powerCollection = "power-" + world.LocalPlayer.Country.Race; - var resources = world.LocalPlayer.PlayerActor.traits.Get(); + var resources = world.LocalPlayer.PlayerActor.Trait(); // Nothing to draw if (resources.PowerProvided == 0 @@ -83,4 +83,4 @@ namespace OpenRA.Mods.RA.Widgets Game.Renderer.RgbaSpriteRenderer.Flush(); } } -} +} diff --git a/OpenRA.Mods.RA/Widgets/SpecialPowerBinWidget.cs b/OpenRA.Mods.RA/Widgets/SpecialPowerBinWidget.cs index b587d78d9b..d04ab699dc 100755 --- a/OpenRA.Mods.RA/Widgets/SpecialPowerBinWidget.cs +++ b/OpenRA.Mods.RA/Widgets/SpecialPowerBinWidget.cs @@ -68,7 +68,7 @@ namespace OpenRA.Mods.RA.Widgets { buttons.Clear(); - var powers = world.LocalPlayer.PlayerActor.traits.WithInterface(); + var powers = world.LocalPlayer.PlayerActor.TraitsImplementing(); var numPowers = powers.Count(p => p.IsAvailable); if (numPowers == 0) return; var rectBounds = RenderBounds; diff --git a/OpenRA.Mods.RA/WithMuzzleFlash.cs b/OpenRA.Mods.RA/WithMuzzleFlash.cs index ac1d7d132d..7b1671394b 100644 --- a/OpenRA.Mods.RA/WithMuzzleFlash.cs +++ b/OpenRA.Mods.RA/WithMuzzleFlash.cs @@ -26,9 +26,9 @@ namespace OpenRA.Mods.RA public WithMuzzleFlash(Actor self) { var attackInfo = self.Info.Traits.Get(); - var render = self.traits.Get(); + var render = self.Trait(); - muzzleFlash = new Animation(render.GetImage(self), () => self.traits.Get().Facing); + muzzleFlash = new Animation(render.GetImage(self), () => self.Trait().Facing); muzzleFlash.Play("muzzle"); render.anims.Add("muzzle", new RenderSimple.AnimationWithOffset( diff --git a/OpenRA.Mods.RA/WithShadow.cs b/OpenRA.Mods.RA/WithShadow.cs index afc4e6af9e..a67ef54aed 100644 --- a/OpenRA.Mods.RA/WithShadow.cs +++ b/OpenRA.Mods.RA/WithShadow.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.RA { public IEnumerable ModifyRender(Actor self, IEnumerable r) { - var move = self.traits.Get(); + var move = self.Trait(); var shadowSprites = r.Select(a => a.WithPalette("shadow")); var flyingSprites = (move.Altitude <= 0) ? r diff --git a/OpenRA.Mods.RA/World/ChoosePaletteOnSelect.cs b/OpenRA.Mods.RA/World/ChoosePaletteOnSelect.cs index 907f515b5b..b43338f5ec 100755 --- a/OpenRA.Mods.RA/World/ChoosePaletteOnSelect.cs +++ b/OpenRA.Mods.RA/World/ChoosePaletteOnSelect.cs @@ -21,7 +21,7 @@ namespace OpenRA.Mods.RA.Widgets public void SelectionChanged() { var firstItem = Game.world.Selection.Actors.FirstOrDefault( - a => a.World.LocalPlayer == a.Owner && a.traits.Contains()); + a => a.World.LocalPlayer == a.Owner && a.HasTrait()); if (firstItem == null) return;