Replace ActorInfo.Traits.WithInterface with ActorInfo.TraitInfos<T>()
This commit is contained in:
@@ -90,7 +90,7 @@ namespace OpenRA.Graphics
|
||||
var width = b.Width;
|
||||
var height = b.Height + heightOffset;
|
||||
|
||||
var resources = resourceRules.Actors["world"].Traits.WithInterface<ResourceTypeInfo>()
|
||||
var resources = resourceRules.Actors["world"].TraitInfos<ResourceTypeInfo>()
|
||||
.ToDictionary(r => r.ResourceType, r => r.TerrainType);
|
||||
|
||||
var bitmapData = terrain.LockBits(terrain.Bounds(),
|
||||
|
||||
@@ -28,8 +28,8 @@ namespace OpenRA
|
||||
|
||||
public MapPlayers(Ruleset rules, int playerCount)
|
||||
{
|
||||
var firstFaction = rules.Actors["world"].Traits
|
||||
.WithInterface<FactionInfo>().First(f => f.Selectable).InternalName;
|
||||
var firstFaction = rules.Actors["world"].TraitInfos<FactionInfo>()
|
||||
.First(f => f.Selectable).InternalName;
|
||||
|
||||
Players = new Dictionary<string, PlayerReference>
|
||||
{
|
||||
|
||||
@@ -53,8 +53,8 @@ namespace OpenRA
|
||||
|
||||
static FactionInfo ChooseFaction(World world, string name, bool requireSelectable = true)
|
||||
{
|
||||
var selectableFactions = world.Map.Rules.Actors["world"].Traits
|
||||
.WithInterface<FactionInfo>().Where(f => !requireSelectable || f.Selectable)
|
||||
var selectableFactions = world.Map.Rules.Actors["world"].TraitInfos<FactionInfo>()
|
||||
.Where(f => !requireSelectable || f.Selectable)
|
||||
.ToList();
|
||||
|
||||
var selected = selectableFactions.FirstOrDefault(f => f.InternalName == name)
|
||||
@@ -75,7 +75,7 @@ namespace OpenRA
|
||||
|
||||
static FactionInfo ChooseDisplayFaction(World world, string factionName)
|
||||
{
|
||||
var factions = world.Map.Rules.Actors["world"].Traits.WithInterface<FactionInfo>().ToArray();
|
||||
var factions = world.Map.Rules.Actors["world"].TraitInfos<FactionInfo>().ToArray();
|
||||
|
||||
return factions.FirstOrDefault(f => f.InternalName == factionName) ?? factions.First();
|
||||
}
|
||||
|
||||
@@ -394,7 +394,7 @@ namespace OpenRA
|
||||
public static string SanitizedPlayerName(string dirty)
|
||||
{
|
||||
var forbiddenNames = new string[] { "Open", "Closed" };
|
||||
var botNames = OpenRA.Game.ModData.DefaultRules.Actors["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name);
|
||||
var botNames = OpenRA.Game.ModData.DefaultRules.Actors["player"].TraitInfos<IBotInfo>().Select(t => t.Name);
|
||||
|
||||
var clean = SanitizedName(dirty);
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ namespace OpenRA.Traits
|
||||
bool HasVoice(Actor self, string voice);
|
||||
}
|
||||
|
||||
public interface IDemolishableInfo { bool IsValidTarget(ActorInfo actorInfo, Actor saboteur); }
|
||||
public interface IDemolishableInfo : ITraitInfo { bool IsValidTarget(ActorInfo actorInfo, Actor saboteur); }
|
||||
public interface IDemolishable
|
||||
{
|
||||
void Demolish(Actor self, Actor saboteur);
|
||||
@@ -172,7 +172,7 @@ namespace OpenRA.Traits
|
||||
IEnumerable<Pair<CPos, Color>> RadarSignatureCells(Actor self);
|
||||
}
|
||||
|
||||
public interface IDefaultVisibilityInfo { }
|
||||
public interface IDefaultVisibilityInfo : ITraitInfo { }
|
||||
public interface IDefaultVisibility { bool IsVisible(Actor self, Player byPlayer); }
|
||||
public interface IVisibilityModifier { bool IsVisible(Actor self, Player byPlayer); }
|
||||
public interface IFogVisibilityModifier { bool HasFogVisibility(Player byPlayer); }
|
||||
@@ -286,7 +286,7 @@ namespace OpenRA.Traits
|
||||
public interface IWorldLoaded { void WorldLoaded(World w, WorldRenderer wr); }
|
||||
public interface ICreatePlayers { void CreatePlayers(World w); }
|
||||
|
||||
public interface IBotInfo { string Name { get; } }
|
||||
public interface IBotInfo : ITraitInfo { string Name { get; } }
|
||||
public interface IBot
|
||||
{
|
||||
void Activate(Player p);
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
var endPos = new CPos(owner.World.Map.Bounds.Left - 5, self.Location.Y);
|
||||
|
||||
// Assume a single exit point for simplicity
|
||||
var exit = self.Info.Traits.WithInterface<ExitInfo>().First();
|
||||
var exit = self.Info.TraitInfos<ExitInfo>().First();
|
||||
|
||||
foreach (var tower in self.TraitsImplementing<INotifyDelivery>())
|
||||
tower.IncomingDelivery(self);
|
||||
|
||||
@@ -209,7 +209,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
|
||||
bool HasSufficientPowerForActor(ActorInfo actorInfo)
|
||||
{
|
||||
return (actorInfo.Traits.WithInterface<PowerInfo>().Where(i => i.UpgradeMinEnabledLevel < 1)
|
||||
return (actorInfo.TraitInfos<PowerInfo>().Where(i => i.UpgradeMinEnabledLevel < 1)
|
||||
.Sum(p => p.Amount) + playerPower.ExcessPower) >= ai.Info.MinimumExcessPower;
|
||||
}
|
||||
|
||||
@@ -219,12 +219,12 @@ namespace OpenRA.Mods.Common.AI
|
||||
|
||||
// This gets used quite a bit, so let's cache it here
|
||||
var power = GetProducibleBuilding("Power", buildableThings,
|
||||
a => a.Traits.WithInterface<PowerInfo>().Where(i => i.UpgradeMinEnabledLevel < 1).Sum(p => p.Amount));
|
||||
a => a.TraitInfos<PowerInfo>().Where(i => i.UpgradeMinEnabledLevel < 1).Sum(p => p.Amount));
|
||||
|
||||
// First priority is to get out of a low power situation
|
||||
if (playerPower.ExcessPower < ai.Info.MinimumExcessPower)
|
||||
{
|
||||
if (power != null && power.Traits.WithInterface<PowerInfo>().Where(i => i.UpgradeMinEnabledLevel < 1).Sum(p => p.Amount) > 0)
|
||||
if (power != null && power.TraitInfos<PowerInfo>().Where(i => i.UpgradeMinEnabledLevel < 1).Sum(p => p.Amount) > 0)
|
||||
{
|
||||
HackyAI.BotDebug("AI: {0} decided to build {1}: Priority override (low power)", queue.Actor.Owner, power.Name);
|
||||
return power;
|
||||
@@ -331,7 +331,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
if (playerPower.ExcessPower < ai.Info.MinimumExcessPower || !HasSufficientPowerForActor(actor))
|
||||
{
|
||||
// Try building a power plant instead
|
||||
if (power != null && power.Traits.WithInterface<PowerInfo>().Where(i => i.UpgradeMinEnabledLevel < 1).Sum(pi => pi.Amount) > 0)
|
||||
if (power != null && power.TraitInfos<PowerInfo>().Where(i => i.UpgradeMinEnabledLevel < 1).Sum(pi => pi.Amount) > 0)
|
||||
{
|
||||
if (playerPower.PowerOutageRemainingTicks > 0)
|
||||
HackyAI.BotDebug("{0} decided to build {1}: Priority override (is low power)", queue.Actor.Owner, power.Name);
|
||||
|
||||
@@ -272,7 +272,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
minAttackForceDelayTicks = Random.Next(0, Info.MinimumAttackForceDelay);
|
||||
|
||||
resourceTypeIndices = new BitArray(World.TileSet.TerrainInfo.Length); // Big enough
|
||||
foreach (var t in Map.Rules.Actors["world"].Traits.WithInterface<ResourceTypeInfo>())
|
||||
foreach (var t in Map.Rules.Actors["world"].TraitInfos<ResourceTypeInfo>())
|
||||
resourceTypeIndices.Set(World.TileSet.GetTerrainIndex(t.TerrainType), true);
|
||||
}
|
||||
|
||||
@@ -437,7 +437,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
if (aircraftInfo == null)
|
||||
return true;
|
||||
|
||||
var ammoPoolsInfo = actorInfo.Traits.WithInterface<AmmoPoolInfo>();
|
||||
var ammoPoolsInfo = actorInfo.TraitInfos<AmmoPoolInfo>();
|
||||
|
||||
if (ammoPoolsInfo.Any(x => !x.SelfReloads))
|
||||
{
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
heli.Reservation = res.Reserve(dest, self, heli);
|
||||
}
|
||||
|
||||
var exit = dest.Info.Traits.WithInterface<ExitInfo>().FirstOrDefault();
|
||||
var exit = dest.Info.TraitInfos<ExitInfo>().FirstOrDefault();
|
||||
var offset = (exit != null) ? exit.SpawnOffset : WVec.Zero;
|
||||
|
||||
return Util.SequenceActivities(
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Lint
|
||||
this.emitError = emitError;
|
||||
|
||||
foreach (var actorInfo in rules.Actors)
|
||||
foreach (var traitInfo in actorInfo.Value.Traits.WithInterface<ITraitInfo>())
|
||||
foreach (var traitInfo in actorInfo.Value.TraitInfos<ITraitInfo>())
|
||||
CheckTrait(actorInfo.Value, traitInfo, rules);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Lint
|
||||
{
|
||||
foreach (var actorInfo in rules.Actors)
|
||||
{
|
||||
var animations = actorInfo.Value.Traits.WithInterface<WithDeathAnimationInfo>().ToList();
|
||||
var animations = actorInfo.Value.TraitInfos<WithDeathAnimationInfo>().ToList();
|
||||
if (!animations.Any())
|
||||
continue;
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Lint
|
||||
if (!deathTypes.Any())
|
||||
continue;
|
||||
|
||||
var targetable = actorInfo.Value.Traits.WithInterface<ITargetableInfo>().SelectMany(x => x.GetTargetTypes()).ToList();
|
||||
var targetable = actorInfo.Value.TraitInfos<ITargetableInfo>().SelectMany(x => x.GetTargetTypes()).ToList();
|
||||
if (!targetable.Any())
|
||||
continue;
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Lint
|
||||
if (actorInfo.Key.StartsWith("^"))
|
||||
continue;
|
||||
|
||||
var count = actorInfo.Value.Traits.WithInterface<IDefaultVisibilityInfo>().Count();
|
||||
var count = actorInfo.Value.TraitInfos<IDefaultVisibilityInfo>().Count();
|
||||
|
||||
if (count == 0)
|
||||
emitError("Actor type `{0}` does not define a default visibility type!".F(actorInfo.Key));
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Lint
|
||||
|
||||
var worldActor = map.Rules.Actors["world"];
|
||||
|
||||
var factions = worldActor.Traits.WithInterface<FactionInfo>().Select(f => f.InternalName).ToHashSet();
|
||||
var factions = worldActor.TraitInfos<FactionInfo>().Select(f => f.InternalName).ToHashSet();
|
||||
foreach (var player in players.Values)
|
||||
if (!string.IsNullOrWhiteSpace(player.Faction) && !factions.Contains(player.Faction))
|
||||
emitError("Invalid faction {0} chosen for player {1}.".F(player.Faction, player.Name));
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Lint
|
||||
continue;
|
||||
|
||||
var ios = actorInfo.Value.TraitInfoOrDefault<IOccupySpaceInfo>();
|
||||
foreach (var rsi in actorInfo.Value.Traits.WithInterface<RevealsShroudInfo>())
|
||||
foreach (var rsi in actorInfo.Value.TraitInfos<RevealsShroudInfo>())
|
||||
{
|
||||
if (rsi.Type == VisibilityType.CenterPosition)
|
||||
continue;
|
||||
|
||||
@@ -36,12 +36,12 @@ namespace OpenRA.Mods.Common.Lint
|
||||
Game.ModData.Manifest.Sequences.Select(MiniYaml.FromFile).Aggregate(MiniYaml.MergeLiberal));
|
||||
|
||||
var rules = map == null ? Game.ModData.DefaultRules : map.Rules;
|
||||
var factions = rules.Actors["world"].Traits.WithInterface<FactionInfo>().Select(f => f.InternalName).ToArray();
|
||||
var factions = rules.Actors["world"].TraitInfos<FactionInfo>().Select(f => f.InternalName).ToArray();
|
||||
var sequenceProviders = map == null ? rules.Sequences.Values : new[] { rules.Sequences[map.Tileset] };
|
||||
|
||||
foreach (var actorInfo in rules.Actors)
|
||||
{
|
||||
foreach (var renderInfo in actorInfo.Value.Traits.WithInterface<RenderSpritesInfo>())
|
||||
foreach (var renderInfo in actorInfo.Value.TraitInfos<RenderSpritesInfo>())
|
||||
{
|
||||
foreach (var faction in factions)
|
||||
{
|
||||
@@ -68,7 +68,7 @@ namespace OpenRA.Mods.Common.Lint
|
||||
if (string.IsNullOrEmpty(sequence))
|
||||
continue;
|
||||
|
||||
var renderInfo = actorInfo.Value.Traits.WithInterface<RenderSpritesInfo>().FirstOrDefault();
|
||||
var renderInfo = actorInfo.Value.TraitInfos<RenderSpritesInfo>().FirstOrDefault();
|
||||
if (renderInfo == null)
|
||||
continue;
|
||||
|
||||
|
||||
@@ -111,14 +111,14 @@ namespace OpenRA.Mods.Common.Lint
|
||||
}
|
||||
|
||||
// TODO: HACK because GainsExperience grants upgrades differently to most other sources.
|
||||
var gainsExperience = rules.Actors.SelectMany(x => x.Value.Traits.WithInterface<GainsExperienceInfo>()
|
||||
var gainsExperience = rules.Actors.SelectMany(x => x.Value.TraitInfos<GainsExperienceInfo>()
|
||||
.SelectMany(y => y.Upgrades.SelectMany(z => z.Value)));
|
||||
|
||||
foreach (var upgrade in gainsExperience)
|
||||
yield return upgrade;
|
||||
|
||||
// TODO: HACK because Pluggable grants upgrades differently to most other sources.
|
||||
var pluggable = rules.Actors.SelectMany(x => x.Value.Traits.WithInterface<PluggableInfo>()
|
||||
var pluggable = rules.Actors.SelectMany(x => x.Value.TraitInfos<PluggableInfo>()
|
||||
.SelectMany(y => y.Upgrades.SelectMany(z => z.Value)));
|
||||
|
||||
foreach (var upgrade in pluggable)
|
||||
@@ -143,7 +143,7 @@ namespace OpenRA.Mods.Common.Lint
|
||||
|
||||
// TODO: HACK because GainsExperience and GainsStatUpgrades do not play by the rules...
|
||||
// We assume everything GainsExperience grants is used by GainsStatUpgrade
|
||||
var gainsExperience = rules.Actors.SelectMany(x => x.Value.Traits.WithInterface<GainsExperienceInfo>()
|
||||
var gainsExperience = rules.Actors.SelectMany(x => x.Value.TraitInfos<GainsExperienceInfo>()
|
||||
.SelectMany(y => y.Upgrades.SelectMany(z => z.Value)));
|
||||
|
||||
foreach (var upgrade in gainsExperience)
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Lint
|
||||
{
|
||||
foreach (var actorInfo in rules.Actors)
|
||||
{
|
||||
foreach (var traitInfo in actorInfo.Value.Traits.WithInterface<ITraitInfo>())
|
||||
foreach (var traitInfo in actorInfo.Value.TraitInfos<ITraitInfo>())
|
||||
{
|
||||
var fields = traitInfo.GetType().GetFields().Where(f => f.HasAttribute<VoiceSetReferenceAttribute>());
|
||||
foreach (var field in fields)
|
||||
@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Lint
|
||||
{
|
||||
var soundInfo = rules.Voices[voiceSet.ToLowerInvariant()];
|
||||
|
||||
foreach (var traitInfo in actorInfo.Traits.WithInterface<ITraitInfo>())
|
||||
foreach (var traitInfo in actorInfo.TraitInfos<ITraitInfo>())
|
||||
{
|
||||
var fields = traitInfo.GetType().GetFields().Where(f => f.HasAttribute<VoiceReferenceAttribute>());
|
||||
foreach (var field in fields)
|
||||
|
||||
@@ -20,13 +20,12 @@ namespace OpenRA.Mods.Common.Lint
|
||||
public void Run(Action<string> emitError, Action<string> emitWarning, Ruleset rules)
|
||||
{
|
||||
// ProvidesPrerequisite allows arbitrary prereq definitions
|
||||
var customPrereqs = rules.Actors.SelectMany(a => a.Value.Traits
|
||||
.WithInterface<ProvidesPrerequisiteInfo>().Select(p => p.Prerequisite ?? a.Value.Name));
|
||||
var customPrereqs = rules.Actors.SelectMany(a => a.Value.TraitInfos<ProvidesPrerequisiteInfo>()
|
||||
.Select(p => p.Prerequisite ?? a.Value.Name));
|
||||
|
||||
// ProvidesTechPrerequisite allows arbitrary prereq definitions
|
||||
// (but only one group at a time during gameplay)
|
||||
var techPrereqs = rules.Actors.SelectMany(a => a.Value.Traits
|
||||
.WithInterface<ProvidesTechPrerequisiteInfo>())
|
||||
var techPrereqs = rules.Actors.SelectMany(a => a.Value.TraitInfos<ProvidesTechPrerequisiteInfo>())
|
||||
.SelectMany(p => p.Prerequisites);
|
||||
|
||||
var providedPrereqs = customPrereqs.Concat(techPrereqs);
|
||||
|
||||
@@ -142,7 +142,7 @@ namespace OpenRA.Mods.Common.Orders
|
||||
var rules = world.Map.Rules;
|
||||
|
||||
var actorInfo = rules.Actors[building];
|
||||
foreach (var dec in actorInfo.Traits.WithInterface<IPlaceBuildingDecoration>())
|
||||
foreach (var dec in actorInfo.TraitInfos<IPlaceBuildingDecorationInfo>())
|
||||
foreach (var r in dec.Render(wr, world, actorInfo, world.Map.CenterOfCell(xy)))
|
||||
yield return r;
|
||||
|
||||
@@ -177,7 +177,7 @@ namespace OpenRA.Mods.Common.Orders
|
||||
};
|
||||
|
||||
var init = new ActorPreviewInitializer(rules.Actors[building], wr, td);
|
||||
preview = rules.Actors[building].Traits.WithInterface<IRenderActorPreviewInfo>()
|
||||
preview = rules.Actors[building].TraitInfos<IRenderActorPreviewInfo>()
|
||||
.SelectMany(rpi => rpi.RenderPreview(init))
|
||||
.ToArray();
|
||||
|
||||
|
||||
@@ -620,7 +620,7 @@ namespace OpenRA.Mods.Common.Server
|
||||
return true;
|
||||
}
|
||||
|
||||
var startUnitsInfo = server.Map.Rules.Actors["world"].Traits.WithInterface<MPStartUnitsInfo>();
|
||||
var startUnitsInfo = server.Map.Rules.Actors["world"].TraitInfos<MPStartUnitsInfo>();
|
||||
var selectedClass = startUnitsInfo.Where(u => u.Class == s).Select(u => u.ClassName).FirstOrDefault();
|
||||
var className = selectedClass != null ? selectedClass : s;
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Server
|
||||
|
||||
if (server.LobbyInfo.GlobalSettings.StartingUnitsClass != defaults.StartingUnitsClass)
|
||||
{
|
||||
var startUnitsInfo = server.Map.Rules.Actors["world"].Traits.WithInterface<MPStartUnitsInfo>();
|
||||
var startUnitsInfo = server.Map.Rules.Actors["world"].TraitInfos<MPStartUnitsInfo>();
|
||||
var selectedClass = startUnitsInfo.Where(u => u.Class == server.LobbyInfo.GlobalSettings.StartingUnitsClass).Select(u => u.ClassName).FirstOrDefault();
|
||||
var className = selectedClass != null ? selectedClass : server.LobbyInfo.GlobalSettings.StartingUnitsClass;
|
||||
server.SendOrderTo(conn, "Message", "Starting Units: {0}".F(className));
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (res != null)
|
||||
Reservation = res.Reserve(order.TargetActor, self, this);
|
||||
|
||||
var exit = order.TargetActor.Info.Traits.WithInterface<ExitInfo>().FirstOrDefault();
|
||||
var exit = order.TargetActor.Info.TraitInfos<ExitInfo>().FirstOrDefault();
|
||||
var offset = (exit != null) ? exit.SpawnOffset : WVec.Zero;
|
||||
|
||||
self.SetTargetLine(Target.FromActor(order.TargetActor), Color.Green);
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
return target.Info.Traits.WithInterface<IDemolishableInfo>().Any(i => i.IsValidTarget(target.Info, self));
|
||||
return target.Info.TraitInfos<IDemolishableInfo>().Any(i => i.IsValidTarget(target.Info, self));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Allows the player to execute build orders.", " Attach this to the player actor.")]
|
||||
public class PlaceBuildingInfo : ITraitInfo, IPlaceBuildingDecoration
|
||||
public class PlaceBuildingInfo : ITraitInfo, IPlaceBuildingDecorationInfo
|
||||
{
|
||||
[Desc("Palette to use for rendering the placement sprite.")]
|
||||
[PaletteReference] public readonly string Palette = "terrain";
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return false;
|
||||
|
||||
// Pick a spawn/exit point pair
|
||||
var exit = self.Info.Traits.WithInterface<ExitInfo>().Shuffle(self.World.SharedRandom)
|
||||
var exit = self.Info.TraitInfos<ExitInfo>().Shuffle(self.World.SharedRandom)
|
||||
.FirstOrDefault(e => CanUseExit(self, producee, e));
|
||||
|
||||
if (exit != null || !occupiesSpace)
|
||||
|
||||
@@ -18,7 +18,7 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Draw a circle indicating my weapon's range.")]
|
||||
class RenderRangeCircleInfo : ITraitInfo, IPlaceBuildingDecoration, Requires<AttackBaseInfo>
|
||||
class RenderRangeCircleInfo : ITraitInfo, IPlaceBuildingDecorationInfo, Requires<AttackBaseInfo>
|
||||
{
|
||||
public readonly string RangeCircleType = null;
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition)
|
||||
{
|
||||
var armaments = ai.Traits.WithInterface<ArmamentInfo>()
|
||||
var armaments = ai.TraitInfos<ArmamentInfo>()
|
||||
.Where(a => a.UpgradeMinEnabledLevel == 0);
|
||||
var range = FallbackRange;
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public interface IRenderActorPreviewSpritesInfo
|
||||
public interface IRenderActorPreviewSpritesInfo : ITraitInfo
|
||||
{
|
||||
IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p);
|
||||
}
|
||||
@@ -64,7 +64,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var spi in init.Actor.Traits.WithInterface<IRenderActorPreviewSpritesInfo>())
|
||||
foreach (var spi in init.Actor.TraitInfos<IRenderActorPreviewSpritesInfo>())
|
||||
foreach (var preview in spi.RenderPreviewSprites(init, this, image, facings, palette))
|
||||
yield return preview;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public interface IRenderActorPreviewVoxelsInfo
|
||||
public interface IRenderActorPreviewVoxelsInfo : ITraitInfo
|
||||
{
|
||||
IEnumerable<VoxelAnimation> RenderPreviewVoxels(
|
||||
ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, WRot orientation, int facings, PaletteReference p);
|
||||
@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var ifacing = init.Actor.TraitInfoOrDefault<IFacingInfo>();
|
||||
var facing = ifacing != null ? init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : ifacing.GetInitialFacing() : 0;
|
||||
var orientation = WRot.FromFacing(facing);
|
||||
var components = init.Actor.Traits.WithInterface<IRenderActorPreviewVoxelsInfo>()
|
||||
var components = init.Actor.TraitInfos<IRenderActorPreviewVoxelsInfo>()
|
||||
.SelectMany(rvpi => rvpi.RenderPreviewVoxels(init, this, image, orientation, facings, palette))
|
||||
.ToArray();
|
||||
|
||||
|
||||
@@ -37,9 +37,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
yield break;
|
||||
|
||||
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
||||
var armament = init.Actor.Traits.WithInterface<ArmamentInfo>()
|
||||
var armament = init.Actor.TraitInfos<ArmamentInfo>()
|
||||
.First(a => a.Name == Armament);
|
||||
var t = init.Actor.Traits.WithInterface<TurretedInfo>()
|
||||
var t = init.Actor.TraitInfos<TurretedInfo>()
|
||||
.First(tt => tt.Turret == armament.Turret);
|
||||
|
||||
var anim = new Animation(init.World, image, () => t.InitialFacing);
|
||||
|
||||
@@ -17,7 +17,7 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Renders an arbitrary circle when selected or placing a structure")]
|
||||
class WithRangeCircleInfo : ITraitInfo, IPlaceBuildingDecoration
|
||||
class WithRangeCircleInfo : ITraitInfo, IPlaceBuildingDecorationInfo
|
||||
{
|
||||
[Desc("Type of range circle. used to decide which circles to draw on other structures during building placement.")]
|
||||
public readonly string Type = null;
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
yield break;
|
||||
|
||||
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
||||
var t = init.Actor.Traits.WithInterface<TurretedInfo>()
|
||||
var t = init.Actor.TraitInfos<TurretedInfo>()
|
||||
.First(tt => tt.Turret == Turret);
|
||||
|
||||
var ifacing = init.Actor.TraitInfoOrDefault<IFacingInfo>();
|
||||
|
||||
@@ -24,8 +24,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public override IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||
{
|
||||
var t = init.Actor.Traits.WithInterface<TurretedInfo>().FirstOrDefault();
|
||||
var wsb = init.Actor.Traits.WithInterface<WithSpriteBodyInfo>().FirstOrDefault();
|
||||
var t = init.Actor.TraitInfos<TurretedInfo>().FirstOrDefault();
|
||||
var wsb = init.Actor.TraitInfos<WithSpriteBodyInfo>().FirstOrDefault();
|
||||
|
||||
// Show the correct turret facing
|
||||
var anim = new Animation(init.World, image, () => t.InitialFacing);
|
||||
|
||||
@@ -35,9 +35,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
yield break;
|
||||
|
||||
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
||||
var armament = init.Actor.Traits.WithInterface<ArmamentInfo>()
|
||||
var armament = init.Actor.TraitInfos<ArmamentInfo>()
|
||||
.First(a => a.Name == Armament);
|
||||
var t = init.Actor.Traits.WithInterface<TurretedInfo>()
|
||||
var t = init.Actor.TraitInfos<TurretedInfo>()
|
||||
.First(tt => tt.Turret == armament.Turret);
|
||||
|
||||
var voxel = VoxelProvider.GetVoxel(image, Sequence);
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
yield break;
|
||||
|
||||
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
||||
var t = init.Actor.Traits.WithInterface<TurretedInfo>()
|
||||
var t = init.Actor.TraitInfos<TurretedInfo>()
|
||||
.First(tt => tt.Turret == Turret);
|
||||
|
||||
var voxel = VoxelProvider.GetVoxel(image, Sequence);
|
||||
|
||||
@@ -156,7 +156,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
void GeneratePreviews()
|
||||
{
|
||||
var init = new ActorPreviewInitializer(Info, worldRenderer, actor.InitDict);
|
||||
previews = Info.Traits.WithInterface<IRenderActorPreviewInfo>()
|
||||
previews = Info.TraitInfos<IRenderActorPreviewInfo>()
|
||||
.SelectMany(rpi => rpi.RenderPreview(init))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
static void SpawnUnitsForPlayer(World w, Player p, CPos sp)
|
||||
{
|
||||
var spawnClass = p.PlayerReference.StartingUnitsClass ?? w.LobbyInfo.GlobalSettings.StartingUnitsClass;
|
||||
var unitGroup = w.Map.Rules.Actors["world"].Traits.WithInterface<MPStartUnitsInfo>()
|
||||
var unitGroup = w.Map.Rules.Actors["world"].TraitInfos<MPStartUnitsInfo>()
|
||||
.Where(g => g.Class == spawnClass && g.Factions != null && g.Factions.Contains(p.Faction.InternalName))
|
||||
.RandomOrDefault(w.SharedRandom);
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
void OnNotifyResourceClaimLost(Actor self, ResourceClaim claim, Actor claimer);
|
||||
}
|
||||
|
||||
public interface IPlaceBuildingDecoration
|
||||
public interface IPlaceBuildingDecorationInfo : ITraitInfo
|
||||
{
|
||||
IEnumerable<IRenderable> Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
public void SetPreview(ActorInfo actor, TypeDictionary td)
|
||||
{
|
||||
var init = new ActorPreviewInitializer(actor, worldRenderer, td);
|
||||
preview = actor.Traits.WithInterface<IRenderActorPreviewInfo>()
|
||||
preview = actor.TraitInfos<IRenderActorPreviewInfo>()
|
||||
.SelectMany(rpi => rpi.RenderPreview(init))
|
||||
.ToArray();
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
layerTemplateList.RemoveChildren();
|
||||
|
||||
var resources = modRules.Actors["world"].Traits.WithInterface<ResourceTypeInfo>();
|
||||
var resources = modRules.Actors["world"].TraitInfos<ResourceTypeInfo>();
|
||||
foreach (var resource in resources)
|
||||
{
|
||||
var newResourcePreviewTemplate = ScrollItemWidget.Setup(layerPreviewTemplate,
|
||||
|
||||
@@ -242,7 +242,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var assets = template.Get<LabelWidget>("ASSETS");
|
||||
assets.GetText = () => "$" + world.Actors
|
||||
.Where(a => a.Owner == player && !a.IsDead && a.Info.HasTraitInfo<ValuedInfo>())
|
||||
.Sum(a => a.Info.Traits.WithInterface<ValuedInfo>().First().Cost);
|
||||
.Sum(a => a.Info.TraitInfos<ValuedInfo>().First().Cost);
|
||||
|
||||
var harvesters = template.Get<LabelWidget>("HARVESTERS");
|
||||
harvesters.GetText = () => world.Actors.Count(a => a.Owner == player && !a.IsDead && a.Info.HasTraitInfo<HarvesterInfo>()).ToString();
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var requiresString = prereqs.Any() ? requiresLabel.Text.F(prereqs.JoinWith(", ")) : "";
|
||||
requiresLabel.GetText = () => requiresString;
|
||||
|
||||
var power = actor.Traits.WithInterface<PowerInfo>().Where(i => i.UpgradeMinEnabledLevel < 1).Sum(i => i.Amount);
|
||||
var power = actor.TraitInfos<PowerInfo>().Where(i => i.UpgradeMinEnabledLevel < 1).Sum(i => i.Amount);
|
||||
var powerString = power.ToString();
|
||||
powerLabel.GetText = () => powerString;
|
||||
powerLabel.GetColor = () => ((pm.PowerProvided - pm.PowerDrained) >= -power || power > 0)
|
||||
|
||||
@@ -144,7 +144,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
colorPreview = lobby.Get<ColorPreviewManagerWidget>("COLOR_MANAGER");
|
||||
colorPreview.Color = Game.Settings.Player.Color;
|
||||
|
||||
foreach (var f in modRules.Actors["world"].Traits.WithInterface<FactionInfo>())
|
||||
foreach (var f in modRules.Actors["world"].TraitInfos<FactionInfo>())
|
||||
factions.Add(f.InternalName, new LobbyFaction { Selectable = f.Selectable, Name = f.Name, Side = f.Side, Description = f.Description });
|
||||
|
||||
var gameStarting = false;
|
||||
@@ -187,7 +187,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
slotsButton.IsDisabled = () => configurationDisabled() || panel != PanelType.Players ||
|
||||
Map.RuleStatus != MapRuleStatus.Cached || !orderManager.LobbyInfo.Slots.Values.Any(s => s.AllowBots || !s.LockTeam);
|
||||
|
||||
var botNames = modRules.Actors["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name);
|
||||
var botNames = modRules.Actors["player"].TraitInfos<IBotInfo>().Select(t => t.Name);
|
||||
slotsButton.OnMouseDown = _ =>
|
||||
{
|
||||
var options = new Dictionary<string, IEnumerable<DropDownOption>>();
|
||||
@@ -395,7 +395,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var startingUnits = optionsBin.GetOrNull<DropDownButtonWidget>("STARTINGUNITS_DROPDOWNBUTTON");
|
||||
if (startingUnits != null)
|
||||
{
|
||||
var startUnitsInfo = modRules.Actors["world"].Traits.WithInterface<MPStartUnitsInfo>();
|
||||
var startUnitsInfo = modRules.Actors["world"].TraitInfos<MPStartUnitsInfo>();
|
||||
var classes = startUnitsInfo.Select(a => a.Class).Distinct();
|
||||
Func<string, string> className = c =>
|
||||
{
|
||||
@@ -459,7 +459,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var techLevel = optionsBin.GetOrNull<DropDownButtonWidget>("TECHLEVEL_DROPDOWNBUTTON");
|
||||
if (techLevel != null)
|
||||
{
|
||||
var techTraits = modRules.Actors["player"].Traits.WithInterface<ProvidesTechPrerequisiteInfo>().ToList();
|
||||
var techTraits = modRules.Actors["player"].TraitInfos<ProvidesTechPrerequisiteInfo>().ToList();
|
||||
techLevel.IsVisible = () => techTraits.Count > 0;
|
||||
|
||||
var techLevelDescription = optionsBin.GetOrNull<LabelWidget>("TECHLEVEL_DESC");
|
||||
@@ -610,7 +610,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
Game.LobbyInfoChanged += WidgetUtils.Once(() =>
|
||||
{
|
||||
var slot = orderManager.LobbyInfo.FirstEmptyBotSlot();
|
||||
var bot = modRules.Actors["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name).FirstOrDefault();
|
||||
var bot = modRules.Actors["player"].TraitInfos<IBotInfo>().Select(t => t.Name).FirstOrDefault();
|
||||
var botController = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin);
|
||||
if (slot != null && bot != null)
|
||||
orderManager.IssueOrder(Order.Command("slot_bot {0} {1} {2}".F(slot, botController.Index, bot)));
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var bots = new List<SlotDropDownOption>();
|
||||
if (slot.AllowBots)
|
||||
{
|
||||
foreach (var b in rules.Actors["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name))
|
||||
foreach (var b in rules.Actors["player"].TraitInfos<IBotInfo>().Select(t => t.Name))
|
||||
{
|
||||
var bot = b;
|
||||
var botController = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin);
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
{
|
||||
this.world = world;
|
||||
|
||||
Groups = world.Map.Rules.Actors.Values.SelectMany(a => a.Traits.WithInterface<ProductionQueueInfo>())
|
||||
Groups = world.Map.Rules.Actors.Values.SelectMany(a => a.TraitInfos<ProductionQueueInfo>())
|
||||
.Select(q => q.Group).Distinct().ToDictionary(g => g, g => new ProductionTabGroup() { Group = g });
|
||||
|
||||
// Only visible if the production palette has icons to display
|
||||
|
||||
@@ -170,7 +170,7 @@ namespace OpenRA.Mods.RA.Traits
|
||||
var renderSprites = actorInfo.TraitInfoOrDefault<RenderSpritesInfo>();
|
||||
AsSprite = renderSprites == null ? null : renderSprites.GetImage(actorInfo, self.World.Map.SequenceProvider, newOwner.Faction.InternalName);
|
||||
AsPlayer = newOwner;
|
||||
AsTooltipInfo = actorInfo.Traits.WithInterface<TooltipInfo>().FirstOrDefault();
|
||||
AsTooltipInfo = actorInfo.TraitInfos<TooltipInfo>().FirstOrDefault();
|
||||
|
||||
HandleDisguise(oldEffectiveOwner, oldDisguiseSetting);
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ namespace OpenRA.Mods.RA.Traits
|
||||
if (!info.ValidStances.HasStance(stance))
|
||||
return false;
|
||||
|
||||
return target.Info.Traits.WithInterface<ITargetableInfo>().Any(t => info.Types.Overlaps(t.GetTargetTypes()));
|
||||
return target.Info.TraitInfos<ITargetableInfo>().Any(t => info.Types.Overlaps(t.GetTargetTypes()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
// TODO: remove all the Render*Circle duplication
|
||||
class RenderJammerCircleInfo : ITraitInfo, IPlaceBuildingDecoration
|
||||
class RenderJammerCircleInfo : ITraitInfo, IPlaceBuildingDecorationInfo
|
||||
{
|
||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition)
|
||||
{
|
||||
|
||||
@@ -17,7 +17,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
class RenderShroudCircleInfo : ITraitInfo, IPlaceBuildingDecoration
|
||||
class RenderShroudCircleInfo : ITraitInfo, IPlaceBuildingDecorationInfo
|
||||
{
|
||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user