Remove some misc redundancies

This commit is contained in:
ScottNZ
2013-11-12 17:40:34 +13:00
parent 8197f29606
commit 1394c1dcee
48 changed files with 104 additions and 103 deletions

View File

@@ -79,7 +79,7 @@ namespace OpenRA.Editor
} }
catch (Exception ed) catch (Exception ed)
{ {
Console.WriteLine("No map preview image found: {0}", ed.ToString()); Console.WriteLine("No map preview image found: {0}", ed);
} }
} }
} }

View File

@@ -314,7 +314,7 @@ namespace OpenRA.FileFormats
return null; return null;
} }
static object ParseYesNo(string p, System.Type fieldType, string field) static object ParseYesNo(string p, Type fieldType, string field)
{ {
p = p.ToLowerInvariant(); p = p.ToLowerInvariant();
if (p == "yes") return true; if (p == "yes") return true;

View File

@@ -48,7 +48,7 @@ namespace OpenRA.FileFormats
public static MiniYamlNode SaveField(object o, string field) public static MiniYamlNode SaveField(object o, string field)
{ {
return new MiniYamlNode(field, FieldSaver.FormatValue(o, o.GetType().GetField(field))); return new MiniYamlNode(field, FormatValue(o, o.GetType().GetField(field)));
} }
public static string FormatValue(object v, Type t) public static string FormatValue(object v, Type t)

View File

@@ -92,7 +92,7 @@ namespace OpenRA.FileFormats
/// A fast (native) CRC32 implementation that can be used on a regular byte arrays. /// A fast (native) CRC32 implementation that can be used on a regular byte arrays.
/// </summary> /// </summary>
/// <param name="data">The data from which to calculate the checksum.</param> /// <param name="data">The data from which to calculate the checksum.</param>
/// <param name="polynomal">The polynomal.</param> /// <param name="polynomial">The polynomal.</param>
/// <returns> /// <returns>
/// The calculated checksum. /// The calculated checksum.
/// </returns> /// </returns>
@@ -115,7 +115,7 @@ namespace OpenRA.FileFormats
/// </summary> /// </summary>
/// <param name="data"> [in,out] If non-null, the.</param> /// <param name="data"> [in,out] If non-null, the.</param>
/// <param name="len"> The length of the data data.</param> /// <param name="len"> The length of the data data.</param>
/// <param name="polynomal">The polynomal to xor with.</param> /// <param name="polynomial">The polynomal to xor with.</param>
/// <returns>The calculated checksum.</returns> /// <returns>The calculated checksum.</returns>
public static unsafe uint Calculate(byte* data, uint len, uint polynomial) public static unsafe uint Calculate(byte* data, uint len, uint polynomial)
{ {

View File

@@ -56,7 +56,7 @@ namespace OpenRA.FileFormats
IniSection ProcessSection(string line) IniSection ProcessSection(string line)
{ {
Match m = sectionPattern.Match(line); Match m = sectionPattern.Match(line);
if (m == null || !m.Success) if (!m.Success)
return null; return null;
string sectionName = m.Groups[1].Value.ToLowerInvariant(); string sectionName = m.Groups[1].Value.ToLowerInvariant();

View File

@@ -97,7 +97,7 @@ namespace OpenRA.FileFormats
name = Platform.SupportDir + name.Substring(1); name = Platform.SupportDir + name.Substring(1);
FolderPaths.Add(name); FolderPaths.Add(name);
Action a = () => FileSystem.MountInner(OpenPackage(name, annotation, order++)); Action a = () => MountInner(OpenPackage(name, annotation, order++));
if (optional) if (optional)
try { a(); } try { a(); }
@@ -197,8 +197,8 @@ namespace OpenRA.FileFormats
if (assemblyCache.TryGetValue(filename, out a)) if (assemblyCache.TryGetValue(filename, out a))
return a; return a;
if (FileSystem.Exists(filename)) if (Exists(filename))
using (var s = FileSystem.Open(filename)) using (var s = Open(filename))
{ {
var buf = new byte[s.Length]; var buf = new byte[s.Length];
s.Read(buf, 0, buf.Length); s.Read(buf, 0, buf.Length);

View File

@@ -53,7 +53,7 @@ namespace OpenRA.FileFormats.Primitives
public IEnumerable ObservedItems public IEnumerable ObservedItems
{ {
get { return base.Items; } get { return Items; }
} }
} }
} }

View File

@@ -103,7 +103,7 @@ namespace OpenRA
// Load a widget with world, orderManager, worldRenderer args, without adding it to the widget tree // Load a widget with world, orderManager, worldRenderer args, without adding it to the widget tree
public static Widget LoadWidget(World world, string id, Widget parent, WidgetArgs args) public static Widget LoadWidget(World world, string id, Widget parent, WidgetArgs args)
{ {
return Game.modData.WidgetLoader.LoadWidget(new WidgetArgs(args) return modData.WidgetLoader.LoadWidget(new WidgetArgs(args)
{ {
{ "world", world }, { "world", world },
{ "orderManager", orderManager }, { "orderManager", orderManager },
@@ -135,23 +135,23 @@ namespace OpenRA
// worldRenderer is null during the initial install/download screen // worldRenderer is null during the initial install/download screen
if (worldRenderer != null) if (worldRenderer != null)
{ {
Game.Renderer.BeginFrame(worldRenderer.Viewport.TopLeft.ToFloat2(), worldRenderer.Viewport.Zoom); Renderer.BeginFrame(worldRenderer.Viewport.TopLeft.ToFloat2(), worldRenderer.Viewport.Zoom);
Sound.SetListenerPosition(worldRenderer.Position(worldRenderer.Viewport.CenterLocation)); Sound.SetListenerPosition(worldRenderer.Position(worldRenderer.Viewport.CenterLocation));
worldRenderer.Draw(); worldRenderer.Draw();
} }
else else
Game.Renderer.BeginFrame(float2.Zero, 1f); Renderer.BeginFrame(float2.Zero, 1f);
using (new PerfSample("render_widgets")) using (new PerfSample("render_widgets"))
{ {
Ui.Draw(); Ui.Draw();
var cursorName = Ui.Root.GetCursorOuter(Viewport.LastMousePos) ?? "default"; var cursorName = Ui.Root.GetCursorOuter(Viewport.LastMousePos) ?? "default";
CursorProvider.DrawCursor(Game.Renderer, cursorName, Viewport.LastMousePos, (int)cursorFrame); CursorProvider.DrawCursor(Renderer, cursorName, Viewport.LastMousePos, (int)cursorFrame);
} }
using (new PerfSample("render_flip")) using (new PerfSample("render_flip"))
{ {
Game.Renderer.EndFrame(new DefaultInputHandler(orderManager.world)); Renderer.EndFrame(new DefaultInputHandler(orderManager.world));
} }
} }
@@ -374,13 +374,13 @@ namespace OpenRA
JoinLocal(); JoinLocal();
if (Game.Settings.Server.Dedicated) if (Settings.Server.Dedicated)
{ {
while (true) while (true)
{ {
Game.Settings.Server.Map = WidgetUtils.ChooseInitialMap(Game.Settings.Server.Map); Settings.Server.Map = WidgetUtils.ChooseInitialMap(Settings.Server.Map);
Game.Settings.Save(); Settings.Save();
Game.CreateServer(new ServerSettings(Game.Settings.Server)); CreateServer(new ServerSettings(Settings.Server));
while (true) while (true)
{ {
System.Threading.Thread.Sleep(100); System.Threading.Thread.Sleep(100);
@@ -393,15 +393,14 @@ namespace OpenRA
break; break;
} }
} }
if (Game.Settings.Server.DedicatedLoop) if (Settings.Server.DedicatedLoop)
{ {
Console.WriteLine("Starting a new server instance..."); Console.WriteLine("Starting a new server instance...");
continue; continue;
} }
else break;
break;
} }
System.Environment.Exit(0); Environment.Exit(0);
} }
else else
{ {
@@ -420,7 +419,7 @@ namespace OpenRA
var shellmaps = modData.AvailableMaps var shellmaps = modData.AvailableMaps
.Where(m => m.Value.UseAsShellmap); .Where(m => m.Value.UseAsShellmap);
if (shellmaps.Count() == 0) if (!shellmaps.Any())
throw new InvalidDataException("No valid shellmaps available"); throw new InvalidDataException("No valid shellmaps available");
return shellmaps.Random(CosmeticRandom).Key; return shellmaps.Random(CosmeticRandom).Key;
@@ -482,7 +481,7 @@ namespace OpenRA
public static void CreateServer(ServerSettings settings) public static void CreateServer(ServerSettings settings)
{ {
server = new Server.Server(new IPEndPoint(IPAddress.Any, settings.ListenPort), server = new Server.Server(new IPEndPoint(IPAddress.Any, settings.ListenPort),
Game.Settings.Game.Mods, settings, modData); Settings.Game.Mods, settings, modData);
} }
public static int CreateLocalServer(string map) public static int CreateLocalServer(string map)
@@ -496,7 +495,7 @@ namespace OpenRA
}; };
server = new Server.Server(new IPEndPoint(IPAddress.Loopback, 0), server = new Server.Server(new IPEndPoint(IPAddress.Loopback, 0),
Game.Settings.Game.Mods, settings, modData); Settings.Game.Mods, settings, modData);
return server.Port; return server.Port;
} }
@@ -510,7 +509,7 @@ namespace OpenRA
{ {
try try
{ {
var mod = Game.CurrentMods.FirstOrDefault().Value.Id; var mod = CurrentMods.First().Value.Id;
var dirPath = "{1}maps{0}{2}".F(Path.DirectorySeparatorChar, Platform.SupportDir, mod); var dirPath = "{1}maps{0}{2}".F(Path.DirectorySeparatorChar, Platform.SupportDir, mod);
if(!Directory.Exists(dirPath)) if(!Directory.Exists(dirPath))
Directory.CreateDirectory(dirPath); Directory.CreateDirectory(dirPath);

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Graphics
public static Sheet AllocateSheet() public static Sheet AllocateSheet()
{ {
return new Sheet(new Size(Renderer.SheetSize, Renderer.SheetSize));; return new Sheet(new Size(Renderer.SheetSize, Renderer.SheetSize));
} }
internal SheetBuilder(SheetType t) internal SheetBuilder(SheetType t)

View File

@@ -258,7 +258,7 @@ namespace OpenRA.Graphics
for (var i = 0; i < 8; i++) 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[ix[i]], bounds[iy[i]], bounds[iz[i]], 1};
var tvec = Util.MatrixVectorMultiply(mtx, vec); var tvec = MatrixVectorMultiply(mtx, vec);
ret[0] = Math.Min(ret[0], tvec[0]/tvec[3]); ret[0] = Math.Min(ret[0], tvec[0]/tvec[3]);
ret[1] = Math.Min(ret[1], tvec[1]/tvec[3]); ret[1] = Math.Min(ret[1], tvec[1]/tvec[3]);

View File

@@ -162,7 +162,7 @@ namespace OpenRA
catch (Exception e) catch (Exception e)
{ {
Console.WriteLine("Failed to load map: {0}", path); Console.WriteLine("Failed to load map: {0}", path);
Console.WriteLine("Details: {0}", e.ToString()); Console.WriteLine("Details: {0}", e);
} }
} }

View File

@@ -42,11 +42,11 @@ namespace OpenRA.Network
break; break;
case "Client": case "Client":
session.Clients.Add(FieldLoader.Load<Session.Client>(y.Value)); session.Clients.Add(FieldLoader.Load<Client>(y.Value));
break; break;
case "Slot": case "Slot":
var s = FieldLoader.Load<Session.Slot>(y.Value); var s = FieldLoader.Load<Slot>(y.Value);
session.Slots.Add(s.PlayerReference, s); session.Slots.Add(s.PlayerReference, s);
break; break;
} }
@@ -143,7 +143,7 @@ namespace OpenRA.Network
public Session(string[] mods) public Session(string[] mods)
{ {
this.GlobalSettings.Mods = mods.ToArray(); this.GlobalSettings.Mods = mods.ToArray();
this.GlobalSettings.GameUid = System.Guid.NewGuid().ToString(); this.GlobalSettings.GameUid = Guid.NewGuid().ToString();
} }
public string Serialize() public string Serialize()

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Network
{ {
this.orderManager = orderManager; this.orderManager = orderManager;
for (var i = 0; i < NumSyncReports; i++) for (var i = 0; i < NumSyncReports; i++)
syncReports[i] = new SyncReport.Report(); syncReports[i] = new Report();
} }
internal void UpdateSyncReport() internal void UpdateSyncReport()

View File

@@ -9,10 +9,12 @@
#endregion #endregion
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets; using System.Net.Sockets;
using System.Threading; using System.Threading;
@@ -338,7 +340,7 @@ namespace OpenRA.Server
if (File.Exists("{0}motd_{1}.txt".F(Platform.SupportDir, LobbyInfo.GlobalSettings.Mods[0]))) if (File.Exists("{0}motd_{1}.txt".F(Platform.SupportDir, LobbyInfo.GlobalSettings.Mods[0])))
{ {
var motd = System.IO.File.ReadAllText("{0}motd_{1}.txt".F(Platform.SupportDir, LobbyInfo.GlobalSettings.Mods[0])); var motd = File.ReadAllText("{0}motd_{1}.txt".F(Platform.SupportDir, LobbyInfo.GlobalSettings.Mods[0]));
SendOrderTo(newConn, "Message", motd); SendOrderTo(newConn, "Message", motd);
} }

View File

@@ -604,8 +604,8 @@ namespace OpenRA
int state; int state;
Al.alGetSourcei(b, Al.AL_SOURCE_STATE, out state); Al.alGetSourcei(b, Al.AL_SOURCE_STATE, out state);
return ((state == Al.AL_PLAYING || state == Al.AL_PAUSED) && return ((state == Al.AL_PLAYING || state == Al.AL_PAUSED) &&
((music != null) ? b != ((OpenAlSound)music).source : true) && ((music == null) || b != ((OpenAlSound)music).source) &&
((video != null) ? b != ((OpenAlSound)video).source : true)); ((video == null) || b != ((OpenAlSound)video).source));
}).ToList(); }).ToList();
foreach (var s in sounds) foreach (var s in sounds)
{ {

View File

@@ -21,11 +21,11 @@ namespace OpenRA
public Arguments(params string[] src) public Arguments(params string[] src)
{ {
Regex regex = new Regex("([^=]+)=(.*)"); var regex = new Regex("([^=]+)=(.*)");
foreach (string s in src) foreach (var s in src)
{ {
Match m = regex.Match(s); Match m = regex.Match(s);
if (m == null || !m.Success) if (!m.Success)
continue; continue;
args[m.Groups[1].Value] = m.Groups[2].Value; args[m.Groups[1].Value] = m.Groups[2].Value;

View File

@@ -64,7 +64,7 @@ namespace OpenRA.Traits
return; return;
var pipSources = self.TraitsImplementing<IPips>(); var pipSources = self.TraitsImplementing<IPips>();
if (pipSources.Count() == 0) if (!pipSources.Any())
return; return;
var pipImages = new Animation("pips"); var pipImages = new Animation("pips");

View File

@@ -32,14 +32,14 @@ namespace OpenRA.Traits
public static Target FromOrder(Order o) public static Target FromOrder(Order o)
{ {
return o.TargetActor != null return o.TargetActor != null
? Target.FromActor(o.TargetActor) ? FromActor(o.TargetActor)
: Target.FromCell(o.TargetLocation); : FromCell(o.TargetLocation);
} }
public static Target FromActor(Actor a) public static Target FromActor(Actor a)
{ {
if (a == null) if (a == null)
return Target.Invalid; return Invalid;
return new Target return new Target
{ {

View File

@@ -134,7 +134,7 @@ namespace OpenRA.Traits
public static IEnumerable<CPos> AdjacentCells(Target target) public static IEnumerable<CPos> AdjacentCells(Target target)
{ {
var cells = target.Positions.Select(p => p.ToCPos()).Distinct(); var cells = target.Positions.Select(p => p.ToCPos()).Distinct();
return Util.ExpandFootprint(cells, true); return ExpandFootprint(cells, true);
} }
} }
} }

View File

@@ -185,7 +185,7 @@ namespace OpenRA.Widgets
public virtual void DrawBackground(Rectangle rect, bool disabled, bool pressed, bool hover, bool highlighted) public virtual void DrawBackground(Rectangle rect, bool disabled, bool pressed, bool hover, bool highlighted)
{ {
ButtonWidget.DrawBackground("button", rect, disabled, pressed, hover, highlighted); DrawBackground("button", rect, disabled, pressed, hover, highlighted);
} }
public static void DrawBackground(string baseName, Rectangle rect, bool disabled, bool pressed, bool hover, bool highlighted) public static void DrawBackground(string baseName, Rectangle rect, bool disabled, bool pressed, bool hover, bool highlighted)

View File

@@ -57,8 +57,8 @@ namespace OpenRA.Widgets
var useClassicMouseStyle = Game.Settings.Game.UseClassicMouseStyle; var useClassicMouseStyle = Game.Settings.Game.UseClassicMouseStyle;
var hasBox = (SelectionBox != null) ? true : false; var hasBox = SelectionBox != null;
var multiClick = (mi.MultiTapCount >= 2) ? true : false; var multiClick = mi.MultiTapCount >= 2;
if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Down) if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Down)
{ {
@@ -68,7 +68,7 @@ namespace OpenRA.Widgets
dragStart = dragEnd = xy; dragStart = dragEnd = xy;
// place buildings // place buildings
if (!useClassicMouseStyle || (useClassicMouseStyle && !World.Selection.Actors.Any())) if (!useClassicMouseStyle || !World.Selection.Actors.Any())
ApplyOrders(World, xy, mi); ApplyOrders(World, xy, mi);
} }

View File

@@ -91,7 +91,7 @@ namespace OpenRA
public static string GetTerrainType(this World world, CPos cell) public static string GetTerrainType(this World world, CPos cell)
{ {
var custom = world.Map.CustomTerrain[cell.X, cell.Y]; var custom = world.Map.CustomTerrain[cell.X, cell.Y];
return custom != null ? custom : world.TileSet.GetTerrainType(world.Map.MapTiles.Value[cell.X, cell.Y]); return custom ?? world.TileSet.GetTerrainType(world.Map.MapTiles.Value[cell.X, cell.Y]);
} }
public static TerrainTypeInfo GetTerrainInfo(this World world, CPos cell) public static TerrainTypeInfo GetTerrainInfo(this World world, CPos cell)

View File

@@ -12,6 +12,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.FileFormats; using OpenRA.FileFormats;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Air; using OpenRA.Mods.RA.Air;
using OpenRA.Mods.RA.Buildings; using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Move; using OpenRA.Mods.RA.Move;
@@ -181,15 +182,13 @@ namespace OpenRA.Mods.RA.AI
int CountBuilding(string frac, Player owner) int CountBuilding(string frac, Player owner)
{ {
return world.ActorsWithTrait<Building>() return world.ActorsWithTrait<Building>()
.Where(a => a.Actor.Owner == owner && a.Actor.Info.Name == frac) .Count(a => a.Actor.Owner == owner && a.Actor.Info.Name == frac);
.Count();
} }
int CountUnits(string unit, Player owner) int CountUnits(string unit, Player owner)
{ {
return world.ActorsWithTrait<IPositionable>() return world.ActorsWithTrait<IPositionable>()
.Where(a => a.Actor.Owner == owner && a.Actor.Info.Name == unit) .Count(a => a.Actor.Owner == owner && a.Actor.Info.Name == unit);
.Count();
} }
int? CountBuildingByCommonName(string commonName, Player owner) int? CountBuildingByCommonName(string commonName, Player owner)
@@ -198,8 +197,7 @@ namespace OpenRA.Mods.RA.AI
return null; return null;
return world.ActorsWithTrait<Building>() return world.ActorsWithTrait<Building>()
.Where(a => a.Actor.Owner == owner && Info.BuildingCommonNames[commonName].Contains(a.Actor.Info.Name)) .Count(a => a.Actor.Owner == owner && Info.BuildingCommonNames[commonName].Contains(a.Actor.Info.Name));
.Count();
} }
ActorInfo GetBuildingInfoByCommonName(string commonName, Player owner) ActorInfo GetBuildingInfoByCommonName(string commonName, Player owner)
@@ -553,8 +551,8 @@ namespace OpenRA.Mods.RA.AI
var act = a.GetCurrentActivity(); var act = a.GetCurrentActivity();
// A Wait activity is technically idle: // A Wait activity is technically idle:
if ((act.GetType() != typeof(OpenRA.Mods.RA.Activities.Wait)) && if ((act.GetType() != typeof(Wait)) &&
(act.NextActivity == null || act.NextActivity.GetType() != typeof(OpenRA.Mods.RA.Activities.FindResources))) (act.NextActivity == null || act.NextActivity.GetType() != typeof(FindResources)))
continue; continue;
} }
@@ -814,7 +812,7 @@ namespace OpenRA.Mods.RA.AI
return; return;
// No construction yards - Build a new MCV // No construction yards - Build a new MCV
if (!HasAdequateFact() && !self.World.Actors.Where(a => a.Owner == p && a.HasTrait<BaseBuilding>() && a.HasTrait<Mobile>()).Any()) if (!HasAdequateFact() && !self.World.Actors.Any(a => a.Owner == p && a.HasTrait<BaseBuilding>() && a.HasTrait<Mobile>()))
BuildUnit("Vehicle", GetUnitInfoByCommonName("Mcv", p).Name); BuildUnit("Vehicle", GetUnitInfoByCommonName("Mcv", p).Name);
foreach (var q in Info.UnitQueues) foreach (var q in Info.UnitQueues)

View File

@@ -10,6 +10,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Air; using OpenRA.Mods.RA.Air;
using OpenRA.Traits; using OpenRA.Traits;
@@ -125,7 +126,7 @@ namespace OpenRA.Mods.RA.AI
return false; return false;
var type = activity.GetType(); var type = activity.GetType();
if (type == typeof(OpenRA.Mods.RA.Activities.Rearm) || type == typeof(ResupplyAircraft)) if (type == typeof(Rearm) || type == typeof(ResupplyAircraft))
return true; return true;
var next = activity.NextActivity; var next = activity.NextActivity;
@@ -133,7 +134,7 @@ namespace OpenRA.Mods.RA.AI
return false; return false;
var nextType = next.GetType(); var nextType = next.GetType();
if (nextType == typeof(OpenRA.Mods.RA.Activities.Rearm) || nextType == typeof(ResupplyAircraft)) if (nextType == typeof(Rearm) || nextType == typeof(ResupplyAircraft))
return true; return true;
return false; return false;

View File

@@ -11,6 +11,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Air; using OpenRA.Mods.RA.Air;
using OpenRA.Mods.RA.Buildings; using OpenRA.Mods.RA.Buildings;
using OpenRA.Traits; using OpenRA.Traits;
@@ -44,7 +45,7 @@ namespace OpenRA.Mods.RA.AI
return false; return false;
var type = a.GetCurrentActivity().GetType(); var type = a.GetCurrentActivity().GetType();
if (type == typeof(OpenRA.Mods.RA.Activities.Attack) || type == typeof(FlyAttack)) if (type == typeof(Attack) || type == typeof(FlyAttack))
return true; return true;
var next = a.GetCurrentActivity().NextActivity; var next = a.GetCurrentActivity().NextActivity;
@@ -52,7 +53,7 @@ namespace OpenRA.Mods.RA.AI
return false; return false;
var nextType = a.GetCurrentActivity().NextActivity.GetType(); var nextType = a.GetCurrentActivity().NextActivity.GetType();
if (nextType == typeof(OpenRA.Mods.RA.Activities.Attack) || nextType == typeof(FlyAttack)) if (nextType == typeof(Attack) || nextType == typeof(FlyAttack))
return true; return true;
return false; return false;

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA.Air
var helicopter = self.Trait<Helicopter>(); var helicopter = self.Trait<Helicopter>();
var cruiseAltitude = new WRange(helicopter.Info.CruiseAltitude * 1024 / Game.CellSize); var cruiseAltitude = new WRange(helicopter.Info.CruiseAltitude * 1024 / Game.CellSize);
if (HeliFly.AdjustAltitude(self, helicopter, cruiseAltitude)) if (AdjustAltitude(self, helicopter, cruiseAltitude))
return this; return this;
// Rotate towards the target // Rotate towards the target

View File

@@ -97,7 +97,7 @@ namespace OpenRA.Mods.RA
{ {
get get
{ {
if (Armaments.Count() == 0) if (!Armaments.Any())
yield break; yield break;
var negativeDamage = Armaments.First().Weapon.Warheads[0].Damage < 0; var negativeDamage = Armaments.First().Weapon.Warheads[0].Damage < 0;

View File

@@ -44,9 +44,9 @@ namespace OpenRA.Mods.RA
var others = self.World.Players.Where( p => !p.NonCombatant var others = self.World.Players.Where( p => !p.NonCombatant
&& p != self.Owner && p.Stances[self.Owner] != Stance.Ally ); && p != self.Owner && p.Stances[self.Owner] != Stance.Ally );
if (others.Count() == 0) return; if (!others.Any()) return;
if(others.All(p => p.WinState == WinState.Lost)) if (others.All(p => p.WinState == WinState.Lost))
Win(self); Win(self);
} }

View File

@@ -103,7 +103,7 @@ namespace OpenRA.Mods.RA.Move
{ {
var passable = mi.GetMovementClass(world.TileSet); var passable = mi.GetMovementClass(world.TileSet);
tilesInRange = new List<CPos>(tilesInRange.Where(t => domainIndex.IsPassable(src, t, (uint)passable))); tilesInRange = new List<CPos>(tilesInRange.Where(t => domainIndex.IsPassable(src, t, (uint)passable)));
if (tilesInRange.Count() == 0) if (!tilesInRange.Any())
return emptyPath; return emptyPath;
} }

View File

@@ -9,6 +9,7 @@
#endregion #endregion
using OpenRA.FileFormats; using OpenRA.FileFormats;
using OpenRA.Graphics;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
@@ -36,7 +37,7 @@ namespace OpenRA.Mods.RA
this.info = info; this.info = info;
} }
public void InitPalette(OpenRA.Graphics.WorldRenderer wr) public void InitPalette(WorldRenderer wr)
{ {
wr.AddPalette(info.Name, new Palette(FileSystem.Open(world.TileSet.Palette), info.ShadowIndex), info.AllowModifiers); wr.AddPalette(info.Name, new Palette(FileSystem.Open(world.TileSet.Palette), info.ShadowIndex), info.AllowModifiers);
} }

View File

@@ -9,6 +9,7 @@
#endregion #endregion
using OpenRA.FileFormats; using OpenRA.FileFormats;
using OpenRA.Graphics;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
@@ -36,10 +37,10 @@ namespace OpenRA.Mods.RA
this.info = info; this.info = info;
} }
public void InitPalette (OpenRA.Graphics.WorldRenderer wr) public void InitPalette(WorldRenderer wr)
{ {
string Filename = world.TileSet.PlayerPalette == null ? world.TileSet.Palette : world.TileSet.PlayerPalette; var filename = world.TileSet.PlayerPalette ?? world.TileSet.Palette;
wr.AddPalette(info.Name, new Palette(FileSystem.Open(Filename), info.ShadowIndex), info.AllowModifiers); wr.AddPalette(info.Name, new Palette(FileSystem.Open(filename), info.ShadowIndex), info.AllowModifiers);
} }
} }
} }

View File

@@ -9,6 +9,7 @@
#endregion #endregion
using System.Drawing; using System.Drawing;
using System.Linq;
using OpenRA.FileFormats; using OpenRA.FileFormats;
using OpenRA.Mods.RA.Move; using OpenRA.Mods.RA.Move;
using OpenRA.Traits; using OpenRA.Traits;

View File

@@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA.Render
protected override string PaletteName(Actor self) protected override string PaletteName(Actor self)
{ {
var player = spy.disguisedAsPlayer != null ? spy.disguisedAsPlayer : self.Owner; var player = spy.disguisedAsPlayer ?? self.Owner;
return info.Palette ?? info.PlayerPalette + player.InternalName; return info.Palette ?? info.PlayerPalette + player.InternalName;
} }
@@ -39,10 +39,7 @@ namespace OpenRA.Mods.RA.Render
if (spy.disguisedAsSprite != disguisedAsSprite) if (spy.disguisedAsSprite != disguisedAsSprite)
{ {
disguisedAsSprite = spy.disguisedAsSprite; disguisedAsSprite = spy.disguisedAsSprite;
if (disguisedAsSprite != null) anim.ChangeImage(disguisedAsSprite ?? GetImage(self), info.StandAnimations.Random(Game.CosmeticRandom));
anim.ChangeImage(disguisedAsSprite, info.StandAnimations.Random(Game.CosmeticRandom));
else
anim.ChangeImage(GetImage(self), info.StandAnimations.Random(Game.CosmeticRandom));
UpdatePalette(); UpdatePalette();
} }
base.Tick(self); base.Tick(self);

View File

@@ -97,7 +97,7 @@ namespace OpenRA.Mods.RA
// Quantize orientation to match a rendered sprite // Quantize orientation to match a rendered sprite
// Implies no pitch or yaw // Implies no pitch or yaw
var facing = Traits.Util.QuantizeFacing(local.Yaw.Angle / 4, QuantizedFacings) * (256 / QuantizedFacings); var facing = Util.QuantizeFacing(local.Yaw.Angle / 4, QuantizedFacings) * (256 / QuantizedFacings);
return new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing)); return new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing));
} }
} }

View File

@@ -290,7 +290,7 @@ namespace OpenRA.Mods.RA.Widgets
new float2(Game.Renderer.Resolution.Width - 14, origin.Y - 23)); new float2(Game.Renderer.Resolution.Width - 14, origin.Y - 23));
for (int i = 0; i < numActualRows; i++) for (int i = 0; i < numActualRows; i++)
WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "dock-" + (i % 4).ToString()), WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "dock-" + (i % 4)),
new float2(Game.Renderer.Resolution.Width - 14, origin.Y + IconHeight * i)); new float2(Game.Renderer.Resolution.Width - 14, origin.Y + IconHeight * i));
WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "dock-bottom"), WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "dock-bottom"),

View File

@@ -12,6 +12,7 @@ using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using OpenRA.Utility;
using OpenRA.Widgets; using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets.Logic namespace OpenRA.Mods.RA.Widgets.Logic
@@ -69,21 +70,21 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{ {
progressBar.Percentage = i*100/ExtractGameFiles.Count(); progressBar.Percentage = i*100/ExtractGameFiles.Count();
statusLabel.GetText = () => "Extracting..."; statusLabel.GetText = () => "Extracting...";
Utility.Command.ExtractFiles(ExtractGameFiles[i]); Command.ExtractFiles(ExtractGameFiles[i]);
} }
for (int i = 0; i < ExportToPng.Length; i++) for (int i = 0; i < ExportToPng.Length; i++)
{ {
progressBar.Percentage = i*100/ExportToPng.Count(); progressBar.Percentage = i*100/ExportToPng.Count();
statusLabel.GetText = () => "Exporting SHP to PNG..."; statusLabel.GetText = () => "Exporting SHP to PNG...";
Utility.Command.ConvertShpToPng(ExportToPng[i]); Command.ConvertShpToPng(ExportToPng[i]);
} }
for (int i = 0; i < ImportFromPng.Length; i++) for (int i = 0; i < ImportFromPng.Length; i++)
{ {
progressBar.Percentage = i*100/ImportFromPng.Count(); progressBar.Percentage = i*100/ImportFromPng.Count();
statusLabel.GetText = () => "Converting PNG to SHP..."; statusLabel.GetText = () => "Converting PNG to SHP...";
Utility.Command.ConvertPngToShp(ImportFromPng[i]); Command.ConvertPngToShp(ImportFromPng[i]);
} }
Game.RunAfterTick(() => Game.RunAfterTick(() =>

View File

@@ -319,7 +319,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
fragileAlliance.IsDisabled = () => Map.Options.FragileAlliances.HasValue || configurationDisabled(); fragileAlliance.IsDisabled = () => Map.Options.FragileAlliances.HasValue || configurationDisabled();
fragileAlliance.OnClick = () => orderManager.IssueOrder(Order.Command( fragileAlliance.OnClick = () => orderManager.IssueOrder(Order.Command(
"fragilealliance {0}".F(!orderManager.LobbyInfo.GlobalSettings.FragileAlliances))); "fragilealliance {0}".F(!orderManager.LobbyInfo.GlobalSettings.FragileAlliances)));
}; }
var difficulty = optionsBin.GetOrNull<DropDownButtonWidget>("DIFFICULTY_DROPDOWNBUTTON"); var difficulty = optionsBin.GetOrNull<DropDownButtonWidget>("DIFFICULTY_DROPDOWNBUTTON");
if (difficulty != null) if (difficulty != null)
@@ -417,7 +417,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
enableShroud.IsDisabled = () => Map.Options.Shroud.HasValue || configurationDisabled(); enableShroud.IsDisabled = () => Map.Options.Shroud.HasValue || configurationDisabled();
enableShroud.OnClick = () => orderManager.IssueOrder(Order.Command( enableShroud.OnClick = () => orderManager.IssueOrder(Order.Command(
"shroud {0}".F(!orderManager.LobbyInfo.GlobalSettings.Shroud))); "shroud {0}".F(!orderManager.LobbyInfo.GlobalSettings.Shroud)));
}; }
var enableFog = optionsBin.GetOrNull<CheckboxWidget>("FOG_CHECKBOX"); var enableFog = optionsBin.GetOrNull<CheckboxWidget>("FOG_CHECKBOX");
if (enableFog != null) if (enableFog != null)
@@ -426,7 +426,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
enableFog.IsDisabled = () => Map.Options.Fog.HasValue || configurationDisabled(); enableFog.IsDisabled = () => Map.Options.Fog.HasValue || configurationDisabled();
enableFog.OnClick = () => orderManager.IssueOrder(Order.Command( enableFog.OnClick = () => orderManager.IssueOrder(Order.Command(
"fog {0}".F(!orderManager.LobbyInfo.GlobalSettings.Fog))); "fog {0}".F(!orderManager.LobbyInfo.GlobalSettings.Fog)));
}; }
var disconnectButton = lobby.Get<ButtonWidget>("DISCONNECT_BUTTON"); var disconnectButton = lobby.Get<ButtonWidget>("DISCONNECT_BUTTON");
disconnectButton.OnClick = () => { CloseWindow(); onExit(); }; disconnectButton.OnClick = () => { CloseWindow(); onExit(); };

View File

@@ -254,7 +254,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
slot.IsVisible = () => true; slot.IsVisible = () => true;
slot.IsDisabled = () => orderManager.LocalClient.IsReady; slot.IsDisabled = () => orderManager.LocalClient.IsReady;
slot.GetText = () => c != null ? c.Name : s.Closed ? "Closed" : "Open"; slot.GetText = () => c != null ? c.Name : s.Closed ? "Closed" : "Open";
slot.OnMouseDown = _ => LobbyUtils.ShowSlotDropDown(slot, s, c, orderManager); slot.OnMouseDown = _ => ShowSlotDropDown(slot, s, c, orderManager);
// Ensure Name selector (if present) is hidden // Ensure Name selector (if present) is hidden
var name = parent.GetOrNull("NAME"); var name = parent.GetOrNull("NAME");
@@ -297,7 +297,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{ {
var color = parent.Get<DropDownButtonWidget>("COLOR"); var color = parent.Get<DropDownButtonWidget>("COLOR");
color.IsDisabled = () => (s != null && s.LockColor) || orderManager.LocalClient.IsReady; color.IsDisabled = () => (s != null && s.LockColor) || orderManager.LocalClient.IsReady;
color.OnMouseDown = _ => LobbyUtils.ShowColorDropDown(color, c, orderManager, colorPreview); color.OnMouseDown = _ => ShowColorDropDown(color, c, orderManager, colorPreview);
SetupColorWidget(color, s, c); SetupColorWidget(color, s, c);
} }
@@ -312,7 +312,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{ {
var dropdown = parent.Get<DropDownButtonWidget>("FACTION"); var dropdown = parent.Get<DropDownButtonWidget>("FACTION");
dropdown.IsDisabled = () => s.LockRace || orderManager.LocalClient.IsReady; dropdown.IsDisabled = () => s.LockRace || orderManager.LocalClient.IsReady;
dropdown.OnMouseDown = _ => LobbyUtils.ShowRaceDropDown(dropdown, c, orderManager, countryNames); dropdown.OnMouseDown = _ => ShowRaceDropDown(dropdown, c, orderManager, countryNames);
SetupFactionWidget(dropdown, s, c, countryNames); SetupFactionWidget(dropdown, s, c, countryNames);
} }
@@ -329,7 +329,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{ {
var dropdown = parent.Get<DropDownButtonWidget>("TEAM"); var dropdown = parent.Get<DropDownButtonWidget>("TEAM");
dropdown.IsDisabled = () => s.LockTeam || orderManager.LocalClient.IsReady; dropdown.IsDisabled = () => s.LockTeam || orderManager.LocalClient.IsReady;
dropdown.OnMouseDown = _ => LobbyUtils.ShowTeamDropDown(dropdown, c, orderManager, teamCount); dropdown.OnMouseDown = _ => ShowTeamDropDown(dropdown, c, orderManager, teamCount);
dropdown.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString(); dropdown.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString();
} }

View File

@@ -11,6 +11,7 @@
using System; using System;
using System.Linq; using System.Linq;
using OpenRA.GameRules; using OpenRA.GameRules;
using OpenRA.Traits;
using OpenRA.Widgets; using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets.Logic namespace OpenRA.Mods.RA.Widgets.Logic

View File

@@ -194,7 +194,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
return; return;
} }
if (games.Count() == 0) if (!games.Any())
{ {
searchStatus = SearchStatus.NoGames; searchStatus = SearchStatus.NoGames;
return; return;

View File

@@ -126,7 +126,7 @@ namespace OpenRA.Mods.RA.Widgets
if (sp.TotalTime > 0) if (sp.TotalTime > 0)
{ {
pos += new int2(0,20); pos += new int2(0,20);
Game.Renderer.Fonts["Bold"].DrawText(WidgetUtils.FormatTime(sp.RemainingTime).ToString(), pos, Color.White); 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);
} }

View File

@@ -147,8 +147,7 @@ namespace OpenRA.Mods.RA
var toProcess = new Stack<int>(); var toProcess = new Stack<int>();
toProcess.Push(d1); toProcess.Push(d1);
var i = 0; while (toProcess.Any())
while (toProcess.Count() > 0)
{ {
var current = toProcess.Pop(); var current = toProcess.Pop();
if (!transientConnections.ContainsKey(current)) if (!transientConnections.ContainsKey(current))
@@ -163,7 +162,6 @@ namespace OpenRA.Mods.RA
} }
visited.Add(current); visited.Add(current);
i += 1;
} }
return false; return false;

View File

@@ -17,7 +17,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
class PathfinderDebugOverlayInfo : Traits.TraitInfo<PathfinderDebugOverlay> { } class PathfinderDebugOverlayInfo : TraitInfo<PathfinderDebugOverlay> { }
class PathfinderDebugOverlay : IRenderOverlay, IWorldLoaded class PathfinderDebugOverlay : IRenderOverlay, IWorldLoaded
{ {
Dictionary<Player, int[,]> layers; Dictionary<Player, int[,]> layers;

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA
} }
} }
public void WorldLoaded(OpenRA.World w, WorldRenderer wr) public void WorldLoaded(World w, WorldRenderer wr)
{ {
// NOTE(jsd): 32 seems a sane default initial capacity for the total # of harvesters in a game. Purely a guesstimate. // NOTE(jsd): 32 seems a sane default initial capacity for the total # of harvesters in a game. Purely a guesstimate.
claimByCell = new Dictionary<CPos, ResourceClaim>(32); claimByCell = new Dictionary<CPos, ResourceClaim>(32);

View File

@@ -55,8 +55,8 @@ namespace OpenRA.Renderer.Cg
Tao.Cg.Cg.cgSetErrorCallback(errorCallback); Tao.Cg.Cg.cgSetErrorCallback(errorCallback);
Tao.Cg.CgGl.cgGLRegisterStates(Context); CgGl.cgGLRegisterStates(Context);
Tao.Cg.CgGl.cgGLSetManageTextureParameters(Context, true); CgGl.cgGLSetManageTextureParameters(Context, true);
VertexProfile = CgGl.cgGLGetLatestProfile(CgGl.CG_GL_VERTEX); VertexProfile = CgGl.cgGLGetLatestProfile(CgGl.CG_GL_VERTEX);
FragmentProfile = CgGl.cgGLGetLatestProfile(CgGl.CG_GL_FRAGMENT); FragmentProfile = CgGl.cgGLGetLatestProfile(CgGl.CG_GL_FRAGMENT);
} }

View File

@@ -47,7 +47,7 @@ namespace OpenRA.Renderer.Sdl2
switch (e.type) switch (e.type)
{ {
case SDL.SDL_EventType.SDL_QUIT: case SDL.SDL_EventType.SDL_QUIT:
OpenRA.Game.Exit(); Game.Exit();
break; break;
case SDL.SDL_EventType.SDL_WINDOWEVENT: case SDL.SDL_EventType.SDL_WINDOWEVENT:
@@ -176,7 +176,7 @@ namespace OpenRA.Renderer.Sdl2
if (e.key.keysym.sym == SDL.SDL_Keycode.SDLK_F4 && mods.HasModifier(Modifiers.Alt) && if (e.key.keysym.sym == SDL.SDL_Keycode.SDLK_F4 && mods.HasModifier(Modifiers.Alt) &&
Platform.CurrentPlatform == PlatformType.Windows) Platform.CurrentPlatform == PlatformType.Windows)
{ {
OpenRA.Game.Exit(); Game.Exit();
} }
else else
inputHandler.OnKeyInput(keyEvent); inputHandler.OnKeyInput(keyEvent);

View File

@@ -185,7 +185,7 @@ namespace OpenRA.Renderer.SdlCommon
switch (e.type) switch (e.type)
{ {
case Sdl.SDL_QUIT: case Sdl.SDL_QUIT:
OpenRA.Game.Exit(); Game.Exit();
break; break;
case Sdl.SDL_MOUSEBUTTONDOWN: case Sdl.SDL_MOUSEBUTTONDOWN:
@@ -264,7 +264,7 @@ namespace OpenRA.Renderer.SdlCommon
if (e.key.keysym.sym == Sdl.SDLK_F4 && mods.HasModifier(Modifiers.Alt) && if (e.key.keysym.sym == Sdl.SDLK_F4 && mods.HasModifier(Modifiers.Alt) &&
Platform.CurrentPlatform == PlatformType.Windows) Platform.CurrentPlatform == PlatformType.Windows)
{ {
OpenRA.Game.Exit(); Game.Exit();
} }
else else
inputHandler.OnKeyInput(keyEvent); inputHandler.OnKeyInput(keyEvent);

View File

@@ -429,7 +429,7 @@ namespace OpenRA.TilesetBuilder
Console.WriteLine("{0} {1} {2} {3} {4} {5} {6}", Console.WriteLine("{0} {1} {2} {3} {4} {5} {6}",
cur, cur,
idx, idx,
((t.Key.Y * surface1.TilesPerRow) + t.Key.X).ToString(), ((t.Key.Y * surface1.TilesPerRow) + t.Key.X),
tp.Width, tp.Width,
tp.Height, tp.Height,
t.Key.X, t.Key.X,