More HashSet trait fields & Lint support

This commit is contained in:
atlimit8
2015-09-05 15:54:00 -05:00
parent e74c0d6c13
commit 8250f223c4
57 changed files with 115 additions and 89 deletions

View File

@@ -22,8 +22,8 @@ namespace OpenRA.GameRules
public readonly Dictionary<string, string[]> Notifications = new Dictionary<string, string[]>();
public readonly string DefaultVariant = ".aud";
public readonly string DefaultPrefix = "";
public readonly string[] DisableVariants = { };
public readonly string[] DisablePrefixes = { };
public readonly HashSet<string> DisableVariants = new HashSet<string>();
public readonly HashSet<string> DisablePrefixes = new HashSet<string>();
public readonly Lazy<Dictionary<string, SoundPool>> VoicePools;
public readonly Lazy<Dictionary<string, SoundPool>> NotificationsPools;

View File

@@ -49,8 +49,8 @@ namespace OpenRA
static readonly TerrainTypeInfo Default = new TerrainTypeInfo();
public readonly string Type;
public readonly string[] TargetTypes = { };
public readonly string[] AcceptsSmudgeType = { };
public readonly HashSet<string> TargetTypes = new HashSet<string>();
public readonly HashSet<string> AcceptsSmudgeType = new HashSet<string>();
public readonly bool IsWater = false; // TODO: Remove this
public readonly Color Color;
public readonly string CustomCursor;

View File

@@ -8,12 +8,14 @@
*/
#endregion
using System.Collections.Generic;
namespace OpenRA.Traits
{
public class EditorTilesetFilterInfo : TraitInfo<EditorTilesetFilter>
{
public readonly string[] RequireTilesets = null;
public readonly string[] ExcludeTilesets = null;
public readonly HashSet<string> RequireTilesets = null;
public readonly HashSet<string> ExcludeTilesets = null;
}
public class EditorTilesetFilter { }

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System.Collections.Generic;
using System.Linq;
namespace OpenRA.Traits
@@ -16,14 +17,14 @@ namespace OpenRA.Traits
public class RejectsOrdersInfo : ITraitInfo
{
[Desc("Possible values include Attack, AttackMove, Guard, Move.")]
public readonly string[] Except = { };
public readonly HashSet<string> Except = new HashSet<string>();
public object Create(ActorInitializer init) { return new RejectsOrders(this); }
}
public class RejectsOrders
{
public string[] Except { get { return info.Except; } }
public HashSet<string> Except { get { return info.Except; } }
readonly RejectsOrdersInfo info;

View File

@@ -268,7 +268,7 @@ namespace OpenRA.Traits
{
void OnCrush(Actor crusher);
void WarnCrush(Actor crusher);
bool CrushableBy(string[] crushClasses, Player owner);
bool CrushableBy(HashSet<string> crushClasses, Player owner);
}
public interface ITraitInfo { object Create(ActorInitializer init); }

View File

@@ -8,6 +8,8 @@
*/
#endregion
using System.Collections.Generic;
namespace OpenRA.Traits
{
[Desc("Attach this to the `World` actor.")]
@@ -20,7 +22,7 @@ namespace OpenRA.Traits
public readonly string InternalName = null;
[Desc("Pick a random faction as the player's facton out of this list.")]
public readonly string[] RandomFactionMembers = { };
public readonly HashSet<string> RandomFactionMembers = new HashSet<string>();
[Desc("The side that the faction belongs to. For example, England belongs to the 'Allies' side.")]
public readonly string Side = null;

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Traits
public readonly string Name = null;
public readonly string TerrainType = "Ore";
public readonly string[] AllowedTerrainTypes = { };
public readonly HashSet<string> AllowedTerrainTypes = new HashSet<string>();
public readonly bool AllowUnderActors = false;
public readonly bool AllowUnderBuildings = false;
public readonly bool AllowOnRamps = false;

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.GameRules;
using OpenRA.Mods.Common.Traits;
@@ -18,7 +19,7 @@ namespace OpenRA.Mods.Cnc.Traits
class PoisonedByTiberiumInfo : UpgradableTraitInfo
{
[WeaponReference] public readonly string Weapon = "Tiberium";
public readonly string[] Resources = { "Tiberium", "BlueTiberium" };
public readonly HashSet<string> Resources = new HashSet<string> { "Tiberium", "BlueTiberium" };
public override object Create(ActorInitializer init) { return new PoisonedByTiberium(this); }
}

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Cnc.Traits
public readonly WVec[] LocalOffset = { WVec.Zero };
[Desc("Passenger CargoType to display.")]
public readonly string[] DisplayTypes = { };
public readonly HashSet<string> DisplayTypes = new HashSet<string>();
public object Create(ActorInitializer init) { return new WithCargo(init.Self, this); }
}

View File

@@ -32,10 +32,10 @@ namespace OpenRA.Mods.Common.AI
public readonly int SquadSizeRandomBonus = 30;
[Desc("Production queues AI uses for buildings.")]
public readonly string[] BuildingQueues = { "Building" };
public readonly HashSet<string> BuildingQueues = new HashSet<string> { "Building" };
[Desc("Production queues AI uses for defenses.")]
public readonly string[] DefenseQueues = { "Defense" };
public readonly HashSet<string> DefenseQueues = new HashSet<string> { "Defense" };
[Desc("Delay (in ticks) between giving out orders to units.")]
public readonly int AssignRolesInterval = 20;
@@ -106,7 +106,7 @@ namespace OpenRA.Mods.Common.AI
public readonly int CheckForWaterRadius = 8;
[Desc("Production queues AI uses for producing units.")]
public readonly string[] UnitQueues = { "Vehicle", "Infantry", "Plane", "Ship", "Aircraft" };
public readonly HashSet<string> UnitQueues = new HashSet<string> { "Vehicle", "Infantry", "Plane", "Ship", "Aircraft" };
[Desc("Should the AI repair its buildings if damaged?")]
public readonly bool ShouldRepairBuildings = true;

View File

@@ -23,8 +23,8 @@ namespace OpenRA.Mods.Common
public readonly string MenuWidget = null;
public readonly string MusicMenuWidget = null;
public readonly string BackgroundWidget = null;
public readonly string[] TestFiles = { };
public readonly string[] DiskTestFiles = { };
public readonly HashSet<string> TestFiles = new HashSet<string>();
public readonly HashSet<string> DiskTestFiles = new HashSet<string>();
public readonly string PackageToExtractFromCD = null;
public readonly bool OverwriteFiles = true;
@@ -37,10 +37,10 @@ namespace OpenRA.Mods.Common
public readonly int ShippedSoundtracks = 0;
/// <summary> InstallShield .cab File Ids, used to extract Mod specific files. </summary>
public readonly int[] InstallShieldCABFileIds = { };
public readonly HashSet<int> InstallShieldCABFileIds = new HashSet<int>();
/// <summary> InstallShield .cab File Ids, used to extract Mod specific archives and extract contents of ExtractFilesFromCD. </summary>
public readonly string[] InstallShieldCABFilePackageIds = { };
public readonly HashSet<string> InstallShieldCABFilePackageIds = new HashSet<string>();
}
public static class InstallUtils

View File

@@ -9,21 +9,24 @@
#endregion
using System;
using System.Collections.Generic;
using System.Reflection;
namespace OpenRA.Mods.Common.Lint
{
public class LintExts
{
public static string[] GetFieldValues(object ruleInfo, FieldInfo fieldInfo, Action<string> emitError)
public static IEnumerable<string> GetFieldValues(object ruleInfo, FieldInfo fieldInfo, Action<string> emitError)
{
var type = fieldInfo.FieldType;
if (type == typeof(string))
return new[] { (string)fieldInfo.GetValue(ruleInfo) };
if (type == typeof(string[]))
return (string[])fieldInfo.GetValue(ruleInfo);
if (type == typeof(HashSet<string>))
return (HashSet<string>)fieldInfo.GetValue(ruleInfo);
emitError("Bad type for reference on {0}.{1}. Supported types: string, string[]"
emitError("Bad type for reference on {0}.{1}. Supported types: string, string[], HashSet<string>"
.F(ruleInfo.GetType().Name, fieldInfo.Name));
return new string[] { };

View File

@@ -9,6 +9,8 @@
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Traits;
using OpenRA.Scripting;
@@ -19,7 +21,7 @@ namespace OpenRA.Mods.Common.Scripting
[Desc("Part of the new Lua API.")]
public class LuaScriptInfo : ITraitInfo, Requires<SpawnMapActorsInfo>
{
public readonly string[] Scripts = { };
public readonly HashSet<string> Scripts = new HashSet<string>();
public object Create(ActorInitializer init) { return new LuaScript(this); }
}
@@ -36,7 +38,7 @@ namespace OpenRA.Mods.Common.Scripting
public void WorldLoaded(World world, WorldRenderer worldRenderer)
{
var scripts = info.Scripts ?? new string[0];
var scripts = info.Scripts ?? Enumerable.Empty<string>();
context = new ScriptContext(world, worldRenderer, scripts);
context.WorldLoaded();
}

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System.Collections.Generic;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Scripting
@@ -17,7 +18,7 @@ namespace OpenRA.Mods.Common.Scripting
{
[UpgradeGrantedReference]
[Desc("Upgrades that can be granted from the scripts.")]
public readonly string[] Upgrades = { };
public readonly HashSet<string> Upgrades = new HashSet<string>();
public object Create(ActorInitializer init) { return new ScriptUpgradesCache(this); }
}

View File

@@ -29,16 +29,16 @@ namespace OpenRA.Mods.Common.Traits
public readonly int RepulsionSpeed = -1;
[ActorReference]
public readonly string[] RepairBuildings = { "fix" };
public readonly HashSet<string> RepairBuildings = new HashSet<string> { "fix" };
[ActorReference]
public readonly string[] RearmBuildings = { "hpad", "afld" };
public readonly HashSet<string> RearmBuildings = new HashSet<string> { "hpad", "afld" };
public readonly int InitialFacing = 0;
public readonly int ROT = 255;
public readonly int Speed = 1;
[Desc("Minimum altitude where this aircraft is considered airborne")]
public readonly int MinAirborneAltitude = 1;
public readonly string[] LandableTerrainTypes = { };
public readonly HashSet<string> LandableTerrainTypes = new HashSet<string>();
[Desc("Can the actor be ordered to move in to shroud?")]
public readonly bool MoveIntoShroud = true;

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System.Collections.Generic;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
@@ -21,7 +22,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly string[] Prerequisites = { };
[Desc("Production queue(s) that can produce this.")]
public readonly string[] Queue = { };
public readonly HashSet<string> Queue = new HashSet<string>();
[Desc("Override the production structure type (from the Production Produces list) that this unit should be built at.")]
public readonly string BuildAtProductionType = null;

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits
public class BuildingInfo : ITraitInfo, IOccupySpaceInfo, UsesInit<LocationInit>
{
[Desc("Where you are allowed to place the building (Water, Clear, ...)")]
public readonly string[] TerrainTypes = { };
public readonly HashSet<string> TerrainTypes = new HashSet<string>();
[Desc("The range to the next building it can be constructed. Set it higher for walls.")]
public readonly int Adjacent = 2;
[Desc("x means space it blocks, _ is a part that is passable by actors.")]

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System.Collections.Generic;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
@@ -19,7 +20,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly int Range = 5;
[Desc("LineBuildNode 'Types' to attach to.")]
public readonly string[] NodeTypes = { "wall" };
public readonly HashSet<string> NodeTypes = new HashSet<string> { "wall" };
}
public class LineBuild { }

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Mods.Common.Traits
public class CapturesInfo : ITraitInfo
{
[Desc("Types of actors that it can capture, as long as the type also exists in the Capturable Type: trait.")]
public readonly string[] CaptureTypes = { "building" };
public readonly HashSet<string> CaptureTypes = new HashSet<string> { "building" };
[Desc("Unit will do damage to the actor instead of capturing it. Unit is destroyed when sabotaging.")]
public readonly bool Sabotage = true;
[Desc("Only used if Sabotage=true. Sabotage damage expressed as a percentage of enemy health removed.")]

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly int PipCount = 0;
[Desc("`Passenger.CargoType`s that can be loaded into this actor.")]
public readonly string[] Types = { };
public readonly HashSet<string> Types = new HashSet<string>();
[Desc("A list of actor types that are initially spawned into this actor.")]
public readonly string[] InitialUnits = { };
@@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly bool EjectOnSell = true;
[Desc("Terrain types that this actor is allowed to eject actors onto. Leave empty for all terrain types.")]
public readonly string[] UnloadTerrainTypes = { };
public readonly HashSet<string> UnloadTerrainTypes = new HashSet<string>();
[Desc("Voice to play when ordered to unload the passengers.")]
[VoiceReference] public readonly string UnloadVoice = "Action";
@@ -79,7 +79,7 @@ namespace OpenRA.Mods.Common.Traits
self = init.Self;
Info = info;
Unloading = false;
checkTerrainType = info.UnloadTerrainTypes.Length > 0;
checkTerrainType = info.UnloadTerrainTypes.Count > 0;
if (init.Contains<RuntimeCargoInit>())
{

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly int Lifetime = 0;
[Desc("Allowed to land on.")]
public readonly string[] TerrainTypes = { };
public readonly HashSet<string> TerrainTypes = new HashSet<string>();
[Desc("Define actors that can collect crates by setting this into the Crushes field from the Mobile trait.")]
public readonly string CrushClass = "crate";
@@ -187,7 +187,7 @@ namespace OpenRA.Mods.Common.Traits
return GetAvailableSubCell(a, SubCell.Any, ignoreActor, checkTransientActors) != SubCell.Invalid;
}
public bool CrushableBy(string[] crushClasses, Player owner)
public bool CrushableBy(HashSet<string> crushClasses, Player owner)
{
// Crate can only be crushed if it is not in the air.
return self.IsAtGroundLevel() && crushClasses.Contains(info.CrushClass);

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly HashSet<string> ValidTargets = new HashSet<string> { "Ground", "Water" };
[Desc("Which factions this crate action can occur for.")]
public readonly string[] ValidFactions = { };
public readonly HashSet<string> ValidFactions = new HashSet<string>();
[Desc("Is the new duplicates given to a specific owner, regardless of whom collected it?")]
public readonly string Owner = null;

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly string[] Units = { };
[Desc("Factions that are allowed to trigger this action.")]
public readonly string[] ValidFactions = { };
public readonly HashSet<string> ValidFactions = new HashSet<string>();
[Desc("Override the owner of the newly spawned unit: e.g. Creeps or Neutral")]
public readonly string Owner = null;

View File

@@ -64,7 +64,7 @@ namespace OpenRA.Mods.Common.Traits
self.Kill(crusher);
}
public bool CrushableBy(string[] crushClasses, Player crushOwner)
public bool CrushableBy(HashSet<string> crushClasses, Player crushOwner)
{
// Only make actor crushable if it is on the ground.
if (!self.IsAtGroundLevel())

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Primitives;
using OpenRA.Traits;
@@ -26,7 +27,7 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Spawns actors only if the selling player's faction is in this list. " +
"Leave empty to allow all factions by default.")]
public readonly string[] Factions = { };
public readonly HashSet<string> Factions = new HashSet<string>();
public object Create(ActorInitializer init) { return new EmitInfantryOnSell(init.Self, this); }
}
@@ -40,7 +41,7 @@ namespace OpenRA.Mods.Common.Traits
{
this.info = info;
var factionsList = info.Factions;
correctFaction = factionsList.Length == 0 || factionsList.Contains(self.Owner.Faction.InternalName);
correctFaction = factionsList.Count == 0 || factionsList.Contains(self.Owner.Faction.InternalName);
}
public void Selling(Actor self) { }

View File

@@ -9,6 +9,7 @@
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Warheads;
using OpenRA.Traits;
@@ -31,7 +32,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly int Chance = 100;
[Desc("DeathType(s) to apply upon explosion.")]
public readonly string[] DeathType = null;
public readonly HashSet<string> DeathType = new HashSet<string>();
public object Create(ActorInitializer init) { return new Explodes(this); }
}
@@ -51,7 +52,7 @@ namespace OpenRA.Mods.Common.Traits
return;
var warhead = e.Warhead as DamageWarhead;
if (info.DeathType != null && warhead != null && !warhead.DamageTypes.Overlaps(info.DeathType))
if (warhead != null && !warhead.DamageTypes.Overlaps(info.DeathType))
return;
var weaponName = ChooseWeaponForExplosion(self);

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Mods.Common.Traits
class ExternalCapturesInfo : ITraitInfo
{
[Desc("Types of actors that it can capture, as long as the type also exists in the ExternalCapturable Type: trait.")]
public readonly string[] CaptureTypes = { "building" };
public readonly HashSet<string> CaptureTypes = new HashSet<string> { "building" };
[Desc("Destroy the unit after capturing.")]
public readonly bool ConsumeActor = false;

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Traits
{
public class HarvesterInfo : ITraitInfo, Requires<MobileInfo>
{
public readonly string[] DeliveryBuildings = { };
public readonly HashSet<string> DeliveryBuildings = new HashSet<string>();
[Desc("How long (in ticks) to wait until (re-)checking for a nearby available DeliveryBuilding if not yet linked to one.")]
public readonly int SearchForDeliveryBuildingDelay = 125;
@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly int HarvestFacings = 0;
[Desc("Which resources it can harvest.")]
public readonly string[] Resources = { };
public readonly HashSet<string> Resources = new HashSet<string>();
[Desc("Percentage of maximum speed when fully loaded.")]
public readonly int FullyLoadedSpeed = 85;
@@ -151,7 +151,7 @@ namespace OpenRA.Mods.Common.Traits
bool IsAcceptableProcType(Actor proc)
{
return info.DeliveryBuildings.Length == 0 ||
return info.DeliveryBuildings.Count == 0 ||
info.DeliveryBuildings.Contains(proc.Info.Name);
}

View File

@@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Spawns remains of a husk actor with the correct facing.")]
public class HuskInfo : IOccupySpaceInfo, IFacingInfo
{
public readonly string[] AllowedTerrain = { };
public readonly HashSet<string> AllowedTerrain = new HashSet<string>();
public object Create(ActorInitializer init) { return new Husk(init, this); }

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits
[FieldLoader.Require]
[Desc("Damage types that trigger prone state. Defined on the warheads.")]
public readonly string[] DamageTriggers = null;
public readonly HashSet<string> DamageTriggers = new HashSet<string>();
[Desc("Damage modifiers for each damage type (defined on the warheads) while the unit is prone.")]
public readonly Dictionary<string, int> DamageModifiers = new Dictionary<string, int>();
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Traits
public void Damaged(Actor self, AttackInfo e)
{
var warhead = e.Warhead as DamageWarhead;
if (e.Damage <= 0 || warhead == null || !warhead.DamageTypes.Any(x => info.DamageTriggers.Contains(x)))
if (e.Damage <= 0 || warhead == null || !warhead.DamageTypes.Overlaps(info.DamageTriggers))
return;
if (!IsProne)

View File

@@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly Dictionary<string, TerrainInfo> TerrainSpeeds;
[Desc("e.g. crate, wall, infantry")]
public readonly string[] Crushes = { };
public readonly HashSet<string> Crushes = new HashSet<string>();
public readonly int WaitAverage = 5;
@@ -237,7 +237,7 @@ namespace OpenRA.Mods.Common.Traits
return false;
// If we cannot crush the other actor in our way, we are blocked.
if (self == null || Crushes == null || Crushes.Length == 0)
if (self == null || Crushes == null || Crushes.Count == 0)
return true;
// If the other actor in our way cannot be crushed, we are blocked.

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Used for bursted one-colored whole screen effects. Add this to the world actor.")]
public class FlashPaletteEffectInfo : ITraitInfo
{
public readonly string[] ExcludePalettes = { "cursor", "chrome", "colorpicker", "fog", "shroud" };
public readonly HashSet<string> ExcludePalettes = new HashSet<string> { "cursor", "chrome", "colorpicker", "fog", "shroud" };
[Desc("Measured in ticks.")]
public readonly int Length = 20;

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
@@ -19,10 +20,10 @@ namespace OpenRA.Mods.Common.Traits
class GlobalLightingPaletteEffectInfo : ITraitInfo
{
[Desc("Do not modify graphics that use any palette in this list.")]
public readonly string[] ExcludePalettes = { "cursor", "chrome", "colorpicker", "fog", "shroud", "alpha" };
public readonly HashSet<string> ExcludePalettes = new HashSet<string> { "cursor", "chrome", "colorpicker", "fog", "shroud", "alpha" };
[Desc("Do not modify graphics that start with these letters.")]
public readonly string[] ExcludePalettePrefixes = { };
public readonly HashSet<string> ExcludePalettePrefixes = new HashSet<string>();
public readonly float Red = 1f;
public readonly float Green = 1f;

View File

@@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Palette effect used for sprinkle \"animations\" on terrain tiles.")]
class WaterPaletteRotationInfo : ITraitInfo
{
public readonly string[] ExcludePalettes = { };
public readonly HashSet<string> ExcludePalettes = new HashSet<string>();
public object Create(ActorInitializer init) { return new WaterPaletteRotation(init.World, this); }
}

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly string Group = null;
[Desc("Only enable this queue for certain factions.")]
public readonly string[] Factions = { };
public readonly HashSet<string> Factions = new HashSet<string>();
[Desc("Should the prerequisite remain enabled if the owner changes?")]
public readonly bool Sticky = true;

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly string[] RequiresPrerequisites = { };
[Desc("Only grant this prerequisite for certain factions.")]
public readonly string[] Factions = { };
public readonly HashSet<string> Factions = new HashSet<string>();
[Desc("Should it recheck everything when it is captured?")]
public readonly bool ResetOnOwnerChange = false;

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits;
@@ -17,7 +18,7 @@ namespace OpenRA.Mods.Common.Traits
public class ProximityCaptorInfo : ITraitInfo
{
[FieldLoader.Require]
public readonly string[] Types = { };
public readonly HashSet<string> Types = new HashSet<string>();
public object Create(ActorInitializer init) { return new ProximityCaptor(this); }
}
@@ -27,9 +28,9 @@ namespace OpenRA.Mods.Common.Traits
public ProximityCaptor(ProximityCaptorInfo info) { Info = info; }
public bool HasAny(string[] typesList)
public bool HasAny(IEnumerable<string> typesList)
{
return typesList.Any(flag => Info.Types.Contains(flag));
return Info.Types.Overlaps(typesList);
}
}
}

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly bool Permanent = false;
public readonly int Range = 5;
public readonly bool MustBeClear = false;
public readonly string[] CaptorTypes = { "Vehicle", "Tank", "Infantry" };
public readonly HashSet<string> CaptorTypes = new HashSet<string> { "Vehicle", "Tank", "Infantry" };
public object Create(ActorInitializer init) { return new ProximityCapturable(init.Self, this); }
}

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Effects;
using OpenRA.Traits;
@@ -21,7 +22,7 @@ namespace OpenRA.Mods.Common.Traits
[PaletteReference] public readonly string Palette = "effect";
[Desc("Only do so when the terrain types match with the previous cell.")]
public readonly string[] TerrainTypes = { };
public readonly HashSet<string> TerrainTypes = new HashSet<string>();
public object Create(ActorInitializer init) { return new LeavesTrails(this, init.Self); }
}

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Traits
[Desc("This actor can be sent to a structure for repairs.")]
class RepairableInfo : ITraitInfo, Requires<HealthInfo>
{
public readonly string[] RepairBuildings = { "fix" };
public readonly HashSet<string> RepairBuildings = new HashSet<string> { "fix" };
[VoiceReference] public readonly string Voice = "Action";

View File

@@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Traits
{
class RepairableNearInfo : ITraitInfo, Requires<HealthInfo>, Requires<IMoveInfo>
{
[ActorReference] public readonly string[] Buildings = { "spen", "syrd" };
[ActorReference] public readonly HashSet<string> Buildings = new HashSet<string> { "spen", "syrd" };
public readonly int CloseEnough = 4; /* cells */
public object Create(ActorInitializer init) { return new RepairableNear(init.Self, this); }

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Warheads;
using OpenRA.Traits;
@@ -25,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Damage types that this should be used for (defined on the warheads).",
"If empty, this will be used as the default sound for all death types.")]
public readonly string[] DeathTypes = { };
public readonly HashSet<string> DeathTypes = new HashSet<string>();
public object Create(ActorInitializer init) { return new DeathSounds(this); }
}

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Activities;
using OpenRA.Traits;
@@ -16,7 +17,7 @@ namespace OpenRA.Mods.Common.Traits
{
public class TransformOnPassengerInfo : ITraitInfo
{
[ActorReference, FieldLoader.Require] public readonly string[] PassengerTypes = { };
[ActorReference, FieldLoader.Require] public readonly HashSet<string> PassengerTypes = new HashSet<string>();
[ActorReference] public readonly string OnEnter = null;
[ActorReference] public readonly string OnExit = null;
public readonly bool SkipMakeAnims = false;

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits
[Desc("The terrain types that this actor can deploy on to receive these upgrades. " +
"Leave empty to allow any.")]
public readonly string[] AllowedTerrainTypes = { };
public readonly HashSet<string> AllowedTerrainTypes = new HashSet<string>();
[Desc("Cursor to display when able to (un)deploy the actor.")]
public readonly string DeployCursor = "deploy";
@@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Traits
this.self = self;
this.info = info;
manager = self.Trait<UpgradeManager>();
checkTerrainType = info.AllowedTerrainTypes.Length > 0;
checkTerrainType = info.AllowedTerrainTypes.Count > 0;
canTurn = self.Info.Traits.WithInterface<IFacingInfo>().Any();
body = Exts.Lazy(self.TraitOrDefault<ISpriteBody>);
}

View File

@@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Traits
{
[UpgradeUsedReference]
[Desc("The upgrade types which can enable or disable this trait.")]
public readonly string[] UpgradeTypes = { };
public readonly HashSet<string> UpgradeTypes = new HashSet<string>();
[Desc("The minimum upgrade level at which this trait is enabled.", "Defaults to 0 (enabled by default).")]
public readonly int UpgradeMinEnabledLevel = 0;
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits
public UpgradableTrait(InfoType info)
{
Info = info;
IsTraitDisabled = info.UpgradeTypes != null && info.UpgradeTypes.Length > 0 && info.UpgradeMinEnabledLevel > 0;
IsTraitDisabled = info.UpgradeTypes != null && info.UpgradeTypes.Count > 0 && info.UpgradeMinEnabledLevel > 0;
}
public bool AcceptsUpgradeLevel(Actor self, string type, int level)

View File

@@ -9,6 +9,7 @@
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Activities;
using OpenRA.Primitives;
@@ -28,10 +29,10 @@ namespace OpenRA.Mods.Common.Traits
public readonly int SpawnInterval = 180;
[Desc("Which terrain types can we drop on?")]
public readonly string[] ValidGround = { "Clear", "Rough", "Road", "Ore", "Beach" };
public readonly HashSet<string> ValidGround = new HashSet<string> { "Clear", "Rough", "Road", "Ore", "Beach" };
[Desc("Which terrain types count as water?")]
public readonly string[] ValidWater = { "Water" };
public readonly HashSet<string> ValidWater = new HashSet<string> { "Water" };
[Desc("Chance of generating a water crate instead of a land crate")]
public readonly float WaterChance = .2f;

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System.Collections.Generic;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
@@ -22,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly string ClassName = "Unlabeled";
[Desc("Only available when selecting one of these factions.", "Leave empty for no restrictions.")]
public readonly string[] Factions = { };
public readonly HashSet<string> Factions = new HashSet<string>();
[Desc("The mobile construction vehicle.")]
public readonly string BaseActor = null;

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Warheads
public readonly int[] Size = { 0, 0 };
[Desc("Type of smudge to apply to terrain.")]
public readonly string[] SmudgeType = { };
public readonly HashSet<string> SmudgeType = new HashSet<string>();
public override void DoImpact(Target target, Actor firedBy, IEnumerable<int> damageModifiers)
{
@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Warheads
// Draw the smudges:
foreach (var sc in allCells)
{
var smudgeType = world.Map.GetTerrainInfo(sc).AcceptsSmudgeType.FirstOrDefault(t => SmudgeType.Contains(t));
var smudgeType = world.Map.GetTerrainInfo(sc).AcceptsSmudgeType.FirstOrDefault(SmudgeType.Contains);
if (smudgeType == null) continue;
SmudgeLayer smudgeLayer;

View File

@@ -69,7 +69,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (path != null)
Install(path);
else if ((installData.InstallShieldCABFileIds.Length != 0 || installData.InstallShieldCABFilePackageIds.Length != 0)
else if ((installData.InstallShieldCABFileIds.Count != 0 || installData.InstallShieldCABFilePackageIds.Count != 0)
&& (path = InstallUtils.GetMountedDisk(IsTFD)) != null)
InstallTFD(Platform.ResolvePath(path, "data1.hdr"));
else
@@ -91,10 +91,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
using (var cabExtractor = new InstallShieldCABExtractor(source))
{
var denom = installData.InstallShieldCABFileIds.Length;
var denom = installData.InstallShieldCABFileIds.Count;
var extractFiles = installData.ExtractFilesFromCD;
if (installData.InstallShieldCABFilePackageIds.Length > 0)
if (installData.InstallShieldCABFilePackageIds.Count > 0)
denom += extractFiles.SelectMany(x => x.Value).Count();
var installPercent = 100 / denom;

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.GameRules;
using OpenRA.Traits;
@@ -19,7 +20,7 @@ namespace OpenRA.Mods.D2k.Traits
{
[WeaponReference]
public readonly string Weapon = "weathering";
public readonly string[] SafeTerrain = { "Concrete" };
public readonly HashSet<string> SafeTerrain = new HashSet<string> { "Concrete" };
public readonly int DamageThreshold = 50;
public object Create(ActorInitializer init) { return new DamagedWithoutFoundation(init.Self, this); }

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
@@ -22,7 +23,7 @@ namespace OpenRA.Mods.D2k.Traits
[FieldLoader.Require]
[Desc("The terrain types that this template will be placed on")]
public readonly string[] TerrainTypes = { };
public readonly HashSet<string> TerrainTypes = new HashSet<string>();
[Desc("Offset relative to the actor TopLeft. Not used if the template is PickAny")]
public readonly CVec Offset = CVec.Zero;

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA.Activities
readonly MinelayerInfo info;
readonly AmmoPool[] ammoPools;
readonly IMove movement;
readonly string[] rearmBuildings;
readonly HashSet<string> rearmBuildings;
public LayMines(Actor self)
{

View File

@@ -8,7 +8,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Traits
@@ -18,7 +18,7 @@ namespace OpenRA.Mods.RA.Traits
{
[FieldLoader.Require]
[Desc("This unit's cloneable type is:")]
public readonly string[] Types = { };
public readonly HashSet<string> Types = new HashSet<string>();
}
public class Cloneable { }

View File

@@ -49,7 +49,7 @@ namespace OpenRA.Mods.RA.Traits
self.Kill(crusher);
}
public bool CrushableBy(string[] crushClasses, Player owner)
public bool CrushableBy(HashSet<string> crushClasses, Player owner)
{
return info.CrushClasses.Overlaps(crushClasses);
}

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Mods.RA.Traits
public class MinelayerInfo : ITraitInfo
{
[ActorReference] public readonly string Mine = "minv";
[ActorReference] public readonly string[] RearmBuildings = { "fix" };
[ActorReference] public readonly HashSet<string> RearmBuildings = new HashSet<string> { "fix" };
public readonly string AmmoPoolName = "primary";

View File

@@ -18,7 +18,7 @@ namespace OpenRA.Mods.RA.Traits
[Desc("Palette effect used for blinking \"animations\" on actors.")]
class LightPaletteRotatorInfo : ITraitInfo
{
public readonly string[] ExcludePalettes = { };
public readonly HashSet<string> ExcludePalettes = new HashSet<string>();
public object Create(ActorInitializer init) { return new LightPaletteRotator(this); }
}

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
@@ -16,7 +17,7 @@ namespace OpenRA.Mods.RA.Traits
{
public class WithLandingCraftAnimationInfo : ITraitInfo, Requires<IMoveInfo>, Requires<WithSpriteBodyInfo>, Requires<CargoInfo>
{
public readonly string[] OpenTerrainTypes = { "Clear" };
public readonly HashSet<string> OpenTerrainTypes = new HashSet<string> { "Clear" };
[SequenceReference] public readonly string OpenSequence = "open";
[SequenceReference] public readonly string CloseSequence = "close";
[SequenceReference] public readonly string UnloadSequence = "unload";