Remove some misc redundancies
This commit is contained in:
@@ -12,6 +12,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Mods.RA.Air;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
@@ -181,15 +182,13 @@ namespace OpenRA.Mods.RA.AI
|
||||
int CountBuilding(string frac, Player owner)
|
||||
{
|
||||
return world.ActorsWithTrait<Building>()
|
||||
.Where(a => a.Actor.Owner == owner && a.Actor.Info.Name == frac)
|
||||
.Count();
|
||||
.Count(a => a.Actor.Owner == owner && a.Actor.Info.Name == frac);
|
||||
}
|
||||
|
||||
int CountUnits(string unit, Player owner)
|
||||
{
|
||||
return world.ActorsWithTrait<IPositionable>()
|
||||
.Where(a => a.Actor.Owner == owner && a.Actor.Info.Name == unit)
|
||||
.Count();
|
||||
.Count(a => a.Actor.Owner == owner && a.Actor.Info.Name == unit);
|
||||
}
|
||||
|
||||
int? CountBuildingByCommonName(string commonName, Player owner)
|
||||
@@ -198,8 +197,7 @@ namespace OpenRA.Mods.RA.AI
|
||||
return null;
|
||||
|
||||
return world.ActorsWithTrait<Building>()
|
||||
.Where(a => a.Actor.Owner == owner && Info.BuildingCommonNames[commonName].Contains(a.Actor.Info.Name))
|
||||
.Count();
|
||||
.Count(a => a.Actor.Owner == owner && Info.BuildingCommonNames[commonName].Contains(a.Actor.Info.Name));
|
||||
}
|
||||
|
||||
ActorInfo GetBuildingInfoByCommonName(string commonName, Player owner)
|
||||
@@ -553,8 +551,8 @@ namespace OpenRA.Mods.RA.AI
|
||||
var act = a.GetCurrentActivity();
|
||||
|
||||
// A Wait activity is technically idle:
|
||||
if ((act.GetType() != typeof(OpenRA.Mods.RA.Activities.Wait)) &&
|
||||
(act.NextActivity == null || act.NextActivity.GetType() != typeof(OpenRA.Mods.RA.Activities.FindResources)))
|
||||
if ((act.GetType() != typeof(Wait)) &&
|
||||
(act.NextActivity == null || act.NextActivity.GetType() != typeof(FindResources)))
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -814,7 +812,7 @@ namespace OpenRA.Mods.RA.AI
|
||||
return;
|
||||
|
||||
// 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);
|
||||
|
||||
foreach (var q in Info.UnitQueues)
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Mods.RA.Air;
|
||||
using OpenRA.Traits;
|
||||
|
||||
@@ -125,7 +126,7 @@ namespace OpenRA.Mods.RA.AI
|
||||
return false;
|
||||
|
||||
var type = activity.GetType();
|
||||
if (type == typeof(OpenRA.Mods.RA.Activities.Rearm) || type == typeof(ResupplyAircraft))
|
||||
if (type == typeof(Rearm) || type == typeof(ResupplyAircraft))
|
||||
return true;
|
||||
|
||||
var next = activity.NextActivity;
|
||||
@@ -133,7 +134,7 @@ namespace OpenRA.Mods.RA.AI
|
||||
return false;
|
||||
|
||||
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 false;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Mods.RA.Air;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Traits;
|
||||
@@ -44,7 +45,7 @@ namespace OpenRA.Mods.RA.AI
|
||||
return false;
|
||||
|
||||
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;
|
||||
|
||||
var next = a.GetCurrentActivity().NextActivity;
|
||||
@@ -52,7 +53,7 @@ namespace OpenRA.Mods.RA.AI
|
||||
return false;
|
||||
|
||||
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 false;
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA.Air
|
||||
var helicopter = self.Trait<Helicopter>();
|
||||
|
||||
var cruiseAltitude = new WRange(helicopter.Info.CruiseAltitude * 1024 / Game.CellSize);
|
||||
if (HeliFly.AdjustAltitude(self, helicopter, cruiseAltitude))
|
||||
if (AdjustAltitude(self, helicopter, cruiseAltitude))
|
||||
return this;
|
||||
|
||||
// Rotate towards the target
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Armaments.Count() == 0)
|
||||
if (!Armaments.Any())
|
||||
yield break;
|
||||
|
||||
var negativeDamage = Armaments.First().Weapon.Warheads[0].Damage < 0;
|
||||
|
||||
@@ -44,9 +44,9 @@ namespace OpenRA.Mods.RA
|
||||
var others = self.World.Players.Where( p => !p.NonCombatant
|
||||
&& 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
{
|
||||
var passable = mi.GetMovementClass(world.TileSet);
|
||||
tilesInRange = new List<CPos>(tilesInRange.Where(t => domainIndex.IsPassable(src, t, (uint)passable)));
|
||||
if (tilesInRange.Count() == 0)
|
||||
if (!tilesInRange.Any())
|
||||
return emptyPath;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#endregion
|
||||
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
@@ -36,7 +37,7 @@ namespace OpenRA.Mods.RA
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#endregion
|
||||
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
@@ -36,10 +37,10 @@ namespace OpenRA.Mods.RA
|
||||
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;
|
||||
wr.AddPalette(info.Name, new Palette(FileSystem.Open(Filename), info.ShadowIndex), info.AllowModifiers);
|
||||
var filename = world.TileSet.PlayerPalette ?? world.TileSet.Palette;
|
||||
wr.AddPalette(info.Name, new Palette(FileSystem.Open(filename), info.ShadowIndex), info.AllowModifiers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#endregion
|
||||
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
using OpenRA.Traits;
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA.Render
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -39,10 +39,7 @@ namespace OpenRA.Mods.RA.Render
|
||||
if (spy.disguisedAsSprite != disguisedAsSprite)
|
||||
{
|
||||
disguisedAsSprite = spy.disguisedAsSprite;
|
||||
if (disguisedAsSprite != null)
|
||||
anim.ChangeImage(disguisedAsSprite, info.StandAnimations.Random(Game.CosmeticRandom));
|
||||
else
|
||||
anim.ChangeImage(GetImage(self), info.StandAnimations.Random(Game.CosmeticRandom));
|
||||
anim.ChangeImage(disguisedAsSprite ?? GetImage(self), info.StandAnimations.Random(Game.CosmeticRandom));
|
||||
UpdatePalette();
|
||||
}
|
||||
base.Tick(self);
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
// Quantize orientation to match a rendered sprite
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,7 +290,7 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
new float2(Game.Renderer.Resolution.Width - 14, origin.Y - 23));
|
||||
|
||||
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));
|
||||
|
||||
WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "dock-bottom"),
|
||||
|
||||
@@ -12,6 +12,7 @@ using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using OpenRA.Utility;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
@@ -69,21 +70,21 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
progressBar.Percentage = i*100/ExtractGameFiles.Count();
|
||||
statusLabel.GetText = () => "Extracting...";
|
||||
Utility.Command.ExtractFiles(ExtractGameFiles[i]);
|
||||
Command.ExtractFiles(ExtractGameFiles[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < ExportToPng.Length; i++)
|
||||
{
|
||||
progressBar.Percentage = i*100/ExportToPng.Count();
|
||||
statusLabel.GetText = () => "Exporting SHP to PNG...";
|
||||
Utility.Command.ConvertShpToPng(ExportToPng[i]);
|
||||
Command.ConvertShpToPng(ExportToPng[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < ImportFromPng.Length; i++)
|
||||
{
|
||||
progressBar.Percentage = i*100/ImportFromPng.Count();
|
||||
statusLabel.GetText = () => "Converting PNG to SHP...";
|
||||
Utility.Command.ConvertPngToShp(ImportFromPng[i]);
|
||||
Command.ConvertPngToShp(ImportFromPng[i]);
|
||||
}
|
||||
|
||||
Game.RunAfterTick(() =>
|
||||
|
||||
@@ -319,7 +319,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
fragileAlliance.IsDisabled = () => Map.Options.FragileAlliances.HasValue || configurationDisabled();
|
||||
fragileAlliance.OnClick = () => orderManager.IssueOrder(Order.Command(
|
||||
"fragilealliance {0}".F(!orderManager.LobbyInfo.GlobalSettings.FragileAlliances)));
|
||||
};
|
||||
}
|
||||
|
||||
var difficulty = optionsBin.GetOrNull<DropDownButtonWidget>("DIFFICULTY_DROPDOWNBUTTON");
|
||||
if (difficulty != null)
|
||||
@@ -417,7 +417,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
enableShroud.IsDisabled = () => Map.Options.Shroud.HasValue || configurationDisabled();
|
||||
enableShroud.OnClick = () => orderManager.IssueOrder(Order.Command(
|
||||
"shroud {0}".F(!orderManager.LobbyInfo.GlobalSettings.Shroud)));
|
||||
};
|
||||
}
|
||||
|
||||
var enableFog = optionsBin.GetOrNull<CheckboxWidget>("FOG_CHECKBOX");
|
||||
if (enableFog != null)
|
||||
@@ -426,7 +426,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
enableFog.IsDisabled = () => Map.Options.Fog.HasValue || configurationDisabled();
|
||||
enableFog.OnClick = () => orderManager.IssueOrder(Order.Command(
|
||||
"fog {0}".F(!orderManager.LobbyInfo.GlobalSettings.Fog)));
|
||||
};
|
||||
}
|
||||
|
||||
var disconnectButton = lobby.Get<ButtonWidget>("DISCONNECT_BUTTON");
|
||||
disconnectButton.OnClick = () => { CloseWindow(); onExit(); };
|
||||
|
||||
@@ -254,7 +254,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
slot.IsVisible = () => true;
|
||||
slot.IsDisabled = () => orderManager.LocalClient.IsReady;
|
||||
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
|
||||
var name = parent.GetOrNull("NAME");
|
||||
@@ -297,7 +297,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
var color = parent.Get<DropDownButtonWidget>("COLOR");
|
||||
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);
|
||||
}
|
||||
@@ -312,7 +312,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
var dropdown = parent.Get<DropDownButtonWidget>("FACTION");
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -329,7 +329,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
var dropdown = parent.Get<DropDownButtonWidget>("TEAM");
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
|
||||
@@ -194,7 +194,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
return;
|
||||
}
|
||||
|
||||
if (games.Count() == 0)
|
||||
if (!games.Any())
|
||||
{
|
||||
searchStatus = SearchStatus.NoGames;
|
||||
return;
|
||||
|
||||
@@ -126,7 +126,7 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
if (sp.TotalTime > 0)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -147,8 +147,7 @@ namespace OpenRA.Mods.RA
|
||||
var toProcess = new Stack<int>();
|
||||
toProcess.Push(d1);
|
||||
|
||||
var i = 0;
|
||||
while (toProcess.Count() > 0)
|
||||
while (toProcess.Any())
|
||||
{
|
||||
var current = toProcess.Pop();
|
||||
if (!transientConnections.ContainsKey(current))
|
||||
@@ -163,7 +162,6 @@ namespace OpenRA.Mods.RA
|
||||
}
|
||||
|
||||
visited.Add(current);
|
||||
i += 1;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -17,7 +17,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class PathfinderDebugOverlayInfo : Traits.TraitInfo<PathfinderDebugOverlay> { }
|
||||
class PathfinderDebugOverlayInfo : TraitInfo<PathfinderDebugOverlay> { }
|
||||
class PathfinderDebugOverlay : IRenderOverlay, IWorldLoaded
|
||||
{
|
||||
Dictionary<Player, int[,]> layers;
|
||||
|
||||
@@ -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.
|
||||
claimByCell = new Dictionary<CPos, ResourceClaim>(32);
|
||||
|
||||
Reference in New Issue
Block a user