diff --git a/OpenRA.Mods.Common/Effects/Contrail.cs b/OpenRA.Mods.Common/Effects/Contrail.cs index 0a784df1a3..c5c54df60b 100644 --- a/OpenRA.Mods.Common/Effects/Contrail.cs +++ b/OpenRA.Mods.Common/Effects/Contrail.cs @@ -36,9 +36,11 @@ namespace OpenRA.Mods.Common.Effects class Contrail : ITick, IRender { - ContrailInfo info; + readonly ContrailInfo info; + readonly IBodyOrientation body; + + // This is a mutable struct, so it can't be readonly. ContrailRenderable trail; - IBodyOrientation body; public Contrail(Actor self, ContrailInfo info) { diff --git a/OpenRA.Mods.Common/Traits/ExternalCapturableBar.cs b/OpenRA.Mods.Common/Traits/ExternalCapturableBar.cs index 02651c10f9..2634392f15 100644 --- a/OpenRA.Mods.Common/Traits/ExternalCapturableBar.cs +++ b/OpenRA.Mods.Common/Traits/ExternalCapturableBar.cs @@ -21,20 +21,20 @@ namespace OpenRA.Mods.Common.Traits class ExternalCapturableBar : ISelectionBar { - ExternalCapturable cap; + readonly ExternalCapturable capturable; public ExternalCapturableBar(Actor self) { - this.cap = self.Trait(); + capturable = self.Trait(); } public float GetValue() { // only show when building is being captured - if (!cap.CaptureInProgress) + if (!capturable.CaptureInProgress) return 0f; - return (float)cap.CaptureProgressTime / (cap.Info.CaptureCompleteTime * 25); + return (float)capturable.CaptureProgressTime / (capturable.Info.CaptureCompleteTime * 25); } public Color GetColor() { return Color.Orange; } diff --git a/OpenRA.Mods.Common/Traits/Render/RenderBuildingTurreted.cs b/OpenRA.Mods.Common/Traits/Render/RenderBuildingTurreted.cs index 337847128a..413ee3f180 100644 --- a/OpenRA.Mods.Common/Traits/Render/RenderBuildingTurreted.cs +++ b/OpenRA.Mods.Common/Traits/Render/RenderBuildingTurreted.cs @@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits class RenderBuildingTurreted : RenderBuilding { - Turreted t; + readonly Turreted turreted; static Func MakeTurretFacingFunc(Actor self) { @@ -48,14 +48,14 @@ namespace OpenRA.Mods.Common.Traits public RenderBuildingTurreted(ActorInitializer init, RenderBuildingInfo info) : base(init, info, MakeTurretFacingFunc(init.Self)) { - t = init.Self.TraitsImplementing().FirstOrDefault(); - t.QuantizedFacings = DefaultAnimation.CurrentSequence.Facings; + turreted = init.Self.TraitsImplementing().FirstOrDefault(); + turreted.QuantizedFacings = DefaultAnimation.CurrentSequence.Facings; } public override void DamageStateChanged(Actor self, AttackInfo e) { base.DamageStateChanged(self, e); - t.QuantizedFacings = DefaultAnimation.CurrentSequence.Facings; + turreted.QuantizedFacings = DefaultAnimation.CurrentSequence.Facings; } } } diff --git a/OpenRA.Mods.Common/Traits/Render/RenderDetectionCircle.cs b/OpenRA.Mods.Common/Traits/Render/RenderDetectionCircle.cs index 2c5e25b266..33f49144ef 100644 --- a/OpenRA.Mods.Common/Traits/Render/RenderDetectionCircle.cs +++ b/OpenRA.Mods.Common/Traits/Render/RenderDetectionCircle.cs @@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Traits class RenderDetectionCircle : IPostRenderSelection { - Actor self; + readonly Actor self; public RenderDetectionCircle(Actor self) { this.self = self; } diff --git a/OpenRA.Mods.Common/Traits/Render/RenderRangeCircle.cs b/OpenRA.Mods.Common/Traits/Render/RenderRangeCircle.cs index 387a98b926..bf205f39b8 100644 --- a/OpenRA.Mods.Common/Traits/Render/RenderRangeCircle.cs +++ b/OpenRA.Mods.Common/Traits/Render/RenderRangeCircle.cs @@ -56,8 +56,8 @@ namespace OpenRA.Mods.Common.Traits class RenderRangeCircle : IPostRenderSelection { - Actor self; - AttackBase attack; + readonly Actor self; + readonly AttackBase attack; public RenderRangeCircle(Actor self) { diff --git a/OpenRA.Mods.Common/Traits/Render/RenderVoxels.cs b/OpenRA.Mods.Common/Traits/Render/RenderVoxels.cs index 0895f1654f..42adab4235 100644 --- a/OpenRA.Mods.Common/Traits/Render/RenderVoxels.cs +++ b/OpenRA.Mods.Common/Traits/Render/RenderVoxels.cs @@ -73,11 +73,11 @@ namespace OpenRA.Mods.Common.Traits public class RenderVoxels : IRender, INotifyOwnerChanged { readonly List components = new List(); - Actor self; - RenderVoxelsInfo info; - IBodyOrientation body; - WRot camera; - WRot lightSource; + readonly Actor self; + readonly RenderVoxelsInfo info; + readonly IBodyOrientation body; + readonly WRot camera; + readonly WRot lightSource; public RenderVoxels(Actor self, RenderVoxelsInfo info) { diff --git a/OpenRA.Mods.Common/Traits/Render/WithBuildingExplosion.cs b/OpenRA.Mods.Common/Traits/Render/WithBuildingExplosion.cs index c5f90e386b..bd9e55d052 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithBuildingExplosion.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithBuildingExplosion.cs @@ -35,8 +35,8 @@ namespace OpenRA.Mods.Common.Traits class WithBuildingExplosion : INotifyKilled { - WithBuildingExplosionInfo info; - BuildingInfo buildingInfo; + readonly WithBuildingExplosionInfo info; + readonly BuildingInfo buildingInfo; public WithBuildingExplosion(Actor self, WithBuildingExplosionInfo info) { diff --git a/OpenRA.Mods.Common/Traits/Render/WithBuildingPlacedAnimation.cs b/OpenRA.Mods.Common/Traits/Render/WithBuildingPlacedAnimation.cs index 783a3c6a4b..0e5b19bd93 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithBuildingPlacedAnimation.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithBuildingPlacedAnimation.cs @@ -23,8 +23,8 @@ namespace OpenRA.Mods.Common.Traits public class WithBuildingPlacedAnimation : INotifyBuildingPlaced, INotifyBuildComplete { - WithBuildingPlacedAnimationInfo info; - RenderSimple renderSimple; + readonly WithBuildingPlacedAnimationInfo info; + readonly RenderSimple renderSimple; bool buildComplete; public WithBuildingPlacedAnimation(Actor self, WithBuildingPlacedAnimationInfo info) diff --git a/OpenRA.Mods.Common/Traits/Render/WithBuildingPlacedOverlay.cs b/OpenRA.Mods.Common/Traits/Render/WithBuildingPlacedOverlay.cs index f886e826a7..87cf8a5ae6 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithBuildingPlacedOverlay.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithBuildingPlacedOverlay.cs @@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Traits public class WithBuildingPlacedOverlay : INotifyBuildComplete, INotifySold, INotifyDamageStateChanged, INotifyBuildingPlaced, INotifyTransform { - Animation overlay; + readonly Animation overlay; bool buildComplete; public WithBuildingPlacedOverlay(Actor self, WithBuildingPlacedOverlayInfo info) diff --git a/OpenRA.Mods.Common/Traits/Render/WithHarvestOverlay.cs b/OpenRA.Mods.Common/Traits/Render/WithHarvestOverlay.cs index ce6ed88fa1..295eadc1bb 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithHarvestOverlay.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithHarvestOverlay.cs @@ -30,8 +30,8 @@ namespace OpenRA.Mods.Common.Traits class WithHarvestOverlay : INotifyHarvesterAction { - WithHarvestOverlayInfo info; - Animation anim; + readonly WithHarvestOverlayInfo info; + readonly Animation anim; bool visible; public WithHarvestOverlay(Actor self, WithHarvestOverlayInfo info) diff --git a/OpenRA.Mods.Common/Traits/Render/WithIdleOverlay.cs b/OpenRA.Mods.Common/Traits/Render/WithIdleOverlay.cs index 5a8014f3a3..e1e148a937 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithIdleOverlay.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithIdleOverlay.cs @@ -59,7 +59,7 @@ namespace OpenRA.Mods.Common.Traits public class WithIdleOverlay : UpgradableTrait, INotifyDamageStateChanged, INotifyBuildComplete, INotifySold, INotifyTransform { - Animation overlay; + readonly Animation overlay; bool buildComplete; public WithIdleOverlay(Actor self, WithIdleOverlayInfo info) diff --git a/OpenRA.Mods.Common/Traits/Render/WithProductionOverlay.cs b/OpenRA.Mods.Common/Traits/Render/WithProductionOverlay.cs index 2bf8988f92..da73cf03dd 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithProductionOverlay.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithProductionOverlay.cs @@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits public class WithProductionOverlay : INotifyDamageStateChanged, ITick, INotifyBuildComplete, INotifySold { - Animation overlay; + readonly Animation overlay; ProductionQueue queue; bool buildComplete; diff --git a/OpenRA.Mods.Common/Traits/Render/WithRepairAnimation.cs b/OpenRA.Mods.Common/Traits/Render/WithRepairAnimation.cs index 7e4eecd030..d42abf1a1a 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithRepairAnimation.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithRepairAnimation.cs @@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Traits public class WithRepairAnimation : INotifyRepair { - WithRepairAnimationInfo info; + readonly WithRepairAnimationInfo info; public WithRepairAnimation(Actor self, WithRepairAnimationInfo info) { diff --git a/OpenRA.Mods.Common/Traits/Render/WithRepairOverlay.cs b/OpenRA.Mods.Common/Traits/Render/WithRepairOverlay.cs index bb3d8b9b9b..fccd3e285f 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithRepairOverlay.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithRepairOverlay.cs @@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Traits public class WithRepairOverlay : INotifyDamageStateChanged, INotifyBuildComplete, INotifySold, INotifyRepair { - Animation overlay; + readonly Animation overlay; bool buildComplete; public WithRepairOverlay(Actor self, WithRepairOverlayInfo info) diff --git a/OpenRA.Mods.Common/Traits/Render/WithRotor.cs b/OpenRA.Mods.Common/Traits/Render/WithRotor.cs index 8db1df98a1..6a7f98693c 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithRotor.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithRotor.cs @@ -45,9 +45,9 @@ namespace OpenRA.Mods.Common.Traits public class WithRotor : ITick { - WithRotorInfo info; - Animation rotorAnim; - IMove movement; + readonly WithRotorInfo info; + readonly Animation rotorAnim; + readonly IMove movement; public WithRotor(Actor self, WithRotorInfo info) { diff --git a/OpenRA.Mods.Common/Traits/Render/WithTurret.cs b/OpenRA.Mods.Common/Traits/Render/WithTurret.cs index 8ff1251a6e..2259e1aa3e 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithTurret.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithTurret.cs @@ -58,11 +58,11 @@ namespace OpenRA.Mods.Common.Traits public class WithTurret : UpgradableTrait, ITick, INotifyDamageStateChanged { - RenderSprites rs; - IBodyOrientation body; - AttackBase ab; - Turreted t; - Armament[] arms; + readonly RenderSprites rs; + readonly IBodyOrientation body; + readonly AttackBase ab; + readonly Turreted t; + readonly Armament[] arms; public readonly Animation DefaultAnimation; public WithTurret(Actor self, WithTurretInfo info) diff --git a/OpenRA.Mods.Common/Traits/Render/WithVoxelBarrel.cs b/OpenRA.Mods.Common/Traits/Render/WithVoxelBarrel.cs index 621af1dce1..4aaf785543 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithVoxelBarrel.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithVoxelBarrel.cs @@ -48,11 +48,11 @@ namespace OpenRA.Mods.Common.Traits public class WithVoxelBarrel { - WithVoxelBarrelInfo info; - Actor self; - Armament armament; - Turreted turreted; - IBodyOrientation body; + readonly WithVoxelBarrelInfo info; + readonly Actor self; + readonly Armament armament; + readonly Turreted turreted; + readonly IBodyOrientation body; public WithVoxelBarrel(Actor self, WithVoxelBarrelInfo info) { diff --git a/OpenRA.Mods.Common/Traits/Render/WithVoxelBody.cs b/OpenRA.Mods.Common/Traits/Render/WithVoxelBody.cs index ea840465b4..0f44be7fae 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithVoxelBody.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithVoxelBody.cs @@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits public class WithVoxelBody : IAutoSelectionSize { - int2 size; + readonly int2 size; public WithVoxelBody(Actor self, WithVoxelBodyInfo info) { diff --git a/OpenRA.Mods.Common/Traits/SmokeTrailWhenDamaged.cs b/OpenRA.Mods.Common/Traits/SmokeTrailWhenDamaged.cs index a62020d088..26ca8f5d0b 100644 --- a/OpenRA.Mods.Common/Traits/SmokeTrailWhenDamaged.cs +++ b/OpenRA.Mods.Common/Traits/SmokeTrailWhenDamaged.cs @@ -28,8 +28,8 @@ namespace OpenRA.Mods.Common.Traits class SmokeTrailWhenDamaged : ITick { - IBodyOrientation body; - SmokeTrailWhenDamagedInfo info; + readonly SmokeTrailWhenDamagedInfo info; + readonly IBodyOrientation body; int ticks; public SmokeTrailWhenDamaged(Actor self, SmokeTrailWhenDamagedInfo info) diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/NukePower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/NukePower.cs index ac3548ffdd..cf4d141ab7 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/NukePower.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/NukePower.cs @@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Traits class NukePower : SupportPower { readonly NukePowerInfo info; - IBodyOrientation body; + readonly IBodyOrientation body; public NukePower(Actor self, NukePowerInfo info) : base(self, info)