diff --git a/OpenRA.Game/Activities/CallFunc.cs b/OpenRA.Game/Activities/CallFunc.cs index ca06163b6f..1685c4bfc2 100644 --- a/OpenRA.Game/Activities/CallFunc.cs +++ b/OpenRA.Game/Activities/CallFunc.cs @@ -22,7 +22,7 @@ namespace OpenRA.Activities IsInterruptible = interruptible; } - Action a; + readonly Action a; public override bool Tick(Actor self) { diff --git a/OpenRA.Game/Effects/AsyncAction.cs b/OpenRA.Game/Effects/AsyncAction.cs index af24fb1906..2dbf499c14 100644 --- a/OpenRA.Game/Effects/AsyncAction.cs +++ b/OpenRA.Game/Effects/AsyncAction.cs @@ -17,8 +17,8 @@ namespace OpenRA.Effects { public class AsyncAction : IEffect { - Action a; - IAsyncResult ar; + readonly Action a; + readonly IAsyncResult ar; public AsyncAction(IAsyncResult ar, Action a) { diff --git a/OpenRA.Game/Effects/DelayedAction.cs b/OpenRA.Game/Effects/DelayedAction.cs index d41cb4512a..bbffb741a7 100644 --- a/OpenRA.Game/Effects/DelayedAction.cs +++ b/OpenRA.Game/Effects/DelayedAction.cs @@ -17,7 +17,7 @@ namespace OpenRA.Effects { public class DelayedAction : IEffect { - Action a; + readonly Action a; int delay; public DelayedAction(int delay, Action a) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 092cb9d748..896e4d16ba 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -119,7 +119,7 @@ namespace OpenRA } // More accurate replacement for Environment.TickCount - static Stopwatch stopwatch = Stopwatch.StartNew(); + static readonly Stopwatch stopwatch = Stopwatch.StartNew(); public static long RunTime => stopwatch.ElapsedMilliseconds; public static int RenderFrame = 0; diff --git a/OpenRA.Game/Graphics/CursorManager.cs b/OpenRA.Game/Graphics/CursorManager.cs index cebe94cd53..db8bd87ac4 100644 --- a/OpenRA.Game/Graphics/CursorManager.cs +++ b/OpenRA.Game/Graphics/CursorManager.cs @@ -35,7 +35,7 @@ namespace OpenRA.Graphics Cursor cursor; bool isLocked = false; int2 lockedPosition; - bool hardwareCursorsDisabled = false; + readonly bool hardwareCursorsDisabled = false; bool hardwareCursorsDoubled = false; public CursorManager(CursorProvider cursorProvider) diff --git a/OpenRA.Game/Graphics/Palette.cs b/OpenRA.Game/Graphics/Palette.cs index e04f1c396a..8bcc4406fd 100644 --- a/OpenRA.Game/Graphics/Palette.cs +++ b/OpenRA.Game/Graphics/Palette.cs @@ -42,7 +42,7 @@ namespace OpenRA.Graphics class ReadOnlyPalette : IPalette { - IPalette palette; + readonly IPalette palette; public ReadOnlyPalette(IPalette palette) { this.palette = palette; } public uint this[int index] => palette[index]; diff --git a/OpenRA.Game/Map/ActorReference.cs b/OpenRA.Game/Map/ActorReference.cs index 67438134d1..82c78b35bc 100644 --- a/OpenRA.Game/Map/ActorReference.cs +++ b/OpenRA.Game/Map/ActorReference.cs @@ -25,7 +25,7 @@ namespace OpenRA public class ActorReference : IEnumerable { public string Type; - Lazy initDict; + readonly Lazy initDict; internal TypeDictionary InitDict => initDict.Value; diff --git a/OpenRA.Game/Map/MapCache.cs b/OpenRA.Game/Map/MapCache.cs index c6f41ebabf..9149e2f9ac 100644 --- a/OpenRA.Game/Map/MapCache.cs +++ b/OpenRA.Game/Map/MapCache.cs @@ -34,8 +34,8 @@ namespace OpenRA readonly SheetBuilder sheetBuilder; Thread previewLoaderThread; bool previewLoaderThreadShutDown = true; - object syncRoot = new object(); - Queue generateMinimap = new Queue(); + readonly object syncRoot = new object(); + readonly Queue generateMinimap = new Queue(); public Dictionary StringPool { get; } = new Dictionary(); diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index 46f920b7bc..b6bbac0c5a 100644 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -128,7 +128,7 @@ namespace OpenRA } // HACK: Only update the loading screen if we're in the main thread. - int initialThreadId; + readonly int initialThreadId; internal void HandleLoadingProgress() { if (LoadScreen != null && IsOnMainThread) diff --git a/OpenRA.Game/Network/ReplayRecorder.cs b/OpenRA.Game/Network/ReplayRecorder.cs index 5f5f7e070c..52381d226f 100644 --- a/OpenRA.Game/Network/ReplayRecorder.cs +++ b/OpenRA.Game/Network/ReplayRecorder.cs @@ -23,7 +23,7 @@ namespace OpenRA.Network public ReplayMetadata Metadata; BinaryWriter writer; - Func chooseFilename; + readonly Func chooseFilename; MemoryStream preStartBuffer = new MemoryStream(); static bool IsGameStart(byte[] data) diff --git a/OpenRA.Game/Network/SyncReport.cs b/OpenRA.Game/Network/SyncReport.cs index 3b520fffeb..b85614c1e3 100644 --- a/OpenRA.Game/Network/SyncReport.cs +++ b/OpenRA.Game/Network/SyncReport.cs @@ -22,7 +22,7 @@ namespace OpenRA.Network class SyncReport { const int NumSyncReports = 5; - static Cache typeInfoCache = new Cache(t => new TypeInfo(t)); + static readonly Cache typeInfoCache = new Cache(t => new TypeInfo(t)); readonly OrderManager orderManager; @@ -154,9 +154,9 @@ namespace OpenRA.Network public int Frame; public int SyncedRandom; public int TotalCount; - public List Traits = new List(); - public List Effects = new List(); - public List Orders = new List(); + public readonly List Traits = new List(); + public readonly List Effects = new List(); + public readonly List Orders = new List(); } struct TraitReport diff --git a/OpenRA.Game/Platform.cs b/OpenRA.Game/Platform.cs index 3e201d00bd..ebf58e2b99 100644 --- a/OpenRA.Game/Platform.cs +++ b/OpenRA.Game/Platform.cs @@ -25,7 +25,7 @@ namespace OpenRA public static PlatformType CurrentPlatform => currentPlatform.Value; public static readonly Guid SessionGUID = Guid.NewGuid(); - static Lazy currentPlatform = Exts.Lazy(GetCurrentPlatform); + static readonly Lazy currentPlatform = Exts.Lazy(GetCurrentPlatform); static bool engineDirAccessed; static string engineDir; diff --git a/OpenRA.Game/Primitives/DisposableAction.cs b/OpenRA.Game/Primitives/DisposableAction.cs index 70765a2154..89e0eaaa4b 100644 --- a/OpenRA.Game/Primitives/DisposableAction.cs +++ b/OpenRA.Game/Primitives/DisposableAction.cs @@ -21,8 +21,8 @@ namespace OpenRA.Primitives this.onFinalize = onFinalize; } - Action onDispose; - Action onFinalize; + readonly Action onDispose; + readonly Action onFinalize; bool disposed; public void Dispose() diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index e280224b3d..23df495c1e 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -77,7 +77,7 @@ namespace OpenRA.Server ReplayRecorder recorder; GameInformation gameInfo; readonly List worldPlayers = new List(); - Stopwatch pingUpdated = Stopwatch.StartNew(); + readonly Stopwatch pingUpdated = Stopwatch.StartNew(); public ServerState State { diff --git a/OpenRA.Game/Support/Arguments.cs b/OpenRA.Game/Support/Arguments.cs index c850892860..f18137d77f 100644 --- a/OpenRA.Game/Support/Arguments.cs +++ b/OpenRA.Game/Support/Arguments.cs @@ -16,7 +16,7 @@ namespace OpenRA { public class Arguments { - Dictionary args = new Dictionary(); + readonly Dictionary args = new Dictionary(); public static Arguments Empty => new Arguments(); diff --git a/OpenRA.Game/Support/PerfItem.cs b/OpenRA.Game/Support/PerfItem.cs index 84f0c31cb4..d6077ecdad 100644 --- a/OpenRA.Game/Support/PerfItem.cs +++ b/OpenRA.Game/Support/PerfItem.cs @@ -18,7 +18,7 @@ namespace OpenRA.Support { public readonly Color C; public readonly string Name; - double[] samples = new double[100]; + readonly double[] samples = new double[100]; public double Val = 0.0; int head = 1, tail = 0; public bool HasNormalTick = true; diff --git a/OpenRA.Game/Support/PerfTimer.cs b/OpenRA.Game/Support/PerfTimer.cs index a3783031bb..2cfe193f8a 100644 --- a/OpenRA.Game/Support/PerfTimer.cs +++ b/OpenRA.Game/Support/PerfTimer.cs @@ -31,7 +31,7 @@ namespace OpenRA.Support List children; long ticks; - static ThreadLocal parentThreadLocal = new ThreadLocal(); + static readonly ThreadLocal parentThreadLocal = new ThreadLocal(); public PerfTimer(string name, float thresholdMs = 0) { diff --git a/OpenRA.Game/Traits/World/ScreenShaker.cs b/OpenRA.Game/Traits/World/ScreenShaker.cs index f1974af771..7a3df58794 100644 --- a/OpenRA.Game/Traits/World/ScreenShaker.cs +++ b/OpenRA.Game/Traits/World/ScreenShaker.cs @@ -29,7 +29,7 @@ namespace OpenRA.Traits { readonly ScreenShakerInfo info; WorldRenderer worldRenderer; - List shakeEffects = new List(); + readonly List shakeEffects = new List(); int ticks = 0; public ScreenShaker(ScreenShakerInfo info) diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index 6125a2197e..fd8f15bba4 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -370,7 +370,7 @@ namespace OpenRA public int WorldTick { get; private set; } - Dictionary gameSaveTraitData = new Dictionary(); + readonly Dictionary gameSaveTraitData = new Dictionary(); internal void AddGameSaveTraitData(int traitIndex, MiniYaml yaml) { gameSaveTraitData[traitIndex] = yaml; diff --git a/OpenRA.Mods.Cnc/Activities/Teleport.cs b/OpenRA.Mods.Cnc/Activities/Teleport.cs index 6dc7943840..fdd6519137 100644 --- a/OpenRA.Mods.Cnc/Activities/Teleport.cs +++ b/OpenRA.Mods.Cnc/Activities/Teleport.cs @@ -27,9 +27,9 @@ namespace OpenRA.Mods.Cnc.Activities readonly bool killOnFailure; readonly BitSet killDamageTypes; CPos destination; - bool killCargo; - bool screenFlash; - string sound; + readonly bool killCargo; + readonly bool screenFlash; + readonly string sound; public Teleport(Actor teleporter, CPos destination, int? maximumDistance, bool killCargo, bool screenFlash, string sound, bool interruptable = true, diff --git a/OpenRA.Mods.Cnc/FileFormats/Blowfish.cs b/OpenRA.Mods.Cnc/FileFormats/Blowfish.cs index 4f249b14b1..82cff182c2 100644 --- a/OpenRA.Mods.Cnc/FileFormats/Blowfish.cs +++ b/OpenRA.Mods.Cnc/FileFormats/Blowfish.cs @@ -130,7 +130,7 @@ namespace OpenRA.Mods.Cnc.FileFormats return i; } - uint[] lookupMfromP = + readonly uint[] lookupMfromP = { 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, @@ -139,7 +139,7 @@ namespace OpenRA.Mods.Cnc.FileFormats 0x9216d5d9, 0x8979fb1b }; - uint[,] lookupMfromS = + readonly uint[,] lookupMfromS = { { 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, diff --git a/OpenRA.Mods.Cnc/FileFormats/BlowfishKeyProvider.cs b/OpenRA.Mods.Cnc/FileFormats/BlowfishKeyProvider.cs index add895bfe9..6cc4ad228e 100644 --- a/OpenRA.Mods.Cnc/FileFormats/BlowfishKeyProvider.cs +++ b/OpenRA.Mods.Cnc/FileFormats/BlowfishKeyProvider.cs @@ -22,18 +22,18 @@ namespace OpenRA.Mods.Cnc.FileFormats class PublicKey { - public uint[] KeyOne = new uint[64]; - public uint[] KeyTwo = new uint[64]; + public readonly uint[] KeyOne = new uint[64]; + public readonly uint[] KeyTwo = new uint[64]; public uint Len; } - PublicKey pubkey = new PublicKey(); + readonly PublicKey pubkey = new PublicKey(); - uint[] globOne = new uint[64]; + readonly uint[] globOne = new uint[64]; uint globOneBitLen, globOneLenXTwo; - uint[] globTwo = new uint[130]; - uint[] globOneHigh = new uint[4]; - uint[] globOneHighInv = new uint[4]; + readonly uint[] globTwo = new uint[130]; + readonly uint[] globOneHigh = new uint[4]; + readonly uint[] globOneHighInv = new uint[4]; uint globOneHighBitLen; uint globOneHighInvLow, globOneHighInvHigh; diff --git a/OpenRA.Mods.Cnc/FileFormats/VqaVideo.cs b/OpenRA.Mods.Cnc/FileFormats/VqaVideo.cs index 640155e42e..57b1cfb65f 100644 --- a/OpenRA.Mods.Cnc/FileFormats/VqaVideo.cs +++ b/OpenRA.Mods.Cnc/FileFormats/VqaVideo.cs @@ -45,21 +45,21 @@ namespace OpenRA.Mods.Cnc.FileFormats // Stores a list of subpixels, referenced by the VPTZ chunk byte[] cbf; - byte[] cbp; - byte[] cbfBuffer; + readonly byte[] cbp; + readonly byte[] cbfBuffer; bool cbpIsCompressed; // Buffer for loading file subchunks, the maximum chunk size of a file is not defined // and the header definition for the size of the biggest chunks (color data) isn't accurate. // But 256k is large enough for all TS videos(< 200k). - byte[] fileBuffer = new byte[256000]; - int maxCbfzSize = 256000; + readonly byte[] fileBuffer = new byte[256000]; + readonly int maxCbfzSize = 256000; int vtprSize = 0; int currentChunkBuffer = 0; int chunkBufferOffset = 0; // Top half contains block info, bottom half contains references to cbf array - byte[] origData; + readonly byte[] origData; public VqaVideo(Stream stream, bool useFramePadding) { diff --git a/OpenRA.Mods.Cnc/FileFormats/VxlReader.cs b/OpenRA.Mods.Cnc/FileFormats/VxlReader.cs index fedb1fbcf4..62bb46e58e 100644 --- a/OpenRA.Mods.Cnc/FileFormats/VxlReader.cs +++ b/OpenRA.Mods.Cnc/FileFormats/VxlReader.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.Cnc.FileFormats public readonly uint LimbCount; public VxlLimb[] Limbs; - uint bodySize; + readonly uint bodySize; static void ReadVoxelData(Stream s, VxlLimb l) { diff --git a/OpenRA.Mods.Cnc/FileSystem/PackageEntry.cs b/OpenRA.Mods.Cnc/FileSystem/PackageEntry.cs index 9d1bf614fe..855a486461 100644 --- a/OpenRA.Mods.Cnc/FileSystem/PackageEntry.cs +++ b/OpenRA.Mods.Cnc/FileSystem/PackageEntry.cs @@ -105,7 +105,7 @@ namespace OpenRA.Mods.Cnc.FileSystem } } - static Dictionary names = new Dictionary(); + static readonly Dictionary names = new Dictionary(); public static void AddStandardName(string s) { diff --git a/OpenRA.Mods.Cnc/Graphics/TeslaZapRenderable.cs b/OpenRA.Mods.Cnc/Graphics/TeslaZapRenderable.cs index be41a054be..0d3acfc647 100644 --- a/OpenRA.Mods.Cnc/Graphics/TeslaZapRenderable.cs +++ b/OpenRA.Mods.Cnc/Graphics/TeslaZapRenderable.cs @@ -19,7 +19,7 @@ namespace OpenRA.Mods.Cnc.Graphics { class TeslaZapRenderable : IPalettedRenderable, IFinalizedRenderable { - static int[][] steps = new[] + static readonly int[][] steps = new[] { new int[] { 8, 8, 4, 4, 0 }, new int[] { -8, -8, -4, -4, 0 }, @@ -40,8 +40,8 @@ namespace OpenRA.Mods.Cnc.Graphics readonly string brightSequence; readonly int brightZaps, dimZaps; - WPos cachedPos; - WVec cachedLength; + readonly WPos cachedPos; + readonly WVec cachedLength; IEnumerable cache; public TeslaZapRenderable(WPos pos, int zOffset, in WVec length, string image, string brightSequence, int brightZaps, string dimSequence, int dimZaps, string palette) diff --git a/OpenRA.Mods.Cnc/SpriteLoaders/ShpTDLoader.cs b/OpenRA.Mods.Cnc/SpriteLoaders/ShpTDLoader.cs index 339ec62630..9a4789df88 100644 --- a/OpenRA.Mods.Cnc/SpriteLoaders/ShpTDLoader.cs +++ b/OpenRA.Mods.Cnc/SpriteLoaders/ShpTDLoader.cs @@ -87,11 +87,11 @@ namespace OpenRA.Mods.Cnc.SpriteLoaders public uint FileOffset; public Format Format; - public uint RefOffset; - public Format RefFormat; + public readonly uint RefOffset; + public readonly Format RefFormat; public ImageHeader RefImage; - ShpTDSprite reader; + readonly ShpTDSprite reader; // Used by ShpWriter public ImageHeader() { } diff --git a/OpenRA.Mods.Cnc/Traits/Attack/AttackPopupTurreted.cs b/OpenRA.Mods.Cnc/Traits/Attack/AttackPopupTurreted.cs index 74287ca25e..421cb664d6 100644 --- a/OpenRA.Mods.Cnc/Traits/Attack/AttackPopupTurreted.cs +++ b/OpenRA.Mods.Cnc/Traits/Attack/AttackPopupTurreted.cs @@ -56,7 +56,7 @@ namespace OpenRA.Mods.Cnc.Traits int idleTicks = 0; PopupState state = PopupState.Open; - bool skippedMakeAnimation; + readonly bool skippedMakeAnimation; public AttackPopupTurreted(ActorInitializer init, AttackPopupTurretedInfo info) : base(init.Self, info) diff --git a/OpenRA.Mods.Cnc/Traits/ConyardChronoReturn.cs b/OpenRA.Mods.Cnc/Traits/ConyardChronoReturn.cs index d8c8b6f734..1691dd9c35 100644 --- a/OpenRA.Mods.Cnc/Traits/ConyardChronoReturn.cs +++ b/OpenRA.Mods.Cnc/Traits/ConyardChronoReturn.cs @@ -73,7 +73,7 @@ namespace OpenRA.Mods.Cnc.Traits int conditionToken = Actor.InvalidConditionToken; Actor chronosphere; - int duration; + readonly int duration; bool returnOriginal; bool selling; @@ -81,7 +81,7 @@ namespace OpenRA.Mods.Cnc.Traits int returnTicks = 0; [Sync] - CPos origin; + readonly CPos origin; [Sync] bool triggered; diff --git a/OpenRA.Mods.Cnc/Traits/Render/WithCargo.cs b/OpenRA.Mods.Cnc/Traits/Render/WithCargo.cs index a367147a19..1e4cf58949 100644 --- a/OpenRA.Mods.Cnc/Traits/Render/WithCargo.cs +++ b/OpenRA.Mods.Cnc/Traits/Render/WithCargo.cs @@ -40,7 +40,7 @@ namespace OpenRA.Mods.Cnc.Traits.Render readonly IFacing facing; WAngle cachedFacing; - Dictionary previews = new Dictionary(); + readonly Dictionary previews = new Dictionary(); public WithCargo(Actor self, WithCargoInfo info) { diff --git a/OpenRA.Mods.Cnc/Traits/Render/WithVoxelWalkerBody.cs b/OpenRA.Mods.Cnc/Traits/Render/WithVoxelWalkerBody.cs index e26e189c8f..0d77285118 100644 --- a/OpenRA.Mods.Cnc/Traits/Render/WithVoxelWalkerBody.cs +++ b/OpenRA.Mods.Cnc/Traits/Render/WithVoxelWalkerBody.cs @@ -51,7 +51,8 @@ namespace OpenRA.Mods.Cnc.Traits.Render readonly ModelAnimation modelAnimation; readonly RenderVoxels rv; - uint tick, frame, frames; + uint tick, frame; + readonly uint frames; public WithVoxelWalkerBody(Actor self, WithVoxelWalkerBodyInfo info) { diff --git a/OpenRA.Mods.Cnc/UtilityCommands/ImportRedAlertLegacyMapCommand.cs b/OpenRA.Mods.Cnc/UtilityCommands/ImportRedAlertLegacyMapCommand.cs index 5b8446c322..fa99dcacbb 100644 --- a/OpenRA.Mods.Cnc/UtilityCommands/ImportRedAlertLegacyMapCommand.cs +++ b/OpenRA.Mods.Cnc/UtilityCommands/ImportRedAlertLegacyMapCommand.cs @@ -42,7 +42,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands } // Mapping from RA95 overlay index to type string - static string[] redAlertOverlayNames = + static readonly string[] redAlertOverlayNames = { "sbag", "cycl", "brik", "fenc", "wood", "gold01", "gold02", "gold03", "gold04", @@ -51,7 +51,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands "fpls", "wcrate", "scrate", "barb", "sbag", }; - static Dictionary overlayResourceMapping = new Dictionary() + static readonly Dictionary overlayResourceMapping = new Dictionary() { // RA ore & crystals { "gold01", (1, 0) }, @@ -81,7 +81,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands Map.Tiles[new CPos(i, j)] = new TerrainTile(types[i, j], ms.ReadUInt8()); } - static string[] overlayActors = new string[] + static readonly string[] overlayActors = new string[] { // Fences "sbag", "cycl", "brik", "fenc", "wood", diff --git a/OpenRA.Mods.Cnc/UtilityCommands/ImportTiberianDawnLegacyMapCommand.cs b/OpenRA.Mods.Cnc/UtilityCommands/ImportTiberianDawnLegacyMapCommand.cs index 62e142eec8..357d7530d4 100644 --- a/OpenRA.Mods.Cnc/UtilityCommands/ImportTiberianDawnLegacyMapCommand.cs +++ b/OpenRA.Mods.Cnc/UtilityCommands/ImportTiberianDawnLegacyMapCommand.cs @@ -39,7 +39,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands } } - static Dictionary overlayResourceMapping = new Dictionary() + static readonly Dictionary overlayResourceMapping = new Dictionary() { // Tiberium { "ti1", (1, 0) }, @@ -69,7 +69,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands } } - static string[] overlayActors = new string[] + static readonly string[] overlayActors = new string[] { // Fences "sbag", "cycl", "brik", "fenc", "wood", diff --git a/OpenRA.Mods.Common/Activities/Air/FallToEarth.cs b/OpenRA.Mods.Common/Activities/Air/FallToEarth.cs index 8c1d8e1581..e652aa9c47 100644 --- a/OpenRA.Mods.Common/Activities/Air/FallToEarth.cs +++ b/OpenRA.Mods.Common/Activities/Air/FallToEarth.cs @@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Activities readonly Aircraft aircraft; readonly FallsToEarthInfo info; - int acceleration; + readonly int acceleration; int spin; public FallToEarth(Actor self, FallsToEarthInfo info) diff --git a/OpenRA.Mods.Common/Activities/Air/FlyIdle.cs b/OpenRA.Mods.Common/Activities/Air/FlyIdle.cs index c39bc4591c..61119e9e81 100644 --- a/OpenRA.Mods.Common/Activities/Air/FlyIdle.cs +++ b/OpenRA.Mods.Common/Activities/Air/FlyIdle.cs @@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Activities readonly INotifyIdle[] tickIdles; readonly bool idleTurn; int remainingTicks; - bool isIdleTurner; + readonly bool isIdleTurner; public FlyIdle(Actor self, int ticks = -1, bool idleTurn = true) { diff --git a/OpenRA.Mods.Common/Activities/Move/Drag.cs b/OpenRA.Mods.Common/Activities/Move/Drag.cs index 74af83a870..8d3210767b 100644 --- a/OpenRA.Mods.Common/Activities/Move/Drag.cs +++ b/OpenRA.Mods.Common/Activities/Move/Drag.cs @@ -21,10 +21,11 @@ namespace OpenRA.Mods.Common.Activities { readonly IPositionable positionable; readonly IDisabledTrait disableable; - WPos start, end; - int length; + readonly WPos start; + readonly WPos end; + readonly int length; int ticks = 0; - WAngle? desiredFacing; + readonly WAngle? desiredFacing; public Drag(Actor self, WPos start, WPos end, int length, WAngle? facing = null) { diff --git a/OpenRA.Mods.Common/Activities/Move/Move.cs b/OpenRA.Mods.Common/Activities/Move/Move.cs index af1fbdad2f..a861d2819e 100644 --- a/OpenRA.Mods.Common/Activities/Move/Move.cs +++ b/OpenRA.Mods.Common/Activities/Move/Move.cs @@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.Activities int waitTicksRemaining; // To work around queued activity issues while minimizing changes to legacy behaviour - bool evaluateNearestMovableCell; + readonly bool evaluateNearestMovableCell; // Scriptable move order // Ignores lane bias and nearby units diff --git a/OpenRA.Mods.Common/Activities/Move/MoveAdjacentTo.cs b/OpenRA.Mods.Common/Activities/Move/MoveAdjacentTo.cs index f6a68a1d1a..2a622c46d9 100644 --- a/OpenRA.Mods.Common/Activities/Move/MoveAdjacentTo.cs +++ b/OpenRA.Mods.Common/Activities/Move/MoveAdjacentTo.cs @@ -111,7 +111,7 @@ namespace OpenRA.Mods.Common.Activities return TickChild(self); } - List searchCells = new List(); + readonly List searchCells = new List(); int searchCellsTick = -1; List CalculatePathToTarget(Actor self, BlockedByActor check) diff --git a/OpenRA.Mods.Common/Activities/Sell.cs b/OpenRA.Mods.Common/Activities/Sell.cs index 16faafeb98..e700b0c96a 100644 --- a/OpenRA.Mods.Common/Activities/Sell.cs +++ b/OpenRA.Mods.Common/Activities/Sell.cs @@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Activities readonly IHealth health; readonly SellableInfo sellableInfo; readonly PlayerResources playerResources; - bool showTicks; + readonly bool showTicks; public Sell(Actor self, bool showTicks) { diff --git a/OpenRA.Mods.Common/Activities/SimpleTeleport.cs b/OpenRA.Mods.Common/Activities/SimpleTeleport.cs index dd2e22718e..397ce87174 100644 --- a/OpenRA.Mods.Common/Activities/SimpleTeleport.cs +++ b/OpenRA.Mods.Common/Activities/SimpleTeleport.cs @@ -16,7 +16,7 @@ namespace OpenRA.Mods.Common.Activities { public class SimpleTeleport : Activity { - CPos destination; + readonly CPos destination; public SimpleTeleport(CPos destination) { this.destination = destination; } diff --git a/OpenRA.Mods.Common/Activities/Wait.cs b/OpenRA.Mods.Common/Activities/Wait.cs index 70c9a00882..91aeb5b8c7 100644 --- a/OpenRA.Mods.Common/Activities/Wait.cs +++ b/OpenRA.Mods.Common/Activities/Wait.cs @@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Activities public class WaitFor : Activity { - Func f; + readonly Func f; public WaitFor(Func f) { this.f = f; } public WaitFor(Func f, bool interruptible) diff --git a/OpenRA.Mods.Common/Effects/ContrailFader.cs b/OpenRA.Mods.Common/Effects/ContrailFader.cs index d1811d6306..73f1547dbd 100644 --- a/OpenRA.Mods.Common/Effects/ContrailFader.cs +++ b/OpenRA.Mods.Common/Effects/ContrailFader.cs @@ -18,8 +18,8 @@ namespace OpenRA.Mods.Common.Effects { public class ContrailFader : IEffect { - WPos pos; - ContrailRenderable trail; + readonly WPos pos; + readonly ContrailRenderable trail; int ticks; public ContrailFader(WPos pos, ContrailRenderable trail) diff --git a/OpenRA.Mods.Common/Effects/FloatingText.cs b/OpenRA.Mods.Common/Effects/FloatingText.cs index d679f52766..4a70daf413 100644 --- a/OpenRA.Mods.Common/Effects/FloatingText.cs +++ b/OpenRA.Mods.Common/Effects/FloatingText.cs @@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Effects readonly SpriteFont font; readonly string text; - Color color; + readonly Color color; int remaining; WPos pos; diff --git a/OpenRA.Mods.Common/Effects/RallyPointIndicator.cs b/OpenRA.Mods.Common/Effects/RallyPointIndicator.cs index b9beb5814a..149d0d2f3e 100644 --- a/OpenRA.Mods.Common/Effects/RallyPointIndicator.cs +++ b/OpenRA.Mods.Common/Effects/RallyPointIndicator.cs @@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Effects readonly Animation flag; readonly Animation circles; - List targetLineNodes = new List { }; + readonly List targetLineNodes = new List { }; List cachedLocations; public RallyPointIndicator(Actor building, RallyPoint rp) diff --git a/OpenRA.Mods.Common/FileFormats/Blast.cs b/OpenRA.Mods.Common/FileFormats/Blast.cs index 649deaf55c..cfb17b0283 100644 --- a/OpenRA.Mods.Common/FileFormats/Blast.cs +++ b/OpenRA.Mods.Common/FileFormats/Blast.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.FileFormats public static readonly int MAXBITS = 13; // maximum code length public static readonly int MAXWIN = 4096; // maximum window size - static byte[] litlen = + static readonly byte[] litlen = { 11, 124, 8, 7, 28, 7, 188, 13, 76, 4, 10, 8, 12, 10, 12, 10, 8, 23, 8, 9, @@ -40,28 +40,28 @@ namespace OpenRA.Mods.Common.FileFormats }; // bit lengths of length codes 0..15 - static byte[] lenlen = { 2, 35, 36, 53, 38, 23 }; + static readonly byte[] lenlen = { 2, 35, 36, 53, 38, 23 }; // bit lengths of distance codes 0..63 - static byte[] distlen = { 2, 20, 53, 230, 247, 151, 248 }; + static readonly byte[] distlen = { 2, 20, 53, 230, 247, 151, 248 }; // base for length codes - static short[] lengthbase = + static readonly short[] lengthbase = { 3, 2, 4, 5, 6, 7, 8, 9, 10, 12, 16, 24, 40, 72, 136, 264 }; // extra bits for length codes - static byte[] extra = + static readonly byte[] extra = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8 }; - static Huffman litcode = new Huffman(litlen, litlen.Length, 256); - static Huffman lencode = new Huffman(lenlen, lenlen.Length, 16); - static Huffman distcode = new Huffman(distlen, distlen.Length, 64); + static readonly Huffman litcode = new Huffman(litlen, litlen.Length, 256); + static readonly Huffman lencode = new Huffman(lenlen, lenlen.Length, 16); + static readonly Huffman distcode = new Huffman(distlen, distlen.Length, 64); /// PKWare Compression Library stream. /// Compressed input stream. diff --git a/OpenRA.Mods.Common/FileFormats/IniFile.cs b/OpenRA.Mods.Common/FileFormats/IniFile.cs index 805f981afe..b4b35dd438 100644 --- a/OpenRA.Mods.Common/FileFormats/IniFile.cs +++ b/OpenRA.Mods.Common/FileFormats/IniFile.cs @@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.FileFormats { public class IniFile { - Dictionary sections = new Dictionary(); + readonly Dictionary sections = new Dictionary(); public IniFile(Stream s) { @@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.FileFormats } } - Regex sectionPattern = new Regex(@"^\[([^]]*)\]"); + readonly Regex sectionPattern = new Regex(@"^\[([^]]*)\]"); IniSection ProcessSection(string line) { @@ -111,7 +111,7 @@ namespace OpenRA.Mods.Common.FileFormats public class IniSection : IEnumerable> { public string Name { get; private set; } - Dictionary values = new Dictionary(); + readonly Dictionary values = new Dictionary(); public IniSection(string name) { diff --git a/OpenRA.Mods.Common/Graphics/ContrailRenderable.cs b/OpenRA.Mods.Common/Graphics/ContrailRenderable.cs index 101fe5768a..02a8b993d8 100644 --- a/OpenRA.Mods.Common/Graphics/ContrailRenderable.cs +++ b/OpenRA.Mods.Common/Graphics/ContrailRenderable.cs @@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Graphics readonly WDist width; int next; int length; - int skip; + readonly int skip; public ContrailRenderable(World world, Color color, WDist width, int length, int skip, int zOffset) : this(world, new WPos[length], width, 0, 0, skip, color, zOffset) { } diff --git a/OpenRA.Mods.Common/Orders/GlobalButtonOrderGenerator.cs b/OpenRA.Mods.Common/Orders/GlobalButtonOrderGenerator.cs index 22e4386510..d76c573a77 100644 --- a/OpenRA.Mods.Common/Orders/GlobalButtonOrderGenerator.cs +++ b/OpenRA.Mods.Common/Orders/GlobalButtonOrderGenerator.cs @@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.Orders { public abstract class GlobalButtonOrderGenerator : OrderGenerator { - string order; + readonly string order; public GlobalButtonOrderGenerator(string order) { diff --git a/OpenRA.Mods.Common/Projectiles/Bullet.cs b/OpenRA.Mods.Common/Projectiles/Bullet.cs index b53fbce61a..1d7b1d5f50 100644 --- a/OpenRA.Mods.Common/Projectiles/Bullet.cs +++ b/OpenRA.Mods.Common/Projectiles/Bullet.cs @@ -124,7 +124,7 @@ namespace OpenRA.Mods.Common.Projectiles readonly float3 shadowColor; readonly float shadowAlpha; - ContrailRenderable contrail; + readonly ContrailRenderable contrail; [Sync] WPos pos, lastPos, target, source; diff --git a/OpenRA.Mods.Common/Projectiles/Missile.cs b/OpenRA.Mods.Common/Projectiles/Missile.cs index c89e0d7050..d094431f61 100644 --- a/OpenRA.Mods.Common/Projectiles/Missile.cs +++ b/OpenRA.Mods.Common/Projectiles/Missile.cs @@ -189,16 +189,16 @@ namespace OpenRA.Mods.Common.Projectiles int ticks; int ticksToNextSmoke; - ContrailRenderable contrail; - string trailPalette; + readonly ContrailRenderable contrail; + readonly string trailPalette; States state; bool targetPassedBy; - bool lockOn; + readonly bool lockOn; bool allowPassBy; // TODO: use this also with high minimum launch angle settings WPos targetPosition; - WVec offset; + readonly WVec offset; WVec tarVel; WVec predVel; @@ -210,7 +210,7 @@ namespace OpenRA.Mods.Common.Projectiles int speed; int loopRadius; WDist distanceCovered; - WDist rangeLimit; + readonly WDist rangeLimit; WAngle renderFacing; diff --git a/OpenRA.Mods.Common/Scripting/Properties/GuardProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/GuardProperties.cs index 55f14790fd..ea21c99401 100644 --- a/OpenRA.Mods.Common/Scripting/Properties/GuardProperties.cs +++ b/OpenRA.Mods.Common/Scripting/Properties/GuardProperties.cs @@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.Scripting [ScriptPropertyGroup("Combat")] public class GuardProperties : ScriptActorProperties, Requires, Requires { - Guard guard; + readonly Guard guard; public GuardProperties(ScriptContext context, Actor self) : base(context, self) { diff --git a/OpenRA.Mods.Common/Scripting/Properties/HealthProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/HealthProperties.cs index 7aa55a282b..bbccf67bb8 100644 --- a/OpenRA.Mods.Common/Scripting/Properties/HealthProperties.cs +++ b/OpenRA.Mods.Common/Scripting/Properties/HealthProperties.cs @@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Scripting [ScriptPropertyGroup("General")] public class HealthProperties : ScriptActorProperties, Requires { - IHealth health; + readonly IHealth health; public HealthProperties(ScriptContext context, Actor self) : base(context, self) { diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackGarrisoned.cs b/OpenRA.Mods.Common/Traits/Attack/AttackGarrisoned.cs index 03a6c4f379..a5a5f7e7ae 100644 --- a/OpenRA.Mods.Common/Traits/Attack/AttackGarrisoned.cs +++ b/OpenRA.Mods.Common/Traits/Attack/AttackGarrisoned.cs @@ -78,12 +78,12 @@ namespace OpenRA.Mods.Common.Traits public class AttackGarrisoned : AttackFollow, INotifyPassengerEntered, INotifyPassengerExited, IRender { public new readonly AttackGarrisonedInfo Info; - Lazy coords; - List armaments; - List muzzles; - Dictionary paxFacing; - Dictionary paxPos; - Dictionary paxRender; + readonly Lazy coords; + readonly List armaments; + readonly List muzzles; + readonly Dictionary paxFacing; + readonly Dictionary paxPos; + readonly Dictionary paxRender; public AttackGarrisoned(Actor self, AttackGarrisonedInfo info) : base(self, info) diff --git a/OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs index fba9b843b5..53006a2ef9 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs @@ -154,7 +154,7 @@ namespace OpenRA.Mods.Common.Traits CPos initialBaseCenter; CPos defenseCenter; - List builders = new List(); + readonly List builders = new List(); public BaseBuilderBotModule(Actor self, BaseBuilderBotModuleInfo info) : base(info) diff --git a/OpenRA.Mods.Common/Traits/BotModules/CaptureManagerBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/CaptureManagerBotModule.cs index 5855ebafc5..f4969f4f8b 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/CaptureManagerBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/CaptureManagerBotModule.cs @@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Traits int minCaptureDelayTicks; // Units that the bot already knows about and has given a capture order. Any unit not on this list needs to be given a new order. - List activeCapturers = new List(); + readonly List activeCapturers = new List(); public CaptureManagerBotModule(Actor self, CaptureManagerBotModuleInfo info) : base(info) diff --git a/OpenRA.Mods.Common/Traits/CapturableProgressBar.cs b/OpenRA.Mods.Common/Traits/CapturableProgressBar.cs index 47e486be59..95e5a036f0 100644 --- a/OpenRA.Mods.Common/Traits/CapturableProgressBar.cs +++ b/OpenRA.Mods.Common/Traits/CapturableProgressBar.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits class CapturableProgressBar : ConditionalTrait, ISelectionBar, ICaptureProgressWatcher { - Dictionary progress = new Dictionary(); + readonly Dictionary progress = new Dictionary(); public CapturableProgressBar(Actor self, CapturableProgressBarInfo info) : base(info) { } diff --git a/OpenRA.Mods.Common/Traits/CapturableProgressBlink.cs b/OpenRA.Mods.Common/Traits/CapturableProgressBlink.cs index 3ec6c344da..8c180564be 100644 --- a/OpenRA.Mods.Common/Traits/CapturableProgressBlink.cs +++ b/OpenRA.Mods.Common/Traits/CapturableProgressBlink.cs @@ -27,8 +27,8 @@ namespace OpenRA.Mods.Common.Traits class CapturableProgressBlink : ConditionalTrait, ITick, ICaptureProgressWatcher { - List captorOwners = new List(); - HashSet captors = new HashSet(); + readonly List captorOwners = new List(); + readonly HashSet captors = new HashSet(); int tick = 0; public CapturableProgressBlink(CapturableProgressBlinkInfo info) diff --git a/OpenRA.Mods.Common/Traits/CaptureManager.cs b/OpenRA.Mods.Common/Traits/CaptureManager.cs index c5cef7883c..58a57d80e7 100644 --- a/OpenRA.Mods.Common/Traits/CaptureManager.cs +++ b/OpenRA.Mods.Common/Traits/CaptureManager.cs @@ -77,7 +77,7 @@ namespace OpenRA.Mods.Common.Traits int beingCapturedToken = Actor.InvalidConditionToken; bool enteringCurrentTarget; - HashSet currentCaptors = new HashSet(); + readonly HashSet currentCaptors = new HashSet(); public bool BeingCaptured { get; private set; } diff --git a/OpenRA.Mods.Common/Traits/Cargo.cs b/OpenRA.Mods.Common/Traits/Cargo.cs index cf2d7d46fd..7edf58dbbc 100644 --- a/OpenRA.Mods.Common/Traits/Cargo.cs +++ b/OpenRA.Mods.Common/Traits/Cargo.cs @@ -104,7 +104,7 @@ namespace OpenRA.Mods.Common.Traits int reservedWeight = 0; Aircraft aircraft; int loadingToken = Actor.InvalidConditionToken; - Stack loadedTokens = new Stack(); + readonly Stack loadedTokens = new Stack(); bool takeOffAfterLoad; bool initialised; diff --git a/OpenRA.Mods.Common/Traits/Crates/SupportPowerCrateAction.cs b/OpenRA.Mods.Common/Traits/Crates/SupportPowerCrateAction.cs index d938fe6462..b5e8ce12a2 100644 --- a/OpenRA.Mods.Common/Traits/Crates/SupportPowerCrateAction.cs +++ b/OpenRA.Mods.Common/Traits/Crates/SupportPowerCrateAction.cs @@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Traits class SupportPowerCrateAction : CrateAction { - SupportPowerCrateActionInfo info; + readonly SupportPowerCrateActionInfo info; public SupportPowerCrateAction(Actor self, SupportPowerCrateActionInfo info) : base(self, info) { diff --git a/OpenRA.Mods.Common/Traits/Demolishable.cs b/OpenRA.Mods.Common/Traits/Demolishable.cs index 8251fb7bf7..68b8860ab9 100644 --- a/OpenRA.Mods.Common/Traits/Demolishable.cs +++ b/OpenRA.Mods.Common/Traits/Demolishable.cs @@ -46,8 +46,8 @@ namespace OpenRA.Mods.Common.Traits } } - List actions = new List(); - List removeActions = new List(); + readonly List actions = new List(); + readonly List removeActions = new List(); public Demolishable(DemolishableInfo info) : base(info) { } diff --git a/OpenRA.Mods.Common/Traits/EngineerRepair.cs b/OpenRA.Mods.Common/Traits/EngineerRepair.cs index 8c7a4481ae..dc51726726 100644 --- a/OpenRA.Mods.Common/Traits/EngineerRepair.cs +++ b/OpenRA.Mods.Common/Traits/EngineerRepair.cs @@ -102,7 +102,7 @@ namespace OpenRA.Mods.Common.Traits class EngineerRepairOrderTargeter : UnitOrderTargeter { - EngineerRepairInfo info; + readonly EngineerRepairInfo info; public EngineerRepairOrderTargeter(EngineerRepairInfo info) : base("EngineerRepair", 6, info.Cursor, true, true) diff --git a/OpenRA.Mods.Common/Traits/ExperienceTrickler.cs b/OpenRA.Mods.Common/Traits/ExperienceTrickler.cs index b4c852f5d3..61f5cd64be 100644 --- a/OpenRA.Mods.Common/Traits/ExperienceTrickler.cs +++ b/OpenRA.Mods.Common/Traits/ExperienceTrickler.cs @@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits public class ExperienceTrickler : PausableConditionalTrait, ITick, ISync { readonly ExperienceTricklerInfo info; - GainsExperience gainsExperience; + readonly GainsExperience gainsExperience; [Sync] int ticks; diff --git a/OpenRA.Mods.Common/Traits/GivesBounty.cs b/OpenRA.Mods.Common/Traits/GivesBounty.cs index a0123014e6..7522069556 100644 --- a/OpenRA.Mods.Common/Traits/GivesBounty.cs +++ b/OpenRA.Mods.Common/Traits/GivesBounty.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits class GivesBounty : ConditionalTrait, INotifyKilled, INotifyPassengerEntered, INotifyPassengerExited { - Dictionary passengerBounties = new Dictionary(); + readonly Dictionary passengerBounties = new Dictionary(); public GivesBounty(GivesBountyInfo info) : base(info) { } diff --git a/OpenRA.Mods.Common/Traits/Mobile.cs b/OpenRA.Mods.Common/Traits/Mobile.cs index 063d9ed881..ff959639df 100644 --- a/OpenRA.Mods.Common/Traits/Mobile.cs +++ b/OpenRA.Mods.Common/Traits/Mobile.cs @@ -649,7 +649,7 @@ namespace OpenRA.Mods.Common.Traits CPos cell; SubCell subCell; WPos pos; - int delay; + readonly int delay; public ReturnToCellActivity(Actor self, int delay = 0, bool recalculateSubCell = false) { diff --git a/OpenRA.Mods.Common/Traits/PaletteEffects/CloakPaletteEffect.cs b/OpenRA.Mods.Common/Traits/PaletteEffects/CloakPaletteEffect.cs index f38737c8d6..93e03e62b1 100644 --- a/OpenRA.Mods.Common/Traits/PaletteEffects/CloakPaletteEffect.cs +++ b/OpenRA.Mods.Common/Traits/PaletteEffects/CloakPaletteEffect.cs @@ -22,9 +22,9 @@ namespace OpenRA.Mods.Common.Traits public class CloakPaletteEffect : IPaletteModifier, ITick { float t = 0; - string paletteName = "cloak"; + readonly string paletteName = "cloak"; - Color[] colors = + readonly Color[] colors = { Color.FromArgb(55, 205, 205, 220), Color.FromArgb(120, 205, 205, 230), diff --git a/OpenRA.Mods.Common/Traits/Player/TechTree.cs b/OpenRA.Mods.Common/Traits/Player/TechTree.cs index 15cf932402..81fdb565d4 100644 --- a/OpenRA.Mods.Common/Traits/Player/TechTree.cs +++ b/OpenRA.Mods.Common/Traits/Player/TechTree.cs @@ -118,7 +118,7 @@ namespace OpenRA.Mods.Common.Traits readonly string[] prerequisites; readonly ITechTreeElement watcher; bool hasPrerequisites; - int limit; + readonly int limit; bool hidden; bool initialized = false; diff --git a/OpenRA.Mods.Common/Traits/Pluggable.cs b/OpenRA.Mods.Common/Traits/Pluggable.cs index 8bfab6527e..9623efc783 100644 --- a/OpenRA.Mods.Common/Traits/Pluggable.cs +++ b/OpenRA.Mods.Common/Traits/Pluggable.cs @@ -83,7 +83,7 @@ namespace OpenRA.Mods.Common.Traits readonly string initialPlug; int conditionToken = Actor.InvalidConditionToken; - Dictionary plugTypesAvailability = null; + readonly Dictionary plugTypesAvailability = null; string active; diff --git a/OpenRA.Mods.Common/Traits/Render/VeteranProductionIconOverlay.cs b/OpenRA.Mods.Common/Traits/Render/VeteranProductionIconOverlay.cs index 3859ff8569..98fe47480a 100644 --- a/OpenRA.Mods.Common/Traits/Render/VeteranProductionIconOverlay.cs +++ b/OpenRA.Mods.Common/Traits/Render/VeteranProductionIconOverlay.cs @@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Traits.Render readonly Sprite sprite; readonly VeteranProductionIconOverlayInfo info; - Dictionary overlayActive = new Dictionary(); + readonly Dictionary overlayActive = new Dictionary(); public VeteranProductionIconOverlay(ActorInitializer init, VeteranProductionIconOverlayInfo info) { diff --git a/OpenRA.Mods.Common/Traits/Sound/AmbientSound.cs b/OpenRA.Mods.Common/Traits/Sound/AmbientSound.cs index 435d5440b5..e2fa53ce44 100644 --- a/OpenRA.Mods.Common/Traits/Sound/AmbientSound.cs +++ b/OpenRA.Mods.Common/Traits/Sound/AmbientSound.cs @@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Traits.Sound class AmbientSound : ConditionalTrait, ITick, INotifyRemovedFromWorld { readonly bool loop; - HashSet currentSounds = new HashSet(); + readonly HashSet currentSounds = new HashSet(); WPos cachedPosition; int delay; diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/SelectDirectionalTarget.cs b/OpenRA.Mods.Common/Traits/SupportPowers/SelectDirectionalTarget.cs index 6f846cad04..8396560a2a 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/SelectDirectionalTarget.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/SelectDirectionalTarget.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits bool activated; bool dragStarted; Arrow currentArrow; - MouseAttachmentWidget mouseAttachment; + readonly MouseAttachmentWidget mouseAttachment; public SelectDirectionalTarget(World world, string order, SupportPowerManager manager, string cursor, string directionArrowAnimation, string directionArrowPalette) diff --git a/OpenRA.Mods.Common/Traits/ThrowsParticle.cs b/OpenRA.Mods.Common/Traits/ThrowsParticle.cs index fbfed7fe16..5c19f70d25 100644 --- a/OpenRA.Mods.Common/Traits/ThrowsParticle.cs +++ b/OpenRA.Mods.Common/Traits/ThrowsParticle.cs @@ -48,16 +48,16 @@ namespace OpenRA.Mods.Common.Traits class ThrowsParticle : ITick { WVec pos; - WVec initialPos; - WVec finalPos; - WAngle angle; + readonly WVec initialPos; + readonly WVec finalPos; + readonly WAngle angle; int tick = 0; - int length; + readonly int length; WAngle facing; WAngle rotation; - int direction; + readonly int direction; public ThrowsParticle(ActorInitializer init, ThrowsParticleInfo info) { diff --git a/OpenRA.Mods.Common/Traits/World/StartGameNotification.cs b/OpenRA.Mods.Common/Traits/World/StartGameNotification.cs index d2f281e2bf..f1393193f3 100644 --- a/OpenRA.Mods.Common/Traits/World/StartGameNotification.cs +++ b/OpenRA.Mods.Common/Traits/World/StartGameNotification.cs @@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits class StartGameNotification : IWorldLoaded, INotifyGameLoaded, INotifyGameSaved { - StartGameNotificationInfo info; + readonly StartGameNotificationInfo info; public StartGameNotification(StartGameNotificationInfo info) { this.info = info; diff --git a/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs b/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs index 680ae45971..771a691d64 100644 --- a/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs @@ -331,7 +331,7 @@ namespace OpenRA.Mods.Common.UtilityCommands } // TODO: fix this -- will have bitrotted pretty badly. - static Dictionary namedColorMapping = new Dictionary() + static readonly Dictionary namedColorMapping = new Dictionary() { { "gold", Color.FromArgb(246, 214, 121) }, { "blue", Color.FromArgb(226, 230, 246) }, diff --git a/OpenRA.Mods.Common/Widgets/GridLayout.cs b/OpenRA.Mods.Common/Widgets/GridLayout.cs index 4dcf37e23f..514726aa91 100644 --- a/OpenRA.Mods.Common/Widgets/GridLayout.cs +++ b/OpenRA.Mods.Common/Widgets/GridLayout.cs @@ -16,7 +16,7 @@ namespace OpenRA.Mods.Common.Widgets { public class GridLayout : ILayout { - ScrollPanelWidget widget; + readonly ScrollPanelWidget widget; int2 pos; public GridLayout(ScrollPanelWidget w) { widget = w; } diff --git a/OpenRA.Mods.Common/Widgets/ImageWidget.cs b/OpenRA.Mods.Common/Widgets/ImageWidget.cs index f7c14b36f8..582729cc2f 100644 --- a/OpenRA.Mods.Common/Widgets/ImageWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ImageWidget.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Widgets public string TooltipText; - Lazy tooltipContainer; + readonly Lazy tooltipContainer; public Func GetTooltipText; public ImageWidget() diff --git a/OpenRA.Mods.Common/Widgets/ListLayout.cs b/OpenRA.Mods.Common/Widgets/ListLayout.cs index 32de919d76..88b1312132 100644 --- a/OpenRA.Mods.Common/Widgets/ListLayout.cs +++ b/OpenRA.Mods.Common/Widgets/ListLayout.cs @@ -15,7 +15,7 @@ namespace OpenRA.Mods.Common.Widgets { public class ListLayout : ILayout { - ScrollPanelWidget widget; + readonly ScrollPanelWidget widget; public ListLayout(ScrollPanelWidget w) { widget = w; } diff --git a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs index 12fe4fcf6b..d0c53f6c6c 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs @@ -34,12 +34,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic readonly World world; readonly ModData modData; - Widget panel; + readonly Widget panel; - TextFieldWidget filenameInput; - SliderWidget frameSlider; - ScrollPanelWidget assetList; - ScrollItemWidget template; + readonly TextFieldWidget filenameInput; + readonly SliderWidget frameSlider; + readonly ScrollPanelWidget assetList; + readonly ScrollItemWidget template; IReadOnlyPackage assetSource = null; bool animateFrames = false; @@ -385,7 +385,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic currentFrame = currentSprites.Length - 1; } - Dictionary assetVisByName = new Dictionary(); + readonly Dictionary assetVisByName = new Dictionary(); bool FilterAsset(string filename) { diff --git a/OpenRA.Mods.Common/Widgets/Logic/ConnectionLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ConnectionLogic.cs index cfadb29de7..90d9de3736 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ConnectionLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ConnectionLogic.cs @@ -17,8 +17,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic { public class ConnectionLogic : ChromeLogic { - Action onConnect, onAbort; - Action onRetry; + readonly Action onConnect; + readonly Action onAbort; + readonly Action onRetry; void ConnectionStateChanged(OrderManager om, string password, NetworkConnection connection) { @@ -81,7 +82,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic public class ConnectionFailedLogic : ChromeLogic { - PasswordFieldWidget passwordField; + readonly PasswordFieldWidget passwordField; bool passwordOffsetAdjusted; [ObjectCreator.UseCtor] diff --git a/OpenRA.Mods.Common/Widgets/Logic/CreditsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/CreditsLogic.cs index f7096eabbb..f6263cb4ac 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/CreditsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/CreditsLogic.cs @@ -22,8 +22,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic readonly ScrollPanelWidget scrollPanel; readonly LabelWidget template; - bool showModTab; - bool showEngineTab; + readonly bool showModTab; + readonly bool showEngineTab; bool isShowingModTab; readonly IEnumerable modLines; readonly IEnumerable engineLines; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/NewMapLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/NewMapLogic.cs index 10a7b8c974..5f6061b5d7 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/NewMapLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/NewMapLogic.cs @@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { public class NewMapLogic : ChromeLogic { - Widget panel; + readonly Widget panel; [ObjectCreator.UseCtor] public NewMapLogic(Action onExit, Action onSelect, Widget widget, World world, ModData modData) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoLogic.cs index 0d8c6a4d4f..b0e477bca4 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoLogic.cs @@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic readonly Action hideMenu; readonly IObjectivesPanel iop; IngameInfoPanel activePanel; - bool hasError; + readonly bool hasError; [ObjectCreator.UseCtor] public GameInfoLogic(Widget widget, ModData modData, World world, IngameInfoPanel initialPanel, Action hideMenu) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleStatusBarsHotkeyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleStatusBarsHotkeyLogic.cs index 32128dae1b..34754c89d3 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleStatusBarsHotkeyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleStatusBarsHotkeyLogic.cs @@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic.Ingame [ChromeLogicArgsHotkeys("CycleStatusBarsKey")] public class CycleStatusBarsHotkeyLogic : SingleHotkeyBaseLogic { - StatusBarsType[] options = { StatusBarsType.Standard, StatusBarsType.DamageShow, StatusBarsType.AlwaysShow }; + readonly StatusBarsType[] options = { StatusBarsType.Standard, StatusBarsType.DamageShow, StatusBarsType.AlwaysShow }; [ObjectCreator.UseCtor] public CycleStatusBarsHotkeyLogic(Widget widget, ModData modData, Dictionary logicArgs) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs index 1b81c20cc7..f63f65ea77 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs @@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic readonly WorldRenderer worldRenderer; readonly MenuPaletteEffect mpe; readonly bool isSinglePlayer; - bool hasError; + readonly bool hasError; bool leaving; bool hideMenu; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverShroudSelectorLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverShroudSelectorLogic.cs index 839af3c879..45186203e7 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverShroudSelectorLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverShroudSelectorLogic.cs @@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic readonly World world; CameraOption selected; - LabelWidget shroudLabel; + readonly LabelWidget shroudLabel; class CameraOption { diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs index de5e2e73f3..6f8f8170aa 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs @@ -25,9 +25,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic { class SlotDropDownOption { - public string Title; - public string Order; - public Func Selected; + public readonly string Title; + public readonly string Order; + public readonly Func Selected; public SlotDropDownOption(string title, string order, Func selected) { diff --git a/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs index db18021e35..2e95bd74df 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs @@ -24,13 +24,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic MapClassification currentTab; - Dictionary scrollpanels = new Dictionary(); + readonly Dictionary scrollpanels = new Dictionary(); - Dictionary tabMaps = new Dictionary(); + readonly Dictionary tabMaps = new Dictionary(); string[] visibleMaps; string selectedUid; - Action onSelect; + readonly Action onSelect; string category; string mapFilter; diff --git a/OpenRA.Mods.Common/Widgets/LogicKeyListenerWidget.cs b/OpenRA.Mods.Common/Widgets/LogicKeyListenerWidget.cs index f02b34863a..45531c40ea 100644 --- a/OpenRA.Mods.Common/Widgets/LogicKeyListenerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/LogicKeyListenerWidget.cs @@ -17,7 +17,7 @@ namespace OpenRA.Mods.Common.Widgets { public class LogicKeyListenerWidget : Widget { - List> handlers = new List>(); + readonly List> handlers = new List>(); public override bool HandleKeyPress(KeyInput e) { diff --git a/OpenRA.Mods.Common/Widgets/ObserverArmyIconsWidget.cs b/OpenRA.Mods.Common/Widgets/ObserverArmyIconsWidget.cs index a9e71bc1f3..590bf0aee2 100644 --- a/OpenRA.Mods.Common/Widgets/ObserverArmyIconsWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ObserverArmyIconsWidget.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Widgets public int IconHeight = 24; public int IconSpacing = 1; - float2 iconSize; + readonly float2 iconSize; public int MinWidth = 240; public ArmyUnit TooltipUnit { get; private set; } diff --git a/OpenRA.Mods.Common/Widgets/ObserverProductionIconsWidget.cs b/OpenRA.Mods.Common/Widgets/ObserverProductionIconsWidget.cs index 740c05cc69..fd914dbb19 100644 --- a/OpenRA.Mods.Common/Widgets/ObserverProductionIconsWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ObserverProductionIconsWidget.cs @@ -39,12 +39,12 @@ namespace OpenRA.Mods.Common.Widgets public ProductionIcon TooltipIcon { get; private set; } public Func GetTooltipIcon; - Dictionary clocks; + readonly Dictionary clocks; readonly Lazy tooltipContainer; readonly List productionIcons = new List(); readonly List productionIconsBounds = new List(); - float2 iconSize; + readonly float2 iconSize; int lastIconIdx; public int MinWidth = 240; int currentTooltipToken; diff --git a/OpenRA.Mods.Common/Widgets/ProductionPaletteWidget.cs b/OpenRA.Mods.Common/Widgets/ProductionPaletteWidget.cs index b3006dab9c..449ce9c307 100644 --- a/OpenRA.Mods.Common/Widgets/ProductionPaletteWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ProductionPaletteWidget.cs @@ -92,7 +92,7 @@ namespace OpenRA.Mods.Common.Widgets public int IconRowOffset = 0; public int MaxIconRowOffset = int.MaxValue; - Lazy tooltipContainer; + readonly Lazy tooltipContainer; ProductionQueue currentQueue; HotkeyReference[] hotkeys; @@ -111,7 +111,8 @@ namespace OpenRA.Mods.Common.Widgets public override Rectangle EventBounds => eventBounds; Dictionary icons = new Dictionary(); - Animation cantBuild, clock; + readonly Animation cantBuild; + readonly Animation clock; Rectangle eventBounds = Rectangle.Empty; readonly WorldRenderer worldRenderer; diff --git a/OpenRA.Mods.Common/Widgets/ProductionTabsWidget.cs b/OpenRA.Mods.Common/Widgets/ProductionTabsWidget.cs index 638d987b85..f250111556 100644 --- a/OpenRA.Mods.Common/Widgets/ProductionTabsWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ProductionTabsWidget.cs @@ -96,7 +96,7 @@ namespace OpenRA.Mods.Common.Widgets SpriteFont font; Rectangle leftButtonRect; Rectangle rightButtonRect; - Lazy paletteWidget; + readonly Lazy paletteWidget; string queueGroup; [ObjectCreator.UseCtor] diff --git a/OpenRA.Mods.Common/Widgets/ResourceBarWidget.cs b/OpenRA.Mods.Common/Widgets/ResourceBarWidget.cs index bdf9454705..46d2f49b0b 100644 --- a/OpenRA.Mods.Common/Widgets/ResourceBarWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ResourceBarWidget.cs @@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Widgets { public readonly string TooltipTemplate; public readonly string TooltipContainer; - Lazy tooltipContainer; + readonly Lazy tooltipContainer; public string TooltipFormat = ""; public ResourceBarOrientation Orientation = ResourceBarOrientation.Vertical; @@ -31,8 +31,8 @@ namespace OpenRA.Mods.Common.Widgets public Func GetProvided = () => 0; public Func GetUsed = () => 0; public Func GetBarColor = () => Color.White; - EWMA providedLerp = new EWMA(0.3f); - EWMA usedLerp = new EWMA(0.3f); + readonly EWMA providedLerp = new EWMA(0.3f); + readonly EWMA usedLerp = new EWMA(0.3f); readonly World world; Sprite indicator; diff --git a/OpenRA.Mods.Common/Widgets/SupportPowersWidget.cs b/OpenRA.Mods.Common/Widgets/SupportPowersWidget.cs index b4ce68c11c..b150a40469 100644 --- a/OpenRA.Mods.Common/Widgets/SupportPowersWidget.cs +++ b/OpenRA.Mods.Common/Widgets/SupportPowersWidget.cs @@ -53,12 +53,12 @@ namespace OpenRA.Mods.Common.Widgets readonly SupportPowerManager spm; Animation icon; - Animation clock; + readonly Animation clock; Dictionary icons = new Dictionary(); public SupportPowerIcon TooltipIcon { get; private set; } public Func GetTooltipIcon; - Lazy tooltipContainer; + readonly Lazy tooltipContainer; HotkeyReference[] hotkeys; Rectangle eventBounds; diff --git a/OpenRA.Platforms.Default/MultiTapDetection.cs b/OpenRA.Platforms.Default/MultiTapDetection.cs index 2699a4c083..18bbef7599 100644 --- a/OpenRA.Platforms.Default/MultiTapDetection.cs +++ b/OpenRA.Platforms.Default/MultiTapDetection.cs @@ -16,9 +16,9 @@ namespace OpenRA.Platforms.Default { static class MultiTapDetection { - static Cache<(Keycode Key, Modifiers Mods), TapHistory> keyHistoryCache = + static readonly Cache<(Keycode Key, Modifiers Mods), TapHistory> keyHistoryCache = new Cache<(Keycode, Modifiers), TapHistory>(_ => new TapHistory(DateTime.Now - TimeSpan.FromSeconds(1))); - static Cache clickHistoryCache = + static readonly Cache clickHistoryCache = new Cache(_ => new TapHistory(DateTime.Now - TimeSpan.FromSeconds(1))); public static int DetectFromMouse(byte button, int2 xy) diff --git a/OpenRA.Test/OpenRA.Game/VariableExpressionTest.cs b/OpenRA.Test/OpenRA.Game/VariableExpressionTest.cs index ca2d09a642..d965d3eafa 100644 --- a/OpenRA.Test/OpenRA.Game/VariableExpressionTest.cs +++ b/OpenRA.Test/OpenRA.Game/VariableExpressionTest.cs @@ -19,7 +19,7 @@ namespace OpenRA.Test [TestFixture] public class VariableExpressionTest { - IReadOnlyDictionary testValues = new Dictionary + readonly IReadOnlyDictionary testValues = new Dictionary { { "t", 5 }, { "t-1", 7 },