Actor.traits is implementation detail

This commit is contained in:
Bob
2010-08-14 15:19:30 +12:00
committed by alzeih
parent f6c6255f64
commit ae703d50b2
165 changed files with 586 additions and 561 deletions

View File

@@ -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<IOccupySpace>().TopLeft; } }
public int2 Location { get { return Trait<IOccupySpace>().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<IOccupySpace>() )
if( CenterLocation == float2.Zero && HasTrait<IOccupySpace>() )
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<IRender>().SelectMany(x => x.Render(this)).FirstOrDefault();
var firstSprite = TraitsImplementing<IRender>().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<INotifyIdle>())
foreach (var ni in TraitsImplementing<INotifyIdle>())
ni.Idle(this);
break;
@@ -102,8 +102,8 @@ namespace OpenRA
public IEnumerable<Renderable> Render()
{
var mods = traits.WithInterface<IRenderModifier>();
var sprites = traits.WithInterface<IRender>().SelectMany(x => x.Render(this));
var mods = TraitsImplementing<IRenderModifier>();
var sprites = TraitsImplementing<IRender>().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<SelectableInfo>() ? a.Info.Traits.Get<SelectableInfo>().Priority : int.MinValue)
.FirstOrDefault();
return traits.WithInterface<IIssueOrder>()
return TraitsImplementing<IIssueOrder>()
.Select( x => x.IssueOrder( this, xy, mi, underCursor ) )
.FirstOrDefault( x => x != null );
}
@@ -137,7 +137,7 @@ namespace OpenRA
if (useAltitude)
{
var move = traits.GetOrDefault<IMove>();
var move = TraitOrDefault<IMove>();
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<T>()
{
return traits.Get<T>();
}
public T TraitOrDefault<T>()
{
return traits.GetOrDefault<T>();
}
public IEnumerable<T> TraitsImplementing<T>()
{
return traits.WithInterface<T>();
}
public bool HasTrait<T>()
{
return traits.Contains<T>();
}
public void AddTrait( object t )
{
traits.Add( t );
}
}
}

View File

@@ -384,7 +384,7 @@ namespace OpenRA
LoadMap(map);
world.Queries = new World.AllQueries(world);
foreach (var gs in world.WorldActor.traits.WithInterface<IGameStarted>())
foreach (var gs in world.WorldActor.TraitsImplementing<IGameStarted>())
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<IGameStarted>())
foreach (var gs in world.WorldActor.TraitsImplementing<IGameStarted>())
gs.GameStarted(world);
viewport.GoToStartLocation(world.LocalPlayer);

View File

@@ -98,7 +98,7 @@ namespace OpenRA.Graphics
new Range<int>(indicesPerRow * firstRow, indicesPerRow * lastRow),
PrimitiveType.TriangleList, Game.Renderer.SpriteShader));
foreach (var r in world.WorldActor.traits.WithInterface<IRenderOverlay>())
foreach (var r in world.WorldActor.TraitsImplementing<IRenderOverlay>())
r.Render();
}
}

View File

@@ -76,7 +76,7 @@ namespace OpenRA.Graphics
public void RefreshPalette()
{
Game.world.WorldRenderer.palette.Update(
Game.world.WorldActor.traits.WithInterface<IPaletteModifier>());
Game.world.WorldActor.TraitsImplementing<IPaletteModifier>());
}
public void Tick()

View File

@@ -70,7 +70,7 @@ namespace OpenRA.Network
order.Player.Stances[targetPlayer] = (Stance)order.TargetLocation.Y;
if (targetPlayer == world.LocalPlayer)
world.WorldActor.traits.Get<Shroud>().UpdatePlayerStance(world, order.Player, oldStance, order.Player.Stances[targetPlayer]);
world.WorldActor.Trait<Shroud>().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<IResolveOrder>())
foreach (var t in order.Subject.TraitsImplementing<IResolveOrder>())
t.ResolveOrder(order.Subject, order);
break;
}

View File

@@ -56,7 +56,7 @@ namespace OpenRA.Orders
public void Tick( World world )
{
var producing = Producer.traits.Get<Traits.ProductionQueue>().CurrentItem( Rules.Info[ Building ].Category );
var producing = Producer.Trait<Traits.ProductionQueue>().CurrentItem( Rules.Info[ Building ].Category );
if (producing == null || producing.Item != Building || producing.RemainingTime != 0)
world.CancelInputMode();
}

View File

@@ -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<IPreRenderSelection>())
foreach (var t in a.TraitsImplementing<IPreRenderSelection>())
t.RenderBeforeWorld(a);
}
public void RenderAfterWorld( World world )
{
foreach (var a in world.Selection.Actors)
foreach (var t in a.traits.WithInterface<IPostRenderSelection>())
foreach (var t in a.TraitsImplementing<IPostRenderSelection>())
t.RenderAfterWorld(a);
}
public string GetCursor( World world, int2 xy, MouseInput mi )
{
var c = Order(world, xy, mi)
.Select(o => o.Subject.traits.WithInterface<IOrderCursor>()
.Select(o => o.Subject.TraitsImplementing<IOrderCursor>()
.Select(pc => pc.CursorForOrder(o.Subject, o)).FirstOrDefault(a => a != null))
.FirstOrDefault(a => a != null);

View File

@@ -69,7 +69,7 @@ namespace OpenRA
{
using( new PerfSample( "find_unit_path_multiple_src" ) )
{
var mobile = self.traits.Get<Mobile>();
var mobile = self.Trait<Mobile>();
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<UnitInfluence>().GetUnitsAt(q).Any(a => a.Group != self.Group));
(world.WorldActor.Trait<UnitInfluence>().GetUnitsAt(q).Any(a => a.Group != self.Group));
}
public List<int2> FindPath( PathSearch search )

View File

@@ -33,7 +33,7 @@ namespace OpenRA
this.self = self;
world = self.World;
cellInfo = InitCellInfo();
mobile = self.traits.Get<Mobile>();
mobile = self.Trait<Mobile>();
queue = new PriorityQueue<PathDistance>();
}

View File

@@ -21,7 +21,7 @@ namespace OpenRA
public void Add(World w, Actor a)
{
actors.Add(a);
foreach (var ns in w.WorldActor.traits.WithInterface<INotifySelection>())
foreach (var ns in w.WorldActor.TraitsImplementing<INotifySelection>())
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<INotifySelection>())
foreach (var ns in world.WorldActor.TraitsImplementing<INotifySelection>())
ns.SelectionChanged();
}

View File

@@ -28,7 +28,7 @@ namespace OpenRA
public ShroudRenderer(Player owner, Map map)
{
this.shroud = owner.World.WorldActor.traits.Get<Traits.Shroud>();
this.shroud = owner.World.WorldActor.Trait<Traits.Shroud>();
this.map = map;
sprites = new Sprite[map.MapSize.X, map.MapSize.Y];

View File

@@ -90,7 +90,7 @@ namespace OpenRA.Traits.Activities
public IActivity Tick( Actor self )
{
var mobile = self.traits.Get<Mobile>();
var mobile = self.Trait<Mobile>();
if( move != null )
{
@@ -165,10 +165,10 @@ namespace OpenRA.Traits.Activities
void NudgeBlocker(Actor self, int2 nextCell)
{
var blocker = self.World.WorldActor.traits.Get<UnitInfluence>().GetUnitsAt(nextCell).FirstOrDefault();
var blocker = self.World.WorldActor.Trait<UnitInfluence>().GetUnitsAt(nextCell).FirstOrDefault();
if (blocker == null) return;
var nudge = blocker.traits.GetOrDefault<INudge>();
var nudge = blocker.TraitOrDefault<INudge>();
if (nudge != null)
nudge.OnNudge(blocker, self);
}

View File

@@ -23,12 +23,12 @@ namespace OpenRA.Traits.Activities
var csv = self.Info.Traits.GetOrDefault<CustomSellValueInfo>();
var cost = csv != null ? csv.Value : self.Info.Traits.Get<ValuedInfo>().Cost;
var health = self.traits.GetOrDefault<Health>();
var health = self.TraitOrDefault<Health>();
var refundFraction = self.Info.Traits.Get<BuildingInfo>().RefundPercent * (health == null ? 1f : health.HPFraction);
self.Owner.PlayerActor.traits.Get<PlayerResources>().GiveCash((int)(refundFraction * cost));
self.Owner.PlayerActor.Trait<PlayerResources>().GiveCash((int)(refundFraction * cost));
foreach (var ns in self.traits.WithInterface<INotifySold>())
foreach (var ns in self.TraitsImplementing<INotifySold>())
ns.Sold(self);
self.World.AddFrameEndTask( _ => self.World.Remove( self ) );
}
@@ -37,10 +37,10 @@ namespace OpenRA.Traits.Activities
{
if( !started )
{
framesRemaining = self.traits.Get<RenderSimple>().anim.HasSequence("make")
? self.traits.Get<RenderSimple>().anim.GetSequence( "make" ).Length : 0;
framesRemaining = self.Trait<RenderSimple>().anim.HasSequence("make")
? self.Trait<RenderSimple>().anim.GetSequence( "make" ).Length : 0;
foreach( var ns in self.traits.WithInterface<INotifySold>() )
foreach( var ns in self.TraitsImplementing<INotifySold>() )
ns.Selling( self );
started = true;

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Traits.Activities
public IActivity Tick( Actor self )
{
var facing = self.traits.Get<IFacing>();
var facing = self.Trait<IFacing>();
if( desiredFacing == facing.Facing )
return NextActivity;
@@ -35,7 +35,7 @@ namespace OpenRA.Traits.Activities
public void Cancel( Actor self )
{
desiredFacing = self.traits.Get<IFacing>().Facing;
desiredFacing = self.Trait<IFacing>().Facing;
NextActivity = null;
}
}

View File

@@ -47,7 +47,7 @@ namespace OpenRA.Traits
public bool Disabled
{
get { return self.traits.WithInterface<IDisable>().Any(t => t.Disabled); }
get { return self.TraitsImplementing<IDisable>().Any(t => t.Disabled); }
}
public Building(ActorInitializer init)
@@ -61,14 +61,14 @@ namespace OpenRA.Traits
public int GetPowerUsage()
{
var modifier = self.traits
.WithInterface<IPowerModifier>()
var modifier = self
.TraitsImplementing<IPowerModifier>()
.Select(t => t.GetPowerModifier())
.Product();
if (Info.Power > 0)
{
var health = self.traits.GetOrDefault<Health>();
var health = self.TraitOrDefault<Health>();
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<ScreenShaker>().AddEffect(10, self.CenterLocation, 1);
self.World.WorldActor.Trait<ScreenShaker>().AddEffect(10, self.CenterLocation, 1);
Sound.Play(Info.DestroyedSound, self.CenterLocation);
}
}

View File

@@ -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<IDamageModifier>()
var modifier = (float)self.TraitsImplementing<IDamageModifier>()
.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<INotifyDamage>())
foreach (var nd in self.TraitsImplementing<INotifyDamage>())
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<Health>();
var health = self.TraitOrDefault<Health>();
return (health == null) ? true : health.IsDead;
}
public static DamageState GetDamageState(this Actor self)
{
var health = self.traits.GetOrDefault<Health>();
var health = self.TraitOrDefault<Health>();
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<Health>();
var health = self.TraitOrDefault<Health>();
if (health == null) return;
health.InflictDamage(self, attacker, damage, warhead);
}
public static void Kill(this Actor self, Actor attacker)
{
var health = self.traits.GetOrDefault<Health>();
var health = self.TraitOrDefault<Health>();
if (health == null) return;
health.InflictDamage(self, attacker, health.HP, null);
}

View File

@@ -79,10 +79,10 @@ namespace OpenRA.Traits
this.self = init.self;
this.Info = info;
shroud = self.World.WorldActor.traits.Get<Shroud>();
uim = self.World.WorldActor.traits.Get<UnitInfluence>();
bim = self.World.WorldActor.traits.Get<BuildingInfluence>();
canShareCell = self.traits.Contains<SharesCell>();
shroud = self.World.WorldActor.Trait<Shroud>();
uim = self.World.WorldActor.Trait<UnitInfluence>();
bim = self.World.WorldActor.Trait<BuildingInfluence>();
canShareCell = self.HasTrait<SharesCell>();
if (init.Contains<LocationInit>())
{
@@ -149,7 +149,7 @@ namespace OpenRA.Traits
self.World.AddFrameEndTask(w =>
{
w.Add(new MoveFlash(self.World, order.TargetLocation));
var line = self.traits.GetOrDefault<DrawLineToTarget>();
var line = self.TraitOrDefault<DrawLineToTarget>();
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<ICrushable>();
var crushable = building.TraitsImplementing<ICrushable>();
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<SharesCell>()).ToArray();
var nonshareable = canShareCell ? actors : actors.Where(a => !a.HasTrait<SharesCell>()).ToArray();
if (canShareCell)
{
var shareable = actors.Where(a => a.traits.Contains<SharesCell>());
var shareable = actors.Where(a => a.HasTrait<SharesCell>());
// 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<ICrushable>() &&
a.traits.WithInterface<ICrushable>().Any(b => b.CrushClasses.Intersect(Info.Crushes).Any()))))
if (nonshareable.Length > 0 && nonshareable.Any(a => !(a.HasTrait<ICrushable>() &&
a.TraitsImplementing<ICrushable>().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<ICrushable>());
var crushable = uim.GetUnitsAt(toCell).Where(a => a != self && a.HasTrait<ICrushable>());
foreach (var a in crushable)
{
var crushActions = a.traits.WithInterface<ICrushable>().Where(b => b.CrushClasses.Intersect(Info.Crushes).Any());
var crushActions = a.TraitsImplementing<ICrushable>().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<ISpeedModifier>()
var modifier = self
.TraitsImplementing<ISpeedModifier>()
.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<DrawLineToTarget>();
var line = self.TraitOrDefault<DrawLineToTarget>();
if (line != null)
line.SetTargetSilently(self, Target.FromCell(moveTo.Value), Color.Green);
});

View File

@@ -58,7 +58,7 @@ namespace OpenRA.Traits
}
case "DevGiveCash":
{
self.traits.Get<PlayerResources>().GiveCash(Info.Cash);
self.Trait<PlayerResources>().GiveCash(Info.Cash);
break;
}
case "DevShroud":

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Traits
{
var prevItems = GetNumBuildables(self.Owner);
var queue = self.traits.Get<ProductionQueue>();
var queue = self.Trait<ProductionQueue>();
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<RenderSimple>().First().PlayCustomAnim( producer.Actor, "build" );
producer.Actor.TraitsImplementing<RenderSimple>().First().PlayCustomAnim( producer.Actor, "build" );
}
static int GetNumBuildables(Player p)

View File

@@ -57,7 +57,7 @@ namespace OpenRA.Traits
void TickOre(Actor self)
{
OreCapacity = self.World.Queries.OwnedBy[Owner].WithTrait<IStoreOre>()
.Sum(a => a.Actor.traits.WithInterface<IStoreOre>().Sum(b => b.Capacity));
.Sum(a => a.Actor.TraitsImplementing<IStoreOre>().Sum(b => b.Capacity));
if (Ore > OreCapacity)
Ore = OreCapacity;

View File

@@ -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<PlayerResources>().GiveCash(p.Value[0].TotalCost - p.Value[0].RemainingCost); // refund what's been paid so far.
self.Owner.PlayerActor.Trait<PlayerResources>().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<BuildableInfo>())
return 0;
if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.traits.Get<DeveloperMode>().FastBuild) return 0;
if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.Trait<DeveloperMode>().FastBuild) return 0;
var ui = unit.Traits.Get<BuildableInfo>();
var time = ui.Cost
* self.Owner.PlayerActor.Info.Traits.Get<ProductionQueueInfo>().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<PlayerResources>().GiveCash(item.TotalCost - item.RemainingCost); // refund what's been paid so far.
self.Owner.PlayerActor.Trait<PlayerResources>().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<Building>();
var building = a.TraitOrDefault<Building>();
return building != null && building.Disabled;
}
@@ -227,7 +227,7 @@ namespace OpenRA.Traits
if (Paused) return;
if (player.PlayerActor.traits.Get<PlayerResources>().GetPowerState() != PowerState.Normal)
if (player.PlayerActor.Trait<PlayerResources>().GetPowerState() != PowerState.Normal)
{
if (--slowdown <= 0)
slowdown = player.PlayerActor.Info.Traits.Get<ProductionQueueInfo>().LowPowerSlowdown;
@@ -236,7 +236,7 @@ namespace OpenRA.Traits
}
var costThisFrame = RemainingCost / RemainingTime;
if (costThisFrame != 0 && !player.PlayerActor.traits.Get<PlayerResources>().TakeCash(costThisFrame)) return;
if (costThisFrame != 0 && !player.PlayerActor.Trait<PlayerResources>().TakeCash(costThisFrame)) return;
RemainingCost -= costThisFrame;
RemainingTime -= 1;
if (RemainingTime > 0) return;

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Traits
{
var effectivePrereq = prerequisites.Where( a => a.Traits.Get<BuildableInfo>().Owner.Contains( owner.Country.Race ) );
var nowHasPrerequisites = effectivePrereq.Any() &&
effectivePrereq.All( a => buildings[ a.Name ].Any( b => !b.traits.Get<Building>().Disabled ) );
effectivePrereq.All( a => buildings[ a.Name ].Any( b => !b.Trait<Building>().Disabled ) );
if( nowHasPrerequisites && !hasPrerequisites )
watcher.Available();

View File

@@ -70,7 +70,7 @@ namespace OpenRA.Traits
{
public static bool IsPrimaryBuilding(this Actor a)
{
var pb = a.traits.GetOrDefault<PrimaryBuilding>();
var pb = a.TraitOrDefault<PrimaryBuilding>();
return pb != null && pb.IsPrimary;
}
}

View File

@@ -40,8 +40,8 @@ namespace OpenRA.Traits
public void DoProduction(Actor self, Actor newUnit, int2 exit, float2 spawn)
{
var move = newUnit.traits.Get<IMove>();
var facing = newUnit.traits.GetOrDefault<IFacing>();
var move = newUnit.Trait<IMove>();
var facing = newUnit.TraitOrDefault<IFacing>();
// 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<RallyPoint>();
var rp = self.TraitOrDefault<RallyPoint>();
if (rp != null)
{
target = rp.rallyPoint;
@@ -70,13 +70,13 @@ namespace OpenRA.Traits
{
self.World.AddFrameEndTask(w =>
{
var line = newUnit.traits.GetOrDefault<DrawLineToTarget>();
var line = newUnit.TraitOrDefault<DrawLineToTarget>();
if (line != null)
line.SetTargetSilently(newUnit, Target.FromCell(target), Color.Green);
});
}
foreach (var t in self.traits.WithInterface<INotifyProduction>())
foreach (var t in self.TraitsImplementing<INotifyProduction>())
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<Mobile>();
var mobile = newUnit.Trait<Mobile>();
// Pick a spawn/exit point pair
// Todo: Reorder in a synced random way

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Traits
bool UpdateActive(Actor self)
{
// Check if powered
var b = self.traits.Get<Building>();
var b = self.Trait<Building>();
if (b.Disabled) return false;
var isJammed = self.World.Queries.WithTrait<JamsRadar>().Any(a => self.Owner != a.Actor.Owner

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Traits
RepairableBuildingInfo Info;
public RepairableBuilding(Actor self, RepairableBuildingInfo info)
{
Health = self.traits.Get<Health>();
Health = self.Trait<Health>();
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<PlayerResources>().TakeCash(cost))
if (!self.Owner.PlayerActor.Trait<PlayerResources>().TakeCash(cost))
{
remainingTicks = 1;
return;

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Traits
if (!self.IsIdle && previousLocation != self.Location)
{
previousLocation = self.Location;
self.World.WorldActor.traits.Get<Shroud>().UpdateActor(self);
self.World.WorldActor.Trait<Shroud>().UpdateActor(self);
}
}

View File

@@ -61,7 +61,7 @@ namespace OpenRA.Traits
void DrawHealthBar(Actor self, float2 xy, float2 Xy)
{
var health = self.traits.GetOrDefault<Health>();
var health = self.TraitOrDefault<Health>();
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<IPips>())
foreach (var pips in self.TraitsImplementing<IPips>())
{
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<ITags>())
foreach (var tags in self.TraitsImplementing<ITags>())
{
foreach (var tag in tags.GetTags())
{
@@ -154,9 +154,9 @@ namespace OpenRA.Traits
void DrawUnitPath(Actor self)
{
if (!Game.world.LocalPlayer.PlayerActor.traits.Get<DeveloperMode>().PathDebug) return;
if (!Game.world.LocalPlayer.PlayerActor.Trait<DeveloperMode>().PathDebug) return;
var mobile = self.traits.GetOrDefault<IMove>();
var mobile = self.TraitOrDefault<IMove>();
if (mobile != null)
{
var alt = new float2(0, -mobile.Altitude);

View File

@@ -56,7 +56,7 @@ namespace OpenRA.Traits
RemainingTime = TotalTime;
Owner = self.Owner;
self.traits.Get<TechTreeCache>().Add( Info.Prerequisites.Select( a => Rules.Info[ a.ToLowerInvariant() ] ).ToList(), this );
self.Trait<TechTreeCache>().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<DeveloperMode>().FastCharge) RemainingTime = 0;
if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.Trait<DeveloperMode>().FastCharge) RemainingTime = 0;
if (RemainingTime > 0) --RemainingTime;
if (!notifiedCharging)
{
@@ -96,10 +96,10 @@ namespace OpenRA.Traits
.Where(a => Rules.Info[a].Traits.Get<ValuedInfo>().Owner.Contains(Owner.Country.Race));
if (Info.Prerequisites.Count() == 0)
return Owner.PlayerActor.traits.Get<PlayerResources>().GetPowerState() == PowerState.Normal;
return Owner.PlayerActor.Trait<PlayerResources>().GetPowerState() == PowerState.Normal;
return effectivePrereq.Any() &&
effectivePrereq.All(a => buildings[a].Any(b => !b.traits.Get<Building>().Disabled));
effectivePrereq.All(a => buildings[a].Any(b => !b.Trait<Building>().Disabled));
}
public void FinishActivate()

View File

@@ -30,7 +30,7 @@ namespace OpenRA.Traits
{
this.info = info;
turretFacing = info.InitialFacing;
facing = self.traits.GetOrDefault<IFacing>();
facing = self.TraitOrDefault<IFacing>();
}
public void Tick( Actor self )

View File

@@ -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<Bib>()) DoBib(a,true); };
a => { if (a.HasTrait<Bib>()) DoBib(a,true); };
self.World.ActorRemoved +=
a => { if (a.traits.Contains<Bib>()) DoBib(a,false); };
a => { if (a.HasTrait<Bib>()) 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");
}
}

View File

@@ -32,11 +32,11 @@ namespace OpenRA.Traits
influence = new Actor[map.MapSize.X, map.MapSize.Y];
world.ActorAdded +=
a => { if (a.traits.Contains<Building>())
ChangeInfluence(a, a.traits.Get<Building>(), true); };
a => { if (a.HasTrait<Building>())
ChangeInfluence(a, a.Trait<Building>(), true); };
world.ActorRemoved +=
a => { if (a.traits.Contains<Building>())
ChangeInfluence(a, a.traits.Get<Building>(), false); };
a => { if (a.HasTrait<Building>())
ChangeInfluence(a, a.Trait<Building>(), false); };
}
void ChangeInfluence( Actor a, Building building, bool isAdd )

View File

@@ -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<ResourceType>().ToArray();
resourceTypes = w.WorldActor.TraitsImplementing<ResourceType>().ToArray();
foreach (var rt in resourceTypes)
rt.info.Sprites = rt.info.SpriteNames.Select(a => SpriteSheetBuilder.LoadAllSprites(a)).ToArray();

View File

@@ -64,7 +64,7 @@ namespace OpenRA.Traits
void AddActor(Actor a)
{
if (!a.traits.Contains<RevealsShroud>())
if (!a.HasTrait<RevealsShroud>())
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<RevealsShroud>().RevealRange,
range = a.Trait<RevealsShroud>().RevealRange,
vis = GetVisOrigins(a).ToArray()
};
@@ -129,7 +129,7 @@ namespace OpenRA.Traits
}
else
{
var mobile = a.traits.GetOrDefault<Mobile>();
var mobile = a.TraitOrDefault<Mobile>();
if (mobile != null)
return new[] { mobile.fromCell, mobile.toCell };
else

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Traits
for (int j = 0; j < world.Map.MapSize.Y; j++)
influence[ i, j ] = new List<Actor>();
world.ActorRemoved += a => Remove( a, a.traits.GetOrDefault<IOccupySpace>() );
world.ActorRemoved += a => Remove( a, a.TraitOrDefault<IOccupySpace>() );
}
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<IOccupySpace>().OccupiedCells().Contains( new int2( x, y ) ) )
if (!a.Trait<IOccupySpace>().OccupiedCells().Contains( new int2( x, y ) ) )
throw new InvalidOperationException( "UIM: Sanity check failed A" );
foreach( var t in self.World.Queries.WithTraitMultiple<IOccupySpace>() )

View File

@@ -44,7 +44,7 @@ namespace OpenRA
{
if (Game.Settings.UnitDebug)
{
var uim = world.WorldActor.traits.Get<UnitInfluence>();
var uim = world.WorldActor.Trait<UnitInfluence>();
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<ResourceLayer>();
var res = world.WorldActor.Trait<ResourceLayer>();
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)

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Widgets.Delegates
};
devmodeBG.GetWidget<CheckboxWidget>("SETTINGS_CHECKBOX_SHROUD").Checked =
() => Game.world.LocalPlayer.PlayerActor.traits.Get<DeveloperMode>().DisableShroud;
() => Game.world.LocalPlayer.PlayerActor.Trait<DeveloperMode>().DisableShroud;
devmodeBG.GetWidget<CheckboxWidget>("SETTINGS_CHECKBOX_SHROUD").OnMouseDown = mi =>
{
Game.IssueOrder(new Order("DevShroud", Game.world.LocalPlayer.PlayerActor));
@@ -57,7 +57,7 @@ namespace OpenRA.Widgets.Delegates
};
devmodeBG.GetWidget<CheckboxWidget>("SETTINGS_CHECKBOX_PATHDEBUG").Checked =
() => Game.world.LocalPlayer.PlayerActor.traits.Get<DeveloperMode>().PathDebug;
() => Game.world.LocalPlayer.PlayerActor.Trait<DeveloperMode>().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<CheckboxWidget>("SETTINGS_BUILD_SPEED").Checked =
() => Game.world.LocalPlayer.PlayerActor.traits.Get<DeveloperMode>().FastBuild;
() => Game.world.LocalPlayer.PlayerActor.Trait<DeveloperMode>().FastBuild;
devmodeBG.GetWidget<CheckboxWidget>("SETTINGS_BUILD_SPEED").OnMouseDown = mi =>
{
Game.IssueOrder(new Order("DevFastBuild", Game.world.LocalPlayer.PlayerActor));
@@ -79,7 +79,7 @@ namespace OpenRA.Widgets.Delegates
};
devmodeBG.GetWidget<CheckboxWidget>("SETTINGS_CHARGE_TIME").Checked =
() => Game.world.LocalPlayer.PlayerActor.traits.Get<DeveloperMode>().FastCharge;
() => Game.world.LocalPlayer.PlayerActor.Trait<DeveloperMode>().FastCharge;
devmodeBG.GetWidget<CheckboxWidget>("SETTINGS_CHARGE_TIME").OnMouseDown = mi =>
{
Game.IssueOrder(new Order("DevFastCharge", Game.world.LocalPlayer.PlayerActor));

View File

@@ -96,7 +96,7 @@ namespace OpenRA.Widgets
var done = false;
foreach (var o in orders)
{
foreach (var v in o.Subject.traits.WithInterface<IOrderVoice>())
foreach (var v in o.Subject.TraitsImplementing<IOrderVoice>())
{
if (Sound.PlayVoice(v.VoicePhraseForOrder(o.Subject, o), o.Subject))
{
@@ -174,7 +174,7 @@ namespace OpenRA.Widgets
IEnumerable<Actor> SelectActorsInBox(World world, float2 a, float2 b)
{
return world.FindUnits(a, b)
.Where( x => x.traits.Contains<Selectable>() && x.IsVisible() )
.Where( x => x.HasTrait<Selectable>() && x.IsVisible() )
.GroupBy(x => (x.Owner == world.LocalPlayer) ? x.Info.Traits.Get<SelectableInfo>().Priority : 0)
.OrderByDescending(g => g.Key)
.Select( g => g.AsEnumerable() )

View File

@@ -116,7 +116,7 @@ namespace OpenRA
Timer.Time( "worldActor: {0}" );
foreach (var wlh in WorldActor.traits.WithInterface<ILoadWorldHook>())
foreach (var wlh in WorldActor.TraitsImplementing<ILoadWorldHook>())
wlh.WorldLoaded(this);
PathFinder = new PathFinder(this);
@@ -235,8 +235,8 @@ namespace OpenRA
return ret;
ret = new CachedView<Actor, TraitPair<T>>(
set,
x => x.traits.Contains<T>(),
x => new TraitPair<T> { Actor = x, Trait = x.traits.Get<T>() } );
x => x.HasTrait<T>(),
x => new TraitPair<T> { Actor = x, Trait = x.Trait<T>() } );
hasTrait.Add( ret );
return ret;
}
@@ -248,8 +248,8 @@ namespace OpenRA
return ret;
ret = new CachedView<Actor, TraitPair<T>>(
world.actors,
x => x.traits.Contains<T>(),
x => x.traits.WithInterface<T>().Select( t => new TraitPair<T> { Actor = x, Trait = t } ) );
x => x.HasTrait<T>(),
x => x.TraitsImplementing<T>().Select( t => new TraitPair<T> { Actor = x, Trait = t } ) );
hasTrait.Add( ret );
return ret;
}

View File

@@ -28,8 +28,8 @@ namespace OpenRA
public static bool IsCellBuildable(this World world, int2 a, bool waterBound, Actor toIgnore)
{
if (world.WorldActor.traits.Get<BuildingInfluence>().GetBuildingAt(a) != null) return false;
if (world.WorldActor.traits.Get<UnitInfluence>().GetUnitsAt(a).Any(b => b != toIgnore)) return false;
if (world.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(a) != null) return false;
if (world.WorldActor.Trait<UnitInfluence>().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<SpatialBins>().ActorsInBox(u,v);
return world.WorldActor.Trait<SpatialBins>().ActorsInBox(u,v);
}
public static IEnumerable<Actor> 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<ResourceLayer>();
var res = world.WorldActor.Trait<ResourceLayer>();
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<Shroud>();
var shroud = a.World.WorldActor.Trait<Shroud>();
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<IVisibilityModifier>().Any(t => !t.IsVisible(a)))
if (a.TraitsImplementing<IVisibilityModifier>().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<BuildingInfluence>().GetBuildingAt( new int2( x, y ) );
var at = world.WorldActor.Trait<BuildingInfluence>().GetBuildingAt( new int2( x, y ) );
if( at != null && at.Owner.Stances[ p ] == Stance.Ally && at.Info.Traits.Get<BuildingInfo>().BaseNormal )
nearnessCandidates.Add( new int2( x, y ) );
}

View File

@@ -27,8 +27,8 @@ namespace OpenRA.Mods.Cnc
public DeadBuildingState(Actor self, DeadBuildingStateInfo info)
{
this.info = info;
rs = self.traits.Get<RenderSimple>();
self.traits.Get<Health>().RemoveOnDeath = !rs.anim.HasSequence("dead");
rs = self.Trait<RenderSimple>();
self.Trait<Health>().RemoveOnDeath = !rs.anim.HasSequence("dead");
}
public void Damaged(Actor self, AttackInfo e)

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Cnc
{
if (--poisonTicks <= 0)
{
var rl = self.World.WorldActor.traits.Get<ResourceLayer>();
var rl = self.World.WorldActor.Trait<ResourceLayer>();
var r = rl.GetResource(self.Location);
if (r != null && info.Resources.Contains(r.info.Name))

View File

@@ -51,7 +51,7 @@ namespace OpenRA.Mods.Cnc
new AltitudeInit( Rules.Info["c17"].Traits.Get<PlaneInfo>().CruiseAltitude ),
});
var cargo = a.traits.Get<Cargo>();
var cargo = a.Trait<Cargo>();
var newUnit = self.World.CreateActor(false, producee.Name, new TypeDictionary
{
new OwnerInit( self.Owner ),

View File

@@ -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<Harvester>();
var harvester = harv.Trait<Harvester>();
harv.QueueActivity( new Turn(112) );
harv.QueueActivity( new CallFunc( () =>
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Cnc
if (!preventDock)
{
dockedHarv = harv;
self.traits.Get<RenderBuilding>().PlayCustomAnim(self, "active");
self.Trait<RenderBuilding>().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<DrawLineToTarget>();
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<DrawLineToTarget>();
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<Harvester>().Visible = true;
harv.Trait<Harvester>().Visible = true;
}
public void Selling (Actor self) { CancelDock(self, dockedHarv); }

View File

@@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA.Activities
public IActivity Tick( Actor self )
{
var facing = self.traits.Get<IFacing>();
var facing = self.Trait<IFacing>();
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<RenderUnit>();
var renderUnit = self.TraitOrDefault<RenderUnit>();
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<AttackBase>();
var attack = self.Trait<AttackBase>();
attack.target = Target;
attack.DoAttack(self);
return this;

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA.Activities
target.Owner = self.Owner;
w.Add(target);
foreach (var t in target.traits.WithInterface<INotifyCapture>())
foreach (var t in target.TraitsImplementing<INotifyCapture>())
t.OnCapture(target, self, oldOwner, self.Owner);
w.Remove(self);

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Activities
if( NextActivity != null )
return NextActivity;
var harv = self.traits.Get<Harvester>();
var harv = self.Trait<Harvester>();
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<IAcceptOre>().DeliverOffset )
if( self.Location != proc.Location + proc.Trait<IAcceptOre>().DeliverOffset )
{
return new Move(proc.Location + proc.traits.Get<IAcceptOre>().DeliverOffset, 0) { NextActivity = this };
return new Move(proc.Location + proc.Trait<IAcceptOre>().DeliverOffset, 0) { NextActivity = this };
}
else if (!isDocking)
{
isDocking = true;
proc.traits.Get<IAcceptOre>().OnDock(self, this);
proc.Trait<IAcceptOre>().OnDock(self, this);
}
return new Wait(10) { NextActivity = this };
}

View File

@@ -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<Cargo>();
var cargo = transport.Trait<Cargo>();
if (cargo.IsFull(transport))
return NextActivity;

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA.Activities
if (d.LengthSquared < 50) /* close enough */
return NextActivity;
var aircraft = self.traits.Get<Aircraft>();
var aircraft = self.Trait<Aircraft>();
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<Aircraft>();
var aircraft = self.Trait<Aircraft>();
var speed = .2f * aircraft.MovementSpeedForCell(self, self.Location);
var angle = aircraft.Facing / 128f * Math.PI;
self.CenterLocation += speed * -float2.FromAngle((float)angle);

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA.Activities
if (!Target.IsValid)
return NextActivity;
var limitedAmmo = self.traits.GetOrDefault<LimitedAmmo>();
var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();
if (limitedAmmo != null && !limitedAmmo.HasAmmo())
return NextActivity;

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Mods.RA.Activities
if( isHarvesting ) return this;
if( NextActivity != null ) return NextActivity;
var harv = self.traits.Get<Harvester>();
var harv = self.Trait<Harvester>();
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<Harvester>();
var renderUnit = self.traits.Get<RenderUnit>(); /* better have one of these! */
var harv = self.Trait<Harvester>();
var renderUnit = self.Trait<RenderUnit>(); /* better have one of these! */
var resource = self.World.WorldActor.traits.Get<ResourceLayer>().Harvest(self.Location);
var resource = self.World.WorldActor.Trait<ResourceLayer>().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<ResourceLayer>();
var res = self.World.WorldActor.Trait<ResourceLayer>();
var harv = self.Info.Traits.Get<HarvesterInfo>();
self.QueueActivity(new Move(

View File

@@ -26,14 +26,14 @@ namespace OpenRA.Mods.RA.Activities
if (!target.IsValid)
return NextActivity;
var limitedAmmo = self.traits.GetOrDefault<LimitedAmmo>();
var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();
if (limitedAmmo != null && !limitedAmmo.HasAmmo())
{
self.QueueActivity(new HeliReturn());
return NextActivity;
}
var aircraft = self.traits.Get<Aircraft>();
var aircraft = self.Trait<Aircraft>();
var info = self.Info.Traits.Get<HelicopterInfo>();
if (aircraft.Altitude != info.CruiseAltitude)
{
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA.Activities
return this;
}
var range = self.traits.Get<AttackBase>().GetMaximumRange() - 1;
var range = self.Trait<AttackBase>().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;
}

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA.Activities
return NextActivity;
var info = self.Info.Traits.Get<HelicopterInfo>();
var aircraft = self.traits.Get<Aircraft>();
var aircraft = self.Trait<Aircraft>();
if (aircraft.Altitude != info.CruiseAltitude)
{

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Mods.RA.Activities
public IActivity Tick(Actor self)
{
if (isCanceled) return NextActivity;
var aircraft = self.traits.Get<Aircraft>();
var aircraft = self.Trait<Aircraft>();
if (aircraft.Altitude == 0)
return NextActivity;

View File

@@ -40,11 +40,11 @@ namespace OpenRA.Mods.RA.Activities
new HeliLand(true),
NextActivity);
var res = dest.traits.GetOrDefault<Reservable>();
var res = dest.TraitOrDefault<Reservable>();
if (res != null)
self.traits.Get<Helicopter>().reservation = res.Reserve(self);
self.Trait<Helicopter>().reservation = res.Reserve(self);
var pi = dest.traits.Get<Production>();
var pi = dest.Trait<Production>();
var offset = pi != null ? pi.Spawns.First().First : float2.Zero;
return Util.SequenceActivities(

View File

@@ -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<IAcceptSpy>())
foreach (var t in target.TraitsImplementing<IAcceptSpy>())
t.OnInfiltrate(target, self);
self.World.AddFrameEndTask(w => w.Remove(self));

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA.Activities
if (d.LengthSquared < 50) /* close enough */
return NextActivity;
var aircraft = self.traits.Get<Aircraft>();
var aircraft = self.Trait<Aircraft>();
if (aircraft.Altitude > 0)
--aircraft.Altitude;

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Activities
{
if (canceled) return NextActivity;
var limitedAmmo = self.traits.GetOrDefault<LimitedAmmo>();
var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();
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<Minelayer>();
var ml = self.Trait<Minelayer>();
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<UnitInfluence>()
return !self.World.WorldActor.Trait<UnitInfluence>()
.GetUnitsAt(p).Any(a => a != self);
}
void LayMine(Actor self)
{
var limitedAmmo = self.traits.GetOrDefault<LimitedAmmo>();
var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();
if (limitedAmmo != null) limitedAmmo.Attacking(self);
self.World.AddFrameEndTask(

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA.Activities
this.target = target;
initialLocation = self.CenterLocation;
self.traits.Get<RenderInfantry>().Attacking(self);
self.Trait<RenderInfantry>().Attacking(self);
Sound.Play("dogg5p.aud", self.CenterLocation);
}
@@ -44,7 +44,7 @@ namespace OpenRA.Mods.RA.Activities
if (t >= 1f)
{
self.traits.WithInterface<IMove>().FirstOrDefault()
self.TraitsImplementing<IMove>().FirstOrDefault()
.SetPosition(self, Util.CellContaining(target.CenterLocation));
if (target.IsActor)

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Mods.RA.Activities
public IActivity Tick(Actor self)
{
if (isCanceled) return NextActivity;
var limitedAmmo = self.traits.GetOrDefault<LimitedAmmo>();
var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();
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<RenderBuilding>());
.FirstOrDefault(a => a.HasTrait<RenderBuilding>());
if (hostBuilding != null)
hostBuilding.traits.Get<RenderBuilding>().PlayCustomAnim(hostBuilding, "active");
hostBuilding.Trait<RenderBuilding>().PlayCustomAnim(hostBuilding, "active");
remainingTicks = ticksPerPip;
}

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA.Activities
if (isCanceled) return NextActivity;
if (remainingTicks == 0)
{
var health = self.traits.GetOrDefault<Health>();
var health = self.TraitOrDefault<Health>();
if (health == null) return NextActivity;
var unitCost = self.Info.Traits.Get<ValuedInfo>().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<RepairsUnitsInfo>().URepairStep, health.MaxHP - health.HP);
var cost = (int)Math.Ceiling(costPerHp * hpToRepair);
if (!self.Owner.PlayerActor.traits.Get<PlayerResources>().TakeCash(cost))
if (!self.Owner.PlayerActor.Trait<PlayerResources>().TakeCash(cost))
{
remainingTicks = 1;
return this;
@@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA.Activities
return NextActivity;
if (host != null)
host.traits.Get<RenderBuilding>()
host.Trait<RenderBuilding>()
.PlayCustomAnim(host, "active");
remainingTicks = (int)(repairsUnits.RepairRate * 60 * 25);

View File

@@ -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<Health>();
var health = target.Trait<Health>();
if (health.DamageState == DamageState.Undamaged)
return NextActivity;

View File

@@ -40,16 +40,16 @@ namespace OpenRA.Mods.RA.Activities
dest = ChooseAirfield(self);
}
var res = dest.traits.GetOrDefault<Reservable>();
var res = dest.TraitOrDefault<Reservable>();
if (res != null)
{
var plane = self.traits.Get<Plane>();
var plane = self.Trait<Plane>();
plane.UnReserve();
plane.reservation = res.Reserve(self);
}
var landPos = dest.CenterLocation;
var aircraft = self.traits.Get<Aircraft>();
var aircraft = self.Trait<Aircraft>();
var speed = .2f * aircraft.MovementSpeedForCell(self, self.Location);

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Activities
public IActivity Tick(Actor self)
{
self.traits.WithInterface<IMove>().FirstOrDefault().SetPosition(self, destination);
self.TraitsImplementing<IMove>().FirstOrDefault().SetPosition(self, destination);
return NextActivity;
}

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA.Activities
this.offset = offset;
this.sounds = sounds;
this.facing = facing;
rb = self.traits.GetOrDefault<RenderBuilding>();
rb = self.TraitOrDefault<RenderBuilding>();
}
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<Health>())
init.Add( new HealthInit( self.traits.Get<Health>().HPFraction ));
if (self.HasTrait<Health>())
init.Add( new HealthInit( self.Trait<Health>().HPFraction ));
var a = w.CreateActor( actor, init );

View File

@@ -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<UnitInfluence>().GetUnitsAt(self.Location).Count() > 1)
if (self.World.WorldActor.Trait<UnitInfluence>().GetUnitsAt(self.Location).Count() > 1)
return null;
var mobile = cargo.traits.Get<Mobile>();
var mobile = cargo.Trait<Mobile>();
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<IFacing>();
var facing = self.TraitOrDefault<IFacing>();
var unloadFacing = self.Info.Traits.Get<CargoInfo>().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<Cargo>();
var cargo = self.Trait<Cargo>();
if (cargo.IsEmpty(self))
return NextActivity;
var ru = self.traits.GetOrDefault<RenderUnit>();
var ru = self.TraitOrDefault<RenderUnit>();
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<IMove>().FirstOrDefault().SetPosition(actor, self.Location);
actor.TraitsImplementing<IMove>().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<DrawLineToTarget>();
var line = actor.TraitOrDefault<DrawLineToTarget>();
if (line != null)
line.SetTargetSilently(self, Target.FromCell(exitTile.Value), Color.Green);
}

View File

@@ -84,8 +84,8 @@ namespace OpenRA.Mods.RA
public float MovementSpeedForCell(Actor self, int2 cell)
{
var modifier = self.traits
.WithInterface<ISpeedModifier>()
var modifier = self
.TraitsImplementing<ISpeedModifier>()
.Select(t => t.GetSpeedModifier())
.Product();
return Info.Speed * modifier;

View File

@@ -23,13 +23,13 @@ namespace OpenRA.Mods.RA
public IEnumerable<int2> RadarSignatureCells(Actor self)
{
if (Space == null)
Space = self.traits.Get<IOccupySpace>();
Space = self.Trait<IOccupySpace>();
return Space.OccupiedCells();
}
public Color RadarSignatureColor(Actor self)
{
var mod = self.traits.WithInterface<IRadarColorModifier>().FirstOrDefault();
var mod = self.TraitsImplementing<IRadarColorModifier>().FirstOrDefault();
if (mod != null)
return mod.RadarColorOverride(self);

View File

@@ -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<IDisable>().Any(d => d.Disabled)) return false;
if (self.TraitsImplementing<IDisable>().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<IMove>();
var facing = self.traits.GetOrDefault<IFacing>();
var move = self.TraitOrDefault<IMove>();
var facing = self.TraitOrDefault<IFacing>();
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<LimitedAmmo>();
var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();
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<IMove>() : null;
var destMove = target.IsActor ? target.Actor.TraitOrDefault<IMove>() : 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<Turreted>() ? self.traits.Get<Turreted>().turretFacing :
(self.HasTrait<Turreted>() ? self.Trait<Turreted>().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<INotifyAttack>())
foreach (var na in self.TraitsImplementing<INotifyAttack>())
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<DrawLineToTarget>();
var line = self.TraitOrDefault<DrawLineToTarget>();
if (line != null)
if (order.TargetActor != null) line.SetTarget(self, Target.FromOrder(order), Color.Red);
else line.SetTarget(self, Target.FromOrder(order), Color.Red);

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA
if (!target.IsValid) return;
var facing = self.traits.Get<IFacing>().Facing;
var facing = self.Trait<IFacing>().Facing;
var facingToTarget = Util.GetFacing(target.CenterLocation - self.CenterLocation, facing);
if (Math.Abs(facingToTarget - facing) % 256 < FacingTolerance)

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA
if (!target.IsValid) return;
if (self.GetCurrentActivity() is Leap) return;
var weapon = self.traits.Get<AttackBase>().Weapons[0].Info;
var weapon = self.Trait<AttackBase>().Weapons[0].Info;
if (weapon.Range * Game.CellSize * weapon.Range * Game.CellSize
< (target.CenterLocation - self.CenterLocation).LengthSquared) return;

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA
protected override bool CanAttack( Actor self )
{
var isBuilding = ( self.traits.Contains<Building>() && !buildComplete );
var isBuilding = ( self.HasTrait<Building>() && !buildComplete );
return base.CanAttack( self ) && !isBuilding;
}

View File

@@ -68,7 +68,7 @@ namespace OpenRA.Mods.RA
if (target.Actor != previousTarget)
{
previousTarget = target.Actor;
self.traits.Get<RenderBuildingCharge>().PlayCharge(self);
self.Trait<RenderBuildingCharge>().PlayCharge(self);
}
}
}

View File

@@ -25,11 +25,11 @@ namespace OpenRA.Mods.RA
protected override bool CanAttack( Actor self )
{
if( self.traits.Contains<Building>() && !buildComplete )
if( self.HasTrait<Building>() && !buildComplete )
return false;
if (!target.IsValid) return false;
var turreted = self.traits.Get<Turreted>();
var turreted = self.Trait<Turreted>();
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<Building>() && self.traits.Get<Building>().Disabled)
if (self.HasTrait<Building>() && self.Trait<Building>().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<Mobile>())
if (self.HasTrait<Mobile>())
self.QueueActivity( new Follow( target,
Math.Max( 0, (int)weapon.Info.Range - RangeTolerance ) ) );
}

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Mods.RA
{
void AttackTarget(Actor self, Actor target)
{
var attack = self.traits.Get<AttackBase>();
var attack = self.Trait<AttackBase>();
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<AttackBase>();
var attack = self.Trait<AttackBase>();
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<AttackBase>();
var attack = self.Trait<AttackBase>();
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<AttackBase>();
var attack = self.Trait<AttackBase>();
return inRange
.Where(a => a != self && self.Owner.Stances[a.Owner] == Stance.Ally)
.Where(a => !a.IsDead())
.Where(a => a.traits.Contains<Health>() && a.GetDamageState() > DamageState.Undamaged)
.Where(a => a.HasTrait<Health>() && a.GetDamageState() > DamageState.Undamaged)
.Where(a => attack.HasAnyValidWeapons(Target.FromActor(a)))
.OrderBy(a => (a.Location - self.Location).LengthSquared)
.FirstOrDefault();

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA
void AttackTarget(Actor self, Actor target)
{
var attack = self.traits.Get<AttackBase>();
var attack = self.Trait<AttackBase>();
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<AttackBase>();
var attack = self.Trait<AttackBase>();
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<AttackBase>();
var attack = self.Trait<AttackBase>();
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<Cloak>() || !a.traits.Get<Cloak>().Cloaked)
.Where(a => !a.HasTrait<Cloak>() || !a.Trait<Cloak>().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<AttackBase>();
var attack = self.Trait<AttackBase>();
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.

View File

@@ -80,7 +80,7 @@ namespace OpenRA.Mods.RA
public Bridge(Actor self, BridgeInfo info)
{
this.self = self;
Health = self.traits.Get<Health>();
Health = self.Trait<Health>();
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<UnitInfluence>();
var uim = self.World.WorldActor.Trait<UnitInfluence>();
foreach (var c in TileSprites[currentTemplate].Keys)
foreach (var a in uim.GetUnitsAt(c))
if (a.traits.Contains<IMove>() && !a.traits.Get<IMove>().CanEnterCell(c))
if (a.HasTrait<IMove>() && !a.Trait<IMove>().CanEnterCell(c))
a.Kill(self);
}

View File

@@ -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<Bridge>()))
foreach (var b in w.Actors.SelectMany(a => a.TraitsImplementing<Bridge>()))
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<Bridge>();
}).Trait<Bridge>();
Dictionary<int2, byte> subTiles = new Dictionary<int2, byte>();

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA
var anim = new Animation("fire", () => 0);
anim.PlayRepeating(self.Info.Traits.Get<BurnsInfo>().Anim);
self.traits.Get<RenderSimple>().anims.Add("fire",
self.Trait<RenderSimple>().anims.Add("fire",
new RenderSimple.AnimationWithOffset(anim, () => new float2(0, -3), null));
}

View File

@@ -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<Building>()) return null;
if (!underCursor.HasTrait<Building>()) 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<DrawLineToTarget>();
var line = self.TraitOrDefault<DrawLineToTarget>();
if (line != null)
line.SetTarget(self, Target.FromOrder(order), Color.Red);
});

View File

@@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA
return false;
// Cannot unload mid-air
var move = self.traits.GetOrDefault<IMove>();
var move = self.TraitOrDefault<IMove>();
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<Passenger>().ColorOfCargoPip( a );
return a.Trait<Passenger>().ColorOfCargoPip( a );
}
public void Load(Actor self, Actor a)

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA
if ((self.Location - Target).LengthSquared > info.Range * info.Range)
return;
var limitedAmmo = self.traits.GetOrDefault<LimitedAmmo>();
var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();
if (limitedAmmo != null && !limitedAmmo.HasAmmo())
return;
@@ -45,11 +45,11 @@ namespace OpenRA.Mods.RA
var args = new ProjectileArgs
{
srcAltitude = self.traits.Get<IMove>().Altitude,
srcAltitude = self.Trait<IMove>().Altitude,
destAltitude = 0,
src = self.CenterLocation.ToInt2(),
dest = self.CenterLocation.ToInt2(),
facing = self.traits.Get<IFacing>().Facing,
facing = self.Trait<IFacing>().Facing,
firedBy = self,
weapon = weapon
};

View File

@@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA
return;
}
var movement = self.traits.GetOrDefault<IMove>();
var movement = self.TraitOrDefault<IMove>();
if (order.OrderString == "ChronoshiftSelf" && movement.CanEnterCell(order.TargetLocation))
{
if (self.Owner == self.World.LocalPlayer)

View File

@@ -47,9 +47,9 @@ namespace OpenRA.Mods.RA
chronoshiftReturnTicks = duration;
// Kill cargo
if (killCargo && self.traits.Contains<Cargo>())
if (killCargo && self.HasTrait<Cargo>())
{
var cargo = self.traits.Get<Cargo>();
var cargo = self.Trait<Cargo>();
while (!cargo.IsEmpty(self))
{
chronosphere.Owner.Kills++;

View File

@@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA
if (warhead.SmudgeType != null)
{
var smudgeLayer = world.WorldActor.traits.WithInterface<SmudgeLayer>()
var smudgeLayer = world.WorldActor.TraitsImplementing<SmudgeLayer>()
.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<ResourceLayer>().Destroy(targetTile);
world.WorldActor.Trait<ResourceLayer>().Destroy(targetTile);
var firepowerModifier = args.firedBy.traits
.WithInterface<IFirepowerModifier>()
var firepowerModifier = args.firedBy
.TraitsImplementing<IFirepowerModifier>()
.Select(a => a.GetFirepowerModifier())
.Product();
@@ -184,10 +184,10 @@ namespace OpenRA.Mods.RA
var abInfo = self.Info.Traits.GetOrDefault<AttackBaseInfo>();
if (abInfo == null || abInfo.Recoil == 0) return float2.Zero;
var rut = self.traits.GetOrDefault<RenderUnitTurreted>();
var rut = self.TraitOrDefault<RenderUnitTurreted>();
if (rut == null) return float2.Zero;
var facing = self.traits.Get<Turreted>().turretFacing;
var facing = self.Trait<Turreted>().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<RenderUnit>();
var ru = self.TraitOrDefault<RenderUnit>();
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<Turreted>();
var turreted = self.TraitOrDefault<Turreted>();
if (turreted == null && facing == null)
return float2.Zero;

View File

@@ -54,12 +54,12 @@ namespace OpenRA.Mods.RA
this.Info = info;
self.World.WorldActor.traits.Get<UnitInfluence>().Add(self, this);
self.World.WorldActor.Trait<UnitInfluence>().Add(self, this);
}
public void OnCrush(Actor crusher)
{
var shares = self.traits.WithInterface<CrateAction>().Select(
var shares = self.TraitsImplementing<CrateAction>().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<UnitInfluence>();
var uim = self.World.WorldActor.Trait<UnitInfluence>();
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<RenderSimple>().anim.CurrentSequence.Name)
self.traits.Get<RenderSimple>().anim.PlayRepeating(seq);
if (seq != self.Trait<RenderSimple>().anim.CurrentSequence.Name)
self.Trait<RenderSimple>().anim.PlayRepeating(seq);
uim.Add(self, this);
}

View File

@@ -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<BuildingInfluence>().GetBuildingAt(p) != null) continue;
if (self.World.WorldActor.traits.Get<UnitInfluence>().GetUnitsAt(p).Any()) continue;
if (self.World.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(p) != null) continue;
if (self.World.WorldActor.Trait<UnitInfluence>().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<ParaDrop>().SetLZ(p, null);
plane.traits.Get<Cargo>().Load(plane, crate);
plane.Trait<ParaDrop>().SetLZ(p, null);
plane.Trait<Cargo>().Load(plane, crate);
});
return;
}

View File

@@ -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<CrateSpawner>
@@ -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<BuildingInfluence>().GetBuildingAt(p) != null) continue;
if (self.World.WorldActor.traits.Get<UnitInfluence>().GetUnitsAt(p).Any()) continue;
if (self.World.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(p) != null) continue;
if (self.World.WorldActor.Trait<UnitInfluence>().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;
}

View File

@@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA.Crates
public override int GetSelectionShares(Actor collector)
{
return collector.traits.Contains<Cloak>()
return collector.HasTrait<Cloak>()
? 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);
});

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA
collector.World.AddFrameEndTask(w =>
{
var amount = (info as GiveCashCrateActionInfo).Amount;
collector.Owner.PlayerActor.traits.Get<PlayerResources>().GiveCash(amount);
collector.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(amount);
});
base.Activate(collector);
}

View File

@@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA.Crates
int2? ChooseEmptyCellNear(Actor a)
{
// hack: use `a`'s movement capability.
var move = a.traits.Get<ITeleportable>();
var move = a.Trait<ITeleportable>();
var loc = a.Location;
for (var i = -1; i < 2; i++)

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA
{
collector.World.AddFrameEndTask(w =>
{
var gainsExperience = collector.traits.GetOrDefault<GainsExperience>();
var gainsExperience = collector.TraitOrDefault<GainsExperience>();
if (gainsExperience != null)
gainsExperience.GiveOneLevel();
});

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA
{
base.Activate(collector);
if (collector.Owner == collector.World.LocalPlayer)
collector.World.WorldActor.traits.Get<Shroud>().ResetExploration();
collector.World.WorldActor.Trait<Shroud>().ResetExploration();
}
}
}

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Crates
public override void Activate(Actor collector)
{
var p = collector.Owner.PlayerActor.traits.WithInterface<SupportPower>()
var p = collector.Owner.PlayerActor.TraitsImplementing<SupportPower>()
.FirstOrDefault(sp => sp.GetType().Name == (info as SupportPowerCrateActionInfo).Power);
if (p != null) p.Give(1);

View File

@@ -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<DefaultShellmapScript> { }
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<SpawnMapActors>().MapActors;
MapActors = w.WorldActor.Trait<SpawnMapActors>().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<Chronosphere>().Teleport(MapActors["ca1"], new int2(90, 70));
MapActors["pdox"].traits.Get<Chronosphere>().Teleport(MapActors["ca2"], new int2(92, 71));
{
if (ticks == 250)
{
MapActors["pdox"].Trait<Chronosphere>().Teleport(MapActors["ca1"], new int2(90, 70));
MapActors["pdox"].Trait<Chronosphere>().Teleport(MapActors["ca2"], new int2(92, 71));
}
if (ticks == 100)
MapActors["mslo1"].traits.Get<NukeSilo>().Attack(new int2(96,53));
MapActors["mslo1"].Trait<NukeSilo>().Attack(new int2(96,53));
if (ticks == 110)
MapActors["mslo2"].traits.Get<NukeSilo>().Attack(new int2(92,53));
MapActors["mslo2"].Trait<NukeSilo>().Attack(new int2(92,53));
if (ticks == 120)
MapActors["mslo3"].traits.Get<NukeSilo>().Attack(new int2(94,50));
MapActors["mslo3"].Trait<NukeSilo>().Attack(new int2(94,50));
ticks++;
}

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.RA
public void Detonate(Actor self, Actor detonatedBy)
{
var move = self.traits.GetOrDefault<IMove>();
var move = self.TraitOrDefault<IMove>();
var info = self.Info.Traits.Get<AttackBaseInfo>();
var altitude = move != null ? move.Altitude : 0;

View File

@@ -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<Cloak>());
.Where(a => a.HasTrait<Cloak>());
if (!info.AffectOwnUnits)
toDecloak = toDecloak.Where(a => self.Owner.Stances[a.Owner] != Stance.Ally);
foreach (var a in toDecloak)
a.traits.Get<Cloak>().Decloak((int)(25 * info.DecloakTime));
a.Trait<Cloak>().Decloak((int)(25 * info.DecloakTime));
}
}
}

View File

@@ -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<UnitInfluence>().GetUnitsAt(cell).Any(
a => a.traits.Contains<IBlocksBullets>()))
if (world.WorldActor.Trait<UnitInfluence>().GetUnitsAt(cell).Any(
a => a.HasTrait<IBlocksBullets>()))
{
Args.dest = pos.ToInt2();
Explode(world);

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Mods.RA.Effects
public Corpse(Actor fromActor, int death)
{
anim = new Animation(fromActor.traits.GetOrDefault<RenderSimple>().GetImage(fromActor));
anim = new Animation(fromActor.TraitOrDefault<RenderSimple>().GetImage(fromActor));
anim.PlayThen("die{0}".F(death + 1),
() => fromActor.World.AddFrameEndTask(w => w.Remove(this)));

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA.Effects
public InvulnEffect(Actor a)
{
this.a = a;
this.b = a.traits.Get<IronCurtainable>();
this.b = a.Trait<IronCurtainable>();
}
public void Tick( World world )

Some files were not shown because too many files have changed in this diff Show More