Merge pull request #10537 from pchote/move-util

Move OpenRA.Traits.Util to Mods.Common
This commit is contained in:
abcdefg30
2016-01-21 17:13:03 +01:00
47 changed files with 170 additions and 130 deletions

View File

@@ -145,7 +145,7 @@ namespace OpenRA
public void Tick() public void Tick()
{ {
var wasIdle = IsIdle; var wasIdle = IsIdle;
currentActivity = Traits.Util.RunActivity(this, currentActivity); currentActivity = ActivityUtils.RunActivity(this, currentActivity);
if (!wasIdle && IsIdle) if (!wasIdle && IsIdle)
foreach (var n in TraitsImplementing<INotifyBecomingIdle>()) foreach (var n in TraitsImplementing<INotifyBecomingIdle>())

View File

@@ -181,7 +181,6 @@
<Compile Include="Traits\Selectable.cs" /> <Compile Include="Traits\Selectable.cs" />
<Compile Include="Traits\Target.cs" /> <Compile Include="Traits\Target.cs" />
<Compile Include="Traits\TraitsInterfaces.cs" /> <Compile Include="Traits\TraitsInterfaces.cs" />
<Compile Include="Traits\Util.cs" />
<Compile Include="Traits\ValidateOrder.cs" /> <Compile Include="Traits\ValidateOrder.cs" />
<Compile Include="Traits\World\Faction.cs" /> <Compile Include="Traits\World\Faction.cs" />
<Compile Include="Traits\World\ResourceType.cs" /> <Compile Include="Traits\World\ResourceType.cs" />
@@ -255,6 +254,7 @@
<Compile Include="Primitives\ObservableList.cs" /> <Compile Include="Primitives\ObservableList.cs" />
<Compile Include="Graphics\RgbaColorRenderer.cs" /> <Compile Include="Graphics\RgbaColorRenderer.cs" />
<Compile Include="Traits\Player\IndexedPlayerPalette.cs" /> <Compile Include="Traits\Player\IndexedPlayerPalette.cs" />
<Compile Include="Traits\ActivityUtils.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="FileSystem\D2kSoundResources.cs" /> <Compile Include="FileSystem\D2kSoundResources.cs" />

View File

@@ -0,0 +1,59 @@
#region Copyright & License Information
/*
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System.Diagnostics;
using System.Linq;
using OpenRA.Activities;
using OpenRA.Support;
namespace OpenRA.Traits
{
public static class ActivityUtils
{
public static Activity RunActivity(Actor self, Activity act)
{
// PERF: If there are no activities we can bail straight away and save ourselves a call to
// Stopwatch.GetTimestamp.
if (act == null)
return act;
// PERF: This is a hot path and must run with minimal added overhead.
// Calling Stopwatch.GetTimestamp is a bit expensive, so we enumerate manually to allow us to call it only
// once per iteration in the normal case.
// See also: DoTimed
var longTickThresholdInStopwatchTicks = PerfTimer.LongTickThresholdInStopwatchTicks;
var start = Stopwatch.GetTimestamp();
while (act != null)
{
var prev = act;
act = act.Tick(self);
var current = Stopwatch.GetTimestamp();
if (current - start > longTickThresholdInStopwatchTicks)
{
PerfTimer.LogLongTick(start, current, "Activity", prev);
start = Stopwatch.GetTimestamp();
}
else
start = current;
if (prev == act)
break;
}
return act;
}
public static Activity SequenceActivities(params Activity[] acts)
{
return acts.Reverse().Aggregate(
(next, a) => { a.Queue(next); return a; });
}
}
}

View File

@@ -52,12 +52,12 @@ namespace OpenRA.Mods.Common.Activities
// TODO: This should fire each weapon at its maximum range // TODO: This should fire each weapon at its maximum range
if (attackPlane != null && target.IsInRange(self.CenterPosition, attackPlane.Armaments.Select(a => a.Weapon.MinRange).Min())) if (attackPlane != null && target.IsInRange(self.CenterPosition, attackPlane.Armaments.Select(a => a.Weapon.MinRange).Min()))
inner = Util.SequenceActivities(new FlyTimed(ticksUntilTurn, self), new Fly(self, target), new FlyTimed(ticksUntilTurn, self)); inner = ActivityUtils.SequenceActivities(new FlyTimed(ticksUntilTurn, self), new Fly(self, target), new FlyTimed(ticksUntilTurn, self));
else else
inner = Util.SequenceActivities(new Fly(self, target), new FlyTimed(ticksUntilTurn, self)); inner = ActivityUtils.SequenceActivities(new Fly(self, target), new FlyTimed(ticksUntilTurn, self));
} }
inner = Util.RunActivity(self, inner); inner = ActivityUtils.RunActivity(self, inner);
return this; return this;
} }

View File

@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Activities
return this; return this;
} }
return Util.SequenceActivities(new Fly(self, target, minRange, maxRange), this); return ActivityUtils.SequenceActivities(new Fly(self, target, minRange, maxRange), this);
} }
} }
} }

View File

@@ -61,13 +61,13 @@ namespace OpenRA.Mods.Common.Activities
self.CancelActivity(); self.CancelActivity();
self.SetTargetLine(newTarget, Color.Green); self.SetTargetLine(newTarget, Color.Green);
return Util.SequenceActivities(new HeliFly(self, newTarget)); return ActivityUtils.SequenceActivities(new HeliFly(self, newTarget));
} }
// If all ammo pools are depleted and none reload automatically, return to helipad to reload and then move to next activity // If all ammo pools are depleted and none reload automatically, return to helipad to reload and then move to next activity
// TODO: This should check whether there is ammo left that is actually suitable for the target // TODO: This should check whether there is ammo left that is actually suitable for the target
if (ammoPools.All(x => !x.Info.SelfReloads && !x.HasAmmo())) if (ammoPools.All(x => !x.Info.SelfReloads && !x.HasAmmo()))
return Util.SequenceActivities(new HeliReturnToBase(self), NextActivity); return ActivityUtils.SequenceActivities(new HeliReturnToBase(self), NextActivity);
var dist = target.CenterPosition - self.CenterPosition; var dist = target.CenterPosition - self.CenterPosition;

View File

@@ -47,9 +47,9 @@ namespace OpenRA.Mods.Common.Activities
.ClosestTo(self); .ClosestTo(self);
if (nearestHpad == null) if (nearestHpad == null)
return Util.SequenceActivities(new Turn(self, initialFacing), new HeliLand(self, true), NextActivity); return ActivityUtils.SequenceActivities(new Turn(self, initialFacing), new HeliLand(self, true), NextActivity);
else else
return Util.SequenceActivities(new HeliFly(self, Target.FromActor(nearestHpad))); return ActivityUtils.SequenceActivities(new HeliFly(self, Target.FromActor(nearestHpad)));
} }
heli.MakeReservation(dest); heli.MakeReservation(dest);
@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Activities
var exit = dest.Info.TraitInfos<ExitInfo>().FirstOrDefault(); var exit = dest.Info.TraitInfos<ExitInfo>().FirstOrDefault();
var offset = (exit != null) ? exit.SpawnOffset : WVec.Zero; var offset = (exit != null) ? exit.SpawnOffset : WVec.Zero;
return Util.SequenceActivities( return ActivityUtils.SequenceActivities(
new HeliFly(self, Target.FromPos(dest.CenterPosition + offset)), new HeliFly(self, Target.FromPos(dest.CenterPosition + offset)),
new Turn(self, initialFacing), new Turn(self, initialFacing),
new HeliLand(self, false), new HeliLand(self, false),

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Activities
if (host == null) if (host == null)
return NextActivity; return NextActivity;
return Util.SequenceActivities( return ActivityUtils.SequenceActivities(
aircraft.GetResupplyActivities(host).Append(NextActivity).ToArray()); aircraft.GetResupplyActivities(host).Append(NextActivity).ToArray());
} }
} }

View File

@@ -106,12 +106,12 @@ namespace OpenRA.Mods.Common.Activities
self.CancelActivity(); self.CancelActivity();
if (nearestAfld != null) if (nearestAfld != null)
return Util.SequenceActivities(new Fly(self, Target.FromActor(nearestAfld)), new FlyCircle(self)); return ActivityUtils.SequenceActivities(new Fly(self, Target.FromActor(nearestAfld)), new FlyCircle(self));
else else
return new FlyCircle(self); return new FlyCircle(self);
} }
return Util.SequenceActivities( return ActivityUtils.SequenceActivities(
new Fly(self, Target.FromPos(w1)), new Fly(self, Target.FromPos(w1)),
new Fly(self, Target.FromPos(w2)), new Fly(self, Target.FromPos(w2)),
new Fly(self, Target.FromPos(w3)), new Fly(self, Target.FromPos(w3)),

View File

@@ -78,11 +78,11 @@ namespace OpenRA.Mods.Common.Activities
// Try to move within range // Try to move within range
if (move != null && (!Target.IsInRange(self.CenterPosition, maxRange) || Target.IsInRange(self.CenterPosition, minRange))) if (move != null && (!Target.IsInRange(self.CenterPosition, maxRange) || Target.IsInRange(self.CenterPosition, minRange)))
return Util.SequenceActivities(move.MoveWithinRange(Target, minRange, maxRange), this); return ActivityUtils.SequenceActivities(move.MoveWithinRange(Target, minRange, maxRange), this);
var desiredFacing = (Target.CenterPosition - self.CenterPosition).Yaw.Facing; var desiredFacing = (Target.CenterPosition - self.CenterPosition).Yaw.Facing;
if (facing.Facing != desiredFacing) if (facing.Facing != desiredFacing)
return Util.SequenceActivities(new Turn(self, desiredFacing), this); return ActivityUtils.SequenceActivities(new Turn(self, desiredFacing), this);
attack.DoAttack(self, Target, armaments); attack.DoAttack(self, Target, armaments);

View File

@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Activities
// No refineries exist; check again after delay defined in Harvester. // No refineries exist; check again after delay defined in Harvester.
if (harv.LinkedProc == null) if (harv.LinkedProc == null)
return Util.SequenceActivities(new Wait(harv.Info.SearchForDeliveryBuildingDelay), this); return ActivityUtils.SequenceActivities(new Wait(harv.Info.SearchForDeliveryBuildingDelay), this);
var proc = harv.LinkedProc; var proc = harv.LinkedProc;
var iao = proc.Trait<IAcceptResources>(); var iao = proc.Trait<IAcceptResources>();
@@ -68,7 +68,7 @@ namespace OpenRA.Mods.Common.Activities
foreach (var n in notify) foreach (var n in notify)
n.MovingToRefinery(self, proc.Location + iao.DeliveryOffset, next); n.MovingToRefinery(self, proc.Location + iao.DeliveryOffset, next);
return Util.SequenceActivities(movement.MoveTo(proc.Location + iao.DeliveryOffset, 0), this); return ActivityUtils.SequenceActivities(movement.MoveTo(proc.Location + iao.DeliveryOffset, 0), this);
} }
if (!isDocking) if (!isDocking)
@@ -77,7 +77,7 @@ namespace OpenRA.Mods.Common.Activities
iao.OnDock(self, this); iao.OnDock(self, this);
} }
return Util.SequenceActivities(new Wait(10), this); return ActivityUtils.SequenceActivities(new Wait(10), this);
} }
// Cannot be cancelled // Cannot be cancelled

View File

@@ -252,10 +252,10 @@ namespace OpenRA.Mods.Common.Activities
Activity CanceledTick(Actor self) Activity CanceledTick(Actor self)
{ {
if (inner == null) if (inner == null)
return Util.RunActivity(self, NextActivity); return ActivityUtils.RunActivity(self, NextActivity);
inner.Cancel(self); inner.Cancel(self);
inner.Queue(NextActivity); inner.Queue(NextActivity);
return Util.RunActivity(self, inner); return ActivityUtils.RunActivity(self, inner);
} }
public override Activity Tick(Actor self) public override Activity Tick(Actor self)
@@ -272,7 +272,7 @@ namespace OpenRA.Mods.Common.Activities
return CanceledTick(self); return CanceledTick(self);
// Run inner activity/InsideTick // Run inner activity/InsideTick
inner = inner == this ? InsideTick(self) : Util.RunActivity(self, inner); inner = inner == this ? InsideTick(self) : ActivityUtils.RunActivity(self, inner);
// If we are finished, move on to next activity // If we are finished, move on to next activity
if (inner == null && nextState == State.Done) if (inner == null && nextState == State.Done)

View File

@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Activities
var nearest = target.Actor.OccupiesSpace.NearestCellTo(mobile.ToCell); var nearest = target.Actor.OccupiesSpace.NearestCellTo(mobile.ToCell);
if ((nearest - mobile.ToCell).LengthSquared > 2) if ((nearest - mobile.ToCell).LengthSquared > 2)
return Util.SequenceActivities(new MoveAdjacentTo(self, target), this); return ActivityUtils.SequenceActivities(new MoveAdjacentTo(self, target), this);
if (!capturable.CaptureInProgress) if (!capturable.CaptureInProgress)
capturable.BeginCapture(self); capturable.BeginCapture(self);

View File

@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Activities
var deliver = new DeliverResources(self); var deliver = new DeliverResources(self);
if (harv.IsFull) if (harv.IsFull)
return Util.SequenceActivities(deliver, NextActivity); return ActivityUtils.SequenceActivities(deliver, NextActivity);
var closestHarvestablePosition = ClosestHarvestablePos(self); var closestHarvestablePosition = ClosestHarvestablePos(self);
@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Activities
} }
var randFrames = self.World.SharedRandom.Next(100, 175); var randFrames = self.World.SharedRandom.Next(100, 175);
return Util.SequenceActivities(NextActivity, new Wait(randFrames), this); return ActivityUtils.SequenceActivities(NextActivity, new Wait(randFrames), this);
} }
else else
{ {
@@ -90,7 +90,7 @@ namespace OpenRA.Mods.Common.Activities
if (territory != null) if (territory != null)
{ {
if (!territory.ClaimResource(self, closestHarvestablePosition.Value)) if (!territory.ClaimResource(self, closestHarvestablePosition.Value))
return Util.SequenceActivities(new Wait(25), next); return ActivityUtils.SequenceActivities(new Wait(25), next);
} }
// If not given a direct order, assume ordered to the first resource location we find: // If not given a direct order, assume ordered to the first resource location we find:
@@ -104,7 +104,7 @@ namespace OpenRA.Mods.Common.Activities
foreach (var n in notify) foreach (var n in notify)
n.MovingToResources(self, closestHarvestablePosition.Value, next); n.MovingToResources(self, closestHarvestablePosition.Value, next);
return Util.SequenceActivities(mobile.MoveTo(closestHarvestablePosition.Value, 1), new HarvestResource(self), next); return ActivityUtils.SequenceActivities(mobile.MoveTo(closestHarvestablePosition.Value, 1), new HarvestResource(self), next);
} }
} }

View File

@@ -21,12 +21,14 @@ namespace OpenRA.Mods.Common.Activities
readonly IFacing facing; readonly IFacing facing;
readonly ResourceClaimLayer territory; readonly ResourceClaimLayer territory;
readonly ResourceLayer resLayer; readonly ResourceLayer resLayer;
readonly BodyOrientation body;
public HarvestResource(Actor self) public HarvestResource(Actor self)
{ {
harv = self.Trait<Harvester>(); harv = self.Trait<Harvester>();
harvInfo = self.Info.TraitInfo<HarvesterInfo>(); harvInfo = self.Info.TraitInfo<HarvesterInfo>();
facing = self.Trait<IFacing>(); facing = self.Trait<IFacing>();
body = self.Trait<BodyOrientation>();
territory = self.World.WorldActor.TraitOrDefault<ResourceClaimLayer>(); territory = self.World.WorldActor.TraitOrDefault<ResourceClaimLayer>();
resLayer = self.World.WorldActor.Trait<ResourceLayer>(); resLayer = self.World.WorldActor.Trait<ResourceLayer>();
} }
@@ -53,9 +55,9 @@ namespace OpenRA.Mods.Common.Activities
if (harvInfo.HarvestFacings != 0) if (harvInfo.HarvestFacings != 0)
{ {
var current = facing.Facing; var current = facing.Facing;
var desired = Util.QuantizeFacing(current, harvInfo.HarvestFacings) * (256 / harvInfo.HarvestFacings); var desired = body.QuantizeFacing(current, harvInfo.HarvestFacings);
if (desired != current) if (desired != current)
return Util.SequenceActivities(new Turn(self, desired), this); return ActivityUtils.SequenceActivities(new Turn(self, desired), this);
} }
var resource = resLayer.Harvest(self.Location); var resource = resLayer.Harvest(self.Location);
@@ -71,7 +73,7 @@ namespace OpenRA.Mods.Common.Activities
foreach (var t in self.TraitsImplementing<INotifyHarvesterAction>()) foreach (var t in self.TraitsImplementing<INotifyHarvesterAction>())
t.Harvested(self, resource); t.Harvested(self, resource);
return Util.SequenceActivities(new Wait(harvInfo.LoadTicksPerBale), this); return ActivityUtils.SequenceActivities(new Wait(harvInfo.LoadTicksPerBale), this);
} }
} }
} }

View File

@@ -53,8 +53,8 @@ namespace OpenRA.Mods.Common.Activities
case State.Turn: case State.Turn:
dockingState = State.Dock; dockingState = State.Dock;
if (IsDragRequired) if (IsDragRequired)
return Util.SequenceActivities(new Turn(self, DockAngle), new Drag(self, StartDrag, EndDrag, DragLength), this); return ActivityUtils.SequenceActivities(new Turn(self, DockAngle), new Drag(self, StartDrag, EndDrag, DragLength), this);
return Util.SequenceActivities(new Turn(self, DockAngle), this); return ActivityUtils.SequenceActivities(new Turn(self, DockAngle), this);
case State.Dock: case State.Dock:
if (Refinery.IsInWorld && !Refinery.IsDead) if (Refinery.IsInWorld && !Refinery.IsDead)
foreach (var nd in Refinery.TraitsImplementing<INotifyDocking>()) foreach (var nd in Refinery.TraitsImplementing<INotifyDocking>())
@@ -73,7 +73,7 @@ namespace OpenRA.Mods.Common.Activities
Harv.LastLinkedProc = Harv.LinkedProc; Harv.LastLinkedProc = Harv.LinkedProc;
Harv.LinkProc(self, null); Harv.LinkProc(self, null);
if (IsDragRequired) if (IsDragRequired)
return Util.SequenceActivities(new Drag(self, EndDrag, StartDrag, DragLength), NextActivity); return ActivityUtils.SequenceActivities(new Drag(self, EndDrag, StartDrag, DragLength), NextActivity);
return NextActivity; return NextActivity;
} }

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Activities
if (target == null) if (target == null)
return this; return this;
return Util.SequenceActivities( return ActivityUtils.SequenceActivities(
new AttackMoveActivity(self, new Move(self, target.Location, WDist.FromCells(2))), new AttackMoveActivity(self, new Move(self, target.Location, WDist.FromCells(2))),
new Wait(25), new Wait(25),
this); this);

View File

@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Activities
if (inner == null) if (inner == null)
return NextActivity; return NextActivity;
inner = Util.RunActivity(self, inner); inner = ActivityUtils.RunActivity(self, inner);
return this; return this;
} }

View File

@@ -41,10 +41,10 @@ namespace OpenRA.Mods.Common.Activities
if (target.IsInRange(self.CenterPosition, maxRange) && !target.IsInRange(self.CenterPosition, minRange)) if (target.IsInRange(self.CenterPosition, maxRange) && !target.IsInRange(self.CenterPosition, minRange))
{ {
var wait = new WaitFor(() => !target.IsValidFor(self) || target.CenterPosition != cachedPosition); var wait = new WaitFor(() => !target.IsValidFor(self) || target.CenterPosition != cachedPosition);
return Util.SequenceActivities(wait, path, this); return ActivityUtils.SequenceActivities(wait, path, this);
} }
return Util.SequenceActivities(path, this); return ActivityUtils.SequenceActivities(path, this);
} }
} }
} }

View File

@@ -182,7 +182,7 @@ namespace OpenRA.Mods.Common.Activities
if (firstFacing != mobile.Facing) if (firstFacing != mobile.Facing)
{ {
path.Add(nextCell.Value.First); path.Add(nextCell.Value.First);
return Util.SequenceActivities(new Turn(self, firstFacing), this); return ActivityUtils.SequenceActivities(new Turn(self, firstFacing), this);
} }
else else
{ {

View File

@@ -90,7 +90,7 @@ namespace OpenRA.Mods.Common.Activities
inner.Cancel(self); inner.Cancel(self);
self.SetTargetLine(Target.FromCell(self.World, targetPosition), Color.Green); self.SetTargetLine(Target.FromCell(self.World, targetPosition), Color.Green);
return Util.RunActivity(self, new AttackMoveActivity(self, mobile.MoveTo(targetPosition, 0))); return ActivityUtils.RunActivity(self, new AttackMoveActivity(self, mobile.MoveTo(targetPosition, 0)));
} }
// Inner move order has completed. // Inner move order has completed.
@@ -129,7 +129,7 @@ namespace OpenRA.Mods.Common.Activities
} }
// Ticks the inner move activity to actually move the actor. // Ticks the inner move activity to actually move the actor.
inner = Util.RunActivity(self, inner); inner = ActivityUtils.RunActivity(self, inner);
return this; return this;
} }

View File

@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Activities
{ {
self.NotifyBlocker(BlockedExitCells(actor)); self.NotifyBlocker(BlockedExitCells(actor));
return Util.SequenceActivities(new Wait(10), this); return ActivityUtils.SequenceActivities(new Wait(10), this);
} }
cargo.Unload(self); cargo.Unload(self);

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Activities
return NextActivity; return NextActivity;
} }
inner = Util.RunActivity(self, inner); inner = ActivityUtils.RunActivity(self, inner);
return this; return this;
} }

View File

@@ -115,7 +115,7 @@ namespace OpenRA.Mods.Common.Effects
target = args.PassiveTarget; target = args.PassiveTarget;
if (info.Inaccuracy.Length > 0) if (info.Inaccuracy.Length > 0)
{ {
var inaccuracy = OpenRA.Traits.Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers); var inaccuracy = Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers);
var maxOffset = inaccuracy * (target - headPos).Length / args.Weapon.Range.Length; var maxOffset = inaccuracy * (target - headPos).Length / args.Weapon.Range.Length;
target += WVec.FromPDF(world.SharedRandom, 2) * maxOffset / 1024; target += WVec.FromPDF(world.SharedRandom, 2) * maxOffset / 1024;
} }

View File

@@ -116,8 +116,8 @@ namespace OpenRA.Mods.Common.Effects
target = args.PassiveTarget; target = args.PassiveTarget;
if (info.Inaccuracy.Length > 0) if (info.Inaccuracy.Length > 0)
{ {
var inaccuracy = OpenRA.Traits.Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers); var inaccuracy = Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers);
var range = OpenRA.Traits.Util.ApplyPercentageModifiers(args.Weapon.Range.Length, args.RangeModifiers); var range = Util.ApplyPercentageModifiers(args.Weapon.Range.Length, args.RangeModifiers);
var maxOffset = inaccuracy * (target - pos).Length / range; var maxOffset = inaccuracy * (target - pos).Length / range;
target += WVec.FromPDF(world.SharedRandom, 2) * maxOffset / 1024; target += WVec.FromPDF(world.SharedRandom, 2) * maxOffset / 1024;
} }

View File

@@ -14,6 +14,7 @@ using System.Linq;
using OpenRA.Effects; using OpenRA.Effects;
using OpenRA.GameRules; using OpenRA.GameRules;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Mods.Common;
using OpenRA.Mods.Common.Graphics; using OpenRA.Mods.Common.Graphics;
using OpenRA.Mods.Common.Traits; using OpenRA.Mods.Common.Traits;
using OpenRA.Traits; using OpenRA.Traits;
@@ -200,7 +201,7 @@ namespace OpenRA.Mods.Common.Effects
if (info.Inaccuracy.Length > 0) if (info.Inaccuracy.Length > 0)
{ {
var inaccuracy = OpenRA.Traits.Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers); var inaccuracy = Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers);
offset = WVec.FromPDF(world.SharedRandom, 2) * inaccuracy / 1024; offset = WVec.FromPDF(world.SharedRandom, 2) * inaccuracy / 1024;
} }
@@ -723,8 +724,8 @@ namespace OpenRA.Mods.Common.Effects
desiredHFacing = hFacing; desiredHFacing = hFacing;
// Compute new direction the projectile will be facing // Compute new direction the projectile will be facing
hFacing = OpenRA.Traits.Util.TickFacing(hFacing, desiredHFacing, info.HorizontalRateOfTurn); hFacing = Util.TickFacing(hFacing, desiredHFacing, info.HorizontalRateOfTurn);
vFacing = OpenRA.Traits.Util.TickFacing(vFacing, desiredVFacing, info.VerticalRateOfTurn); vFacing = Util.TickFacing(vFacing, desiredVFacing, info.VerticalRateOfTurn);
// Compute the projectile's guided displacement // Compute the projectile's guided displacement
return new WVec(0, -1024 * speed, 0) return new WVec(0, -1024 * speed, 0)

View File

@@ -237,7 +237,7 @@ namespace OpenRA.Mods.Common.Graphics
protected virtual Sprite GetSprite(int start, int frame, int facing) protected virtual Sprite GetSprite(int start, int frame, int facing)
{ {
var f = OpenRA.Traits.Util.QuantizeFacing(facing, Facings); var f = Util.QuantizeFacing(facing, Facings);
if (reverseFacings) if (reverseFacings)
f = (Facings - f) % Facings; f = (Facings - f) % Facings;

View File

@@ -144,19 +144,19 @@ namespace OpenRA.Mods.Common.Graphics
// Draw voxel bounding box // Draw voxel bounding box
var draw = voxel.voxels.Where(v => v.DisableFunc == null || !v.DisableFunc()); var draw = voxel.voxels.Where(v => v.DisableFunc == null || !v.DisableFunc());
var scaleTransform = Util.ScaleMatrix(voxel.scale, voxel.scale, voxel.scale); var scaleTransform = OpenRA.Graphics.Util.ScaleMatrix(voxel.scale, voxel.scale, voxel.scale);
var cameraTransform = Util.MakeFloatMatrix(voxel.camera.AsMatrix()); var cameraTransform = OpenRA.Graphics.Util.MakeFloatMatrix(voxel.camera.AsMatrix());
foreach (var v in draw) foreach (var v in draw)
{ {
var bounds = v.Voxel.Bounds(v.FrameFunc()); var bounds = v.Voxel.Bounds(v.FrameFunc());
var worldTransform = v.RotationFunc().Reverse().Aggregate(scaleTransform, var worldTransform = v.RotationFunc().Reverse().Aggregate(scaleTransform,
(x, y) => Util.MatrixMultiply(x, Util.MakeFloatMatrix(y.AsMatrix()))); (x, y) => OpenRA.Graphics.Util.MatrixMultiply(x, OpenRA.Graphics.Util.MakeFloatMatrix(y.AsMatrix())));
float sx, sy, sz; float sx, sy, sz;
wr.ScreenVectorComponents(v.OffsetFunc(), out sx, out sy, out sz); wr.ScreenVectorComponents(v.OffsetFunc(), out sx, out sy, out sz);
var pxPos = pxOrigin + new float2(sx, sy); var pxPos = pxOrigin + new float2(sx, sy);
var screenTransform = Util.MatrixMultiply(cameraTransform, worldTransform); var screenTransform = OpenRA.Graphics.Util.MatrixMultiply(cameraTransform, worldTransform);
DrawBoundsBox(pxPos, screenTransform, bounds, iz, Color.Yellow); DrawBoundsBox(pxPos, screenTransform, bounds, iz, Color.Yellow);
} }
} }
@@ -171,7 +171,7 @@ namespace OpenRA.Mods.Common.Graphics
for (var i = 0; i < 8; i++) for (var i = 0; i < 8; i++)
{ {
var vec = new float[] { bounds[CornerXIndex[i]], bounds[CornerYIndex[i]], bounds[CornerZIndex[i]], 1 }; var vec = new float[] { bounds[CornerXIndex[i]], bounds[CornerYIndex[i]], bounds[CornerZIndex[i]], 1 };
var screen = Util.MatrixVectorMultiply(transform, vec); var screen = OpenRA.Graphics.Util.MatrixVectorMultiply(transform, vec);
corners[i] = pxPos + new float2(screen[0], screen[1]); corners[i] = pxPos + new float2(screen[0], screen[1]);
} }
@@ -192,8 +192,8 @@ namespace OpenRA.Mods.Common.Graphics
{ {
var pxOrigin = wr.ScreenPosition(voxel.pos); var pxOrigin = wr.ScreenPosition(voxel.pos);
var draw = voxel.voxels.Where(v => v.DisableFunc == null || !v.DisableFunc()); var draw = voxel.voxels.Where(v => v.DisableFunc == null || !v.DisableFunc());
var scaleTransform = Util.ScaleMatrix(voxel.scale, voxel.scale, voxel.scale); var scaleTransform = OpenRA.Graphics.Util.ScaleMatrix(voxel.scale, voxel.scale, voxel.scale);
var cameraTransform = Util.MakeFloatMatrix(voxel.camera.AsMatrix()); var cameraTransform = OpenRA.Graphics.Util.MakeFloatMatrix(voxel.camera.AsMatrix());
var minX = float.MaxValue; var minX = float.MaxValue;
var minY = float.MaxValue; var minY = float.MaxValue;
@@ -203,17 +203,17 @@ namespace OpenRA.Mods.Common.Graphics
{ {
var bounds = v.Voxel.Bounds(v.FrameFunc()); var bounds = v.Voxel.Bounds(v.FrameFunc());
var worldTransform = v.RotationFunc().Reverse().Aggregate(scaleTransform, var worldTransform = v.RotationFunc().Reverse().Aggregate(scaleTransform,
(x, y) => Util.MatrixMultiply(x, Util.MakeFloatMatrix(y.AsMatrix()))); (x, y) => OpenRA.Graphics.Util.MatrixMultiply(x, OpenRA.Graphics.Util.MakeFloatMatrix(y.AsMatrix())));
float sx, sy, sz; float sx, sy, sz;
wr.ScreenVectorComponents(v.OffsetFunc(), out sx, out sy, out sz); wr.ScreenVectorComponents(v.OffsetFunc(), out sx, out sy, out sz);
var pxPos = pxOrigin + new float2(sx, sy); var pxPos = pxOrigin + new float2(sx, sy);
var screenTransform = Util.MatrixMultiply(cameraTransform, worldTransform); var screenTransform = OpenRA.Graphics.Util.MatrixMultiply(cameraTransform, worldTransform);
for (var i = 0; i < 8; i++) for (var i = 0; i < 8; i++)
{ {
var vec = new float[] { bounds[CornerXIndex[i]], bounds[CornerYIndex[i]], bounds[CornerZIndex[i]], 1 }; var vec = new float[] { bounds[CornerXIndex[i]], bounds[CornerYIndex[i]], bounds[CornerZIndex[i]], 1 };
var screen = Util.MatrixVectorMultiply(screenTransform, vec); var screen = OpenRA.Graphics.Util.MatrixVectorMultiply(screenTransform, vec);
minX = Math.Min(minX, pxPos.X + screen[0]); minX = Math.Min(minX, pxPos.X + screen[0]);
minY = Math.Min(minY, pxPos.Y + screen[1]); minY = Math.Min(minY, pxPos.Y + screen[1]);
maxX = Math.Max(maxX, pxPos.X + screen[0]); maxX = Math.Max(maxX, pxPos.X + screen[0]);

View File

@@ -730,6 +730,7 @@
<Compile Include="Orders\GuardOrderGenerator.cs" /> <Compile Include="Orders\GuardOrderGenerator.cs" />
<Compile Include="UtilityCommands\CheckExplicitInterfacesCommand.cs" /> <Compile Include="UtilityCommands\CheckExplicitInterfacesCommand.cs" />
<Compile Include="FileFormats\LZOCompression.cs" /> <Compile Include="FileFormats\LZOCompression.cs" />
<Compile Include="Util.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>

View File

@@ -15,7 +15,7 @@ using OpenRA.Graphics;
using OpenRA.Mods.Common.Graphics; using OpenRA.Mods.Common.Graphics;
using OpenRA.Mods.Common.Traits; using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives; using OpenRA.Primitives;
using Util = OpenRA.Traits.Util; using OpenRA.Traits;
namespace OpenRA.Mods.Common.Orders namespace OpenRA.Mods.Common.Orders
{ {

View File

@@ -424,7 +424,7 @@ namespace OpenRA.Mods.Common.Traits
if (IsPlane) if (IsPlane)
return new Fly(self, target, WDist.FromCells(3), WDist.FromCells(5)); return new Fly(self, target, WDist.FromCells(3), WDist.FromCells(5));
return Util.SequenceActivities(new HeliFly(self, target), new Turn(self, Info.InitialFacing)); return ActivityUtils.SequenceActivities(new HeliFly(self, target), new Turn(self, Info.InitialFacing));
} }
public Activity MoveIntoTarget(Actor self, Target target) public Activity MoveIntoTarget(Actor self, Target target)
@@ -439,11 +439,11 @@ namespace OpenRA.Mods.Common.Traits
{ {
// TODO: Ignore repulsion when moving // TODO: Ignore repulsion when moving
if (IsPlane) if (IsPlane)
return Util.SequenceActivities( return ActivityUtils.SequenceActivities(
new CallFunc(() => SetVisualPosition(self, fromPos)), new CallFunc(() => SetVisualPosition(self, fromPos)),
new Fly(self, Target.FromPos(toPos))); new Fly(self, Target.FromPos(toPos)));
return Util.SequenceActivities(new CallFunc(() => SetVisualPosition(self, fromPos)), return ActivityUtils.SequenceActivities(new CallFunc(() => SetVisualPosition(self, fromPos)),
new HeliFly(self, Target.FromPos(toPos))); new HeliFly(self, Target.FromPos(toPos)));
} }
@@ -538,7 +538,7 @@ namespace OpenRA.Mods.Common.Traits
if (IsPlane) if (IsPlane)
{ {
self.QueueActivity(order.Queued, Util.SequenceActivities( self.QueueActivity(order.Queued, ActivityUtils.SequenceActivities(
new ReturnToBase(self, order.TargetActor), new ReturnToBase(self, order.TargetActor),
new ResupplyAircraft(self))); new ResupplyAircraft(self)));
} }

View File

@@ -107,7 +107,7 @@ namespace OpenRA.Mods.Common.Traits
if (!string.IsNullOrEmpty(attack.info.ChargeAudio)) if (!string.IsNullOrEmpty(attack.info.ChargeAudio))
Game.Sound.Play(attack.info.ChargeAudio, self.CenterPosition); Game.Sound.Play(attack.info.ChargeAudio, self.CenterPosition);
return Util.SequenceActivities(new Wait(attack.info.InitialChargeDelay), new ChargeFire(attack, target), this); return ActivityUtils.SequenceActivities(new Wait(attack.info.InitialChargeDelay), new ChargeFire(attack, target), this);
} }
} }
@@ -132,7 +132,7 @@ namespace OpenRA.Mods.Common.Traits
attack.DoAttack(self, target); attack.DoAttack(self, target);
return Util.SequenceActivities(new Wait(attack.info.ChargeDelay), this); return ActivityUtils.SequenceActivities(new Wait(attack.info.ChargeDelay), this);
} }
} }
} }

View File

@@ -95,7 +95,7 @@ namespace OpenRA.Mods.Common.Traits
attack.Target = target; attack.Target = target;
if (move != null) if (move != null)
return Util.SequenceActivities(move.MoveFollow(self, target, weapon.Weapon.MinRange, maxRange), this); return ActivityUtils.SequenceActivities(move.MoveFollow(self, target, weapon.Weapon.MinRange, maxRange), this);
} }
return NextActivity; return NextActivity;

View File

@@ -159,7 +159,7 @@ namespace OpenRA.Mods.Common.Traits
var sequence = a.Info.MuzzleSequence; var sequence = a.Info.MuzzleSequence;
if (a.Info.MuzzleSplitFacings > 0) if (a.Info.MuzzleSplitFacings > 0)
sequence += OpenRA.Traits.Util.QuantizeFacing(muzzleFacing, a.Info.MuzzleSplitFacings).ToString(); sequence += Util.QuantizeFacing(muzzleFacing, a.Info.MuzzleSplitFacings).ToString();
var muzzleFlash = new AnimationWithOffset(muzzleAnim, var muzzleFlash = new AnimationWithOffset(muzzleAnim,
() => PortOffset(self, port), () => PortOffset(self, port),

View File

@@ -42,12 +42,17 @@ namespace OpenRA.Mods.Common.Traits
return orientation; return orientation;
// Map yaw to the closest facing // Map yaw to the closest facing
var facing = Util.QuantizeFacing(orientation.Yaw.Angle / 4, facings) * (256 / facings); var facing = QuantizeFacing(orientation.Yaw.Angle / 4, facings);
// Roll and pitch are always zero if yaw is quantized // Roll and pitch are always zero if yaw is quantized
return new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing)); return new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing));
} }
public int QuantizeFacing(int facing, int facings)
{
return Util.QuantizeFacing(facing, facings) * (256 / facings);
}
public object Create(ActorInitializer init) { return new BodyOrientation(init, this); } public object Create(ActorInitializer init) { return new BodyOrientation(init, this); }
} }
@@ -97,5 +102,15 @@ namespace OpenRA.Mods.Common.Traits
{ {
return info.QuantizeOrientation(orientation, quantizedFacings.Value); return info.QuantizeOrientation(orientation, quantizedFacings.Value);
} }
public int QuantizeFacing(int facing)
{
return info.QuantizeFacing(facing, quantizedFacings.Value);
}
public int QuantizeFacing(int facing, int facings)
{
return info.QuantizeFacing(facing, facings);
}
} }
} }

View File

@@ -682,7 +682,7 @@ namespace OpenRA.Mods.Common.Traits
var notifyBlocking = new CallFunc(() => self.NotifyBlocker(cellInfo.Cell)); var notifyBlocking = new CallFunc(() => self.NotifyBlocker(cellInfo.Cell));
var waitFor = new WaitFor(() => CanEnterCell(cellInfo.Cell)); var waitFor = new WaitFor(() => CanEnterCell(cellInfo.Cell));
var move = new Move(self, cellInfo.Cell); var move = new Move(self, cellInfo.Cell);
self.QueueActivity(Util.SequenceActivities(notifyBlocking, waitFor, move)); self.QueueActivity(ActivityUtils.SequenceActivities(notifyBlocking, waitFor, move));
Log.Write("debug", "OnNudge (notify next blocking actor, wait and move) #{0} from {1} to {2}", Log.Write("debug", "OnNudge (notify next blocking actor, wait and move) #{0} from {1} to {2}",
self.ActorID, self.Location, cellInfo.Cell); self.ActorID, self.Location, cellInfo.Cell);
@@ -797,7 +797,7 @@ namespace OpenRA.Mods.Common.Traits
var delta = toPos - fromPos; var delta = toPos - fromPos;
var facing = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : Facing; var facing = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : Facing;
return Util.SequenceActivities(new Turn(self, facing), new Drag(self, fromPos, toPos, length)); return ActivityUtils.SequenceActivities(new Turn(self, facing), new Drag(self, fromPos, toPos, length));
} }
public void ModifyDeathActorInit(Actor self, TypeDictionary init) public void ModifyDeathActorInit(Actor self, TypeDictionary init)

View File

@@ -84,7 +84,7 @@ namespace OpenRA.Mods.Common.Traits
return; return;
if (a.Info.MuzzleSplitFacings > 0) if (a.Info.MuzzleSplitFacings > 0)
sequence += OpenRA.Traits.Util.QuantizeFacing(getFacing(), a.Info.MuzzleSplitFacings).ToString(); sequence += Util.QuantizeFacing(getFacing(), a.Info.MuzzleSplitFacings).ToString();
if (barrel == null) if (barrel == null)
return; return;

View File

@@ -94,7 +94,7 @@ namespace OpenRA.Mods.Common.Traits
self.SetTargetLine(target, Color.Green); self.SetTargetLine(target, Color.Green);
self.CancelActivity(); self.CancelActivity();
self.QueueActivity(new WaitForTransport(self, Util.SequenceActivities(new MoveAdjacentTo(self, target), self.QueueActivity(new WaitForTransport(self, ActivityUtils.SequenceActivities(new MoveAdjacentTo(self, target),
new CallFunc(() => AfterReachActivities(self, order, movement))))); new CallFunc(() => AfterReachActivities(self, order, movement)))));
TryCallTransport(self, target, new CallFunc(() => AfterReachActivities(self, order, movement))); TryCallTransport(self, target, new CallFunc(() => AfterReachActivities(self, order, movement)));

View File

@@ -58,7 +58,7 @@ namespace OpenRA.Mods.Common.Traits
var info = Info as AirstrikePowerInfo; var info = Info as AirstrikePowerInfo;
if (randomize) if (randomize)
attackFacing = Util.QuantizeFacing(self.World.SharedRandom.Next(256), info.QuantizedFacings) * (256 / info.QuantizedFacings); attackFacing = 256 * self.World.SharedRandom.Next(info.QuantizedFacings) / info.QuantizedFacings;
var altitude = self.World.Map.Rules.Actors[info.UnitType].TraitInfo<AircraftInfo>().CruiseAltitude.Length; var altitude = self.World.Map.Rules.Actors[info.UnitType].TraitInfo<AircraftInfo>().CruiseAltitude.Length;
var attackRotation = WRot.FromFacing(attackFacing); var attackRotation = WRot.FromFacing(attackFacing);

View File

@@ -133,7 +133,7 @@ namespace OpenRA.Mods.Common.Traits
// 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 = Util.QuantizeFacing(local.Yaw.Angle / 4, QuantizedFacings) * (256 / QuantizedFacings); var facing = body.QuantizeFacing(local.Yaw.Angle / 4, QuantizedFacings);
return new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing)); return new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing));
} }

View File

@@ -108,7 +108,7 @@ namespace OpenRA.Mods.Common.Traits
if (info.DeliveryAircraft != null) if (info.DeliveryAircraft != null)
{ {
var crate = w.CreateActor(false, crateActor, new TypeDictionary { new OwnerInit(w.WorldActor.Owner) }); var crate = w.CreateActor(false, crateActor, new TypeDictionary { new OwnerInit(w.WorldActor.Owner) });
var dropFacing = Util.QuantizeFacing(self.World.SharedRandom.Next(256), info.QuantizedFacings) * (256 / info.QuantizedFacings); var dropFacing = 256 * self.World.SharedRandom.Next(info.QuantizedFacings) / info.QuantizedFacings;
var delta = new WVec(0, -1024, 0).Rotate(WRot.FromFacing(dropFacing)); var delta = new WVec(0, -1024, 0).Rotate(WRot.FromFacing(dropFacing));
var altitude = self.World.Map.Rules.Actors[info.DeliveryAircraft].TraitInfo<AircraftInfo>().CruiseAltitude.Length; var altitude = self.World.Map.Rules.Actors[info.DeliveryAircraft].TraitInfo<AircraftInfo>().CruiseAltitude.Length;

View File

@@ -190,14 +190,14 @@ namespace OpenRA.Mods.Common.Traits
void UpdateNeighbours(IReadOnlyDictionary<CPos, SubCell> footprint) void UpdateNeighbours(IReadOnlyDictionary<CPos, SubCell> footprint)
{ {
// Include actors inside the footprint too // Include actors inside the footprint too
var cells = OpenRA.Traits.Util.ExpandFootprint(footprint.Keys, true); var cells = Util.ExpandFootprint(footprint.Keys, true);
foreach (var p in cells.SelectMany(c => PreviewsAt(c))) foreach (var p in cells.SelectMany(c => PreviewsAt(c)))
p.ReplaceInit(new RuntimeNeighbourInit(NeighbouringPreviews(p.Footprint))); p.ReplaceInit(new RuntimeNeighbourInit(NeighbouringPreviews(p.Footprint)));
} }
Dictionary<CPos, string[]> NeighbouringPreviews(IReadOnlyDictionary<CPos, SubCell> footprint) Dictionary<CPos, string[]> NeighbouringPreviews(IReadOnlyDictionary<CPos, SubCell> footprint)
{ {
var cells = OpenRA.Traits.Util.ExpandFootprint(footprint.Keys, true).Except(footprint.Keys); var cells = Util.ExpandFootprint(footprint.Keys, true).Except(footprint.Keys);
return cells.ToDictionary(c => c, c => PreviewsAt(c).Select(p => p.Info.Name).ToArray()); return cells.ToDictionary(c => c, c => PreviewsAt(c).Select(p => p.Info.Name).ToArray());
} }

View File

@@ -10,12 +10,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using OpenRA.Activities;
using OpenRA.Support; using OpenRA.Support;
using OpenRA.Traits;
namespace OpenRA.Traits namespace OpenRA.Mods.Common
{ {
public static class Util public static class Util
{ {
@@ -54,45 +53,6 @@ namespace OpenRA.Traits
return WPos.Lerp(w.Map.CenterOfCell(from), w.Map.CenterOfCell(to), 1, 2); return WPos.Lerp(w.Map.CenterOfCell(from), w.Map.CenterOfCell(to), 1, 2);
} }
public static Activity SequenceActivities(params Activity[] acts)
{
return acts.Reverse().Aggregate(
(next, a) => { a.Queue(next); return a; });
}
public static Activity RunActivity(Actor self, Activity act)
{
// PERF: If there are no activities we can bail straight away and save ourselves a call to
// Stopwatch.GetTimestamp.
if (act == null)
return act;
// PERF: This is a hot path and must run with minimal added overhead.
// Calling Stopwatch.GetTimestamp is a bit expensive, so we enumerate manually to allow us to call it only
// once per iteration in the normal case.
// See also: DoTimed
var longTickThresholdInStopwatchTicks = PerfTimer.LongTickThresholdInStopwatchTicks;
var start = Stopwatch.GetTimestamp();
while (act != null)
{
var prev = act;
act = act.Tick(self);
var current = Stopwatch.GetTimestamp();
if (current - start > longTickThresholdInStopwatchTicks)
{
PerfTimer.LogLongTick(start, current, "Activity", prev);
start = Stopwatch.GetTimestamp();
}
else
start = current;
if (prev == act)
break;
}
return act;
}
/* pretty crap */ /* pretty crap */
public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> ts, MersenneTwister random) public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> ts, MersenneTwister random)
{ {

View File

@@ -9,6 +9,7 @@
#endregion #endregion
using OpenRA.Activities; using OpenRA.Activities;
using OpenRA.Mods.Common;
using OpenRA.Mods.Common.Activities; using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Traits; using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.D2k.Traits; using OpenRA.Mods.D2k.Traits;
@@ -86,7 +87,7 @@ namespace OpenRA.Mods.D2k.Activities
case State.Transport: case State.Transport:
var targetl = GetLocationToDrop(carryable.Destination); var targetl = GetLocationToDrop(carryable.Destination);
state = State.Land; state = State.Land;
return Util.SequenceActivities(movement.MoveTo(targetl, 0), this); return ActivityUtils.SequenceActivities(movement.MoveTo(targetl, 0), this);
case State.Land: case State.Land:
if (!CanDropHere()) if (!CanDropHere())
@@ -98,7 +99,7 @@ namespace OpenRA.Mods.D2k.Activities
if (HeliFly.AdjustAltitude(self, aircraft, aircraft.Info.LandAltitude)) if (HeliFly.AdjustAltitude(self, aircraft, aircraft.Info.LandAltitude))
return this; return this;
state = State.Release; state = State.Release;
return Util.SequenceActivities(new Wait(15), this); return ActivityUtils.SequenceActivities(new Wait(15), this);
case State.Release: case State.Release:
if (!CanDropHere()) if (!CanDropHere())

View File

@@ -9,6 +9,7 @@
#endregion #endregion
using OpenRA.Activities; using OpenRA.Activities;
using OpenRA.Mods.Common;
using OpenRA.Mods.Common.Activities; using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Traits; using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.D2k.Traits; using OpenRA.Mods.D2k.Traits;
@@ -54,7 +55,7 @@ namespace OpenRA.Mods.D2k.Activities
{ {
case State.Intercept: case State.Intercept:
state = State.LockCarryable; state = State.LockCarryable;
return Util.SequenceActivities(movement.MoveWithinRange(Target.FromActor(cargo), WDist.FromCells(4)), this); return ActivityUtils.SequenceActivities(movement.MoveWithinRange(Target.FromActor(cargo), WDist.FromCells(4)), this);
case State.LockCarryable: case State.LockCarryable:
// Last check // Last check
@@ -75,13 +76,13 @@ namespace OpenRA.Mods.D2k.Activities
return this; return this;
} }
return Util.SequenceActivities(movement.MoveTo(cargo.Location, 0), this); return ActivityUtils.SequenceActivities(movement.MoveTo(cargo.Location, 0), this);
case State.Turn: // Align facing and Land case State.Turn: // Align facing and Land
if (selfFacing.Facing != cargoFacing.Facing) if (selfFacing.Facing != cargoFacing.Facing)
return Util.SequenceActivities(new Turn(self, cargoFacing.Facing), this); return ActivityUtils.SequenceActivities(new Turn(self, cargoFacing.Facing), this);
state = State.Pickup; state = State.Pickup;
return Util.SequenceActivities(new HeliLand(self, false), new Wait(10), this); return ActivityUtils.SequenceActivities(new HeliLand(self, false), new Wait(10), this);
case State.Pickup: case State.Pickup:
// Remove our carryable from world // Remove our carryable from world

View File

@@ -52,7 +52,7 @@ namespace OpenRA.Mods.RA.Activities
if (rearmTarget == null) if (rearmTarget == null)
return new Wait(20); return new Wait(20);
return Util.SequenceActivities( return ActivityUtils.SequenceActivities(
new MoveAdjacentTo(self, Target.FromActor(rearmTarget)), new MoveAdjacentTo(self, Target.FromActor(rearmTarget)),
movement.MoveTo(self.World.Map.CellContaining(rearmTarget.CenterPosition), rearmTarget), movement.MoveTo(self.World.Map.CellContaining(rearmTarget.CenterPosition), rearmTarget),
new Rearm(self), new Rearm(self),
@@ -63,7 +63,7 @@ namespace OpenRA.Mods.RA.Activities
if (minelayer.Minefield.Contains(self.Location) && ShouldLayMine(self, self.Location)) if (minelayer.Minefield.Contains(self.Location) && ShouldLayMine(self, self.Location))
{ {
LayMine(self); LayMine(self);
return Util.SequenceActivities(new Wait(20), this); // A little wait after placing each mine, for show return ActivityUtils.SequenceActivities(new Wait(20), this); // A little wait after placing each mine, for show
} }
if (minelayer.Minefield.Length > 0) if (minelayer.Minefield.Length > 0)
@@ -73,7 +73,7 @@ namespace OpenRA.Mods.RA.Activities
{ {
var p = minelayer.Minefield.Random(self.World.SharedRandom); var p = minelayer.Minefield.Random(self.World.SharedRandom);
if (ShouldLayMine(self, p)) if (ShouldLayMine(self, p))
return Util.SequenceActivities(movement.MoveTo(p, 0), this); return ActivityUtils.SequenceActivities(movement.MoveTo(p, 0), this);
} }
} }

View File

@@ -70,7 +70,7 @@ namespace OpenRA.Mods.RA.Traits
var info = Info as ParatroopersPowerInfo; var info = Info as ParatroopersPowerInfo;
if (randomize) if (randomize)
dropFacing = Util.QuantizeFacing(self.World.SharedRandom.Next(256), info.QuantizedFacings) * (256 / info.QuantizedFacings); dropFacing = 256 * self.World.SharedRandom.Next(info.QuantizedFacings) / info.QuantizedFacings;
var altitude = self.World.Map.Rules.Actors[info.UnitType].TraitInfo<AircraftInfo>().CruiseAltitude.Length; var altitude = self.World.Map.Rules.Actors[info.UnitType].TraitInfo<AircraftInfo>().CruiseAltitude.Length;
var dropRotation = WRot.FromFacing(dropFacing); var dropRotation = WRot.FromFacing(dropFacing);