Merge pull request #9246 from RoosterDragon/array-to-set

Change some arrays to sets
This commit is contained in:
Matthias Mailänder
2015-09-04 08:56:44 +02:00
19 changed files with 43 additions and 38 deletions

View File

@@ -100,7 +100,7 @@ namespace OpenRA.Mods.Common.AI
public readonly Stance Against = Stance.Enemy;
[Desc("What types should the desired targets of this power be?")]
public readonly string[] Types = { "Air", "Ground", "Water" };
public readonly HashSet<string> Types = new HashSet<string> { "Air", "Ground", "Water" };
[Desc("How attractive are these types of targets?")]
public readonly int Attractiveness = 100;
@@ -129,7 +129,7 @@ namespace OpenRA.Mods.Common.AI
if (!targetable.Any(t => t.TargetableBy(a, firedBy.PlayerActor)))
return 0;
if (Types.Intersect(targetable.SelectMany(t => t.TargetTypes)).Any())
if (Types.Overlaps(targetable.SelectMany(t => t.TargetTypes)))
{
switch (TargetMetric)
{

View File

@@ -45,10 +45,10 @@ namespace OpenRA.Mods.Common.Lint
continue;
// This warhead cannot affect this actor.
if (!warhead.ValidTargets.Intersect(targetable).Any())
if (!warhead.ValidTargets.Overlaps(targetable))
continue;
if (!warhead.DamageTypes.Intersect(deathTypes).Any())
if (!warhead.DamageTypes.Overlaps(deathTypes))
emitError("Actor type `{0}` does not define a death animation for weapon `{1}`!"
.F(actorInfo.Key, weaponInfo.Key));
}

View File

@@ -77,12 +77,12 @@ namespace OpenRA.Mods.Common.Orders
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
{
return target.TraitsImplementing<ITargetable>().Any(t => t.IsTraitEnabled() && t.TargetTypes.Intersect(targetTypes).Any());
return target.TraitsImplementing<ITargetable>().Any(t => t.IsTraitEnabled() && t.TargetTypes.Overlaps(targetTypes));
}
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
{
return target.TargetTypes.Intersect(targetTypes).Any();
return target.TargetTypes.Overlaps(targetTypes);
}
}
}

View File

@@ -75,7 +75,7 @@ namespace OpenRA.Mods.Common.Traits
if (world.ActorsWithTrait<LineBuildNode>().Any(a =>
(a.Actor.Location == cell &&
a.Actor.Info.Traits.Get<LineBuildNodeInfo>()
.Types.Intersect(lbi.NodeTypes).Any())))
.Types.Overlaps(lbi.NodeTypes))))
dirs[d] = i; // Cell contains actor of correct type
else
dirs[d] = -1; // Cell is blocked by another actor type

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System.Collections.Generic;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
@@ -16,7 +17,7 @@ namespace OpenRA.Mods.Common.Traits
public class LineBuildNodeInfo : TraitInfo<LineBuildNode>
{
[Desc("This actor is of LineBuild 'NodeType'...")]
public readonly string[] Types = { "wall" };
public readonly HashSet<string> Types = new HashSet<string> { "wall" };
}
public class LineBuildNode { }

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly string UncloakSound = null;
[PaletteReference] public readonly string Palette = "cloak";
public readonly string[] CloakTypes = { "Cloak" };
public readonly HashSet<string> CloakTypes = new HashSet<string> { "Cloak" };
[UpgradeGrantedReference]
[Desc("The upgrades to grant to self while cloaked.")]
@@ -150,7 +150,7 @@ namespace OpenRA.Mods.Common.Traits
return true;
return self.World.ActorsWithTrait<DetectCloaked>().Any(a => !a.Trait.IsTraitDisabled && a.Actor.Owner.IsAlliedWith(viewer)
&& Info.CloakTypes.Intersect(a.Trait.Info.CloakTypes).Any()
&& Info.CloakTypes.Overlaps(a.Trait.Info.CloakTypes)
&& (self.CenterPosition - a.Actor.CenterPosition).Length <= WDist.FromCells(a.Trait.Info.Range).Length);
}

View File

@@ -9,6 +9,7 @@
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Primitives;
using OpenRA.Traits;
@@ -31,7 +32,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly int MaxRadius = 4;
[Desc("The list of unit target types we are allowed to duplicate.")]
public readonly string[] ValidTargets = { "Ground", "Water" };
public readonly HashSet<string> ValidTargets = new HashSet<string> { "Ground", "Water" };
[Desc("Which factions this crate action can occur for.")]
public readonly string[] ValidFactions = { };
@@ -58,7 +59,7 @@ namespace OpenRA.Mods.Common.Traits
return false;
var targetable = collector.TraitsImplementing<ITargetable>();
if (!info.ValidTargets.Intersect(targetable.SelectMany(t => t.TargetTypes)).Any())
if (!info.ValidTargets.Overlaps(targetable.SelectMany(t => t.TargetTypes)))
return false;
var positionable = collector.TraitOrDefault<IPositionable>();

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits;
@@ -19,7 +20,7 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Sound to play when being crushed.")]
public readonly string CrushSound = null;
[Desc("Which crush classes does this actor belong to.")]
public readonly string[] CrushClasses = { "infantry" };
public readonly HashSet<string> CrushClasses = new HashSet<string> { "infantry" };
[Desc("Probability of mobile actors noticing and evading a crush attempt.")]
public readonly int WarnProbability = 75;
[Desc("Will friendly units just crush me instead of pathing around.")]
@@ -72,7 +73,7 @@ namespace OpenRA.Mods.Common.Traits
if (!info.CrushedByFriendlies && crushOwner.IsAlliedWith(self.Owner))
return false;
return info.CrushClasses.Intersect(crushClasses).Any();
return info.CrushClasses.Overlaps(crushClasses);
}
}
}

View File

@@ -8,7 +8,7 @@
*/
#endregion
using OpenRA.Traits;
using System.Collections.Generic;
namespace OpenRA.Mods.Common.Traits
{
@@ -16,7 +16,7 @@ namespace OpenRA.Mods.Common.Traits
public class DetectCloakedInfo : UpgradableTraitInfo
{
[Desc("Specific cloak classifications I can reveal.")]
public readonly string[] CloakTypes = { "Cloak" };
public readonly HashSet<string> CloakTypes = new HashSet<string> { "Cloak" };
[Desc("Measured in cells.")]
public readonly int Range = 5;

View File

@@ -51,7 +51,7 @@ namespace OpenRA.Mods.Common.Traits
return;
var warhead = e.Warhead as DamageWarhead;
if (info.DeathType != null && warhead != null && !info.DeathType.Intersect(warhead.DamageTypes).Any())
if (info.DeathType != null && warhead != null && !warhead.DamageTypes.Overlaps(info.DeathType))
return;
var weaponName = ChooseWeaponForExplosion(self);

View File

@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Traits
if (Info.UseDeathTypeSuffix)
{
var warhead = e.Warhead as DamageWarhead;
var damageType = warhead.DamageTypes.Intersect(Info.DeathTypes.Keys).FirstOrDefault();
var damageType = Info.DeathTypes.Keys.FirstOrDefault(warhead.DamageTypes.Contains);
if (damageType == null)
return;

View File

@@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Traits
if (warhead == null)
return;
if (info.DeathTypes.Intersect(warhead.DamageTypes).Any())
if (warhead.DamageTypes.Overlaps(info.DeathTypes))
self.PlayVoiceLocal(info.Voice, info.VolumeMultiplier);
}
}

View File

@@ -17,8 +17,8 @@ namespace OpenRA.Mods.Common.Traits
public class TargetableInfo : UpgradableTraitInfo, ITargetableInfo
{
[Desc("Target type. Used for filtering (in)valid targets.")]
public readonly string[] TargetTypes = { };
public string[] GetTargetTypes() { return TargetTypes; }
public readonly HashSet<string> TargetTypes = new HashSet<string>();
public HashSet<string> GetTargetTypes() { return TargetTypes; }
public bool RequiresForceFire = false;
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits
return cloak.IsVisible(self, viewer.Owner);
}
public virtual string[] TargetTypes { get { return Info.TargetTypes; } }
public virtual HashSet<string> TargetTypes { get { return Info.TargetTypes; } }
public bool RequiresForceFire { get { return Info.RequiresForceFire; } }
}

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Warheads
public readonly int Damage = 0;
[Desc("Types of damage that this warhead causes. Leave empty for no damage.")]
public readonly string[] DamageTypes = new string[0];
public readonly HashSet<string> DamageTypes = new HashSet<string>();
[FieldLoader.LoadUsing("LoadVersus")]
[Desc("Damage percentage versus each armortype.")]