From 2bac492a654a15734a72e43a668ddec2c81c6d56 Mon Sep 17 00:00:00 2001 From: penev92 Date: Mon, 25 Apr 2022 03:05:30 +0300 Subject: [PATCH] Made all traitInfo fields readonly This came up while working on the new documentation generation and comparing the results to ORAIDE's own code parser. --- .../Traits/Conditions/SpreadsCondition.cs | 2 +- OpenRA.Mods.Common/Traits/Crates/CrateAction.cs | 2 +- .../Traits/Crates/ExplodeCrateAction.cs | 2 +- .../Traits/Crates/GiveCashCrateAction.cs | 4 ++-- .../Traits/Crates/GiveMcvCrateAction.cs | 2 +- OpenRA.Mods.Common/Traits/MustBeDestroyed.cs | 2 +- .../Traits/Player/BaseAttackNotifier.cs | 4 ++-- .../Traits/Player/HarvesterAttackNotifier.cs | 2 +- .../Traits/Player/MissionObjectives.cs | 4 ++-- OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs | 2 +- .../Traits/Player/PlayerStatistics.cs | 6 +++--- .../Traits/ProductionQueueFromSelection.cs | 4 ++-- OpenRA.Mods.Common/Traits/Sellable.cs | 2 +- OpenRA.Mods.Common/Traits/Targetable.cs | 2 +- OpenRA.Mods.D2k/Traits/AttractsWorms.cs | 14 +++++++------- 15 files changed, 27 insertions(+), 27 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Conditions/SpreadsCondition.cs b/OpenRA.Mods.Common/Traits/Conditions/SpreadsCondition.cs index 59d008716f..081bfdcd6e 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/SpreadsCondition.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/SpreadsCondition.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits public readonly string SpreadCondition = "spreading"; [Desc("Time in ticks to wait between spreading further.")] - public int Delay = 5; + public readonly int Delay = 5; public override object Create(ActorInitializer init) { return new SpreadsCondition(this); } } diff --git a/OpenRA.Mods.Common/Traits/Crates/CrateAction.cs b/OpenRA.Mods.Common/Traits/Crates/CrateAction.cs index 500c5e17f2..c5dd60e0e1 100644 --- a/OpenRA.Mods.Common/Traits/Crates/CrateAction.cs +++ b/OpenRA.Mods.Common/Traits/Crates/CrateAction.cs @@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits [ActorReference] [Desc("Actor types that this crate action will not occur for.")] - public string[] ExcludedActorTypes = Array.Empty(); + public readonly string[] ExcludedActorTypes = Array.Empty(); public override object Create(ActorInitializer init) { return new CrateAction(init.Self, this); } } diff --git a/OpenRA.Mods.Common/Traits/Crates/ExplodeCrateAction.cs b/OpenRA.Mods.Common/Traits/Crates/ExplodeCrateAction.cs index 3c8dc37154..f6dced14dd 100644 --- a/OpenRA.Mods.Common/Traits/Crates/ExplodeCrateAction.cs +++ b/OpenRA.Mods.Common/Traits/Crates/ExplodeCrateAction.cs @@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Traits [WeaponReference] [FieldLoader.Require] [Desc("The weapon to fire upon collection.")] - public string Weapon = null; + public readonly string Weapon = null; public override object Create(ActorInitializer init) { return new ExplodeCrateAction(init.Self, this); } } diff --git a/OpenRA.Mods.Common/Traits/Crates/GiveCashCrateAction.cs b/OpenRA.Mods.Common/Traits/Crates/GiveCashCrateAction.cs index d38eabc6c8..dbe85282a6 100644 --- a/OpenRA.Mods.Common/Traits/Crates/GiveCashCrateAction.cs +++ b/OpenRA.Mods.Common/Traits/Crates/GiveCashCrateAction.cs @@ -17,10 +17,10 @@ namespace OpenRA.Mods.Common.Traits class GiveCashCrateActionInfo : CrateActionInfo { [Desc("Amount of cash to give.")] - public int Amount = 2000; + public readonly int Amount = 2000; [Desc("Should the collected amount be displayed as a cash tick?")] - public bool UseCashTick = false; + public readonly bool UseCashTick = false; public override object Create(ActorInitializer init) { return new GiveCashCrateAction(init.Self, this); } } diff --git a/OpenRA.Mods.Common/Traits/Crates/GiveMcvCrateAction.cs b/OpenRA.Mods.Common/Traits/Crates/GiveMcvCrateAction.cs index 8f755e85e9..26b1e8fd90 100644 --- a/OpenRA.Mods.Common/Traits/Crates/GiveMcvCrateAction.cs +++ b/OpenRA.Mods.Common/Traits/Crates/GiveMcvCrateAction.cs @@ -17,7 +17,7 @@ namespace OpenRA.Mods.Common.Traits class GiveMcvCrateActionInfo : GiveUnitCrateActionInfo { [Desc("The selection shares to use if the collector has no base.")] - public int NoBaseSelectionShares = 1000; + public readonly int NoBaseSelectionShares = 1000; public override object Create(ActorInitializer init) { return new GiveMcvCrateAction(init.Self, this); } } diff --git a/OpenRA.Mods.Common/Traits/MustBeDestroyed.cs b/OpenRA.Mods.Common/Traits/MustBeDestroyed.cs index 8adff0ced4..bf791198f8 100644 --- a/OpenRA.Mods.Common/Traits/MustBeDestroyed.cs +++ b/OpenRA.Mods.Common/Traits/MustBeDestroyed.cs @@ -17,7 +17,7 @@ namespace OpenRA.Mods.Common.Traits public class MustBeDestroyedInfo : TraitInfo { [Desc("In a short game only actors that have this value set to true need to be destroyed.")] - public bool RequiredForShortGame = false; + public readonly bool RequiredForShortGame = false; public override object Create(ActorInitializer init) { return new MustBeDestroyed(this); } } diff --git a/OpenRA.Mods.Common/Traits/Player/BaseAttackNotifier.cs b/OpenRA.Mods.Common/Traits/Player/BaseAttackNotifier.cs index f1e26edbca..19ce928e38 100644 --- a/OpenRA.Mods.Common/Traits/Player/BaseAttackNotifier.cs +++ b/OpenRA.Mods.Common/Traits/Player/BaseAttackNotifier.cs @@ -29,12 +29,12 @@ namespace OpenRA.Mods.Common.Traits [NotificationReference("Speech")] [Desc("The audio notification type to play.")] - public string Notification = "BaseAttack"; + public readonly string Notification = "BaseAttack"; [NotificationReference("Speech")] [Desc("The audio notification to play to allies when under attack.", "Won't play a notification to allies if this is null.")] - public string AllyNotification = null; + public readonly string AllyNotification = null; public override object Create(ActorInitializer init) { return new BaseAttackNotifier(init.Self, this); } } diff --git a/OpenRA.Mods.Common/Traits/Player/HarvesterAttackNotifier.cs b/OpenRA.Mods.Common/Traits/Player/HarvesterAttackNotifier.cs index 266e009299..3ae1b698dd 100644 --- a/OpenRA.Mods.Common/Traits/Player/HarvesterAttackNotifier.cs +++ b/OpenRA.Mods.Common/Traits/Player/HarvesterAttackNotifier.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits [NotificationReference("Speech")] [Desc("The audio notification type to play.")] - public string Notification = "HarvesterAttack"; + public readonly string Notification = "HarvesterAttack"; public override object Create(ActorInitializer init) { return new HarvesterAttackNotifier(init.Self, this); } } diff --git a/OpenRA.Mods.Common/Traits/Player/MissionObjectives.cs b/OpenRA.Mods.Common/Traits/Player/MissionObjectives.cs index d1fbeff64b..4c7ffa3fb5 100644 --- a/OpenRA.Mods.Common/Traits/Player/MissionObjectives.cs +++ b/OpenRA.Mods.Common/Traits/Player/MissionObjectives.cs @@ -265,10 +265,10 @@ namespace OpenRA.Mods.Common.Traits "Current options for PanelName are 'SKIRMISH_STATS' and 'MISSION_OBJECTIVES'.")] public class ObjectivesPanelInfo : TraitInfo { - public string PanelName = null; + public readonly string PanelName = null; [Desc("in ms")] - public int ExitDelay = 1400; + public readonly int ExitDelay = 1400; public override object Create(ActorInitializer init) { return new ObjectivesPanel(this); } } diff --git a/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs b/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs index 0aed306006..2b8efe39d0 100644 --- a/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs +++ b/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs @@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Traits public readonly string CannotPlaceNotification = null; [Desc("Hotkey to toggle between PlaceBuildingVariants when placing a structure.")] - public HotkeyReference ToggleVariantKey = new HotkeyReference(); + public readonly HotkeyReference ToggleVariantKey = new HotkeyReference(); public override object Create(ActorInitializer init) { return new PlaceBuilding(this); } } diff --git a/OpenRA.Mods.Common/Traits/Player/PlayerStatistics.cs b/OpenRA.Mods.Common/Traits/Player/PlayerStatistics.cs index a22f477012..65fd3c6e79 100644 --- a/OpenRA.Mods.Common/Traits/Player/PlayerStatistics.cs +++ b/OpenRA.Mods.Common/Traits/Player/PlayerStatistics.cs @@ -176,14 +176,14 @@ namespace OpenRA.Mods.Common.Traits public class UpdatesPlayerStatisticsInfo : TraitInfo { [Desc("Add to army value in statistics")] - public bool AddToArmyValue = false; + public readonly bool AddToArmyValue = false; [Desc("Add to assets value in statistics")] - public bool AddToAssetsValue = true; + public readonly bool AddToAssetsValue = true; [ActorReference] [Desc("Count this actor as a different type in the spectator army display.")] - public string OverrideActor = null; + public readonly string OverrideActor = null; public override object Create(ActorInitializer init) { return new UpdatesPlayerStatistics(this, init.Self); } } diff --git a/OpenRA.Mods.Common/Traits/ProductionQueueFromSelection.cs b/OpenRA.Mods.Common/Traits/ProductionQueueFromSelection.cs index 397e540433..c0f3287057 100644 --- a/OpenRA.Mods.Common/Traits/ProductionQueueFromSelection.cs +++ b/OpenRA.Mods.Common/Traits/ProductionQueueFromSelection.cs @@ -20,8 +20,8 @@ namespace OpenRA.Mods.Common.Traits [TraitLocation(SystemActors.World)] class ProductionQueueFromSelectionInfo : TraitInfo { - public string ProductionTabsWidget = null; - public string ProductionPaletteWidget = null; + public readonly string ProductionTabsWidget = null; + public readonly string ProductionPaletteWidget = null; public override object Create(ActorInitializer init) { return new ProductionQueueFromSelection(init.World, this); } } diff --git a/OpenRA.Mods.Common/Traits/Sellable.cs b/OpenRA.Mods.Common/Traits/Sellable.cs index 5bac22510c..e5c69555e1 100644 --- a/OpenRA.Mods.Common/Traits/Sellable.cs +++ b/OpenRA.Mods.Common/Traits/Sellable.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits [NotificationReference("Speech")] [Desc("The audio notification type to play.")] - public string Notification = null; + public readonly string Notification = null; [Desc("Whether to show the cash tick indicators rising from the actor.")] public readonly bool ShowTicks = true; diff --git a/OpenRA.Mods.Common/Traits/Targetable.cs b/OpenRA.Mods.Common/Traits/Targetable.cs index 10ac273c4f..9a41e26514 100644 --- a/OpenRA.Mods.Common/Traits/Targetable.cs +++ b/OpenRA.Mods.Common/Traits/Targetable.cs @@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits public readonly BitSet TargetTypes; public BitSet GetTargetTypes() { return TargetTypes; } - public bool RequiresForceFire = false; + public readonly bool RequiresForceFire = false; public override object Create(ActorInitializer init) { return new Targetable(this); } } diff --git a/OpenRA.Mods.D2k/Traits/AttractsWorms.cs b/OpenRA.Mods.D2k/Traits/AttractsWorms.cs index 6916d710d0..a4990b42c5 100644 --- a/OpenRA.Mods.D2k/Traits/AttractsWorms.cs +++ b/OpenRA.Mods.D2k/Traits/AttractsWorms.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.D2k.Traits public readonly WDist Spread = new WDist(3072); [Desc("Ranges at which each Falloff step is defined. Overrides Spread.")] - public WDist[] Range = null; + public readonly WDist[] Range = null; public override object Create(ActorInitializer init) { return new AttractsWorms(init, this); } } @@ -34,22 +34,22 @@ namespace OpenRA.Mods.D2k.Traits public class AttractsWorms : ConditionalTrait { readonly Actor self; + readonly WDist[] effectiveRange; public AttractsWorms(ActorInitializer init, AttractsWormsInfo info) : base(info) { self = init.Self; - if (info.Range == null) - info.Range = Exts.MakeArray(info.Falloff.Length, i => i * info.Spread); + effectiveRange = info.Range ?? Exts.MakeArray(info.Falloff.Length, i => i * info.Spread); } int GetNoisePercentageAtDistance(int distance) { - var inner = Info.Range[0].Length; - for (var i = 1; i < Info.Range.Length; i++) + var inner = effectiveRange[0].Length; + for (var i = 1; i < effectiveRange.Length; i++) { - var outer = Info.Range[i].Length; + var outer = effectiveRange[i].Length; if (outer > distance) return int2.Lerp(Info.Falloff[i - 1], Info.Falloff[i], distance - inner, outer - inner); @@ -68,7 +68,7 @@ namespace OpenRA.Mods.D2k.Traits var length = distance.Length; // Actor is too far to hear anything. - if (length > Info.Range[Info.Range.Length - 1].Length) + if (length > effectiveRange[effectiveRange.Length - 1].Length) return WVec.Zero; var direction = 1024 * distance / length;