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