Fix StyleCop warnings in OpenRA.Mods.RA

This commit is contained in:
Hellhake
2015-01-01 23:03:55 +01:00
parent e9989496c4
commit b6410bc1e0
134 changed files with 261 additions and 267 deletions

View File

@@ -13,7 +13,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Traits
{
[Desc("Tag trait for SupplyTruck: actors.")]
class AcceptsSuppliesInfo : TraitInfo<AcceptsSupplies> {}
class AcceptsSuppliesInfo : TraitInfo<AcceptsSupplies> { }
class AcceptsSupplies {}
class AcceptsSupplies { }
}

View File

@@ -176,6 +176,7 @@ namespace OpenRA.Mods.RA.Traits
{
SetPosition(self, self.World.Map.CenterOfCell(cell) + new WVec(0, 0, CenterPosition.Z));
}
public void SetVisualPosition(Actor self, WPos pos) { SetPosition(self, pos); }
public void AddedToWorld(Actor self)

View File

@@ -70,6 +70,7 @@ namespace OpenRA.Mods.RA.Traits
return WVec.Zero;
var dot = WVec.Dot(currentDir, repulsionForce) / length;
// avoid stalling the plane
return dot >= 0 ? repulsionForce : WVec.Zero;
}

View File

@@ -114,10 +114,11 @@ namespace OpenRA.Mods.RA.Traits
{
if (!preventDock)
{
harv.QueueActivity(new CallFunc( () => dockedHarv = harv, false));
harv.QueueActivity(new CallFunc(() => dockedHarv = harv, false));
harv.QueueActivity(DockSequence(harv, self));
harv.QueueActivity(new CallFunc( () => dockedHarv = null, false));
harv.QueueActivity(new CallFunc(() => dockedHarv = null, false));
}
harv.QueueActivity(new CallFunc(() => harv.Trait<Harvester>().ContinueHarvesting(harv)));
}

View File

@@ -8,10 +8,10 @@
*/
#endregion
using System.Linq;
using System.Collections.Generic;
using OpenRA.Traits;
using System.Linq;
using OpenRA.Mods.Common.Orders;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Traits
{

View File

@@ -12,8 +12,8 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.RA.Effects;
using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.RA.Effects;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Traits
@@ -42,7 +42,7 @@ namespace OpenRA.Mods.RA.Traits
public bool RepairActive = false;
public RepairableBuilding(Actor self, RepairableBuildingInfo info)
: base (info)
: base(info)
{
Health = self.Trait<Health>();
}

View File

@@ -38,11 +38,10 @@ namespace OpenRA.Mods.RA.Traits
// NOTE: we really dont care about the GC eating DisposableActions that apply to a world *other* than
// the one we're playing in.
return new DisposableAction(
() => { reservedFor = null; reservedForAircraft = null; },
() => Game.RunAfterTick(
() => { if (Game.IsCurrentWorld( self.World )) throw new InvalidOperationException(
() => { if (Game.IsCurrentWorld(self.World)) throw new InvalidOperationException(
"Attempted to finalize an undisposed DisposableAction. {0} ({1}) reserved {2} ({3})"
.F(forActor.Info.Name, forActor.ActorID, self.Info.Name, self.ActorID)); }));
}

View File

@@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA.Traits
CPos? lastPos;
public Cloak(Actor self, CloakInfo info)
: base (info)
: base(info)
{
this.self = self;

View File

@@ -8,8 +8,8 @@
*/
#endregion
using System.Drawing;
using System.Collections.Generic;
using System.Drawing;
using OpenRA.Activities;
using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Orders;
@@ -68,7 +68,6 @@ namespace OpenRA.Mods.RA.Traits
self.QueueActivity(new MoveAdjacentTo(self, target));
self.QueueActivity(new CallFunc(() => Explode(self)));
}
else if (order.OrderString == "Detonate")
Explode(self);
}

View File

@@ -13,8 +13,8 @@ using System.Drawing;
using System.Linq;
using OpenRA.Activities;
using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.Common.Orders;
using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.RA.Activities;
using OpenRA.Traits;
@@ -47,6 +47,7 @@ namespace OpenRA.Mods.RA.Traits
IExplodeModifier, IOrderVoice, ISpeedModifier, ISync,
INotifyResourceClaimLost, INotifyIdle, INotifyBlockingMove
{
readonly HarvesterInfo Info;
Dictionary<ResourceTypeInfo, int> contents = new Dictionary<ResourceTypeInfo, int>();
[Sync] public Actor OwnerLinkedProc = null;
@@ -56,7 +57,6 @@ namespace OpenRA.Mods.RA.Traits
public CPos? LastHarvestedCell = null;
public CPos? LastOrderLocation = null;
[Sync] public int ContentValue { get { return contents.Sum(c => c.Key.ValuePerUnit * c.Value); } }
readonly HarvesterInfo Info;
bool idleSmart = true;
public Harvester(Actor self, HarvesterInfo info)
@@ -118,8 +118,7 @@ namespace OpenRA.Mods.RA.Traits
from r in self.World.ActorsWithTrait<IAcceptOre>()
where r.Actor != ignore && r.Actor.Owner == self.Owner && IsAcceptableProcType(r.Actor)
let linkedHarvs = self.World.ActorsWithTrait<Harvester>().Where(a => a.Trait.LinkedProc == r.Actor).Count()
select new { Location = r.Actor.Location + r.Trait.DeliverOffset, Actor = r.Actor, Occupancy = linkedHarvs }
).ToDictionary(r => r.Location);
select new { Location = r.Actor.Location + r.Trait.DeliverOffset, Actor = r.Actor, Occupancy = linkedHarvs }).ToDictionary(r => r.Location);
// Start a search from each refinery's delivery location:
var mi = self.Info.Traits.Get<MobileInfo>();
@@ -130,13 +129,13 @@ namespace OpenRA.Mods.RA.Traits
if (!refs.ContainsKey(loc)) return 0;
var occupancy = refs[loc].Occupancy;
// 4 harvesters clogs up the refinery's delivery location:
if (occupancy >= 3) return int.MaxValue;
// Prefer refineries with less occupancy (multiplier is to offset distance cost):
return occupancy * 12;
})
);
}));
// Reverse the found-path to find the refinery location instead of our location:
path.Reverse();
@@ -192,6 +191,7 @@ namespace OpenRA.Mods.RA.Traits
{
// I'm blocking someone else from moving to my location:
var act = self.GetCurrentActivity();
// If I'm just waiting around then get out of the way:
if (act is Wait)
{
@@ -319,6 +319,7 @@ namespace OpenRA.Mods.RA.Traits
{
// A bot order gives us a CPos.Zero TargetLocation, so find some good resources for him:
var loc = FindNextResourceForBot(self);
// No more resources? Oh well.
if (!loc.HasValue)
return;
@@ -386,6 +387,7 @@ namespace OpenRA.Mods.RA.Traits
var resType = resLayer.GetResource(loc);
if (resType == null) return 1;
// Can the harvester collect this kind of resource?
if (!harvInfo.Resources.Contains(resType.Info.Name)) return 1;
@@ -398,8 +400,7 @@ namespace OpenRA.Mods.RA.Traits
return 0;
})
.FromPoint(self.Location)
);
.FromPoint(self.Location));
if (path.Count == 0)
return (CPos?)null;
@@ -459,6 +460,7 @@ namespace OpenRA.Mods.RA.Traits
return false;
var location = self.World.Map.CellContaining(target.CenterPosition);
// Don't leak info about resources under the shroud
if (!self.Owner.Shroud.IsExplored(location))
return false;

View File

@@ -19,7 +19,7 @@ namespace OpenRA.Mods.RA.Traits
public readonly string FullHuskActor = null;
public readonly int FullnessThreshold = 50;
public object Create( ActorInitializer init ) { return new HarvesterHuskModifier(this); }
public object Create(ActorInitializer init) { return new HarvesterHuskModifier(this); }
}
public class HarvesterHuskModifier : IHuskModifier

View File

@@ -8,9 +8,9 @@
*/
#endregion
using System.Linq;
using System.Drawing;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Activities;
using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Orders;
@@ -72,9 +72,11 @@ namespace OpenRA.Mods.RA.Traits
if (info.ThumpDamageWeapon != null)
{
var weapon = self.World.Map.Rules.Weapons[info.ThumpDamageWeapon.ToLowerInvariant()];
// Use .FromPos since this weapon needs to affect more than just the MadTank actor
weapon.Impact(Target.FromPos(self.CenterPosition), self, Enumerable.Empty<int>());
}
screenShaker.AddEffect(info.ThumpShakeTime, self.CenterPosition, info.ThumpShakeIntensity, info.ThumpShakeMultiplier);
tick = 0;
}
@@ -112,9 +114,11 @@ namespace OpenRA.Mods.RA.Traits
if (info.DetonationWeapon != null)
{
var weapon = self.World.Map.Rules.Weapons[info.DetonationWeapon.ToLowerInvariant()];
// Use .FromPos since this actor is killed. Cannot use Target.FromActor
weapon.Impact(Target.FromPos(self.CenterPosition), self, Enumerable.Empty<int>());
}
self.Kill(self);
});
}
@@ -164,7 +168,6 @@ namespace OpenRA.Mods.RA.Traits
self.QueueActivity(new MoveAdjacentTo(self, target));
self.QueueActivity(new CallFunc(StartDetonationSequence));
}
else if (order.OrderString == "Detonate")
{
self.CancelActivity();

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.RA.Traits
this.info = info;
}
public void WarnCrush(Actor crusher) {}
public void WarnCrush(Actor crusher) { }
public void OnCrush(Actor crusher)
{

View File

@@ -9,8 +9,8 @@
#endregion
using System;
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Orders;
using OpenRA.Mods.RA.Activities;

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA.Traits
TransientActors,
BlockedByMovers,
All = TransientActors | BlockedByMovers
};
}
[Desc("Unit is able to move.")]
public class MobileInfo : ITraitInfo, IOccupySpaceInfo, IFacingInfo, IMoveInfo, UsesInit<FacingInit>, UsesInit<LocationInit>, UsesInit<SubCellInit>
@@ -159,7 +159,7 @@ namespace OpenRA.Mods.RA.Traits
if (otherMobile == null) return false;
// Sign of dot-product indicates (roughly) if vectors are facing in same or opposite directions:
var dp = CVec.Dot((selfMobile.toCell - self.Location), (otherMobile.toCell - other.Location));
var dp = CVec.Dot(selfMobile.toCell - self.Location, otherMobile.toCell - other.Location);
if (dp <= 0) return false;
return true;
@@ -177,7 +177,7 @@ namespace OpenRA.Mods.RA.Traits
{
var canIgnoreMovingAllies = self != null && !check.HasFlag(CellConditions.BlockedByMovers);
var needsCellExclusively = self == null || Crushes == null || !Crushes.Any();
foreach(var a in world.ActorMap.GetUnitsAt(cell))
foreach (var a in world.ActorMap.GetUnitsAt(cell))
{
if (a == ignoreActor)
continue;
@@ -239,7 +239,7 @@ namespace OpenRA.Mods.RA.Traits
}
if (!SharesCell)
return world.ActorMap.AnyUnitsAt(cell, SubCell.FullCell)? SubCell.Invalid : SubCell.FullCell;
return world.ActorMap.AnyUnitsAt(cell, SubCell.FullCell) ? SubCell.Invalid : SubCell.FullCell;
return world.ActorMap.FreeSubCell(cell, preferredSubCell);
}
@@ -257,8 +257,6 @@ namespace OpenRA.Mods.RA.Traits
CPos __fromCell, __toCell;
public SubCell fromSubCell, toSubCell;
//int __altitude;
[Sync] public int Facing
{
get { return __facing; }
@@ -333,6 +331,7 @@ namespace OpenRA.Mods.RA.Traits
if (preferred != SubCell.FullCell)
return SubCell.FullCell;
}
return preferred;
}
@@ -388,6 +387,7 @@ namespace OpenRA.Mods.RA.Traits
return new Order("Move", self, queued) { TargetLocation = self.World.Map.CellContaining(target.CenterPosition) };
}
return null;
}
@@ -504,7 +504,7 @@ namespace OpenRA.Mods.RA.Traits
public SubCell GetAvailableSubCell(CPos a, SubCell preferredSubCell = SubCell.Any, Actor ignoreActor = null, bool checkTransientActors = true)
{
return Info.GetAvailableSubCell(self.World, self, a, preferredSubCell, ignoreActor, checkTransientActors? CellConditions.All : CellConditions.None);
return Info.GetAvailableSubCell(self.World, self, a, preferredSubCell, ignoreActor, checkTransientActors ? CellConditions.All : CellConditions.None);
}
public bool CanEnterCell(CPos cell, Actor ignoreActor = null, bool checkTransientActors = true)

View File

@@ -8,8 +8,8 @@
*/
#endregion
using System.Drawing;
using System.Collections.Generic;
using System.Drawing;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Graphics;
using OpenRA.Mods.Common.Orders;
@@ -130,6 +130,7 @@ namespace OpenRA.Mods.RA.Traits
cursor = "chrono-target";
return true;
}
return false;
}
@@ -186,8 +187,7 @@ namespace OpenRA.Mods.RA.Traits
WRange.FromCells(self.Trait<PortableChrono>().Info.MaxDistance),
0,
Color.FromArgb(128, Color.LawnGreen),
Color.FromArgb(96, Color.Black)
);
Color.FromArgb(96, Color.Black));
}
public string GetCursor(World world, CPos xy, MouseInput mi)

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA.Traits
public readonly int Duration = 30;
public readonly bool KillCargo = true;
public override object Create(ActorInitializer init) { return new ChronoshiftPower(init.self,this); }
public override object Create(ActorInitializer init) { return new ChronoshiftPower(init.self, this); }
}
class ChronoshiftPower : SupportPower
@@ -255,19 +255,21 @@ namespace OpenRA.Mods.RA.Traits
foreach (var unit in power.UnitsInRange(sourceLocation))
{
var targetCell = unit.Location + (xy - sourceLocation);
if (manager.self.Owner.Shroud.IsExplored(targetCell) && unit.Trait<Chronoshiftable>().CanChronoshiftTo(unit,targetCell))
if (manager.self.Owner.Shroud.IsExplored(targetCell) && unit.Trait<Chronoshiftable>().CanChronoshiftTo(unit, targetCell))
{
canTeleport = true;
break;
}
}
if (!canTeleport)
{
// Check the terrain types. This will allow chronoshifts to occur on empty terrain to terrain of
// a similar type. This also keeps the cursor from changing in non-visible property, alerting the
// chronoshifter of enemy unit presence
canTeleport = power.SimilarTerrain(sourceLocation,xy);
canTeleport = power.SimilarTerrain(sourceLocation, xy);
}
return canTeleport;
}

View File

@@ -19,7 +19,7 @@ namespace OpenRA.Mods.RA.Traits
[Desc("Required for GpsPower. Attach this to the player actor.")]
class GpsWatcherInfo : ITraitInfo
{
public object Create (ActorInitializer init) { return new GpsWatcher(init.self.Owner); }
public object Create(ActorInitializer init) { return new GpsWatcher(init.self.Owner); }
}
class GpsWatcher : ISync, IFogVisibilityModifier
@@ -68,7 +68,7 @@ namespace OpenRA.Mods.RA.Traits
void RefreshGranted()
{
Granted = (actors.Count > 0 && Launched);
Granted = actors.Count > 0 && Launched;
GrantedAllies = owner.World.ActorsWithTrait<GpsWatcher>().Any(p => p.Actor.Owner.IsAlliedWith(owner) && p.Trait.Granted);
if (Granted || GrantedAllies)
@@ -119,7 +119,7 @@ namespace OpenRA.Mods.RA.Traits
public void Killed(Actor self, AttackInfo e) { RemoveGps(self); }
public void Selling(Actor self) {}
public void Selling(Actor self) { }
public void Sold(Actor self) { RemoveGps(self); }
void RemoveGps(Actor self)

View File

@@ -14,7 +14,7 @@ namespace OpenRA.Mods.RA.Traits
{
public class TargetableSubmarineInfo : TargetableUnitInfo, Requires<CloakInfo>
{
public readonly string[] CloakedTargetTypes = {};
public readonly string[] CloakedTargetTypes = { };
public override object Create(ActorInitializer init) { return new TargetableSubmarine(init.self, this); }
}
@@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA.Traits
public override string[] TargetTypes
{
get { return cloak.Cloaked ? info.CloakedTargetTypes
: info.TargetTypes;}
: info.TargetTypes; }
}
}
}

View File

@@ -13,14 +13,14 @@ using System.Diagnostics;
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Traits;
using OpenRA.Support;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Traits
{
[Desc("Identify untraversable regions of the map for faster pathfinding, especially with AI.",
"This trait is required. Every mod needs it attached to the world actor.")]
class DomainIndexInfo : TraitInfo<DomainIndex> {}
class DomainIndexInfo : TraitInfo<DomainIndex> { }
public class DomainIndex : IWorldLoaded
{

View File

@@ -27,7 +27,8 @@ namespace OpenRA.Mods.RA.Traits
public class PathFinder
{
readonly static List<CPos> emptyPath = new List<CPos>(0);
const int MaxPathAge = 50; /* x 40ms ticks */
static readonly List<CPos> emptyPath = new List<CPos>(0);
readonly World world;
public PathFinder(World world) { this.world = world; }
@@ -42,7 +43,6 @@ namespace OpenRA.Mods.RA.Traits
}
List<CachedPath> CachedPaths = new List<CachedPath>();
const int MaxPathAge = 50; /* x 40ms ticks */
public List<CPos> FindUnitPath(CPos from, CPos target, Actor self)
{
@@ -75,8 +75,7 @@ namespace OpenRA.Mods.RA.Traits
.Reverse();
var pb = FindBidiPath(
fromPoint,
fromPointReverse
);
fromPointReverse);
CheckSanePath2(pb, from, target);
@@ -92,7 +91,7 @@ namespace OpenRA.Mods.RA.Traits
{
var mi = self.Info.Traits.Get<MobileInfo>();
var targetCell = self.World.Map.CellContaining(target);
var rangeSquared = range.Range*range.Range;
var rangeSquared = range.Range * range.Range;
// Correct for SubCell offset
target -= self.World.Map.OffsetOfSubCell(srcSub);
@@ -116,8 +115,7 @@ namespace OpenRA.Mods.RA.Traits
var path = FindBidiPath(
PathSearch.FromPoints(world, mi, self, tilesInRange, src, true),
PathSearch.FromPoint(world, mi, self, src, targetCell, true).Reverse()
);
PathSearch.FromPoint(world, mi, self, src, targetCell, true).Reverse());
return path;
}
@@ -231,6 +229,7 @@ namespace OpenRA.Mods.RA.Traits
ret.Add(q);
q = ca[q].Path;
}
ret.Add(q);
ret.Reverse();

View File

@@ -339,7 +339,6 @@ namespace OpenRA.Mods.RA.Traits
result.CopyValuesFrom(defaultCellInfoLayer);
}
return result;
}