Fix a collection of minor style violations.

This enables several new StyleCopAnalyzer rules to
be enabled immediately during migration.
This commit is contained in:
Paul Chote
2019-05-02 21:35:47 +00:00
committed by reaperrr
parent 76a8ae9f98
commit 353db73381
28 changed files with 58 additions and 49 deletions

View File

@@ -328,7 +328,7 @@ namespace OpenRA.FileSystem
if (!(mod.Package is Folder)) if (!(mod.Package is Folder))
return null; return null;
path = Path.Combine(mod.Package.Name, filename); path = Path.Combine(mod.Package.Name, filename);
} }
else else
path = Path.Combine(parentPath, filename); path = Path.Combine(parentPath, filename);

View File

@@ -83,7 +83,7 @@ namespace OpenRA.Graphics
new float2( new float2(
(int)Math.Round(p.X * deviceScale + g.Offset.X, 0) / deviceScale, (int)Math.Round(p.X * deviceScale + g.Offset.X, 0) / deviceScale,
p.Y + g.Offset.Y / deviceScale), p.Y + g.Offset.Y / deviceScale),
g.Sprite.Size / deviceScale); g.Sprite.Size / deviceScale);
p += new float2(g.Advance / deviceScale, 0); p += new float2(g.Advance / deviceScale, 0);
} }

View File

@@ -169,7 +169,7 @@ namespace OpenRA.Network
var reader = new BinaryReader(networkStream); var reader = new BinaryReader(networkStream);
var serverProtocol = reader.ReadInt32(); var serverProtocol = reader.ReadInt32();
if (ProtocolVersion.Version != serverProtocol) if (serverProtocol != ProtocolVersion.Version)
throw new InvalidOperationException( throw new InvalidOperationException(
"Protocol version mismatch. Server={0} Client={1}" "Protocol version mismatch. Server={0} Client={1}"
.F(serverProtocol, ProtocolVersion.Version)); .F(serverProtocol, ProtocolVersion.Version));

View File

@@ -118,7 +118,7 @@ namespace OpenRA.Network
public string IpAddress; public string IpAddress;
public ClientState State = ClientState.Invalid; public ClientState State = ClientState.Invalid;
public int Team; public int Team;
public string Slot; // Slot ID, or null for observer public string Slot; // Slot ID, or null for observer
public string Bot; // Bot type, null for real clients public string Bot; // Bot type, null for real clients
public int BotControllerClientIndex; // who added the bot to the slot public int BotControllerClientIndex; // who added the bot to the slot
public bool IsAdmin; public bool IsAdmin;
@@ -160,8 +160,8 @@ namespace OpenRA.Network
public class Slot public class Slot
{ {
public string PlayerReference; // PlayerReference to bind against. public string PlayerReference; // PlayerReference to bind against.
public bool Closed; // Host has explicitly closed this slot. public bool Closed; // Host has explicitly closed this slot.
public bool AllowBots; public bool AllowBots;
public bool LockFaction; public bool LockFaction;

View File

@@ -11,6 +11,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Reflection; using System.Reflection;
@@ -18,8 +19,6 @@ using OpenRA.Primitives;
namespace OpenRA.Network namespace OpenRA.Network
{ {
using System.Globalization;
class SyncReport class SyncReport
{ {
const int NumSyncReports = 5; const int NumSyncReports = 5;

View File

@@ -123,18 +123,18 @@ namespace OpenRA.Scripting
public sealed class ScriptContext : IDisposable public sealed class ScriptContext : IDisposable
{ {
public World World { get; private set; }
public WorldRenderer WorldRenderer { get; private set; }
readonly MemoryConstrainedLuaRuntime runtime;
readonly LuaFunction tick;
// Restrict user scripts (excluding system libraries) to 50 MB of memory use // Restrict user scripts (excluding system libraries) to 50 MB of memory use
const int MaxUserScriptMemory = 50 * 1024 * 1024; const int MaxUserScriptMemory = 50 * 1024 * 1024;
// Restrict the number of instructions that will be run per map function call // Restrict the number of instructions that will be run per map function call
const int MaxUserScriptInstructions = 1000000; const int MaxUserScriptInstructions = 1000000;
public World World { get; private set; }
public WorldRenderer WorldRenderer { get; private set; }
readonly MemoryConstrainedLuaRuntime runtime;
readonly LuaFunction tick;
readonly Type[] knownActorCommands; readonly Type[] knownActorCommands;
public readonly Cache<ActorInfo, Type[]> ActorCommands; public readonly Cache<ActorInfo, Type[]> ActorCommands;
public readonly Type[] PlayerCommands; public readonly Type[] PlayerCommands;

View File

@@ -82,7 +82,7 @@ namespace OpenRA
{ {
if (isClick) if (isClick)
{ {
var adjNewSelection = newSelection.Take(1); /* TODO: select BEST, not FIRST */ var adjNewSelection = newSelection.Take(1); // TODO: select BEST, not FIRST
if (isCombine) if (isCombine)
actors.SymmetricExceptWith(adjNewSelection); actors.SymmetricExceptWith(adjNewSelection);
else else
@@ -163,7 +163,7 @@ namespace OpenRA
if (!mods.HasModifier(Modifiers.Shift)) if (!mods.HasModifier(Modifiers.Shift))
controlGroups[group].Clear(); controlGroups[group].Clear();
for (var i = 0; i < 10; i++) /* all control groups */ for (var i = 0; i < 10; i++) // all control groups
controlGroups[i].RemoveAll(a => actors.Contains(a)); controlGroups[i].RemoveAll(a => actors.Contains(a));
controlGroups[group].AddRange(actors.Where(a => a.Owner == world.LocalPlayer)); controlGroups[group].AddRange(actors.Where(a => a.Owner == world.LocalPlayer));

View File

@@ -102,7 +102,9 @@ namespace OpenRA.Server
Log.Write("server", "Dropping client {0} for excessive order length = {1}", PlayerIndex, ExpectLength); Log.Write("server", "Dropping client {0} for excessive order length = {1}", PlayerIndex, ExpectLength);
return; return;
} }
} break;
break;
}
case ReceiveState.Data: case ReceiveState.Data:
{ {
@@ -112,7 +114,9 @@ namespace OpenRA.Server
server.DispatchOrders(this, Frame, bytes); server.DispatchOrders(this, Frame, bytes);
ExpectLength = 8; ExpectLength = 8;
State = ReceiveState.Header; State = ReceiveState.Header;
} break;
break;
}
} }
} }
} }

View File

@@ -70,6 +70,7 @@ namespace OpenRA
var lsq = x * x + y * y + z * z + w * w; var lsq = x * x + y * y + z * z + w * w;
// Quaternion components use 10 bits, so there's no risk of overflow // Quaternion components use 10 bits, so there's no risk of overflow
#pragma warning disable SA1115 // Allow blank lines to visually separate matrix rows
mtx = new Int32Matrix4x4( mtx = new Int32Matrix4x4(
lsq - 2 * (y * y + z * z), lsq - 2 * (y * y + z * z),
2 * (x * y + z * w), 2 * (x * y + z * w),
@@ -90,6 +91,7 @@ namespace OpenRA
0, 0,
0, 0,
lsq); lsq);
#pragma warning restore SA1115
} }
public Int32Matrix4x4 AsMatrix() public Int32Matrix4x4 AsMatrix()

View File

@@ -230,10 +230,10 @@ namespace OpenRA.Mods.Cnc.FileFormats
InitBigNum(nTmp, 0, len); InitBigNum(nTmp, 0, len);
InitBigNum(n1, 0, len); InitBigNum(n1, 0, len);
nTwoBitLen = (int)BitLenBigNum(n2, len); nTwoBitLen = (int)BitLenBigNum(n2, len);
bit = ((uint)1) << (nTwoBitLen % 32); bit = 1U << (nTwoBitLen % 32);
j = ((nTwoBitLen + 32) / 32) - 1; j = ((nTwoBitLen + 32) / 32) - 1;
nTwoByteLen = (uint)((nTwoBitLen - 1) / 32) * 4; nTwoByteLen = (uint)((nTwoBitLen - 1) / 32) * 4;
nTmp[nTwoByteLen / 4] |= ((uint)1) << ((nTwoBitLen - 1) & 0x1f); nTmp[nTwoByteLen / 4] |= 1U << ((nTwoBitLen - 1) & 0x1f);
while (nTwoBitLen > 0) while (nTwoBitLen > 0)
{ {
@@ -431,7 +431,7 @@ namespace OpenRA.Mods.Cnc.FileFormats
InitTwoDw(n4, n4_len); InitTwoDw(n4, n4_len);
n3_bitlen = (int)BitLenBigNum(n3, n4_len); n3_bitlen = (int)BitLenBigNum(n3, n4_len);
n3_len = (uint)((n3_bitlen + 31) / 32); n3_len = (uint)((n3_bitlen + 31) / 32);
bit_mask = (((uint)1) << ((n3_bitlen - 1) % 32)) >> 1; bit_mask = (1U << ((n3_bitlen - 1) % 32)) >> 1;
pn3 += n3_len - 1; pn3 += n3_len - 1;
n3_bitlen--; n3_bitlen--;
MoveBigNum(n1, n2, n4_len); MoveBigNum(n1, n2, n4_len);

View File

@@ -210,7 +210,8 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
{ {
// "tib" - Regular Tiberium // "tib" - Regular Tiberium
{ 0x01, new byte[] { 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, { 0x01, new byte[] { 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79 } }, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79 }
},
// "btib" - Blue Tiberium // "btib" - Blue Tiberium
{ 0x02, new byte[] { 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, { 0x02, new byte[] { 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26,
@@ -221,7 +222,8 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
// Should be "tib3" // Should be "tib3"
0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C,
0x9D, 0x9E, 0x9F, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6 } }, 0x9D, 0x9E, 0x9F, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6 }
},
// Veins // Veins
{ 0x03, new byte[] { 0x7E } } { 0x03, new byte[] { 0x7E } }

View File

@@ -248,7 +248,7 @@ namespace OpenRA.Mods.Common.FileFormats
{ {
*op++ = *ip++; *op++ = *ip++;
if (t > 2) if (t > 2)
*op++ = *ip++; (*op++) = *ip++;
} }
t = *ip++; t = *ip++;

View File

@@ -63,7 +63,8 @@ namespace OpenRA.Mods.Common.LoadScreens
var widgetArgs = new WidgetArgs var widgetArgs = new WidgetArgs
{ {
{ "continueLoading", () => { "continueLoading", () =>
Game.RunAfterTick(() => Game.InitializeMod(modId, new Arguments())) }, Game.RunAfterTick(() => Game.InitializeMod(modId, new Arguments()))
},
{ "mod", selectedMod }, { "mod", selectedMod },
{ "content", content }, { "content", content },
}; };
@@ -77,7 +78,8 @@ namespace OpenRA.Mods.Common.LoadScreens
{ "mod", selectedMod }, { "mod", selectedMod },
{ "content", content }, { "content", content },
{ "onCancel", () => { "onCancel", () =>
Game.RunAfterTick(() => Game.InitializeMod(modId, new Arguments())) } Game.RunAfterTick(() => Game.InitializeMod(modId, new Arguments()))
}
}; };
Ui.OpenWindow("CONTENT_PANEL", widgetArgs); Ui.OpenWindow("CONTENT_PANEL", widgetArgs);

View File

@@ -441,7 +441,7 @@ namespace OpenRA.Mods.Common.Projectiles
} }
// NOTE: It might be desirable to make lookahead more intelligent by outputting more information // NOTE: It might be desirable to make lookahead more intelligent by outputting more information
// than just the highest point in the lookahead distance // than just the highest point in the lookahead distance
void InclineLookahead(World world, int distCheck, out int predClfHgt, out int predClfDist, out int lastHtChg, out int lastHt) void InclineLookahead(World world, int distCheck, out int predClfHgt, out int predClfDist, out int lastHtChg, out int lastHt)
{ {
predClfHgt = 0; // Highest probed terrain height predClfHgt = 0; // Highest probed terrain height

View File

@@ -217,7 +217,7 @@ namespace OpenRA.Mods.Common.SpriteLoaders
bw.Write((ushort)0); bw.Write((ushort)0);
bw.Write((ushort)size.Width); bw.Write((ushort)size.Width);
bw.Write((ushort)size.Height); bw.Write((ushort)size.Height);
bw.Write((uint)0); bw.Write(0U);
foreach (var f in compressedFrames) foreach (var f in compressedFrames)
{ {

View File

@@ -157,7 +157,7 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads
// Checks the number of anti air enemies around units // Checks the number of anti air enemies around units
protected virtual bool ShouldFlee(Squad owner) protected virtual bool ShouldFlee(Squad owner)
{ {
return base.ShouldFlee(owner, enemies => CountAntiAirUnits(enemies) * MissileUnitMultiplier > owner.Units.Count); return ShouldFlee(owner, enemies => CountAntiAirUnits(enemies) * MissileUnitMultiplier > owner.Units.Count);
} }
} }

View File

@@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads
{ {
protected virtual bool ShouldFlee(Squad owner) protected virtual bool ShouldFlee(Squad owner)
{ {
return base.ShouldFlee(owner, enemies => !AttackOrFleeFuzzy.Default.CanAttack(owner.Units, enemies)); return ShouldFlee(owner, enemies => !AttackOrFleeFuzzy.Default.CanAttack(owner.Units, enemies));
} }
protected Actor FindClosestEnemy(Squad owner) protected Actor FindClosestEnemy(Squad owner)

View File

@@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads
{ {
protected virtual bool ShouldFlee(Squad owner) protected virtual bool ShouldFlee(Squad owner)
{ {
return base.ShouldFlee(owner, enemies => !AttackOrFleeFuzzy.Default.CanAttack(owner.Units, enemies)); return ShouldFlee(owner, enemies => !AttackOrFleeFuzzy.Default.CanAttack(owner.Units, enemies));
} }
protected Actor FindClosestEnemy(Squad owner) protected Actor FindClosestEnemy(Squad owner)

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly string Owner = "Creeps"; public readonly string Owner = "Creeps";
[Desc("Type of ActorSpawner with which it connects.")] [Desc("Type of ActorSpawner with which it connects.")]
public readonly HashSet<string> Types = new HashSet<string>() { }; public readonly HashSet<string> Types = new HashSet<string>() { };
public override object Create(ActorInitializer init) { return new ActorSpawnManager(init.Self, this); } public override object Create(ActorInitializer init) { return new ActorSpawnManager(init.Self, this); }
} }

View File

@@ -132,7 +132,7 @@ namespace OpenRA.Mods.Common.Traits
var n = taken.Count == 0 || !separateTeamSpawns var n = taken.Count == 0 || !separateTeamSpawns
? world.SharedRandom.Next(available.Count) ? world.SharedRandom.Next(available.Count)
: available // pick the most distant spawnpoint from everyone else : available // pick the most distant spawnpoint from everyone else
.Select((k, i) => Pair.New(k, i)) .Select((k, i) => Pair.New(k, i))
.MaxBy(a => taken.Sum(t => (t - a.First).LengthSquared)).Second; .MaxBy(a => taken.Sum(t => (t - a.First).LengthSquared)).Second;

View File

@@ -134,7 +134,7 @@ namespace OpenRA.Mods.Common.Widgets
var c = (int*)cc; var c = (int*)cc;
for (var v = 0; v < 256; v++) for (var v = 0; v < 256; v++)
for (var s = 0; s < 256; s++) for (var s = 0; s < 256; s++)
*(c + (v * 256) + s) = Color.FromAhsv(hue, s / 255f, (255 - v) / 255f).ToArgb(); (*(c + (v * 256) + s)) = Color.FromAhsv(hue, s / 255f, (255 - v) / 255f).ToArgb();
} }
} }

View File

@@ -19,10 +19,8 @@ namespace OpenRA.Mods.Common.Widgets
public double ExpA = 1.0e-3; public double ExpA = 1.0e-3;
public double ExpB = 6.908; public double ExpB = 6.908;
public ExponentialSliderWidget() : public ExponentialSliderWidget(ExponentialSliderWidget other)
base() { } : base(other) { }
public ExponentialSliderWidget(ExponentialSliderWidget other) :
base(other) { }
float ExpFromLinear(float x) float ExpFromLinear(float x)
{ {

View File

@@ -136,7 +136,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (!isObserver && orderManager.LocalClient == null && world.LocalPlayer == null) if (!isObserver && orderManager.LocalClient == null && world.LocalPlayer == null)
return true; return true;
var teamNumber = (uint)0; var teamNumber = 0U;
if (team) if (team)
teamNumber = (isObserver || world.LocalPlayer.WinState != WinState.Undefined) ? uint.MaxValue : (uint)orderManager.LocalClient.Team; teamNumber = (isObserver || world.LocalPlayer.WinState != WinState.Undefined) ? uint.MaxValue : (uint)orderManager.LocalClient.Team;

View File

@@ -128,7 +128,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ "orderManager", orderManager }, { "orderManager", orderManager },
{ "getMap", (Func<MapPreview>)(() => map) }, { "getMap", (Func<MapPreview>)(() => map) },
{ "onMouseDown", (Action<MapPreviewWidget, MapPreview, MouseInput>)((preview, mapPreview, mi) => { "onMouseDown", (Action<MapPreviewWidget, MapPreview, MouseInput>)((preview, mapPreview, mi) =>
LobbyUtils.SelectSpawnPoint(orderManager, preview, mapPreview, mi)) }, LobbyUtils.SelectSpawnPoint(orderManager, preview, mapPreview, mi))
},
{ "getSpawnOccupants", (Func<MapPreview, Dictionary<CPos, SpawnOccupant>>)(mapPreview => LobbyUtils.GetSpawnOccupants(orderManager.LobbyInfo, mapPreview)) }, { "getSpawnOccupants", (Func<MapPreview, Dictionary<CPos, SpawnOccupant>>)(mapPreview => LobbyUtils.GetSpawnOccupants(orderManager.LobbyInfo, mapPreview)) },
{ "showUnoccupiedSpawnpoints", true }, { "showUnoccupiedSpawnpoints", true },
}); });
@@ -402,7 +403,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
// Always scroll to bottom when we've typed something // Always scroll to bottom when we've typed something
lobbyChatPanel.ScrollToBottom(); lobbyChatPanel.ScrollToBottom();
var teamNumber = (uint)0; var teamNumber = 0U;
if (teamChat && orderManager.LocalClient != null) if (teamChat && orderManager.LocalClient != null)
teamNumber = orderManager.LocalClient.IsObserver ? uint.MaxValue : (uint)orderManager.LocalClient.Team; teamNumber = orderManager.LocalClient.IsObserver ? uint.MaxValue : (uint)orderManager.LocalClient.Team;

View File

@@ -82,7 +82,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ "getMap", (Func<MapPreview>)(() => map) }, { "getMap", (Func<MapPreview>)(() => map) },
{ "onMouseDown", (Action<MapPreviewWidget, MapPreview, MouseInput>)((preview, mapPreview, mi) => { }) }, { "onMouseDown", (Action<MapPreviewWidget, MapPreview, MouseInput>)((preview, mapPreview, mi) => { }) },
{ "getSpawnOccupants", (Func<MapPreview, Dictionary<CPos, SpawnOccupant>>)(mapPreview => { "getSpawnOccupants", (Func<MapPreview, Dictionary<CPos, SpawnOccupant>>)(mapPreview =>
LobbyUtils.GetSpawnOccupants(selectedReplay.GameInfo.Players, mapPreview)) }, LobbyUtils.GetSpawnOccupants(selectedReplay.GameInfo.Players, mapPreview))
},
{ "showUnoccupiedSpawnpoints", false }, { "showUnoccupiedSpawnpoints", false },
}); });

View File

@@ -70,11 +70,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
current.Save(); current.Save();
Action closeAndExit = () => { Ui.CloseWindow(); onExit(); }; Action closeAndExit = () => { Ui.CloseWindow(); onExit(); };
if (OriginalSoundDevice != current.Sound.Device || if (current.Sound.Device != OriginalSoundDevice ||
OriginalGraphicsMode != current.Graphics.Mode || current.Graphics.Mode != OriginalGraphicsMode ||
OriginalGraphicsWindowedSize != current.Graphics.WindowedSize || current.Graphics.WindowedSize != OriginalGraphicsWindowedSize ||
OriginalGraphicsFullscreenSize != current.Graphics.FullscreenSize || current.Graphics.FullscreenSize != OriginalGraphicsFullscreenSize ||
OriginalServerDiscoverNatDevices != current.Server.DiscoverNatDevices) current.Server.DiscoverNatDevices != OriginalServerDiscoverNatDevices)
{ {
Action restart = () => Action restart = () =>
{ {

View File

@@ -87,7 +87,7 @@ namespace OpenRA.Mods.Common.Widgets
var scaledHeight = (int)videoSize.Y; var scaledHeight = (int)videoSize.Y;
overlay = new uint[Exts.NextPowerOf2(scaledHeight), 1]; overlay = new uint[Exts.NextPowerOf2(scaledHeight), 1];
var black = (uint)255 << 24; var black = 255U << 24;
for (var y = 0; y < scaledHeight; y += 2) for (var y = 0; y < scaledHeight; y += 2)
overlay[y, 0] = black; overlay[y, 0] = black;