Remove Actor.HasTrait<T>()
This commit is contained in:
@@ -226,11 +226,6 @@ namespace OpenRA
|
||||
return World.TraitDict.WithInterface<T>(this);
|
||||
}
|
||||
|
||||
public bool HasTrait<T>()
|
||||
{
|
||||
return World.TraitDict.Contains<T>(this);
|
||||
}
|
||||
|
||||
public void AddTrait(object trait)
|
||||
{
|
||||
World.TraitDict.AddTrait(this, trait);
|
||||
|
||||
@@ -181,7 +181,7 @@ namespace OpenRA.Graphics
|
||||
if (World.Type == WorldType.Regular && Game.Settings.Game.AlwaysShowStatusBars)
|
||||
{
|
||||
foreach (var g in World.Actors.Where(a => !a.Disposed
|
||||
&& a.HasTrait<Selectable>()
|
||||
&& a.Info.Traits.Contains<SelectableInfo>()
|
||||
&& !World.FogObscures(a)
|
||||
&& !World.Selection.Actors.Contains(a)))
|
||||
|
||||
@@ -193,7 +193,7 @@ namespace OpenRA.Graphics
|
||||
|
||||
public void DrawRollover(Actor unit)
|
||||
{
|
||||
if (unit.HasTrait<Selectable>())
|
||||
if (unit.Info.Traits.Contains<SelectableInfo>())
|
||||
new SelectionBarsRenderable(unit).Render(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace OpenRA.Orders
|
||||
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
|
||||
{
|
||||
var underCursor = world.ScreenMap.ActorsAt(mi)
|
||||
.Where(a => !world.FogObscures(a) && a.HasTrait<ITargetable>())
|
||||
.Where(a => !world.FogObscures(a) && a.Info.Traits.Contains<ITargetableInfo>())
|
||||
.WithHighestSelectionPriority();
|
||||
|
||||
Target target;
|
||||
@@ -58,12 +58,12 @@ namespace OpenRA.Orders
|
||||
{
|
||||
var useSelect = false;
|
||||
var underCursor = world.ScreenMap.ActorsAt(mi)
|
||||
.Where(a => !world.FogObscures(a) && a.HasTrait<ITargetable>())
|
||||
.Where(a => !world.FogObscures(a) && a.Info.Traits.Contains<ITargetableInfo>())
|
||||
.WithHighestSelectionPriority();
|
||||
|
||||
if (underCursor != null && (mi.Modifiers.HasModifier(Modifiers.Shift) || !world.Selection.Actors.Any()))
|
||||
{
|
||||
if (underCursor.HasTrait<Selectable>())
|
||||
if (underCursor.Info.Traits.Contains<SelectableInfo>())
|
||||
useSelect = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -84,12 +84,6 @@ namespace OpenRA
|
||||
throw new InvalidOperationException("Attempted to get trait from destroyed object ({0})".F(actor));
|
||||
}
|
||||
|
||||
public bool Contains<T>(Actor actor)
|
||||
{
|
||||
CheckDestroyed(actor);
|
||||
return InnerGet<T>().GetMultiple(actor.ActorID).Any();
|
||||
}
|
||||
|
||||
public T Get<T>(Actor actor)
|
||||
{
|
||||
CheckDestroyed(actor);
|
||||
|
||||
@@ -144,13 +144,13 @@ namespace OpenRA.Traits
|
||||
Player Owner { get; }
|
||||
}
|
||||
|
||||
public interface IToolTip
|
||||
public interface ITooltip
|
||||
{
|
||||
ITooltipInfo TooltipInfo { get; }
|
||||
Player Owner { get; }
|
||||
}
|
||||
|
||||
public interface ITooltipInfo
|
||||
public interface ITooltipInfo : ITraitInfo
|
||||
{
|
||||
string TooltipForPlayerStance(Stance stance);
|
||||
bool IsOwnerRowVisible { get; }
|
||||
@@ -226,6 +226,7 @@ namespace OpenRA.Traits
|
||||
public interface ITags { IEnumerable<TagType> GetTags(); }
|
||||
public interface ISelectionBar { float GetValue(); Color GetColor(); }
|
||||
|
||||
public interface IPositionableInfo : ITraitInfo { }
|
||||
public interface IPositionable : IOccupySpace
|
||||
{
|
||||
bool IsLeavingCell(CPos location, SubCell subCell = SubCell.Any);
|
||||
@@ -296,6 +297,7 @@ namespace OpenRA.Traits
|
||||
public interface INotifyBecomingIdle { void OnBecomingIdle(Actor self); }
|
||||
public interface INotifyIdle { void TickIdle(Actor self); }
|
||||
|
||||
public interface IBlocksProjectilesInfo : ITraitInfo { }
|
||||
public interface IBlocksProjectiles { }
|
||||
public interface IRenderInfantrySequenceModifier
|
||||
{
|
||||
@@ -309,7 +311,7 @@ namespace OpenRA.Traits
|
||||
|
||||
public interface IPostRenderSelection { IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr); }
|
||||
|
||||
public interface ITargetableInfo
|
||||
public interface ITargetableInfo : ITraitInfo
|
||||
{
|
||||
HashSet<string> GetTargetTypes();
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
if (!hasBox && World.Selection.Actors.Any() && !multiClick)
|
||||
{
|
||||
if (!(World.ScreenMap.ActorsAt(xy).Where(x => x.HasTrait<Selectable>() &&
|
||||
if (!(World.ScreenMap.ActorsAt(xy).Where(x => x.Info.Traits.Contains<SelectableInfo>() &&
|
||||
(x.Owner.IsAlliedWith(World.RenderPlayer) || !World.FogObscures(x))).Any() && !mi.Modifiers.HasModifier(Modifiers.Ctrl) &&
|
||||
!mi.Modifiers.HasModifier(Modifiers.Alt) && UnitOrderGenerator.InputOverridesSelection(World, xy, mi)))
|
||||
{
|
||||
@@ -301,7 +301,7 @@ namespace OpenRA.Widgets
|
||||
a = b;
|
||||
|
||||
return world.ScreenMap.ActorsInBox(a, b)
|
||||
.Where(x => x.HasTrait<Selectable>() && (x.Owner.IsAlliedWith(world.RenderPlayer) || !world.FogObscures(x)))
|
||||
.Where(x => x.Info.Traits.Contains<SelectableInfo>() && (x.Owner.IsAlliedWith(world.RenderPlayer) || !world.FogObscures(x)))
|
||||
.SubsetWithHighestSelectionPriority();
|
||||
}
|
||||
|
||||
|
||||
@@ -176,7 +176,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
var sumOfHp = 0;
|
||||
foreach (var a in actors)
|
||||
{
|
||||
if (a.HasTrait<Health>())
|
||||
if (a.Info.Traits.Contains<HealthInfo>())
|
||||
{
|
||||
sumOfMaxHp += a.Trait<Health>().MaxHP;
|
||||
sumOfHp += a.Trait<Health>().HP;
|
||||
@@ -191,7 +191,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
|
||||
protected float RelativePower(IEnumerable<Actor> own, IEnumerable<Actor> enemy)
|
||||
{
|
||||
return RelativeValue(own, enemy, 100, SumOfValues<AttackBase>, a =>
|
||||
return RelativeValue(own, enemy, 100, SumOfValues<AttackBaseInfo>, a =>
|
||||
{
|
||||
var sumOfDamage = 0;
|
||||
var arms = a.TraitsImplementing<Armament>();
|
||||
@@ -208,7 +208,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
|
||||
protected float RelativeSpeed(IEnumerable<Actor> own, IEnumerable<Actor> enemy)
|
||||
{
|
||||
return RelativeValue(own, enemy, 100, Average<Mobile>, (Actor a) => a.Trait<Mobile>().Info.Speed);
|
||||
return RelativeValue(own, enemy, 100, Average<MobileInfo>, (Actor a) => a.Trait<Mobile>().Info.Speed);
|
||||
}
|
||||
|
||||
protected static float RelativeValue(IEnumerable<Actor> own, IEnumerable<Actor> enemy, float normalizeByValue,
|
||||
@@ -224,23 +224,23 @@ namespace OpenRA.Mods.Common.AI
|
||||
return relative.Clamp(0.0f, 999.0f);
|
||||
}
|
||||
|
||||
protected float SumOfValues<Trait>(IEnumerable<Actor> actors, Func<Actor, int> getValue)
|
||||
protected float SumOfValues<TTraitInfo>(IEnumerable<Actor> actors, Func<Actor, int> getValue) where TTraitInfo : ITraitInfo
|
||||
{
|
||||
var sum = 0;
|
||||
foreach (var a in actors)
|
||||
if (a.HasTrait<Trait>())
|
||||
if (a.Info.Traits.Contains<TTraitInfo>())
|
||||
sum += getValue(a);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
protected float Average<Trait>(IEnumerable<Actor> actors, Func<Actor, int> getValue)
|
||||
protected float Average<TTraitInfo>(IEnumerable<Actor> actors, Func<Actor, int> getValue) where TTraitInfo : ITraitInfo
|
||||
{
|
||||
var sum = 0;
|
||||
var countActors = 0;
|
||||
foreach (var a in actors)
|
||||
{
|
||||
if (a.HasTrait<Trait>())
|
||||
if (a.Info.Traits.Contains<TTraitInfo>())
|
||||
{
|
||||
sum += getValue(a);
|
||||
countActors++;
|
||||
|
||||
@@ -167,8 +167,8 @@ namespace OpenRA.Mods.Common.AI
|
||||
{
|
||||
var randomBaseBuilding = World.Actors.Where(
|
||||
a => a.Owner == Player
|
||||
&& a.HasTrait<BaseBuilding>()
|
||||
&& !a.HasTrait<Mobile>())
|
||||
&& a.Info.Traits.Contains<BaseBuildingInfo>()
|
||||
&& !a.Info.Traits.Contains<MobileInfo>())
|
||||
.RandomOrDefault(Random);
|
||||
|
||||
return randomBaseBuilding != null ? randomBaseBuilding.Location : initialBaseCenter;
|
||||
@@ -232,7 +232,9 @@ namespace OpenRA.Mods.Common.AI
|
||||
pathfinder = World.WorldActor.Trait<IPathFinder>();
|
||||
|
||||
isEnemyUnit = unit =>
|
||||
Player.Stances[unit.Owner] == Stance.Enemy && !unit.HasTrait<Husk>() && unit.HasTrait<ITargetable>();
|
||||
Player.Stances[unit.Owner] == Stance.Enemy
|
||||
&& !unit.Info.Traits.Contains<HuskInfo>()
|
||||
&& unit.Info.Traits.Contains<ITargetableInfo>();
|
||||
|
||||
foreach (var decision in info.PowerDecisions)
|
||||
powerDecisions.Add(decision.OrderName, decision);
|
||||
@@ -279,8 +281,8 @@ namespace OpenRA.Mods.Common.AI
|
||||
{
|
||||
var baseProviders = World.Actors.Where(
|
||||
a => a.Owner == Player
|
||||
&& a.HasTrait<BaseProvider>()
|
||||
&& !a.HasTrait<Mobile>());
|
||||
&& a.Info.Traits.Contains<BaseProviderInfo>()
|
||||
&& !a.Info.Traits.Contains<MobileInfo>());
|
||||
|
||||
foreach (var b in baseProviders)
|
||||
{
|
||||
@@ -306,8 +308,8 @@ namespace OpenRA.Mods.Common.AI
|
||||
{
|
||||
var areaProviders = World.Actors.Where(
|
||||
a => a.Owner == Player
|
||||
&& a.HasTrait<GivesBuildableArea>()
|
||||
&& !a.HasTrait<Mobile>());
|
||||
&& a.Info.Traits.Contains<GivesBuildableAreaInfo>()
|
||||
&& !a.Info.Traits.Contains<MobileInfo>());
|
||||
|
||||
foreach (var a in areaProviders)
|
||||
{
|
||||
@@ -487,7 +489,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
case BuildingType.Defense:
|
||||
|
||||
// Build near the closest enemy structure
|
||||
var closestEnemy = World.Actors.Where(a => !a.Disposed && a.HasTrait<Building>() && Player.Stances[a.Owner] == Stance.Enemy)
|
||||
var closestEnemy = World.Actors.Where(a => !a.Disposed && a.Info.Traits.Contains<BuildingInfo>() && Player.Stances[a.Owner] == Stance.Enemy)
|
||||
.ClosestTo(World.Map.CenterOfCell(defenseCenter));
|
||||
|
||||
var targetCell = closestEnemy != null ? closestEnemy.Location : baseCenter;
|
||||
@@ -563,7 +565,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
|
||||
// Pick something worth attacking owned by that player
|
||||
var target = World.Actors
|
||||
.Where(a => a.Owner == enemy && a.HasTrait<IOccupySpace>())
|
||||
.Where(a => a.Owner == enemy && a.Info.Traits.Contains<IOccupySpaceInfo>())
|
||||
.ClosestTo(World.Map.CenterOfCell(GetRandomBaseCenter()));
|
||||
|
||||
if (target == null)
|
||||
@@ -595,7 +597,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
List<Actor> FindEnemyConstructionYards()
|
||||
{
|
||||
return World.Actors.Where(a => Player.Stances[a.Owner] == Stance.Enemy && !a.IsDead
|
||||
&& a.HasTrait<BaseBuilding>() && !a.HasTrait<Mobile>()).ToList();
|
||||
&& a.Info.Traits.Contains<BaseBuildingInfo>() && !a.Info.Traits.Contains<MobileInfo>()).ToList();
|
||||
}
|
||||
|
||||
void CleanSquads()
|
||||
@@ -705,18 +707,18 @@ namespace OpenRA.Mods.Common.AI
|
||||
void FindNewUnits(Actor self)
|
||||
{
|
||||
var newUnits = self.World.ActorsWithTrait<IPositionable>()
|
||||
.Where(a => a.Actor.Owner == Player && !a.Actor.HasTrait<BaseBuilding>()
|
||||
.Where(a => a.Actor.Owner == Player && !a.Actor.Info.Traits.Contains<BaseBuildingInfo>()
|
||||
&& !activeUnits.Contains(a.Actor))
|
||||
.Select(a => a.Actor);
|
||||
|
||||
foreach (var a in newUnits)
|
||||
{
|
||||
if (a.HasTrait<Harvester>())
|
||||
if (a.Info.Traits.Contains<HarvesterInfo>())
|
||||
QueueOrder(new Order("Harvest", a, false));
|
||||
else
|
||||
unitsHangingAroundTheBase.Add(a);
|
||||
|
||||
if (a.HasTrait<Aircraft>() && a.HasTrait<AttackBase>())
|
||||
if (a.Info.Traits.Contains<AircraftInfo>() && a.Info.Traits.Contains<AttackBaseInfo>())
|
||||
{
|
||||
var air = GetSquadOfType(SquadType.Air);
|
||||
if (air == null)
|
||||
@@ -740,7 +742,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
var attackForce = RegisterNewSquad(SquadType.Assault);
|
||||
|
||||
foreach (var a in unitsHangingAroundTheBase)
|
||||
if (!a.HasTrait<Aircraft>())
|
||||
if (!a.Info.Traits.Contains<AircraftInfo>())
|
||||
attackForce.Units.Add(a);
|
||||
|
||||
unitsHangingAroundTheBase.Clear();
|
||||
@@ -751,7 +753,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
{
|
||||
var allEnemyBaseBuilder = FindEnemyConstructionYards();
|
||||
var ownUnits = activeUnits
|
||||
.Where(unit => unit.HasTrait<AttackBase>() && !unit.HasTrait<Aircraft>() && unit.IsIdle).ToList();
|
||||
.Where(unit => unit.Info.Traits.Contains<AttackBaseInfo>() && !unit.Info.Traits.Contains<AircraftInfo>() && unit.IsIdle).ToList();
|
||||
|
||||
if (!allEnemyBaseBuilder.Any() || (ownUnits.Count < Info.SquadSize))
|
||||
return;
|
||||
@@ -759,7 +761,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
foreach (var b in allEnemyBaseBuilder)
|
||||
{
|
||||
var enemies = World.FindActorsInCircle(b.CenterPosition, WDist.FromCells(Info.RushAttackScanRadius))
|
||||
.Where(unit => Player.Stances[unit.Owner] == Stance.Enemy && unit.HasTrait<AttackBase>()).ToList();
|
||||
.Where(unit => Player.Stances[unit.Owner] == Stance.Enemy && unit.Info.Traits.Contains<AttackBaseInfo>()).ToList();
|
||||
|
||||
if (rushFuzzy.CanAttack(ownUnits, enemies))
|
||||
{
|
||||
@@ -788,8 +790,8 @@ namespace OpenRA.Mods.Common.AI
|
||||
if (!protectSq.IsValid)
|
||||
{
|
||||
var ownUnits = World.FindActorsInCircle(World.Map.CenterOfCell(GetRandomBaseCenter()), WDist.FromCells(Info.ProtectUnitScanRadius))
|
||||
.Where(unit => unit.Owner == Player && !unit.HasTrait<Building>()
|
||||
&& unit.HasTrait<AttackBase>());
|
||||
.Where(unit => unit.Owner == Player && !unit.Info.Traits.Contains<BuildingInfo>()
|
||||
&& unit.Info.Traits.Contains<AttackBaseInfo>());
|
||||
|
||||
foreach (var a in ownUnits)
|
||||
protectSq.Units.Add(a);
|
||||
@@ -830,7 +832,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
{
|
||||
// Find and deploy our mcv
|
||||
var mcv = self.World.Actors
|
||||
.FirstOrDefault(a => a.Owner == Player && a.HasTrait<BaseBuilding>());
|
||||
.FirstOrDefault(a => a.Owner == Player && a.Info.Traits.Contains<BaseBuildingInfo>());
|
||||
|
||||
if (mcv != null)
|
||||
{
|
||||
@@ -839,7 +841,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
|
||||
// Don't transform the mcv if it is a fact
|
||||
// HACK: This needs to query against MCVs directly
|
||||
if (mcv.HasTrait<Mobile>())
|
||||
if (mcv.Info.Traits.Contains<MobileInfo>())
|
||||
QueueOrder(new Order("DeployTransform", mcv, false));
|
||||
}
|
||||
else
|
||||
@@ -851,7 +853,8 @@ namespace OpenRA.Mods.Common.AI
|
||||
void FindAndDeployBackupMcv(Actor self)
|
||||
{
|
||||
// HACK: This needs to query against MCVs directly
|
||||
var mcvs = self.World.Actors.Where(a => a.Owner == Player && a.HasTrait<BaseBuilding>() && a.HasTrait<Mobile>());
|
||||
var mcvs = self.World.Actors
|
||||
.Where(a => a.Owner == Player && a.Info.Traits.Contains<BaseBuildingInfo>() && a.Info.Traits.Contains<MobileInfo>());
|
||||
if (!mcvs.Any())
|
||||
return;
|
||||
|
||||
@@ -1010,7 +1013,8 @@ namespace OpenRA.Mods.Common.AI
|
||||
return;
|
||||
|
||||
// No construction yards - Build a new MCV
|
||||
if (!HasAdequateFact() && !self.World.Actors.Any(a => a.Owner == Player && a.HasTrait<BaseBuilding>() && a.HasTrait<Mobile>()))
|
||||
if (!HasAdequateFact() && !self.World.Actors.Any(a =>
|
||||
a.Owner == Player && a.Info.Traits.Contains<BaseBuildingInfo>() && a.Info.Traits.Contains<MobileInfo>()))
|
||||
BuildUnit("Vehicle", GetUnitInfoByCommonName("Mcv", Player).Name);
|
||||
|
||||
foreach (var q in Info.UnitQueues)
|
||||
@@ -1069,14 +1073,14 @@ namespace OpenRA.Mods.Common.AI
|
||||
if (e.Attacker.Disposed)
|
||||
return;
|
||||
|
||||
if (!e.Attacker.HasTrait<ITargetable>())
|
||||
if (!e.Attacker.Info.Traits.Contains<ITargetableInfo>())
|
||||
return;
|
||||
|
||||
if (e.Damage > 0)
|
||||
aggro[e.Attacker.Owner].Aggro += e.Damage;
|
||||
|
||||
// Protected harvesters or building
|
||||
if ((self.HasTrait<Harvester>() || self.HasTrait<Building>()) &&
|
||||
if ((self.Info.Traits.Contains<HarvesterInfo>() || self.Info.Traits.Contains<BuildingInfo>()) &&
|
||||
Player.Stances[e.Attacker.Owner] == Stance.Enemy)
|
||||
{
|
||||
defenseCenter = e.Attacker.Location;
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
|
||||
public bool IsTargetValid
|
||||
{
|
||||
get { return Target.IsValidFor(Units.FirstOrDefault()) && !Target.Actor.HasTrait<Husk>(); }
|
||||
get { return Target.IsValidFor(Units.FirstOrDefault()) && !Target.Actor.Info.Traits.Contains<HuskInfo>(); }
|
||||
}
|
||||
|
||||
public bool IsTargetVisible
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
var missileUnitsCount = 0;
|
||||
foreach (var unit in units)
|
||||
{
|
||||
if (unit != null && unit.HasTrait<AttackBase>() && !unit.HasTrait<Aircraft>()
|
||||
if (unit != null && unit.Info.Traits.Contains<AttackBaseInfo>() && !unit.Info.Traits.Contains<AircraftInfo>()
|
||||
&& !unit.IsDisabled())
|
||||
{
|
||||
var arms = unit.TraitsImplementing<Armament>();
|
||||
@@ -223,7 +223,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
continue;
|
||||
}
|
||||
|
||||
if (owner.TargetActor.HasTrait<ITargetable>() && CanAttackTarget(a, owner.TargetActor))
|
||||
if (owner.TargetActor.Info.Traits.Contains<ITargetableInfo>() && CanAttackTarget(a, owner.TargetActor))
|
||||
owner.Bot.QueueOrder(new Order("Attack", a, false) { TargetActor = owner.TargetActor });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
{
|
||||
var enemies = owner.World.FindActorsInCircle(leader.CenterPosition, WDist.FromCells(12))
|
||||
.Where(a1 => !a1.Disposed && !a1.IsDead);
|
||||
var enemynearby = enemies.Where(a1 => a1.HasTrait<ITargetable>() && leader.Owner.Stances[a1.Owner] == Stance.Enemy);
|
||||
var enemynearby = enemies.Where(a1 => a1.Info.Traits.Contains<ITargetableInfo>() && leader.Owner.Stances[a1.Owner] == Stance.Enemy);
|
||||
var target = enemynearby.ClosestTo(leader.CenterPosition);
|
||||
if (target != null)
|
||||
{
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
|
||||
protected static bool CanAttackTarget(Actor a, Actor target)
|
||||
{
|
||||
if (!a.HasTrait<AttackBase>())
|
||||
if (!a.Info.Traits.Contains<AttackBaseInfo>())
|
||||
return false;
|
||||
|
||||
var targetTypes = target.TraitsImplementing<ITargetable>().Where(Exts.IsTraitEnabled).SelectMany(t => t.TargetTypes);
|
||||
@@ -82,11 +82,11 @@ namespace OpenRA.Mods.Common.AI
|
||||
|
||||
var u = squad.Units.Random(squad.Random);
|
||||
var units = squad.World.FindActorsInCircle(u.CenterPosition, WDist.FromCells(DangerRadius)).ToList();
|
||||
var ownBaseBuildingAround = units.Where(unit => unit.Owner == squad.Bot.Player && unit.HasTrait<Building>());
|
||||
var ownBaseBuildingAround = units.Where(unit => unit.Owner == squad.Bot.Player && unit.Info.Traits.Contains<BuildingInfo>());
|
||||
if (ownBaseBuildingAround.Any())
|
||||
return false;
|
||||
|
||||
var enemyAroundUnit = units.Where(unit => squad.Bot.Player.Stances[unit.Owner] == Stance.Enemy && unit.HasTrait<AttackBase>());
|
||||
var enemyAroundUnit = units.Where(unit => squad.Bot.Player.Stances[unit.Owner] == Stance.Enemy && unit.Info.Traits.Contains<AttackBaseInfo>());
|
||||
if (!enemyAroundUnit.Any())
|
||||
return false;
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
target = value;
|
||||
if (target.Type == TargetType.Actor)
|
||||
canHideUnderFog = target.Actor.HasTrait<HiddenUnderFog>();
|
||||
canHideUnderFog = target.Actor.Info.Traits.Contains<HiddenUnderFogInfo>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
// HACK: This would otherwise break targeting frozen actors
|
||||
// The problem is that Shroud.IsTargetable returns false (as it should) for
|
||||
// frozen actors, but we do want to explicitly target the underlying actor here.
|
||||
if (!attack.Info.IgnoresVisibility && type == TargetType.Actor && !Target.Actor.HasTrait<FrozenUnderFog>() && !self.Owner.CanTargetActor(Target.Actor))
|
||||
if (!attack.Info.IgnoresVisibility && type == TargetType.Actor && !Target.Actor.Info.Traits.Contains<FrozenUnderFogInfo>() && !self.Owner.CanTargetActor(Target.Actor))
|
||||
return NextActivity;
|
||||
|
||||
// Try to move within range
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
var attack = self.Trait<AttackBase>();
|
||||
targets = self.World.Actors.Where(a => self != a && !a.IsDead && a.IsInWorld && a.AppearsHostileTo(self)
|
||||
&& a.HasTrait<Huntable>() && IsTargetable(a, self) && attack.HasAnyValidWeapons(Target.FromActor(a)));
|
||||
&& a.Info.Traits.Contains<HuntableInfo>() && IsTargetable(a, self) && attack.HasAnyValidWeapons(Target.FromActor(a)));
|
||||
}
|
||||
|
||||
bool IsTargetable(Actor self, Actor viewer)
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
target = value;
|
||||
if (target.Type == TargetType.Actor)
|
||||
canHideUnderFog = target.Actor.HasTrait<HiddenUnderFog>();
|
||||
canHideUnderFog = target.Actor.Info.Traits.Contains<HiddenUnderFogInfo>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,8 @@ namespace OpenRA.Mods.Common.Activities
|
||||
continue;
|
||||
|
||||
// HACK to check if we are on the helipad/airfield/etc.
|
||||
var hostBuilding = self.World.ActorMap.GetUnitsAt(self.Location).FirstOrDefault(a => a.HasTrait<Building>());
|
||||
var hostBuilding = self.World.ActorMap.GetUnitsAt(self.Location)
|
||||
.FirstOrDefault(a => a.Info.Traits.Contains<BuildingInfo>());
|
||||
|
||||
if (hostBuilding == null || !hostBuilding.IsInWorld)
|
||||
return NextActivity;
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common
|
||||
if (self.IsDead)
|
||||
return false;
|
||||
|
||||
if (!self.HasTrait<IOccupySpace>())
|
||||
if (!self.Info.Traits.Contains<IOccupySpace>())
|
||||
return false;
|
||||
|
||||
if (!self.IsInWorld)
|
||||
@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common
|
||||
if (stance == Stance.Ally)
|
||||
return true;
|
||||
|
||||
if (self.EffectiveOwner != null && self.EffectiveOwner.Disguised && !toActor.HasTrait<IgnoresDisguise>())
|
||||
if (self.EffectiveOwner != null && self.EffectiveOwner.Disguised && !toActor.Info.Traits.Contains<IgnoresDisguiseInfo>())
|
||||
return toActor.Owner.Stances[self.EffectiveOwner.Owner] == Stance.Ally;
|
||||
|
||||
return stance == Stance.Ally;
|
||||
@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common
|
||||
if (stance == Stance.Ally)
|
||||
return false; /* otherwise, we'll hate friendly disguised spies */
|
||||
|
||||
if (self.EffectiveOwner != null && self.EffectiveOwner.Disguised && !toActor.HasTrait<IgnoresDisguise>())
|
||||
if (self.EffectiveOwner != null && self.EffectiveOwner.Disguised && !toActor.Info.Traits.Contains<IgnoresDisguiseInfo>())
|
||||
return toActor.Owner.Stances[self.EffectiveOwner.Owner] == Stance.Enemy;
|
||||
|
||||
return stance == Stance.Enemy;
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace OpenRA.Mods.Common.Commands
|
||||
var leveluporder = new Order("DevLevelUp", actor, false);
|
||||
leveluporder.ExtraData = (uint)level;
|
||||
|
||||
if (actor.HasTrait<GainsExperience>())
|
||||
if (actor.Info.Traits.Contains<GainsExperienceInfo>())
|
||||
world.IssueOrder(leveluporder);
|
||||
}
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ namespace OpenRA.Mods.Common.Effects
|
||||
contrail.Update(pos);
|
||||
|
||||
if (ticks++ >= length || (info.Blockable && world.ActorMap
|
||||
.GetUnitsAt(world.Map.CellContaining(pos)).Any(a => a.HasTrait<IBlocksProjectiles>())))
|
||||
.GetUnitsAt(world.Map.CellContaining(pos)).Any(a => a.Info.Traits.Contains<IBlocksProjectilesInfo>())))
|
||||
Explode(world);
|
||||
}
|
||||
|
||||
|
||||
@@ -201,7 +201,7 @@ namespace OpenRA.Mods.Common.Effects
|
||||
var shouldExplode = (pos.Z < 0) // Hit the ground
|
||||
|| (dist.LengthSquared < info.CloseEnough.LengthSquared) // Within range
|
||||
|| (info.RangeLimit != 0 && ticks > info.RangeLimit) // Ran out of fuel
|
||||
|| (info.Blockable && world.ActorMap.GetUnitsAt(cell).Any(a => a.HasTrait<IBlocksProjectiles>())) // Hit a wall or other blocking obstacle
|
||||
|| (info.Blockable && world.ActorMap.GetUnitsAt(cell).Any(a => a.Info.Traits.Contains<IBlocksProjectilesInfo>())) // Hit a wall or other blocking obstacle
|
||||
|| !world.Map.Contains(cell) // This also avoids an IndexOutOfRangeException in GetTerrainInfo below.
|
||||
|| (!string.IsNullOrEmpty(info.BoundToTerrainType) && world.Map.GetTerrainInfo(cell).Type != info.BoundToTerrainType); // Hit incompatible terrain
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Orders
|
||||
{
|
||||
public class EnterAlliedActorTargeter<T> : UnitOrderTargeter
|
||||
public class EnterAlliedActorTargeter<T> : UnitOrderTargeter where T : ITraitInfo
|
||||
{
|
||||
readonly Func<Actor, bool> canTarget;
|
||||
readonly Func<Actor, bool> useEnterCursor;
|
||||
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Orders
|
||||
|
||||
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
if (!target.HasTrait<T>() || !canTarget(target))
|
||||
if (!target.Info.Traits.Contains<T>() || !canTarget(target))
|
||||
return false;
|
||||
|
||||
cursor = useEnterCursor(target) ? "enter" : "enter-blocked";
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
if (!target.IsValidFor(Self) || target.Type == TargetType.FrozenActor)
|
||||
Log.Write("lua", "{1} is an invalid target for {0}!", Self, targetActor);
|
||||
|
||||
if (!targetActor.HasTrait<FrozenUnderFog>() && !Self.Owner.CanTargetActor(targetActor))
|
||||
if (!targetActor.Info.Traits.Contains<FrozenUnderFogInfo>() && !Self.Owner.CanTargetActor(targetActor))
|
||||
Log.Write("lua", "{1} is not revealed for player {0}!", Self.Owner, targetActor);
|
||||
|
||||
attackBase.AttackTarget(target, true, allowMove);
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
[Desc("Guard the target actor.")]
|
||||
public void Guard(Actor targetActor)
|
||||
{
|
||||
if (targetActor.HasTrait<Guardable>())
|
||||
if (targetActor.Info.Traits.Contains<GuardableInfo>())
|
||||
guard.GuardTarget(Self, Target.FromActor(targetActor));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
public Actor[] GetGroundAttackers()
|
||||
{
|
||||
return Player.World.ActorsWithTrait<AttackBase>().Select(a => a.Actor)
|
||||
.Where(a => a.Owner == Player && !a.IsDead && a.IsInWorld && a.HasTrait<Mobile>())
|
||||
.Where(a => a.Owner == Player && !a.IsDead && a.IsInWorld && a.Info.Traits.Contains<MobileInfo>())
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public class AircraftInfo : ITraitInfo, IFacingInfo, IOccupySpaceInfo, ICruiseAltitudeInfo, UsesInit<LocationInit>, UsesInit<FacingInit>
|
||||
public class AircraftInfo : IPositionableInfo, IFacingInfo, IOccupySpaceInfo, ICruiseAltitudeInfo, UsesInit<LocationInit>, UsesInit<FacingInit>
|
||||
{
|
||||
public readonly WDist CruiseAltitude = new WDist(1280);
|
||||
public readonly WDist IdealSeparation = new WDist(1706);
|
||||
@@ -120,7 +120,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
firstTick = false;
|
||||
|
||||
// TODO: Aircraft husks don't properly unreserve.
|
||||
if (self.HasTrait<FallsToEarth>())
|
||||
if (self.Info.Traits.Contains<FallsToEarthInfo>())
|
||||
return;
|
||||
|
||||
ReserveSpawnBuilding();
|
||||
@@ -158,7 +158,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return WVec.Zero;
|
||||
|
||||
return self.World.FindActorsInCircle(self.CenterPosition, info.IdealSeparation)
|
||||
.Where(a => !a.IsDead && a.HasTrait<Aircraft>() && a.Info.Traits.Get<AircraftInfo>().CruiseAltitude == info.CruiseAltitude)
|
||||
.Where(a => !a.IsDead && a.Info.Traits.Contains<AircraftInfo>() && a.Info.Traits.Get<AircraftInfo>().CruiseAltitude == info.CruiseAltitude)
|
||||
.Select(GetRepulsionForce)
|
||||
.Aggregate(WVec.Zero, (a, b) => a + b);
|
||||
}
|
||||
@@ -191,7 +191,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return null; // not on the ground.
|
||||
|
||||
return self.World.ActorMap.GetUnitsAt(self.Location)
|
||||
.FirstOrDefault(a => a.HasTrait<Reservable>());
|
||||
.FirstOrDefault(a => a.Info.Traits.Contains<ReservableInfo>());
|
||||
}
|
||||
|
||||
protected void ReserveSpawnBuilding()
|
||||
@@ -341,7 +341,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return new EnterAlliedActorTargeter<Building>("Enter", 5,
|
||||
yield return new EnterAlliedActorTargeter<BuildingInfo>("Enter", 5,
|
||||
target => AircraftCanEnter(target), target => !Reservable.IsReserved(target));
|
||||
|
||||
yield return new AircraftMoveOrderTargeter(info);
|
||||
|
||||
@@ -202,7 +202,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public bool IsReachableTarget(Target target, bool allowMove)
|
||||
{
|
||||
return HasAnyValidWeapons(target)
|
||||
&& (target.IsInRange(self.CenterPosition, GetMaximumRange()) || (allowMove && self.HasTrait<IMove>()));
|
||||
&& (target.IsInRange(self.CenterPosition, GetMaximumRange()) || (allowMove && self.Info.Traits.Contains<IMoveInfo>()));
|
||||
}
|
||||
|
||||
class AttackOrderTargeter : IOrderTargeter
|
||||
|
||||
@@ -81,8 +81,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var weapon = attack.ChooseArmamentForTarget(target);
|
||||
if (weapon != null)
|
||||
{
|
||||
var targetIsMobile = (target.Type == TargetType.Actor && target.Actor.HasTrait<IMove>())
|
||||
|| (target.Type == TargetType.FrozenActor && target.FrozenActor.Info.Traits.Contains<IMove>());
|
||||
var targetIsMobile = (target.Type == TargetType.Actor && target.Actor.Info.Traits.Contains<IMoveInfo>())
|
||||
|| (target.Type == TargetType.FrozenActor && target.FrozenActor.Info.Traits.Contains<IMoveInfo>());
|
||||
|
||||
// Try and sit at least one cell closer than the max range to give some leeway if the target starts moving.
|
||||
var maxRange = targetIsMobile ? new WDist(Math.Max(weapon.Weapon.MinRange.Length, weapon.Weapon.Range.Length - 1024))
|
||||
|
||||
@@ -154,7 +154,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return inRange
|
||||
.Where(a =>
|
||||
a.AppearsHostileTo(self) &&
|
||||
!a.HasTrait<AutoTargetIgnore>() &&
|
||||
!a.Info.Traits.Contains<AutoTargetIgnoreInfo>() &&
|
||||
attack.HasAnyValidWeapons(Target.FromActor(a)) &&
|
||||
self.Owner.CanTargetActor(a))
|
||||
.ClosestTo(self);
|
||||
|
||||
@@ -15,6 +15,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
// TODO: Add functionality like a customizable Height that is compared to projectile altitude
|
||||
[Desc("This actor blocks bullets and missiles with 'Blockable' property.")]
|
||||
public class BlocksProjectilesInfo : TraitInfo<BlocksProjectiles> { }
|
||||
public class BlocksProjectilesInfo : TraitInfo<BlocksProjectiles>, IBlocksProjectilesInfo { }
|
||||
public class BlocksProjectiles : IBlocksProjectiles { }
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// If a sprite actor has neither custom QuantizedFacings nor a trait implementing IQuantizeBodyOrientationInfo, throw
|
||||
if (qboi == null)
|
||||
{
|
||||
if (self.HasTrait<ISpriteBody>())
|
||||
if (self.Info.Traits.Contains<ISpriteBodyInfo>())
|
||||
throw new InvalidOperationException("Actor '" + self.Info.Name + "' has a sprite body but no facing quantization."
|
||||
+ " Either add the QuantizeFacingsFromSequence trait or set custom QuantizedFacings on BodyOrientation.");
|
||||
else
|
||||
|
||||
@@ -201,7 +201,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
foreach (var c in footprint.Keys)
|
||||
foreach (var a in self.World.ActorMap.GetUnitsAt(c))
|
||||
if (a.HasTrait<IPositionable>() && !a.Trait<IPositionable>().CanEnterCell(c))
|
||||
if (a.Info.Traits.Contains<IPositionableInfo>() && !a.Trait<IPositionable>().CanEnterCell(c))
|
||||
a.Kill(self);
|
||||
}
|
||||
|
||||
|
||||
@@ -87,12 +87,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
var unitsAtPos = world.ActorMap.GetUnitsAt(pos).Where(a => a.IsInWorld
|
||||
&& (a.Owner == p || (allyBuildRadius && a.Owner.Stances[p] == Stance.Ally))
|
||||
&& a.HasTrait<GivesBuildableArea>());
|
||||
&& a.Info.Traits.Contains<GivesBuildableAreaInfo>());
|
||||
|
||||
if (unitsAtPos.Any())
|
||||
nearnessCandidates.Add(pos);
|
||||
}
|
||||
else if (buildingAtPos.IsInWorld && buildingAtPos.HasTrait<GivesBuildableArea>()
|
||||
else if (buildingAtPos.IsInWorld && buildingAtPos.Info.Traits.Contains<GivesBuildableAreaInfo>()
|
||||
&& (buildingAtPos.Owner == p || (allyBuildRadius && buildingAtPos.Owner.Stances[p] == Stance.Ally)))
|
||||
nearnessCandidates.Add(pos);
|
||||
}
|
||||
@@ -164,7 +164,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void Created(Actor self)
|
||||
{
|
||||
if (SkipMakeAnimation || !self.HasTrait<WithMakeAnimation>())
|
||||
if (SkipMakeAnimation || !self.Info.Traits.Contains<WithMakeAnimationInfo>())
|
||||
NotifyBuildingComplete(self);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public class RefineryInfo : ITraitInfo, Requires<WithSpriteBodyInfo>
|
||||
public class RefineryInfo : IAcceptResourcesInfo, Requires<WithSpriteBodyInfo>
|
||||
{
|
||||
[Desc("Actual harvester facing when docking, 0-255 counter-clock-wise.")]
|
||||
public readonly int DockAngle = 0;
|
||||
|
||||
@@ -15,7 +15,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
class CrateInfo : ITraitInfo, IOccupySpaceInfo, Requires<RenderSpritesInfo>
|
||||
class CrateInfo : IPositionableInfo, IOccupySpaceInfo, Requires<RenderSpritesInfo>
|
||||
{
|
||||
[Desc("Length of time (in seconds) until the crate gets removed automatically. " +
|
||||
"A value of zero disables auto-removal.")]
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
if (!target.HasTrait<EngineerRepairable>())
|
||||
if (!target.Info.Traits.Contains<EngineerRepairableInfo>())
|
||||
return false;
|
||||
|
||||
if (self.Owner.Stances[target.Owner] != Stance.Ally)
|
||||
@@ -115,7 +115,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
if (!target.Info.Traits.Contains<EngineerRepairable>())
|
||||
if (!target.Info.Traits.Contains<EngineerRepairableInfo>())
|
||||
return false;
|
||||
|
||||
if (self.Owner.Stances[target.Owner] != Stance.Ally)
|
||||
|
||||
@@ -88,7 +88,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void Tick(World world)
|
||||
{
|
||||
if (subjects.All(s => s.IsDead || !s.HasTrait<Guard>()))
|
||||
if (subjects.All(s => s.IsDead || !s.Info.Traits.Contains<GuardInfo>()))
|
||||
world.CancelInputMode();
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return world.ScreenMap.ActorsAt(mi)
|
||||
.Where(a => !world.FogObscures(a) && !a.IsDead &&
|
||||
a.AppearsFriendlyTo(world.LocalPlayer.PlayerActor) &&
|
||||
a.HasTrait<Guardable>());
|
||||
a.Info.Traits.Contains<GuardableInfo>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,7 +297,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return new EnterAlliedActorTargeter<IAcceptResources>("Deliver", 5,
|
||||
yield return new EnterAlliedActorTargeter<IAcceptResourcesInfo>("Deliver", 5,
|
||||
proc => IsAcceptableProcType(proc),
|
||||
proc => !IsEmpty && proc.Trait<IAcceptResources>().AllowDocking);
|
||||
yield return new HarvestOrderTargeter();
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (self.IsDead)
|
||||
return;
|
||||
|
||||
if (Info.RemoveInstead || !self.HasTrait<Health>())
|
||||
if (Info.RemoveInstead || !self.Info.Traits.Contains<HealthInfo>())
|
||||
self.Dispose();
|
||||
else
|
||||
self.Kill(self);
|
||||
|
||||
@@ -38,7 +38,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
|
||||
[Desc("Unit is able to move.")]
|
||||
public class MobileInfo : IMoveInfo, IOccupySpaceInfo, IFacingInfo, UsesInit<FacingInit>, UsesInit<LocationInit>, UsesInit<SubCellInit>
|
||||
public class MobileInfo : IMoveInfo, IPositionableInfo, IOccupySpaceInfo, IFacingInfo,
|
||||
UsesInit<FacingInit>, UsesInit<LocationInit>, UsesInit<SubCellInit>
|
||||
{
|
||||
[FieldLoader.LoadUsing("LoadSpeeds", true)]
|
||||
[Desc("Set Water: 0 for ground units and lower the value on rough terrain.")]
|
||||
@@ -664,7 +665,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
var cellInfo = notStupidCells
|
||||
.SelectMany(c => self.World.ActorMap.GetUnitsAt(c)
|
||||
.Where(a => a.IsIdle && a.HasTrait<Mobile>()),
|
||||
.Where(a => a.IsIdle && a.Info.Traits.Contains<MobileInfo>()),
|
||||
(c, a) => new { Cell = c, Actor = a })
|
||||
.RandomOrDefault(self.World.SharedRandom);
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
readonly bool startsRevealed;
|
||||
readonly PPos[] footprint;
|
||||
|
||||
readonly Lazy<IToolTip> tooltip;
|
||||
readonly Lazy<ITooltip> tooltip;
|
||||
readonly Lazy<Health> health;
|
||||
|
||||
readonly Dictionary<Player, bool> visible;
|
||||
@@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
startsRevealed = info.StartsRevealed && !init.Contains<ParentActorInit>();
|
||||
var footprintCells = FootprintUtils.Tiles(init.Self).ToList();
|
||||
footprint = footprintCells.SelectMany(c => map.ProjectedCellsCovering(c.ToMPos(map))).ToArray();
|
||||
tooltip = Exts.Lazy(() => init.Self.TraitsImplementing<IToolTip>().FirstOrDefault());
|
||||
tooltip = Exts.Lazy(() => init.Self.TraitsImplementing<ITooltip>().FirstOrDefault());
|
||||
health = Exts.Lazy(() => init.Self.TraitOrDefault<Health>());
|
||||
|
||||
frozen = new Dictionary<Player, FrozenActor>();
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public enum AlternateTransportsMode { None, Force, Default, Always }
|
||||
|
||||
public class EnterTransportTargeter : EnterAlliedActorTargeter<Cargo>
|
||||
public class EnterTransportTargeter : EnterAlliedActorTargeter<CargoInfo>
|
||||
{
|
||||
readonly AlternateTransportsMode mode;
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
}
|
||||
|
||||
public class EnterTransportsTargeter : EnterAlliedActorTargeter<Cargo>
|
||||
public class EnterTransportsTargeter : EnterAlliedActorTargeter<CargoInfo>
|
||||
{
|
||||
readonly AlternateTransportsMode mode;
|
||||
|
||||
@@ -116,7 +116,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
Info = info;
|
||||
Func<Actor, bool> canTarget = IsCorrectCargoType;
|
||||
Func<Actor, bool> useEnterCursor = CanEnter;
|
||||
Orders = new EnterAlliedActorTargeter<Cargo>[]
|
||||
Orders = new EnterAlliedActorTargeter<CargoInfo>[]
|
||||
{
|
||||
new EnterTransportTargeter("EnterTransport", 5, canTarget, useEnterCursor, Info.AlternateTransportsMode),
|
||||
new EnterTransportsTargeter("EnterTransports", 5, canTarget, useEnterCursor, Info.AlternateTransportsMode)
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
var building = order.TargetActor;
|
||||
|
||||
if (building.HasTrait<RepairableBuilding>())
|
||||
if (building.Info.Traits.Contains<RepairableBuildingInfo>())
|
||||
if (building.AppearsFriendlyTo(self))
|
||||
building.Trait<RepairableBuilding>().RepairBuilding(building, self.Owner);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public void Damaged(Actor self, AttackInfo e)
|
||||
{
|
||||
// only track last hit against our base
|
||||
if (!self.HasTrait<Building>())
|
||||
if (!self.Info.Traits.Contains<BuildingInfo>())
|
||||
return;
|
||||
|
||||
if (e.Attacker == null)
|
||||
|
||||
@@ -47,8 +47,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void Damaged(Actor self, AttackInfo e)
|
||||
{
|
||||
// only track last hit against our base
|
||||
if (!self.HasTrait<Harvester>())
|
||||
// only track last hit against our harvesters
|
||||
if (!self.Info.Traits.Contains<HarvesterInfo>())
|
||||
return;
|
||||
|
||||
// don't track self-damage
|
||||
|
||||
@@ -107,18 +107,18 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
var attackerStats = e.Attacker.Owner.PlayerActor.Trait<PlayerStatistics>();
|
||||
var defenderStats = self.Owner.PlayerActor.Trait<PlayerStatistics>();
|
||||
if (self.HasTrait<Building>())
|
||||
if (self.Info.Traits.Contains<BuildingInfo>())
|
||||
{
|
||||
attackerStats.BuildingsKilled++;
|
||||
defenderStats.BuildingsDead++;
|
||||
}
|
||||
else if (self.HasTrait<IPositionable>())
|
||||
else if (self.Info.Traits.Contains<IPositionableInfo>())
|
||||
{
|
||||
attackerStats.UnitsKilled++;
|
||||
defenderStats.UnitsDead++;
|
||||
}
|
||||
|
||||
if (self.HasTrait<Valued>())
|
||||
if (self.Info.Traits.Contains<ValuedInfo>())
|
||||
{
|
||||
var cost = self.Info.Traits.Get<ValuedInfo>().Cost;
|
||||
attackerStats.KillsCost += cost;
|
||||
|
||||
@@ -14,7 +14,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public class ProvidesPrerequisiteInfo : ITraitInfo
|
||||
public class ProvidesPrerequisiteInfo : ITechTreePrerequisiteInfo
|
||||
{
|
||||
[Desc("The prerequisite type that this provides. If left empty it defaults to the actor's name.")]
|
||||
public readonly string Prerequisite = null;
|
||||
|
||||
@@ -13,7 +13,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public class ProvidesTechPrerequisiteInfo : ITraitInfo
|
||||
public class ProvidesTechPrerequisiteInfo : ITechTreePrerequisiteInfo
|
||||
{
|
||||
public readonly string Name;
|
||||
public readonly string[] Prerequisites = { };
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public void ActorChanged(Actor a)
|
||||
{
|
||||
var bi = a.Info.Traits.GetOrDefault<BuildableInfo>();
|
||||
if (a.Owner == player && (a.HasTrait<ITechTreePrerequisite>() || (bi != null && bi.BuildLimit > 0)))
|
||||
if (a.Owner == player && (a.Info.Traits.Contains<ITechTreePrerequisiteInfo>() || (bi != null && bi.BuildLimit > 0)))
|
||||
Update();
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public Hovers(HoversInfo info, Actor self)
|
||||
{
|
||||
this.info = info;
|
||||
aircraft = self.HasTrait<Aircraft>();
|
||||
aircraft = self.Info.Traits.Contains<AircraftInfo>();
|
||||
}
|
||||
|
||||
public IEnumerable<IRenderable> ModifyRender(Actor self, WorldRenderer wr, IEnumerable<IRenderable> r)
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
this.info = info;
|
||||
wsb = self.Trait<WithSpriteBody>();
|
||||
buildComplete = !self.HasTrait<Building>();
|
||||
buildComplete = !self.Info.Traits.Contains<BuildingInfo>();
|
||||
}
|
||||
|
||||
public void BuildingComplete(Actor self)
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var rs = self.Trait<RenderSprites>();
|
||||
var body = self.Trait<BodyOrientation>();
|
||||
|
||||
buildComplete = !self.HasTrait<Building>(); // always render instantly for units
|
||||
buildComplete = !self.Info.Traits.Contains<BuildingInfo>(); // always render instantly for units
|
||||
|
||||
overlay = new Animation(self.World, rs.GetImage(self));
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var rs = self.Trait<RenderSprites>();
|
||||
var body = self.Trait<BodyOrientation>();
|
||||
|
||||
buildComplete = !self.HasTrait<Building>(); // always render instantly for units
|
||||
buildComplete = !self.Info.Traits.Contains<BuildingInfo>(); // always render instantly for units
|
||||
|
||||
var overlay = new Animation(self.World, rs.GetImage(self));
|
||||
overlay.Play(info.Sequence);
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var rs = self.Trait<RenderSprites>();
|
||||
var body = self.Trait<BodyOrientation>();
|
||||
|
||||
buildComplete = !self.HasTrait<Building>(); // always render instantly for units
|
||||
buildComplete = !self.Info.Traits.Contains<BuildingInfo>(); // always render instantly for units
|
||||
overlay = new Animation(self.World, rs.GetImage(self));
|
||||
if (info.StartSequence != null)
|
||||
overlay.PlayThen(RenderSprites.NormalizeSequence(overlay, self.GetDamageState(), info.StartSequence),
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var rs = self.Trait<RenderSprites>();
|
||||
var body = self.Trait<BodyOrientation>();
|
||||
|
||||
buildComplete = !self.HasTrait<Building>(); // always render instantly for units
|
||||
buildComplete = !self.Info.Traits.Contains<BuildingInfo>(); // always render instantly for units
|
||||
overlay = new Animation(self.World, rs.GetImage(self));
|
||||
overlay.Play(info.Sequence);
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Default trait for rendering sprite-based actors.")]
|
||||
public class WithSpriteBodyInfo : UpgradableTraitInfo, IRenderActorPreviewSpritesInfo, Requires<RenderSpritesInfo>
|
||||
public class WithSpriteBodyInfo : UpgradableTraitInfo, ISpriteBodyInfo, IRenderActorPreviewSpritesInfo, Requires<RenderSpritesInfo>
|
||||
{
|
||||
[Desc("Animation to play when the actor is created."), SequenceReference]
|
||||
public readonly string StartSequence = null;
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return new EnterAlliedActorTargeter<Building>("Repair", 5, CanRepairAt, _ => CanRepair() || CanRearm());
|
||||
yield return new EnterAlliedActorTargeter<BuildingInfo>("Repair", 5, CanRepairAt, _ => CanRepair() || CanRearm());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return new EnterAlliedActorTargeter<Building>("RepairNear", 5,
|
||||
yield return new EnterAlliedActorTargeter<BuildingInfo>("RepairNear", 5,
|
||||
target => CanRepairAt(target), _ => ShouldRepair());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public AmbientSound(Actor self, AmbientSoundInfo info)
|
||||
{
|
||||
if (self.HasTrait<IOccupySpace>())
|
||||
if (self.Info.Traits.Contains<IOccupySpaceInfo>())
|
||||
Sound.PlayLooped(info.SoundFile, self.CenterPosition);
|
||||
else
|
||||
Sound.PlayLooped(info.SoundFile);
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
return target.HasTrait<AcceptsSupplies>();
|
||||
return target.Info.Traits.Contains<AcceptsSuppliesInfo>();
|
||||
}
|
||||
|
||||
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
void ActorRemoved(Actor a)
|
||||
{
|
||||
if (a.Owner != Self.Owner || !a.HasTrait<SupportPower>())
|
||||
if (a.Owner != Self.Owner || !a.Info.Traits.Contains<SupportPowerInfo>())
|
||||
return;
|
||||
|
||||
foreach (var t in a.TraitsImplementing<SupportPower>())
|
||||
@@ -119,7 +119,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public IEnumerable<SupportPowerInstance> GetPowersForActor(Actor a)
|
||||
{
|
||||
if (a.Owner != Self.Owner || !a.HasTrait<SupportPower>())
|
||||
if (a.Owner != Self.Owner || !a.Info.Traits.Contains<SupportPowerInfo>())
|
||||
return NoInstances;
|
||||
|
||||
return a.TraitsImplementing<SupportPower>()
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
if (IsTraitDisabled)
|
||||
return false;
|
||||
if (cloak == null || (!viewer.IsDead && viewer.HasTrait<IgnoresCloak>()))
|
||||
if (cloak == null || (!viewer.IsDead && viewer.Info.Traits.Contains<IgnoresCloakInfo>()))
|
||||
return true;
|
||||
|
||||
return cloak.IsVisible(self, viewer.Owner);
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public bool IsOwnerRowVisible { get { return ShowOwnerRow; } }
|
||||
}
|
||||
|
||||
public class Tooltip : IToolTip
|
||||
public class Tooltip : ITooltip
|
||||
{
|
||||
readonly Actor self;
|
||||
readonly TooltipInfo info;
|
||||
|
||||
@@ -109,10 +109,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!queued)
|
||||
self.CancelActivity();
|
||||
|
||||
if (self.HasTrait<IFacing>())
|
||||
if (self.Info.Traits.Contains<IFacingInfo>())
|
||||
self.QueueActivity(new Turn(self, info.Facing));
|
||||
|
||||
if (self.HasTrait<Helicopter>())
|
||||
if (self.Info.Traits.Contains<HelicopterInfo>())
|
||||
self.QueueActivity(new HeliLand(self, true));
|
||||
|
||||
foreach (var nt in self.TraitsImplementing<INotifyTransform>())
|
||||
|
||||
@@ -18,6 +18,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public interface ISpriteBodyInfo : ITraitInfo { }
|
||||
public interface ISpriteBody
|
||||
{
|
||||
void PlayCustomAnimation(Actor self, string newAnimation, Action after);
|
||||
@@ -67,6 +68,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
void Undocked();
|
||||
}
|
||||
|
||||
public interface ITechTreePrerequisiteInfo : ITraitInfo { }
|
||||
public interface ITechTreePrerequisite
|
||||
{
|
||||
IEnumerable<string> ProvidesPrerequisites { get; }
|
||||
@@ -91,6 +93,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public interface INotifyTransform { void BeforeTransform(Actor self); void OnTransform(Actor self); void AfterTransform(Actor toActor); }
|
||||
|
||||
public interface IAcceptResourcesInfo : ITraitInfo { }
|
||||
public interface IAcceptResources
|
||||
{
|
||||
void OnDock(Actor harv, DeliverResources dockOrder);
|
||||
|
||||
@@ -245,7 +245,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
.Sum(a => a.Info.Traits.WithInterface<ValuedInfo>().First().Cost);
|
||||
|
||||
var harvesters = template.Get<LabelWidget>("HARVESTERS");
|
||||
harvesters.GetText = () => world.Actors.Count(a => a.Owner == player && !a.IsDead && a.HasTrait<Harvester>()).ToString();
|
||||
harvesters.GetText = () => world.Actors.Count(a => a.Owner == player && !a.IsDead && a.Info.Traits.Contains<HarvesterInfo>()).ToString();
|
||||
|
||||
return template;
|
||||
}
|
||||
@@ -280,7 +280,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
return ScrollItemWidget.Setup(template, () => false, () =>
|
||||
{
|
||||
var playerBase = world.Actors.FirstOrDefault(a => !a.IsDead && a.HasTrait<BaseBuilding>() && a.Owner == player);
|
||||
var playerBase = world.Actors.FirstOrDefault(a => !a.IsDead && a.Info.Traits.Contains<BaseBuildingInfo>() && a.Owner == player);
|
||||
if (playerBase != null)
|
||||
worldRenderer.Viewport.Center(playerBase.CenterPosition);
|
||||
});
|
||||
|
||||
@@ -198,7 +198,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
// Is added to world.ActorAdded by the SidebarLogic handler
|
||||
public void ActorChanged(Actor a)
|
||||
{
|
||||
if (a.HasTrait<ProductionQueue>())
|
||||
if (a.Info.Traits.Contains<ProductionQueueInfo>())
|
||||
{
|
||||
var allQueues = a.World.ActorsWithTrait<ProductionQueue>()
|
||||
.Where(p => p.Actor.Owner == p.Actor.World.LocalPlayer && p.Actor.IsInWorld && p.Trait.Enabled)
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
Lazy<TooltipContainerWidget> tooltipContainer;
|
||||
|
||||
public WorldTooltipType TooltipType { get; private set; }
|
||||
public IToolTip ActorTooltip { get; private set; }
|
||||
public ITooltip ActorTooltip { get; private set; }
|
||||
public IProvideTooltipInfo[] ActorTooltipExtra { get; private set; }
|
||||
public FrozenActor FrozenActorTooltip { get; private set; }
|
||||
|
||||
@@ -106,12 +106,12 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
}
|
||||
|
||||
var underCursor = world.ScreenMap.ActorsAt(worldRenderer.Viewport.ViewToWorldPx(Viewport.LastMousePos))
|
||||
.Where(a => !world.FogObscures(a) && a.HasTrait<IToolTip>())
|
||||
.Where(a => !world.FogObscures(a) && a.Info.Traits.Contains<ITooltipInfo>())
|
||||
.WithHighestSelectionPriority();
|
||||
|
||||
if (underCursor != null)
|
||||
{
|
||||
ActorTooltip = underCursor.TraitsImplementing<IToolTip>().First();
|
||||
ActorTooltip = underCursor.TraitsImplementing<ITooltip>().First();
|
||||
ActorTooltipExtra = underCursor.TraitsImplementing<IProvideTooltipInfo>().ToArray();
|
||||
TooltipType = WorldTooltipType.Actor;
|
||||
return;
|
||||
|
||||
@@ -177,7 +177,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
bool PerformGuard()
|
||||
{
|
||||
var actors = world.Selection.Actors
|
||||
.Where(a => !a.Disposed && a.Owner == world.LocalPlayer && a.HasTrait<Guard>());
|
||||
.Where(a => !a.Disposed && a.Owner == world.LocalPlayer && a.Info.Traits.Contains<GuardInfo>());
|
||||
|
||||
if (actors.Any())
|
||||
world.OrderGenerator = new GuardOrderGenerator(actors);
|
||||
@@ -197,7 +197,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
{
|
||||
var building = world.ActorsWithTrait<Building>()
|
||||
.Select(b => b.Actor)
|
||||
.FirstOrDefault(a => a.Owner == world.LocalPlayer && a.HasTrait<Selectable>());
|
||||
.FirstOrDefault(a => a.Owner == world.LocalPlayer && a.Info.Traits.Contains<SelectableInfo>());
|
||||
|
||||
// No buildings left
|
||||
if (building == null)
|
||||
@@ -223,7 +223,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
bool CycleProductionBuildings()
|
||||
{
|
||||
var facilities = world.ActorsWithTrait<Production>()
|
||||
.Where(a => a.Actor.Owner == world.LocalPlayer && !a.Actor.HasTrait<BaseBuilding>())
|
||||
.Where(a => a.Actor.Owner == world.LocalPlayer && !a.Actor.Info.Traits.Contains<BaseBuildingInfo>())
|
||||
.OrderBy(f => f.Actor.Info.Traits.Get<ProductionInfo>().Produces.First())
|
||||
.Select(b => b.Actor)
|
||||
.ToList();
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace OpenRA.Mods.D2k.Activities
|
||||
actor1.Dispose();
|
||||
|
||||
// Harvester insurance
|
||||
if (!actor1.HasTrait<Harvester>())
|
||||
if (!actor1.Info.Traits.Contains<HarvesterInfo>())
|
||||
return;
|
||||
|
||||
var insurance = actor1.Owner.PlayerActor.TraitOrDefault<HarvesterInsurance>();
|
||||
|
||||
@@ -117,7 +117,7 @@ namespace OpenRA.Mods.D2k.Traits
|
||||
{
|
||||
// HACK: Harvesters need special treatment to avoid getting stuck on resource fields,
|
||||
// so if a Harvester's afterLandActivity is not DeliverResources, queue a new FindResources activity
|
||||
var findResources = self.HasTrait<Harvester>() && !(afterLandActivity is DeliverResources);
|
||||
var findResources = self.Info.Traits.Contains<HarvesterInfo>() && !(afterLandActivity is DeliverResources);
|
||||
if (findResources)
|
||||
self.QueueActivity(new FindResources(self));
|
||||
else
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace OpenRA.Mods.D2k.Traits
|
||||
var body = self.Trait<BodyOrientation>();
|
||||
|
||||
// always render instantly for units
|
||||
buildComplete = !self.HasTrait<Building>();
|
||||
buildComplete = !self.Info.Traits.Contains<BuildingInfo>();
|
||||
|
||||
var overlay = new Animation(self.World, rs.GetImage(self));
|
||||
overlay.Play(info.Sequence);
|
||||
|
||||
@@ -99,7 +99,7 @@ namespace OpenRA.Mods.D2k.Traits
|
||||
targetCountdown = Info.TargetRescanInterval;
|
||||
|
||||
// If close enough, we don't care about other actors.
|
||||
var target = self.World.FindActorsInCircle(self.CenterPosition, Info.IgnoreNoiseAttackRange).FirstOrDefault(x => x.HasTrait<AttractsWorms>());
|
||||
var target = self.World.FindActorsInCircle(self.CenterPosition, Info.IgnoreNoiseAttackRange).FirstOrDefault(x => x.Info.Traits.Contains<AttractsWormsInfo>());
|
||||
if (target != null)
|
||||
{
|
||||
self.CancelActivity();
|
||||
@@ -109,7 +109,7 @@ namespace OpenRA.Mods.D2k.Traits
|
||||
|
||||
Func<Actor, bool> isValidTarget = a =>
|
||||
{
|
||||
if (!a.HasTrait<AttractsWorms>())
|
||||
if (!a.Info.Traits.Contains<AttractsWormsInfo>())
|
||||
return false;
|
||||
|
||||
return mobile.CanEnterCell(a.Location, null, false);
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
|
||||
self.Dispose();
|
||||
|
||||
if (target.HasTrait<Building>())
|
||||
if (target.Info.Traits.Contains<BuildingInfo>())
|
||||
Sound.PlayToPlayer(self.Owner, "bldginf1.aud");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA.Traits
|
||||
public void UnitProducedByOther(Actor self, Actor producer, Actor produced)
|
||||
{
|
||||
// No recursive cloning!
|
||||
if (producer.Owner != self.Owner || producer.HasTrait<ClonesProducedUnits>())
|
||||
if (producer.Owner != self.Owner || producer.Info.Traits.Contains<ClonesProducedUnitsInfo>())
|
||||
return;
|
||||
|
||||
var ci = produced.Info.Traits.GetOrDefault<CloneableInfo>();
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace OpenRA.Mods.RA.Traits
|
||||
public virtual bool CanChronoshiftTo(Actor self, CPos targetLocation)
|
||||
{
|
||||
// TODO: Allow enemy units to be chronoshifted into bad terrain to kill them
|
||||
return self.HasTrait<IPositionable>() && self.Trait<IPositionable>().CanEnterCell(targetLocation);
|
||||
return self.Info.Traits.Contains<IPositionableInfo>() && self.Trait<IPositionable>().CanEnterCell(targetLocation);
|
||||
}
|
||||
|
||||
public virtual bool Teleport(Actor self, CPos targetLocation, int duration, bool killCargo, Actor chronosphere)
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA.Traits
|
||||
public override object Create(ActorInitializer init) { return new DisguiseToolTip(init.Self, this); }
|
||||
}
|
||||
|
||||
class DisguiseToolTip : IToolTip
|
||||
class DisguiseToolTip : ITooltip
|
||||
{
|
||||
readonly Actor self;
|
||||
readonly Disguise disguise;
|
||||
@@ -147,7 +147,7 @@ namespace OpenRA.Mods.RA.Traits
|
||||
else
|
||||
{
|
||||
AsSprite = target.Trait<RenderSprites>().GetImage(target);
|
||||
var tooltip = target.TraitsImplementing<IToolTip>().FirstOrDefault();
|
||||
var tooltip = target.TraitsImplementing<ITooltip>().FirstOrDefault();
|
||||
AsPlayer = tooltip.Owner;
|
||||
AsTooltipInfo = tooltip.TooltipInfo;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.RA.Traits
|
||||
|
||||
public void OnCrush(Actor crusher)
|
||||
{
|
||||
if (crusher.HasTrait<MineImmune>() || (self.Owner.Stances[crusher.Owner] == Stance.Ally && info.AvoidFriendly))
|
||||
if (crusher.Info.Traits.Contains<MineImmuneInfo>() || (self.Owner.Stances[crusher.Owner] == Stance.Ally && info.AvoidFriendly))
|
||||
return;
|
||||
|
||||
var mobile = crusher.TraitOrDefault<Mobile>();
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace OpenRA.Mods.RA.Traits
|
||||
foreach (var t in tiles)
|
||||
units.UnionWith(Self.World.ActorMap.GetUnitsAt(t));
|
||||
|
||||
return units.Where(a => a.HasTrait<Chronoshiftable>() &&
|
||||
return units.Where(a => a.Info.Traits.Contains<ChronoshiftableInfo>() &&
|
||||
!a.TraitsImplementing<IPreventsTeleport>().Any(condition => condition.PreventsTeleport(a)));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user