diff --git a/Makefile b/Makefile index 42885e1768..13ab5d1b09 100644 --- a/Makefile +++ b/Makefile @@ -183,8 +183,14 @@ check: @mono --debug OpenRA.Utility.exe ra --check-code-style OpenRA.Renderer.Null @echo "Checking for code style violations in OpenRA.GameMonitor..." @mono --debug OpenRA.Utility.exe ra --check-code-style OpenRA.GameMonitor + @echo "Checking for code style violations in OpenRA.Mods.Common..." + @mono --debug OpenRA.Utility.exe ra --check-code-style OpenRA.Mods.Common @echo "Checking for code style violations in OpenRA.Mods.Cnc..." @mono --debug OpenRA.Utility.exe cnc --check-code-style OpenRA.Mods.Cnc + @echo "Checking for code style violations in OpenRA.Mods.D2k..." + @mono --debug OpenRA.Utility.exe cnc --check-code-style OpenRA.Mods.D2k + @echo "Checking for code style violations in OpenRA.Mods.TS..." + @mono --debug OpenRA.Utility.exe cnc --check-code-style OpenRA.Mods.TS # Builds and exports tilesets from a bitmap tsbuild_SRCS := $(shell find OpenRA.TilesetBuilder/ -iname '*.cs') diff --git a/OpenRA.Mods.Common/Activities/Turn.cs b/OpenRA.Mods.Common/Activities/Turn.cs index d17d5852b2..079ace5f56 100644 --- a/OpenRA.Mods.Common/Activities/Turn.cs +++ b/OpenRA.Mods.Common/Activities/Turn.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Activities this.desiredFacing = desiredFacing; } - public override Activity Tick( Actor self ) + public override Activity Tick(Actor self) { if (IsCanceled) return NextActivity; @@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Activities var facing = self.Trait(); - if( desiredFacing == facing.Facing ) + if (desiredFacing == facing.Facing) return NextActivity; facing.Facing = Util.TickFacing(facing.Facing, desiredFacing, facing.ROT); diff --git a/OpenRA.Mods.Common/Activities/Wait.cs b/OpenRA.Mods.Common/Activities/Wait.cs index 3d94344804..77a897bdaf 100644 --- a/OpenRA.Mods.Common/Activities/Wait.cs +++ b/OpenRA.Mods.Common/Activities/Wait.cs @@ -30,9 +30,9 @@ namespace OpenRA.Mods.Common.Activities return (remainingTicks-- == 0) ? NextActivity : this; } - public override void Cancel( Actor self ) + public override void Cancel(Actor self) { - if( !interruptable ) + if (!interruptable) return; remainingTicks = 0; @@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Activities return (f == null || f()) ? NextActivity : this; } - public override void Cancel( Actor self ) + public override void Cancel(Actor self) { if (!interruptable) return; diff --git a/OpenRA.Mods.Common/Effects/Beacon.cs b/OpenRA.Mods.Common/Effects/Beacon.cs index c0272ec58d..36c1c31151 100644 --- a/OpenRA.Mods.Common/Effects/Beacon.cs +++ b/OpenRA.Mods.Common/Effects/Beacon.cs @@ -17,6 +17,8 @@ namespace OpenRA.Mods.Common.Effects { public class Beacon : IEffect { + static readonly int MaxArrowHeight = 512; + readonly Player owner; readonly WPos position; readonly string palettePrefix; @@ -26,8 +28,7 @@ namespace OpenRA.Mods.Common.Effects readonly Animation poster; readonly Animation clock; - static readonly int maxArrowHeight = 512; - int arrowHeight = maxArrowHeight; + int arrowHeight = MaxArrowHeight; int arrowSpeed = 50; // Player-placed beacons are removed after a delay @@ -69,7 +70,7 @@ namespace OpenRA.Mods.Common.Effects public void Tick(World world) { arrowHeight += arrowSpeed; - var clamped = arrowHeight.Clamp(0, maxArrowHeight); + var clamped = arrowHeight.Clamp(0, MaxArrowHeight); if (arrowHeight != clamped) { arrowHeight = clamped; diff --git a/OpenRA.Mods.Common/Effects/FloatingText.cs b/OpenRA.Mods.Common/Effects/FloatingText.cs index cf60829954..4d550a4a46 100644 --- a/OpenRA.Mods.Common/Effects/FloatingText.cs +++ b/OpenRA.Mods.Common/Effects/FloatingText.cs @@ -19,6 +19,8 @@ namespace OpenRA.Mods.Common.Effects { public class FloatingText : IEffect { + static readonly WVec Velocity = new WVec(0, 0, 86); + readonly SpriteFont font; readonly string text; Color color; @@ -34,13 +36,12 @@ namespace OpenRA.Mods.Common.Effects this.remaining = duration; } - static readonly WVec velocity = new WVec(0, 0, 86); public void Tick(World world) { if (--remaining <= 0) world.AddFrameEndTask(w => w.Remove(this)); - pos += velocity; + pos += Velocity; } public IEnumerable Render(WorldRenderer wr) diff --git a/OpenRA.Mods.Common/Graphics/ContrailRenderable.cs b/OpenRA.Mods.Common/Graphics/ContrailRenderable.cs index 45195b4e7f..dd1cf9a8d2 100644 --- a/OpenRA.Mods.Common/Graphics/ContrailRenderable.cs +++ b/OpenRA.Mods.Common/Graphics/ContrailRenderable.cs @@ -19,6 +19,8 @@ namespace OpenRA.Mods.Common.Graphics public int Length { get { return trail.Length; } } readonly World world; + readonly Color color; + readonly int zOffset; // Store trail positions in a circular buffer readonly WPos[] trail; @@ -26,9 +28,6 @@ namespace OpenRA.Mods.Common.Graphics int length; int skip; - readonly Color color; - readonly int zOffset; - public ContrailRenderable(World world, Color color, int length, int skip, int zOffset) : this(world, new WPos[length], 0, 0, skip, color, zOffset) { } @@ -43,7 +42,7 @@ namespace OpenRA.Mods.Common.Graphics this.zOffset = zOffset; } - public WPos Pos { get { return trail[idx(next - 1)]; } } + public WPos Pos { get { return trail[Index(next - 1)]; } } public float Scale { get { return 1f; } } public PaletteReference Palette { get { return null; } } public int ZOffset { get { return zOffset; } } @@ -67,13 +66,13 @@ namespace OpenRA.Mods.Common.Graphics wlr.LineWidth = wr.Viewport.Zoom; // Start of the first line segment is the tail of the list - don't smooth it. - var curPos = trail[idx(next - skip - 1)]; + var curPos = trail[Index(next - skip - 1)]; var curCell = wr.world.Map.CellContaining(curPos); var curColor = color; for (var i = 0; i < length - skip - 4; i++) { var j = next - skip - i - 2; - var nextPos = Average(trail[idx(j)], trail[idx(j - 1)], trail[idx(j - 2)], trail[idx(j - 3)]); + var nextPos = Average(trail[Index(j)], trail[Index(j - 1)], trail[Index(j - 2)], trail[Index(j - 3)]); var nextCell = wr.world.Map.CellContaining(nextPos); var nextColor = Exts.ColorLerp(i * 1f / (length - 4), color, Color.Transparent); @@ -91,7 +90,7 @@ namespace OpenRA.Mods.Common.Graphics public void RenderDebugGeometry(WorldRenderer wr) { } // Array index modulo length - int idx(int i) + int Index(int i) { var j = i % trail.Length; return j < 0 ? j + trail.Length : j; @@ -105,7 +104,7 @@ namespace OpenRA.Mods.Common.Graphics public void Update(WPos pos) { trail[next] = pos; - next = idx(next + 1); + next = Index(next + 1); if (length < trail.Length) length++; diff --git a/OpenRA.Mods.Common/Graphics/VoxelRenderable.cs b/OpenRA.Mods.Common/Graphics/VoxelRenderable.cs index bcc6029b83..698db9ff31 100644 --- a/OpenRA.Mods.Common/Graphics/VoxelRenderable.cs +++ b/OpenRA.Mods.Common/Graphics/VoxelRenderable.cs @@ -87,13 +87,13 @@ namespace OpenRA.Mods.Common.Graphics public IRenderable AsDecoration() { return this; } // This will need generalizing once we support TS/RA2 terrain - static readonly float[] groundNormal = new float[] { 0, 0, 1, 1 }; + static readonly float[] GroundNormal = new float[] { 0, 0, 1, 1 }; public void BeforeRender(WorldRenderer wr) { var draw = voxels.Where(v => v.DisableFunc == null || !v.DisableFunc()); renderProxy = Game.Renderer.WorldVoxelRenderer.RenderAsync( - wr, draw, camera, scale, groundNormal, lightSource, + wr, draw, camera, scale, GroundNormal, lightSource, lightAmbientColor, lightDiffuseColor, palette, normalsPalette, shadowPalette); } @@ -154,15 +154,15 @@ namespace OpenRA.Mods.Common.Graphics } } - static readonly uint[] ix = new uint[] { 0, 0, 0, 0, 3, 3, 3, 3 }; - static readonly uint[] iy = new uint[] { 1, 1, 4, 4, 1, 1, 4, 4 }; - static readonly uint[] iz = new uint[] { 2, 5, 2, 5, 2, 5, 2, 5 }; + static readonly uint[] CornerXIndex = new uint[] { 0, 0, 0, 0, 3, 3, 3, 3 }; + static readonly uint[] CornerYIndex = new uint[] { 1, 1, 4, 4, 1, 1, 4, 4 }; + static readonly uint[] CornerZIndex = new uint[] { 2, 5, 2, 5, 2, 5, 2, 5 }; static void DrawBoundsBox(float2 pxPos, float[] transform, float[] bounds, Color c) { var corners = new float2[8]; for (var i = 0; i < 8; i++) { - var vec = new float[] { bounds[ix[i]], bounds[iy[i]], bounds[iz[i]], 1 }; + var vec = new float[] { bounds[CornerXIndex[i]], bounds[CornerYIndex[i]], bounds[CornerZIndex[i]], 1 }; var screen = Util.MatrixVectorMultiply(transform, vec); corners[i] = pxPos + new float2(screen[0], screen[1]); } diff --git a/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs b/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs index a8fcaa3e1a..d5ec770fb0 100644 --- a/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs +++ b/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs @@ -11,8 +11,8 @@ using System.Collections.Generic; using System.Linq; using OpenRA.FileSystem; -using OpenRA.Widgets; using OpenRA.Mods.Common.Widgets.Logic; +using OpenRA.Widgets; namespace OpenRA.Mods.Common.LoadScreens { diff --git a/OpenRA.Mods.Common/Scripting/Global/TriggerGlobal.cs b/OpenRA.Mods.Common/Scripting/Global/TriggerGlobal.cs index 4233c5604b..8ef9785715 100644 --- a/OpenRA.Mods.Common/Scripting/Global/TriggerGlobal.cs +++ b/OpenRA.Mods.Common/Scripting/Global/TriggerGlobal.cs @@ -79,7 +79,7 @@ namespace OpenRA.Mods.Common.Scripting { var group = actors.ToList(); var copy = (LuaFunction)func.CopyReference(); - Action OnMemberKilled = m => + Action onMemberKilled = m => { try { @@ -97,7 +97,7 @@ namespace OpenRA.Mods.Common.Scripting }; foreach (var a in group) - GetScriptTriggers(a).OnKilledInternal += OnMemberKilled; + GetScriptTriggers(a).OnKilledInternal += onMemberKilled; } [Desc("Call a function when one of the actors in a group is killed. The callback " + @@ -106,7 +106,7 @@ namespace OpenRA.Mods.Common.Scripting { var called = false; var copy = (LuaFunction)func.CopyReference(); - Action OnMemberKilled = m => + Action onMemberKilled = m => { try { @@ -126,7 +126,7 @@ namespace OpenRA.Mods.Common.Scripting }; foreach (var a in actors) - GetScriptTriggers(a).OnKilledInternal += OnMemberKilled; + GetScriptTriggers(a).OnKilledInternal += onMemberKilled; } [Desc("Call a function when this actor produces another actor. " + @@ -192,7 +192,7 @@ namespace OpenRA.Mods.Common.Scripting var group = actors.ToList(); var copy = (LuaFunction)func.CopyReference(); - Action OnMemberRemoved = m => + Action onMemberRemoved = m => { try { @@ -210,7 +210,7 @@ namespace OpenRA.Mods.Common.Scripting }; foreach (var a in group) - GetScriptTriggers(a).OnRemovedInternal += OnMemberRemoved; + GetScriptTriggers(a).OnRemovedInternal += onMemberRemoved; } [Desc("Call a function when this actor is captured. The callback function " + @@ -227,7 +227,7 @@ namespace OpenRA.Mods.Common.Scripting var called = false; var copy = (LuaFunction)func.CopyReference(); - Action OnKilledOrCaptured = m => + Action onKilledOrCaptured = m => { try { @@ -244,8 +244,8 @@ namespace OpenRA.Mods.Common.Scripting } }; - GetScriptTriggers(a).OnCapturedInternal += OnKilledOrCaptured; - GetScriptTriggers(a).OnKilledInternal += OnKilledOrCaptured; + GetScriptTriggers(a).OnCapturedInternal += onKilledOrCaptured; + GetScriptTriggers(a).OnKilledInternal += onKilledOrCaptured; } [Desc("Call a function when all of the actors in a group have been killed or captured. " + @@ -255,7 +255,7 @@ namespace OpenRA.Mods.Common.Scripting var group = actors.ToList(); var copy = (LuaFunction)func.CopyReference(); - Action OnMemberKilledOrCaptured = m => + Action onMemberKilledOrCaptured = m => { try { @@ -277,8 +277,8 @@ namespace OpenRA.Mods.Common.Scripting foreach (var a in group) { - GetScriptTriggers(a).OnCapturedInternal += OnMemberKilledOrCaptured; - GetScriptTriggers(a).OnKilledInternal += OnMemberKilledOrCaptured; + GetScriptTriggers(a).OnCapturedInternal += onMemberKilledOrCaptured; + GetScriptTriggers(a).OnKilledInternal += onMemberKilledOrCaptured; } } diff --git a/OpenRA.Mods.Common/ServerTraits/PlayerPinger.cs b/OpenRA.Mods.Common/ServerTraits/PlayerPinger.cs index ae9ee81bbf..70018dc507 100644 --- a/OpenRA.Mods.Common/ServerTraits/PlayerPinger.cs +++ b/OpenRA.Mods.Common/ServerTraits/PlayerPinger.cs @@ -17,9 +17,9 @@ namespace OpenRA.Mods.Common.Server { public class PlayerPinger : ServerTrait, ITick { - int PingInterval = 5000; // Ping every 5 seconds - int ConnReportInterval = 20000; // Report every 20 seconds - int ConnTimeout = 90000; // Drop unresponsive clients after 90 seconds + static readonly int PingInterval = 5000; // Ping every 5 seconds + static readonly int ConnReportInterval = 20000; // Report every 20 seconds + static readonly int ConnTimeout = 90000; // Drop unresponsive clients after 90 seconds // TickTimeout is in microseconds public int TickTimeout { get { return PingInterval * 100; } } diff --git a/OpenRA.Mods.Common/Traits/Buildings/BaseProvider.cs b/OpenRA.Mods.Common/Traits/Buildings/BaseProvider.cs index 9be732dd2a..ec42be0ab1 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/BaseProvider.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/BaseProvider.cs @@ -75,8 +75,7 @@ namespace OpenRA.Mods.Common.Traits WRange.FromCells(Info.Range), 0, Color.FromArgb(128, Ready() ? Color.White : Color.Red), - Color.FromArgb(96, Color.Black) - ); + Color.FromArgb(96, Color.Black)); } // Selection bar diff --git a/OpenRA.Mods.Common/Traits/Buildings/LineBuild.cs b/OpenRA.Mods.Common/Traits/Buildings/LineBuild.cs index f7104f600b..db98735954 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/LineBuild.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/LineBuild.cs @@ -22,5 +22,5 @@ namespace OpenRA.Mods.Common.Traits public readonly string[] NodeTypes = { "wall" }; } - public class LineBuild {} + public class LineBuild { } } diff --git a/OpenRA.Mods.Common/Traits/Buildings/LineBuildNode.cs b/OpenRA.Mods.Common/Traits/Buildings/LineBuildNode.cs index 4beee488f3..aee9bb6239 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/LineBuildNode.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/LineBuildNode.cs @@ -19,5 +19,5 @@ namespace OpenRA.Mods.Common.Traits public readonly string[] Types = { "wall" }; } - public class LineBuildNode {} + public class LineBuildNode { } } diff --git a/OpenRA.Mods.Common/Traits/Burns.cs b/OpenRA.Mods.Common/Traits/Burns.cs index 83a45e5e14..f8c804683a 100644 --- a/OpenRA.Mods.Common/Traits/Burns.cs +++ b/OpenRA.Mods.Common/Traits/Burns.cs @@ -26,15 +26,15 @@ namespace OpenRA.Mods.Common.Traits class Burns : ITick, ISync { [Sync] int ticks; - BurnsInfo Info; + BurnsInfo info; public Burns(Actor self, BurnsInfo info) { - Info = info; + this.info = info; var anim = new Animation(self.World, "fire", () => 0); anim.IsDecoration = true; - anim.PlayRepeating(Info.Anim); + anim.PlayRepeating(info.Anim); self.Trait().Add("fire", anim); } @@ -42,8 +42,8 @@ namespace OpenRA.Mods.Common.Traits { if (--ticks <= 0) { - self.InflictDamage(self, Info.Damage, null); - ticks = Info.Interval; + self.InflictDamage(self, info.Damage, null); + ticks = info.Interval; } } } diff --git a/OpenRA.Mods.Common/Traits/PaletteEffects/LightPaletteRotator.cs b/OpenRA.Mods.Common/Traits/PaletteEffects/LightPaletteRotator.cs index 6eda0e0366..504866fd8e 100644 --- a/OpenRA.Mods.Common/Traits/PaletteEffects/LightPaletteRotator.cs +++ b/OpenRA.Mods.Common/Traits/PaletteEffects/LightPaletteRotator.cs @@ -25,19 +25,19 @@ namespace OpenRA.Mods.Common.Traits class LightPaletteRotator : ITick, IPaletteModifier { - float t = 0; - public void Tick(Actor self) - { - t += .5f; - } - readonly LightPaletteRotatorInfo info; + float t = 0; public LightPaletteRotator(LightPaletteRotatorInfo info) { this.info = info; } + public void Tick(Actor self) + { + t += .5f; + } + public void AdjustPalette(IReadOnlyDictionary palettes) { foreach (var pal in palettes) diff --git a/OpenRA.Mods.Common/Traits/PaletteEffects/NukePaletteEffect.cs b/OpenRA.Mods.Common/Traits/PaletteEffects/NukePaletteEffect.cs index e30f476fa7..c6f1d3f0b8 100644 --- a/OpenRA.Mods.Common/Traits/PaletteEffects/NukePaletteEffect.cs +++ b/OpenRA.Mods.Common/Traits/PaletteEffects/NukePaletteEffect.cs @@ -20,12 +20,12 @@ namespace OpenRA.Mods.Common.Traits public class NukePaletteEffect : IPaletteModifier, ITick { - const int nukeEffectLength = 20; + const int NukeEffectLength = 20; int remainingFrames; public void Enable() { - remainingFrames = nukeEffectLength; + remainingFrames = NukeEffectLength; } public void Tick(Actor self) @@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits if (remainingFrames == 0) return; - var frac = (float)remainingFrames / nukeEffectLength; + var frac = (float)remainingFrames / NukeEffectLength; foreach (var pal in palettes) { diff --git a/OpenRA.Mods.Common/Traits/PaletteEffects/WaterPaletteRotation.cs b/OpenRA.Mods.Common/Traits/PaletteEffects/WaterPaletteRotation.cs index 5187e09e23..b7db86a5fd 100644 --- a/OpenRA.Mods.Common/Traits/PaletteEffects/WaterPaletteRotation.cs +++ b/OpenRA.Mods.Common/Traits/PaletteEffects/WaterPaletteRotation.cs @@ -25,10 +25,9 @@ namespace OpenRA.Mods.Common.Traits class WaterPaletteRotation : ITick, IPaletteModifier { - float t = 0; - readonly WaterPaletteRotationInfo info; readonly World world; + float t = 0; public WaterPaletteRotation(World world, WaterPaletteRotationInfo info) { diff --git a/OpenRA.Mods.Common/Traits/RadarColorFromTerrain.cs b/OpenRA.Mods.Common/Traits/RadarColorFromTerrain.cs index f3c3ba9f9b..bc1dc919ed 100644 --- a/OpenRA.Mods.Common/Traits/RadarColorFromTerrain.cs +++ b/OpenRA.Mods.Common/Traits/RadarColorFromTerrain.cs @@ -16,7 +16,7 @@ namespace OpenRA.Mods.Common.Traits public class RadarColorFromTerrainInfo : ITraitInfo { public readonly string Terrain; - public object Create( ActorInitializer init ) { return new RadarColorFromTerrain(init.self,Terrain); } + public object Create(ActorInitializer init) { return new RadarColorFromTerrain(init.self, Terrain); } } public class RadarColorFromTerrain : IRadarColorModifier diff --git a/OpenRA.Mods.Common/Traits/Render/RenderSprites.cs b/OpenRA.Mods.Common/Traits/Render/RenderSprites.cs index 82a88194e7..bd53469bbe 100644 --- a/OpenRA.Mods.Common/Traits/Render/RenderSprites.cs +++ b/OpenRA.Mods.Common/Traits/Render/RenderSprites.cs @@ -88,6 +88,8 @@ namespace OpenRA.Mods.Common.Traits } } + readonly RenderSpritesInfo info; + string cachedImage = null; Dictionary anims = new Dictionary(); public static Func MakeFacingFunc(Actor self) @@ -97,9 +99,6 @@ namespace OpenRA.Mods.Common.Traits return () => facing.Facing; } - readonly RenderSpritesInfo info; - string cachedImage = null; - public RenderSprites(Actor self) { info = self.Info.Traits.Get(); @@ -107,8 +106,8 @@ namespace OpenRA.Mods.Common.Traits public static string GetImage(ActorInfo actor) { - var Info = actor.Traits.Get(); - return (Info.Image ?? actor.Name).ToLowerInvariant(); + var info = actor.Traits.Get(); + return (info.Image ?? actor.Name).ToLowerInvariant(); } public string GetImage(Actor self) diff --git a/OpenRA.Mods.Common/Traits/Render/WithRotor.cs b/OpenRA.Mods.Common/Traits/Render/WithRotor.cs index e1ac419f1e..a607a4e279 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithRotor.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithRotor.cs @@ -75,7 +75,7 @@ namespace OpenRA.Mods.Common.Traits rotorAnim.ReplaceAnim(isFlying ? info.Sequence : info.GroundSequence); } - static public int ZOffsetFromCenter(Actor self, WPos pos, int offset) + public static int ZOffsetFromCenter(Actor self, WPos pos, int offset) { var delta = self.CenterPosition - pos; return delta.Y + delta.Z + offset; diff --git a/OpenRA.Mods.Common/Traits/ShakeOnDeath.cs b/OpenRA.Mods.Common/Traits/ShakeOnDeath.cs index 63fb583008..fc18cc598b 100644 --- a/OpenRA.Mods.Common/Traits/ShakeOnDeath.cs +++ b/OpenRA.Mods.Common/Traits/ShakeOnDeath.cs @@ -20,16 +20,16 @@ namespace OpenRA.Mods.Common.Traits public class ShakeOnDeath : INotifyKilled { - readonly ShakeOnDeathInfo Info; + readonly ShakeOnDeathInfo info; public ShakeOnDeath(ShakeOnDeathInfo info) { - this.Info = info; + this.info = info; } public void Killed(Actor self, AttackInfo e) { - self.World.WorldActor.Trait().AddEffect(Info.Intensity, self.CenterPosition, 1); + self.World.WorldActor.Trait().AddEffect(info.Intensity, self.CenterPosition, 1); } } } diff --git a/OpenRA.Mods.Common/Traits/Sound/SoundOnDamageTransition.cs b/OpenRA.Mods.Common/Traits/Sound/SoundOnDamageTransition.cs index 74b33fd2af..d5f9fbd2f2 100644 --- a/OpenRA.Mods.Common/Traits/Sound/SoundOnDamageTransition.cs +++ b/OpenRA.Mods.Common/Traits/Sound/SoundOnDamageTransition.cs @@ -22,19 +22,19 @@ namespace OpenRA.Mods.Common.Traits public class SoundOnDamageTransition : INotifyDamageStateChanged { - readonly SoundOnDamageTransitionInfo Info; + readonly SoundOnDamageTransitionInfo info; public SoundOnDamageTransition(SoundOnDamageTransitionInfo info) { - Info = info; + this.info = info; } public void DamageStateChanged(Actor self, AttackInfo e) { if (e.DamageState == DamageState.Dead) - Sound.Play(Info.DestroyedSound, self.CenterPosition); + Sound.Play(info.DestroyedSound, self.CenterPosition); else if (e.DamageState >= DamageState.Heavy && e.PreviousDamageState < DamageState.Heavy) - Sound.Play(Info.DamagedSound, self.CenterPosition); + Sound.Play(info.DamagedSound, self.CenterPosition); } } } diff --git a/OpenRA.Mods.Common/Traits/World/ShroudPalette.cs b/OpenRA.Mods.Common/Traits/World/ShroudPalette.cs index d61639260a..9236852a26 100644 --- a/OpenRA.Mods.Common/Traits/World/ShroudPalette.cs +++ b/OpenRA.Mods.Common/Traits/World/ShroudPalette.cs @@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits wr.AddPalette(info.Name, new ImmutablePalette(Enumerable.Range(0, Palette.Size).Select(i => (uint)c[i % 8].ToArgb()))); } - static Color[] Fog = new[] + static readonly Color[] Fog = new[] { Color.Transparent, Color.Green, Color.Blue, Color.Yellow, @@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.Traits Color.FromArgb(32, 0, 0, 0) }; - static Color[] Shroud = new[] + static readonly Color[] Shroud = new[] { Color.Transparent, Color.Green, Color.Blue, Color.Yellow, diff --git a/OpenRA.Mods.Common/Warheads/SpreadDamageWarhead.cs b/OpenRA.Mods.Common/Warheads/SpreadDamageWarhead.cs index f505dd9834..78bbfd00a7 100644 --- a/OpenRA.Mods.Common/Warheads/SpreadDamageWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/SpreadDamageWarhead.cs @@ -22,12 +22,12 @@ namespace OpenRA.Mods.Common [Desc("Range between falloff steps.")] public readonly WRange Spread = new WRange(43); - [Desc("Ranges at which each Falloff step is defined. Overrides Spread.")] - public WRange[] Range = null; - [Desc("Damage percentage at each range step")] public readonly int[] Falloff = { 100, 37, 14, 5, 2, 1, 0 }; + [Desc("Ranges at which each Falloff step is defined. Overrides Spread.")] + public WRange[] Range = null; + public void InitializeRange() { if (Range != null) diff --git a/OpenRA.Mods.Common/Widgets/ColorMixerWidget.cs b/OpenRA.Mods.Common/Widgets/ColorMixerWidget.cs index 0994ec9bb6..4aa9155676 100644 --- a/OpenRA.Mods.Common/Widgets/ColorMixerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ColorMixerWidget.cs @@ -22,7 +22,10 @@ namespace OpenRA.Mods.Common.Widgets public float[] VRange = { 0.2f, 1.0f }; public event Action OnChange = () => { }; - float H, S, V; + public float H { get; private set; } + public float S { get; private set; } + public float V { get; private set; } + byte[] front, back; Sprite mixerSprite; bool isMoving; diff --git a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs index 308f73b078..8aabc593b7 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs @@ -28,22 +28,22 @@ namespace OpenRA.Mods.Common.Widgets.Logic WorldRenderer worldRenderer; SoundDevice soundDevice; - static readonly string originalSoundDevice; - static readonly string originalSoundEngine; - static readonly WindowMode originalGraphicsMode; - static readonly string originalGraphicsRenderer; - static readonly int2 originalGraphicsWindowedSize; - static readonly int2 originalGraphicsFullscreenSize; + static readonly string OriginalSoundDevice; + static readonly string OriginalSoundEngine; + static readonly WindowMode OriginalGraphicsMode; + static readonly string OriginalGraphicsRenderer; + static readonly int2 OriginalGraphicsWindowedSize; + static readonly int2 OriginalGraphicsFullscreenSize; static SettingsLogic() { var original = Game.Settings; - originalSoundDevice = original.Sound.Device; - originalSoundEngine = original.Sound.Engine; - originalGraphicsMode = original.Graphics.Mode; - originalGraphicsRenderer = original.Graphics.Renderer; - originalGraphicsWindowedSize = original.Graphics.WindowedSize; - originalGraphicsFullscreenSize = original.Graphics.FullscreenSize; + OriginalSoundDevice = original.Sound.Device; + OriginalSoundEngine = original.Sound.Engine; + OriginalGraphicsMode = original.Graphics.Mode; + OriginalGraphicsRenderer = original.Graphics.Renderer; + OriginalGraphicsWindowedSize = original.Graphics.WindowedSize; + OriginalGraphicsFullscreenSize = original.Graphics.FullscreenSize; } [ObjectCreator.UseCtor] @@ -66,12 +66,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic current.Save(); Action closeAndExit = () => { Ui.CloseWindow(); onExit(); }; - if (originalSoundDevice != current.Sound.Device || - originalSoundEngine != current.Sound.Engine || - originalGraphicsMode != current.Graphics.Mode || - originalGraphicsRenderer != current.Graphics.Renderer || - originalGraphicsWindowedSize != current.Graphics.WindowedSize || - originalGraphicsFullscreenSize != current.Graphics.FullscreenSize) + if (OriginalSoundDevice != current.Sound.Device || + OriginalSoundEngine != current.Sound.Engine || + OriginalGraphicsMode != current.Graphics.Mode || + OriginalGraphicsRenderer != current.Graphics.Renderer || + OriginalGraphicsWindowedSize != current.Graphics.WindowedSize || + OriginalGraphicsFullscreenSize != current.Graphics.FullscreenSize) ConfirmationDialogs.PromptConfirmAction( "Restart Now?", "Some changes will not be applied until\nthe game is restarted. Restart now?", diff --git a/OpenRA.Mods.Common/Widgets/RadarWidget.cs b/OpenRA.Mods.Common/Widgets/RadarWidget.cs index a859fc8607..54c70cc2c8 100644 --- a/OpenRA.Mods.Common/Widgets/RadarWidget.cs +++ b/OpenRA.Mods.Common/Widgets/RadarWidget.cs @@ -29,6 +29,10 @@ namespace OpenRA.Mods.Common.Widgets public Action AfterClose = () => { }; public Action Animating = _ => { }; + readonly World world; + readonly WorldRenderer worldRenderer; + readonly RadarPings radarPings; + float radarMinimapHeight; int frame; bool hasRadar; @@ -46,11 +50,6 @@ namespace OpenRA.Mods.Common.Widgets Sprite shroudSprite; Shroud renderShroud; - readonly World world; - readonly WorldRenderer worldRenderer; - - readonly RadarPings radarPings; - [ObjectCreator.UseCtor] public RadarWidget(World world, WorldRenderer worldRenderer) { @@ -100,9 +99,9 @@ namespace OpenRA.Mods.Common.Widgets unsafe { - fixed (byte* _colors = &radarData[0]) + fixed (byte* colorBytes = &radarData[0]) { - var colors = (int*)_colors; + var colors = (int*)colorBytes; colors[(uv.Y + dy) * stride + uv.X + dx] = terrain.Color.ToArgb(); } } @@ -123,9 +122,9 @@ namespace OpenRA.Mods.Common.Widgets unsafe { - fixed (byte* _colors = &radarData[0]) + fixed (byte* colorBytes = &radarData[0]) { - var colors = (int*)_colors; + var colors = (int*)colorBytes; colors[(uv.Y + dy) * stride + uv.X + dx] = color; } } @@ -280,9 +279,9 @@ namespace OpenRA.Mods.Common.Widgets unsafe { - fixed (byte* _colors = &radarData[0]) + fixed (byte* colorBytes = &radarData[0]) { - var colors = (int*)_colors; + var colors = (int*)colorBytes; foreach (var t in world.ActorsWithTrait()) { diff --git a/OpenRA.Mods.D2k/Traits/AutoCarryall.cs b/OpenRA.Mods.D2k/Traits/AutoCarryall.cs index 42c931daa6..ebcb128ed9 100644 --- a/OpenRA.Mods.D2k/Traits/AutoCarryall.cs +++ b/OpenRA.Mods.D2k/Traits/AutoCarryall.cs @@ -95,7 +95,6 @@ namespace OpenRA.Mods.D2k.Traits }) .OrderBy(p => (self.Location - p.Actor.Location).LengthSquared); - foreach (var p in carryables) { // Check if its actually me who's the best candidate diff --git a/OpenRA.Mods.D2k/Traits/Buildings/LaysTerrain.cs b/OpenRA.Mods.D2k/Traits/Buildings/LaysTerrain.cs index 538281ea47..08161fd446 100644 --- a/OpenRA.Mods.D2k/Traits/Buildings/LaysTerrain.cs +++ b/OpenRA.Mods.D2k/Traits/Buildings/LaysTerrain.cs @@ -21,7 +21,7 @@ namespace OpenRA.Mods.D2k.Traits public readonly ushort Template = 0; [Desc("The terrain types that this template will be placed on")] - public readonly string[] TerrainTypes = {}; + public readonly string[] TerrainTypes = { }; [Desc("Offset relative to the actor TopLeft. Not used if the template is PickAny")] public readonly CVec Offset = CVec.Zero; diff --git a/OpenRA.Mods.D2k/Widgets/BuildPaletteWidget.cs b/OpenRA.Mods.D2k/Widgets/BuildPaletteWidget.cs index 1103afdfd0..e3546fed1e 100644 --- a/OpenRA.Mods.D2k/Widgets/BuildPaletteWidget.cs +++ b/OpenRA.Mods.D2k/Widgets/BuildPaletteWidget.cs @@ -41,8 +41,12 @@ namespace OpenRA.Mods.D2k.Widgets public int IconWidth = 64; public int IconHeight = 48; - ProductionQueue CurrentQueue; - List VisibleQueues; + readonly WorldRenderer worldRenderer; + readonly World world; + readonly OrderManager orderManager; + + ProductionQueue currentQueue; + List visibleQueues; bool paletteOpen = false; @@ -59,10 +63,6 @@ namespace OpenRA.Mods.D2k.Widgets Animation cantBuild; Animation clock; - readonly WorldRenderer worldRenderer; - readonly World world; - readonly OrderManager orderManager; - [ObjectCreator.UseCtor] public BuildPaletteWidget(OrderManager orderManager, World world, WorldRenderer worldRenderer) { @@ -73,13 +73,13 @@ namespace OpenRA.Mods.D2k.Widgets cantBuild = new Animation(world, "clock"); cantBuild.PlayFetchIndex("idle", () => 0); clock = new Animation(world, "clock"); - VisibleQueues = new List(); - CurrentQueue = null; + visibleQueues = new List(); + currentQueue = null; } public override void Initialize(WidgetArgs args) { - paletteOpenOrigin = new float2(Game.Renderer.Resolution.Width - Columns*IconWidth - 23, 280); + paletteOpenOrigin = new float2(Game.Renderer.Resolution.Width - Columns * IconWidth - 23, 280); paletteClosedOrigin = new float2(Game.Renderer.Resolution.Width - 16, 280); paletteOrigin = paletteClosedOrigin; base.Initialize(args); @@ -87,29 +87,30 @@ namespace OpenRA.Mods.D2k.Widgets public override Rectangle EventBounds { - get { return new Rectangle((int)(paletteOrigin.X) - 24, (int)(paletteOrigin.Y), 239, Math.Max(IconHeight * numActualRows, 40 * tabs.Count + 9)); } + get { return new Rectangle((int)paletteOrigin.X - 24, (int)paletteOrigin.Y, 239, Math.Max(IconHeight * numActualRows, 40 * tabs.Count + 9)); } } public override void Tick() { - VisibleQueues.Clear(); + visibleQueues.Clear(); var queues = world.ActorsWithTrait() .Where(p => p.Actor.Owner == world.LocalPlayer) .Select(p => p.Trait); - if (CurrentQueue != null && CurrentQueue.Actor.Destroyed) - CurrentQueue = null; + if (currentQueue != null && currentQueue.Actor.Destroyed) + currentQueue = null; foreach (var queue in queues) { if (queue.AllItems().Any()) - VisibleQueues.Add(queue); - else if (CurrentQueue == queue) - CurrentQueue = null; + visibleQueues.Add(queue); + else if (currentQueue == queue) + currentQueue = null; } - if (CurrentQueue == null) - CurrentQueue = VisibleQueues.FirstOrDefault(); + + if (currentQueue == null) + currentQueue = visibleQueues.FirstOrDefault(); TickPaletteAnimation(world); } @@ -151,7 +152,7 @@ namespace OpenRA.Mods.D2k.Widgets paletteAnimating = true; paletteOpen = true; - CurrentQueue = queue; + currentQueue = queue; } public override bool HandleKeyPress(KeyInput e) @@ -195,10 +196,11 @@ namespace OpenRA.Mods.D2k.Widgets public override void Draw() { - if (!IsVisible()) return; - // TODO: fix + if (!IsVisible()) + return; - DrawPalette(CurrentQueue); + // TODO: fix + DrawPalette(currentQueue); DrawBuildTabs(world); } @@ -231,7 +233,6 @@ namespace OpenRA.Mods.D2k.Widgets WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "bottom"), new float2(origin.X - 9, origin.Y - 1 + IconHeight * numActualRows)); - // Icons string tooltipItem = null; var tooltipHotkey = Hotkey.Invalid; @@ -279,7 +280,9 @@ namespace OpenRA.Mods.D2k.Widgets if (++x == Columns) { x = 0; y++; } i++; } - if (x != 0) y++; + + if (x != 0) + y++; foreach (var ob in overlayBits) WidgetUtils.DrawSHPCentered(ob.First, ob.Second + iconOffset, worldRenderer); @@ -334,7 +337,7 @@ namespace OpenRA.Mods.D2k.Widgets Sound.PlayNotification(world.Map.Rules, null, "Sounds", "TabClick", null); if (name != null) - HandleBuildPalette(world, name, (mi.Button == MouseButton.Left)); + HandleBuildPalette(world, name, mi.Button == MouseButton.Left); }; } @@ -347,8 +350,8 @@ namespace OpenRA.Mods.D2k.Widgets Sound.PlayNotification(world.Map.Rules, null, "Sounds", "TabClick", null); var wasOpen = paletteOpen; - paletteOpen = CurrentQueue != queue || !wasOpen; - CurrentQueue = queue; + paletteOpen = currentQueue != queue || !wasOpen; + currentQueue = queue; if (wasOpen != paletteOpen) paletteAnimating = true; }; @@ -367,16 +370,16 @@ namespace OpenRA.Mods.D2k.Widgets void HandleBuildPalette(World world, string item, bool isLmb) { var unit = world.Map.Rules.Actors[item]; - var producing = CurrentQueue.AllQueued().FirstOrDefault(a => a.Item == item); + var producing = currentQueue.AllQueued().FirstOrDefault(a => a.Item == item); if (isLmb) { - if (producing != null && producing == CurrentQueue.CurrentItem()) + if (producing != null && producing == currentQueue.CurrentItem()) { if (producing.Done) { if (unit.Traits.Contains()) - world.OrderGenerator = new PlaceBuildingOrderGenerator(CurrentQueue, item); + world.OrderGenerator = new PlaceBuildingOrderGenerator(currentQueue, item); else StartProduction(world, item); return; @@ -384,21 +387,21 @@ namespace OpenRA.Mods.D2k.Widgets if (producing.Paused) { - world.IssueOrder(Order.PauseProduction(CurrentQueue.Actor, item, false)); + world.IssueOrder(Order.PauseProduction(currentQueue.Actor, item, false)); return; } } else { // Check if the item's build-limit has already been reached - var queued = CurrentQueue.AllQueued().Count(a => a.Item == unit.Name); + var queued = currentQueue.AllQueued().Count(a => a.Item == unit.Name); var inWorld = world.ActorsWithTrait().Count(a => a.Actor.Info.Name == unit.Name && a.Actor.Owner == world.LocalPlayer); var buildLimit = unit.Traits.Get().BuildLimit; if (!((buildLimit != 0) && (inWorld + queued >= buildLimit))) - Sound.PlayNotification(world.Map.Rules, world.LocalPlayer, "Speech", CurrentQueue.Info.QueuedAudio, world.LocalPlayer.Country.Race); + Sound.PlayNotification(world.Map.Rules, world.LocalPlayer, "Speech", currentQueue.Info.QueuedAudio, world.LocalPlayer.Country.Race); else - Sound.PlayNotification(world.Map.Rules, world.LocalPlayer, "Speech", CurrentQueue.Info.BlockedAudio, world.LocalPlayer.Country.Race); + Sound.PlayNotification(world.Map.Rules, world.LocalPlayer, "Speech", currentQueue.Info.BlockedAudio, world.LocalPlayer.Country.Race); } StartProduction(world, item); @@ -410,15 +413,15 @@ namespace OpenRA.Mods.D2k.Widgets // instant cancel of things we havent really started yet, and things that are finished if (producing.Paused || producing.Done || producing.TotalCost == producing.RemainingCost) { - Sound.PlayNotification(world.Map.Rules, world.LocalPlayer, "Speech", CurrentQueue.Info.CancelledAudio, world.LocalPlayer.Country.Race); + Sound.PlayNotification(world.Map.Rules, world.LocalPlayer, "Speech", currentQueue.Info.CancelledAudio, world.LocalPlayer.Country.Race); var numberToCancel = Game.GetModifierKeys().HasModifier(Modifiers.Shift) ? 5 : 1; - world.IssueOrder(Order.CancelProduction(CurrentQueue.Actor, item, numberToCancel)); + world.IssueOrder(Order.CancelProduction(currentQueue.Actor, item, numberToCancel)); } else { - Sound.PlayNotification(world.Map.Rules, world.LocalPlayer, "Speech", CurrentQueue.Info.OnHoldAudio, world.LocalPlayer.Country.Race); - world.IssueOrder(Order.PauseProduction(CurrentQueue.Actor, item, true)); + Sound.PlayNotification(world.Map.Rules, world.LocalPlayer, "Speech", currentQueue.Info.OnHoldAudio, world.LocalPlayer.Country.Race); + world.IssueOrder(Order.PauseProduction(currentQueue.Actor, item, true)); } } } @@ -426,29 +429,29 @@ namespace OpenRA.Mods.D2k.Widgets void StartProduction(World world, string item) { - world.IssueOrder(Order.StartProduction(CurrentQueue.Actor, item, + world.IssueOrder(Order.StartProduction(currentQueue.Actor, item, Game.GetModifierKeys().HasModifier(Modifiers.Shift) ? 5 : 1)); } void DrawBuildTabs(World world) { - const int tabWidth = 24; - const int tabHeight = 40; - var x = paletteOrigin.X - tabWidth; + const int TabWidth = 24; + const int TabHeight = 40; + var x = paletteOrigin.X - TabWidth; var y = paletteOrigin.Y + 9; tabs.Clear(); - foreach (var queue in VisibleQueues) + foreach (var queue in visibleQueues) { string[] tabKeys = { "normal", "ready", "selected" }; var producing = queue.CurrentItem(); - var index = queue == CurrentQueue ? 2 : (producing != null && producing.Done) ? 1 : 0; + var index = queue == currentQueue ? 2 : (producing != null && producing.Done) ? 1 : 0; var race = world.LocalPlayer.Country.Race; WidgetUtils.DrawRGBA(ChromeProvider.GetImage("tabs-" + tabKeys[index], race + "-" + queue.Info.Type), new float2(x, y)); - var rect = new Rectangle((int)x, (int)y, tabWidth, tabHeight); + var rect = new Rectangle((int)x, (int)y, TabWidth, TabHeight); tabs.Add(Pair.New(rect, HandleTabClick(queue, world))); if (rect.Contains(Viewport.LastMousePos)) @@ -463,7 +466,7 @@ namespace OpenRA.Mods.D2k.Widgets font.DrawText(text, new float2(rect.Left - sz.X - 20, rect.Top + 12), Color.White); } - y += tabHeight; + y += TabHeight; } } @@ -484,7 +487,7 @@ namespace OpenRA.Mods.D2k.Widgets var tooltip = info.Traits.Get(); var buildable = info.Traits.Get(); var cost = info.Traits.Get().Cost; - var canBuildThis = CurrentQueue.CanBuild(info); + var canBuildThis = currentQueue.CanBuild(info); var longDescSize = Game.Renderer.Fonts["Regular"].Measure(tooltip.Description.Replace("\\n", "\n")).Y; if (!canBuildThis) longDescSize += 8; @@ -499,11 +502,11 @@ namespace OpenRA.Mods.D2k.Widgets var power = pl.PlayerActor.Trait(); DrawRightAligned("${0}".F(cost), pos + new int2(-5, 5), - (resources.DisplayCash + resources.DisplayResources >= cost ? Color.White : Color.Red)); + resources.DisplayCash + resources.DisplayResources >= cost ? Color.White : Color.Red); var lowpower = power.PowerState != PowerState.Normal; - var time = CurrentQueue.GetBuildTime(info.Name) - * ((lowpower) ? CurrentQueue.Info.LowPowerSlowdown : 1); + var time = currentQueue.GetBuildTime(info.Name) + * (lowpower ? currentQueue.Info.LowPowerSlowdown : 1); DrawRightAligned(WidgetUtils.FormatTime(time), pos + new int2(-5, 35), lowpower ? Color.Red : Color.White); var pis = info.Traits.WithInterface().Where(i => i.UpgradeMinEnabledLevel < 1); @@ -532,7 +535,7 @@ namespace OpenRA.Mods.D2k.Widgets bool DoBuildingHotkey(KeyInput e, World world) { if (!paletteOpen) return false; - if (CurrentQueue == null) return false; + if (currentQueue == null) return false; var key = Hotkey.FromKeyInput(e); var ks = Game.Settings.Keys; @@ -546,7 +549,7 @@ namespace OpenRA.Mods.D2k.Widgets } } - var allBuildables = CurrentQueue.AllItems().OrderBy(a => a.Traits.Get().BuildPaletteOrder).ToArray(); + var allBuildables = currentQueue.AllItems().OrderBy(a => a.Traits.Get().BuildPaletteOrder).ToArray(); var toBuild = allBuildables.ElementAtOrDefault(slot); if (toBuild != null) { @@ -562,16 +565,17 @@ namespace OpenRA.Mods.D2k.Widgets bool ChangeTab(bool reverse) { Sound.PlayNotification(world.Map.Rules, null, "Sounds", "TabClick", null); - var queues = VisibleQueues.Concat(VisibleQueues); + var queues = visibleQueues.Concat(visibleQueues); if (reverse) queues = queues.Reverse(); - var nextQueue = queues.SkipWhile(q => q != CurrentQueue) + var nextQueue = queues.SkipWhile(q => q != currentQueue) .ElementAtOrDefault(1); if (nextQueue != null) { SetCurrentTab(nextQueue); return true; } + return true; } } diff --git a/OpenRA.Mods.D2k/Widgets/Logic/IngameChromeLogic.cs b/OpenRA.Mods.D2k/Widgets/Logic/IngameChromeLogic.cs index a4c64fba71..aa64a72e42 100644 --- a/OpenRA.Mods.D2k/Widgets/Logic/IngameChromeLogic.cs +++ b/OpenRA.Mods.D2k/Widgets/Logic/IngameChromeLogic.cs @@ -11,8 +11,8 @@ using System; using System.Drawing; using System.Linq; -using OpenRA.Mods.Common.Widgets; using OpenRA.Mods.Common.Traits; +using OpenRA.Mods.Common.Widgets; using OpenRA.Mods.D2k.Widgets; using OpenRA.Mods.RA; using OpenRA.Mods.RA.Widgets; @@ -63,7 +63,7 @@ namespace OpenRA.Mods.D2k.Widgets.Logic Game.LoadWidget(world, "OBSERVER_WIDGETS", playerRoot, new WidgetArgs()); } - enum RadarBinState { Closed, BinAnimating, RadarAnimating, Open }; + enum RadarBinState { Closed, BinAnimating, RadarAnimating, Open } void InitPlayerWidgets() { var playerWidgets = Game.LoadWidget(world, "PLAYER_WIDGETS", playerRoot, new WidgetArgs()); @@ -80,11 +80,11 @@ namespace OpenRA.Mods.D2k.Widgets.Logic radarMap.AfterOpen = () => binState = RadarBinState.Open; radarMap.AfterClose = () => binState = RadarBinState.BinAnimating; - radarBin.Get("RADAR_BIN_BG").GetImageCollection = () => "chrome-"+world.LocalPlayer.Country.Race; + radarBin.Get("RADAR_BIN_BG").GetImageCollection = () => "chrome-" + world.LocalPlayer.Country.Race; var powerManager = world.LocalPlayer.PlayerActor.Trait(); var powerBar = radarBin.Get("POWERBAR"); - powerBar.IndicatorCollection = "power-"+world.LocalPlayer.Country.Race; + powerBar.IndicatorCollection = "power-" + world.LocalPlayer.Country.Race; powerBar.GetProvided = () => powerManager.PowerProvided; powerBar.GetUsed = () => powerManager.PowerDrained; powerBar.TooltipFormat = "Power Usage: {0}/{1}"; @@ -106,7 +106,7 @@ namespace OpenRA.Mods.D2k.Widgets.Logic .Any(a => a.Actor.Owner == world.LocalPlayer && a.Trait.IsActive); if (radarActive != cachedRadarActive) - Sound.PlayNotification(world.Map.Rules, null, "Sounds", (radarActive ? "RadarUp" : "RadarDown"), null); + Sound.PlayNotification(world.Map.Rules, null, "Sounds", radarActive ? "RadarUp" : "RadarDown", null); cachedRadarActive = radarActive; // Switch to observer mode after win/loss diff --git a/OpenRA.Mods.D2k/Widgets/MoneyBinWidget.cs b/OpenRA.Mods.D2k/Widgets/MoneyBinWidget.cs index db056e2b72..5136c2e7c5 100644 --- a/OpenRA.Mods.D2k/Widgets/MoneyBinWidget.cs +++ b/OpenRA.Mods.D2k/Widgets/MoneyBinWidget.cs @@ -29,8 +29,11 @@ namespace OpenRA.Mods.D2k.Widgets public override void Draw() { - if( world.LocalPlayer == null ) return; - if( world.LocalPlayer.WinState != WinState.Undefined ) return; + if (world.LocalPlayer == null) + return; + + if (world.LocalPlayer.WinState != WinState.Undefined) + return; var digitCollection = "digits-" + world.LocalPlayer.Country.Race; var chromeCollection = "chrome-" + world.LocalPlayer.Country.Race; diff --git a/OpenRA.Mods.D2k/Widgets/SlidingContainerWidget.cs b/OpenRA.Mods.D2k/Widgets/SlidingContainerWidget.cs index 0f700ac4e1..b559b7e634 100644 --- a/OpenRA.Mods.D2k/Widgets/SlidingContainerWidget.cs +++ b/OpenRA.Mods.D2k/Widgets/SlidingContainerWidget.cs @@ -20,8 +20,8 @@ namespace OpenRA.Mods.D2k.Widgets public int2 ClosedOffset = int2.Zero; public int AnimationLength = 0; public Func IsOpen = () => false; - public Action AfterOpen = () => {}; - public Action AfterClose = () => {}; + public Action AfterOpen = () => { }; + public Action AfterClose = () => { }; int2 offset; int frame; diff --git a/OpenRA.Mods.D2k/Widgets/SupportPowerBinWidget.cs b/OpenRA.Mods.D2k/Widgets/SupportPowerBinWidget.cs index 646d22f8c3..b97ac8d84f 100644 --- a/OpenRA.Mods.D2k/Widgets/SupportPowerBinWidget.cs +++ b/OpenRA.Mods.D2k/Widgets/SupportPowerBinWidget.cs @@ -27,13 +27,14 @@ namespace OpenRA.Mods.D2k.Widgets public int IconWidth = 64; public int IconHeight = 48; - Animation icon; - Animation clock; - readonly List>> buttons = new List>>(); + readonly List>> buttons = new List>>(); readonly World world; readonly WorldRenderer worldRenderer; + Animation icon; + Animation clock; + [ObjectCreator.UseCtor] public SupportPowerBinWidget(World world, WorldRenderer worldRenderer) { @@ -74,7 +75,8 @@ namespace OpenRA.Mods.D2k.Widgets { buttons.Clear(); - if( world.LocalPlayer == null ) return; + if (world.LocalPlayer == null) + return; var manager = world.LocalPlayer.PlayerActor.Trait(); var powers = manager.Powers.Where(p => !p.Value.Disabled); @@ -82,7 +84,7 @@ namespace OpenRA.Mods.D2k.Widgets if (numPowers == 0) return; var rectBounds = RenderBounds; - WidgetUtils.DrawRGBA(WidgetUtils.GetChromeImage(world, "specialbin-top"),new float2(rectBounds.X,rectBounds.Y)); + WidgetUtils.DrawRGBA(WidgetUtils.GetChromeImage(world, "specialbin-top"), new float2(rectBounds.X, rectBounds.Y)); for (var i = 1; i < numPowers; i++) WidgetUtils.DrawRGBA(WidgetUtils.GetChromeImage(world, "specialbin-middle"), new float2(rectBounds.X, rectBounds.Y + i * 51)); WidgetUtils.DrawRGBA(WidgetUtils.GetChromeImage(world, "specialbin-bottom"), new float2(rectBounds.X, rectBounds.Y + numPowers * 51)); @@ -104,17 +106,17 @@ namespace OpenRA.Mods.D2k.Widgets if (rect.Contains(Viewport.LastMousePos)) { var pos = drawPos.ToInt2(); - var tl = new int2(pos.X-3,pos.Y-3); - var m = new int2(pos.X+64+3,pos.Y+48+3); - var br = tl + new int2(64+3+20,40); + var tl = new int2(pos.X - 3, pos.Y - 3); + var m = new int2(pos.X + 64 + 3, pos.Y + 48 + 3); + var br = tl + new int2(64 + 3 + 20, 40); if (sp.TotalTime > 0) - br += new int2(0,20); + br += new int2(0, 20); if (sp.Info.LongDesc != null) br += Game.Renderer.Fonts["Regular"].Measure(sp.Info.LongDesc.Replace("\\n", "\n")); else - br += new int2(300,0); + br += new int2(300, 0); var border = WidgetUtils.GetBorderSizes("dialog4"); @@ -130,9 +132,9 @@ namespace OpenRA.Mods.D2k.Widgets if (sp.TotalTime > 0) { - pos += new int2(0,20); + pos += new int2(0, 20); Game.Renderer.Fonts["Bold"].DrawText(WidgetUtils.FormatTime(sp.RemainingTime), pos, Color.White); - Game.Renderer.Fonts["Bold"].DrawText("/ {0}".F(WidgetUtils.FormatTime(sp.TotalTime)), pos + new int2(45,0), Color.White); + Game.Renderer.Fonts["Bold"].DrawText("/ {0}".F(WidgetUtils.FormatTime(sp.TotalTime)), pos + new int2(45, 0), Color.White); } if (sp.Info.LongDesc != null) @@ -160,7 +162,7 @@ namespace OpenRA.Mods.D2k.Widgets font.DrawTextWithContrast(overlay, overlayPos - new float2(size.X / 2, 0), Color.White, Color.Black, 1); } - buttons.Add(Pair.New(rect,HandleSupportPower(kv.Key, manager))); + buttons.Add(Pair.New(rect, HandleSupportPower(kv.Key, manager))); y += 51; } diff --git a/OpenRA.Mods.TS/Traits/Render/RenderVoxels.cs b/OpenRA.Mods.TS/Traits/Render/RenderVoxels.cs index 3e7593c9d0..62fec30977 100644 --- a/OpenRA.Mods.TS/Traits/Render/RenderVoxels.cs +++ b/OpenRA.Mods.TS/Traits/Render/RenderVoxels.cs @@ -36,8 +36,8 @@ namespace OpenRA.Mods.TS.Traits public readonly WAngle LightPitch = WAngle.FromDegrees(50); public readonly WAngle LightYaw = WAngle.FromDegrees(240); - public readonly float[] LightAmbientColor = new float[] {0.6f, 0.6f, 0.6f}; - public readonly float[] LightDiffuseColor = new float[] {0.4f, 0.4f, 0.4f}; + public readonly float[] LightAmbientColor = new float[] { 0.6f, 0.6f, 0.6f }; + public readonly float[] LightDiffuseColor = new float[] { 0.4f, 0.4f, 0.4f }; public virtual object Create(ActorInitializer init) { return new RenderVoxels(init.self, this); } @@ -59,7 +59,6 @@ namespace OpenRA.Mods.TS.Traits this.LightYaw, this.LightAmbientColor, this.LightDiffuseColor, body.CameraPitch, palette, init.WorldRenderer.Palette(NormalsPalette), init.WorldRenderer.Palette("shadow")); } - } public class RenderVoxels : IRender, INotifyOwnerChanged @@ -77,7 +76,7 @@ namespace OpenRA.Mods.TS.Traits this.info = info; body = self.Trait(); camera = new WRot(WAngle.Zero, body.CameraPitch - new WAngle(256), new WAngle(256)); - lightSource = new WRot(WAngle.Zero,new WAngle(256) - info.LightPitch, info.LightYaw); + lightSource = new WRot(WAngle.Zero, new WAngle(256) - info.LightPitch, info.LightYaw); } bool initializePalettes = true; diff --git a/OpenRA.Mods.TS/Traits/Render/WithVoxelBarrel.cs b/OpenRA.Mods.TS/Traits/Render/WithVoxelBarrel.cs index 3389381e23..91eff71783 100644 --- a/OpenRA.Mods.TS/Traits/Render/WithVoxelBarrel.cs +++ b/OpenRA.Mods.TS/Traits/Render/WithVoxelBarrel.cs @@ -40,7 +40,7 @@ namespace OpenRA.Mods.TS.Traits var turretOrientation = body.QuantizeOrientation(new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(t.InitialFacing) - orientation.Yaw), facings); var turretOffset = body.LocalToWorld(t.Offset.Rotate(orientation)); - yield return new VoxelAnimation(voxel, () => turretOffset, () => new [] { turretOrientation, orientation }, + yield return new VoxelAnimation(voxel, () => turretOffset, () => new[] { turretOrientation, orientation }, () => false, () => 0); } } @@ -76,7 +76,7 @@ namespace OpenRA.Mods.TS.Traits var turretOrientation = turreted != null ? turreted.LocalOrientation(self) : WRot.Zero; var quantizedBody = body.QuantizeOrientation(self, self.Orientation); - var quantizedTurret = body.QuantizeOrientation(self, turretOrientation); + var quantizedTurret = body.QuantizeOrientation(self, turretOrientation); return turretOffset + body.LocalToWorld(localOffset.Rotate(quantizedTurret).Rotate(quantizedBody)); } diff --git a/OpenRA.Mods.TS/Traits/Render/WithVoxelBody.cs b/OpenRA.Mods.TS/Traits/Render/WithVoxelBody.cs index 5f62a7bfed..d80b1e4307 100644 --- a/OpenRA.Mods.TS/Traits/Render/WithVoxelBody.cs +++ b/OpenRA.Mods.TS/Traits/Render/WithVoxelBody.cs @@ -48,12 +48,12 @@ namespace OpenRA.Mods.TS.Traits var voxel = VoxelProvider.GetVoxel(rv.Image, info.Sequence); rv.Add(new VoxelAnimation(voxel, () => WVec.Zero, - () => new[]{ body.QuantizeOrientation(self, self.Orientation) }, + () => new[] { body.QuantizeOrientation(self, self.Orientation) }, () => false, () => 0)); // Selection size var rvi = self.Info.Traits.Get(); - var s = (int)(rvi.Scale*voxel.Size.Aggregate(Math.Max)); + var s = (int)(rvi.Scale * voxel.Size.Aggregate(Math.Max)); size = new int2(s, s); } diff --git a/OpenRA.Mods.TS/Traits/World/VoxelNormalsPalette.cs b/OpenRA.Mods.TS/Traits/World/VoxelNormalsPalette.cs index 0a9ab5a833..26403440dd 100644 --- a/OpenRA.Mods.TS/Traits/World/VoxelNormalsPalette.cs +++ b/OpenRA.Mods.TS/Traits/World/VoxelNormalsPalette.cs @@ -37,7 +37,7 @@ namespace OpenRA.Mods.TS.Traits { // Rotate vectors to expected orientation // Voxel coordinates are x=forward, y=right, z=up - var channel = new int[] {2,1,0}; + var channel = new int[] { 2, 1, 0 }; var n = info.Type == NormalType.RedAlert2 ? RA2Normals : TSNormals; // Map normals into color range @@ -48,8 +48,8 @@ namespace OpenRA.Mods.TS.Traits data[i] = 0xFF000000; for (var j = 0; j < 3; j++) { - var t = (n[3*i + j] + 1) / 2; - data[i] |= (uint)((byte)(t*0xFF + 0.5) << (8*channel[j])); + var t = (n[3 * i + j] + 1) / 2; + data[i] |= (uint)((byte)(t * 0xFF + 0.5) << (8 * channel[j])); } } diff --git a/Settings.StyleCop b/Settings.StyleCop index 822dd88428..94d2d29259 100644 --- a/Settings.StyleCop +++ b/Settings.StyleCop @@ -252,6 +252,11 @@ False + + + False + +