diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index 0a921a3f74..bf211ac472 100644 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -145,7 +145,7 @@ namespace OpenRA public void Tick() { var wasIdle = IsIdle; - currentActivity = Traits.Util.RunActivity(this, currentActivity); + currentActivity = ActivityUtils.RunActivity(this, currentActivity); if (!wasIdle && IsIdle) foreach (var n in TraitsImplementing()) diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 7b7f6bf06d..f8c5e82aa7 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -181,7 +181,6 @@ - @@ -255,6 +254,7 @@ + diff --git a/OpenRA.Game/Traits/ActivityUtils.cs b/OpenRA.Game/Traits/ActivityUtils.cs new file mode 100644 index 0000000000..de79bb307e --- /dev/null +++ b/OpenRA.Game/Traits/ActivityUtils.cs @@ -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; }); + } + } +} diff --git a/OpenRA.Mods.Common/Activities/Air/FlyAttack.cs b/OpenRA.Mods.Common/Activities/Air/FlyAttack.cs index 842ca1afa3..d0f43cb864 100644 --- a/OpenRA.Mods.Common/Activities/Air/FlyAttack.cs +++ b/OpenRA.Mods.Common/Activities/Air/FlyAttack.cs @@ -52,12 +52,12 @@ namespace OpenRA.Mods.Common.Activities // 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())) - 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 - 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; } diff --git a/OpenRA.Mods.Common/Activities/Air/FlyFollow.cs b/OpenRA.Mods.Common/Activities/Air/FlyFollow.cs index 5b717d1af5..012f760a8f 100644 --- a/OpenRA.Mods.Common/Activities/Air/FlyFollow.cs +++ b/OpenRA.Mods.Common/Activities/Air/FlyFollow.cs @@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Activities return this; } - return Util.SequenceActivities(new Fly(self, target, minRange, maxRange), this); + return ActivityUtils.SequenceActivities(new Fly(self, target, minRange, maxRange), this); } } } diff --git a/OpenRA.Mods.Common/Activities/Air/HeliAttack.cs b/OpenRA.Mods.Common/Activities/Air/HeliAttack.cs index 7e0754bdf1..47fc7971e0 100644 --- a/OpenRA.Mods.Common/Activities/Air/HeliAttack.cs +++ b/OpenRA.Mods.Common/Activities/Air/HeliAttack.cs @@ -61,13 +61,13 @@ namespace OpenRA.Mods.Common.Activities self.CancelActivity(); 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 // 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())) - return Util.SequenceActivities(new HeliReturnToBase(self), NextActivity); + return ActivityUtils.SequenceActivities(new HeliReturnToBase(self), NextActivity); var dist = target.CenterPosition - self.CenterPosition; diff --git a/OpenRA.Mods.Common/Activities/Air/HeliReturnToBase.cs b/OpenRA.Mods.Common/Activities/Air/HeliReturnToBase.cs index 2211911e36..338ddfa374 100644 --- a/OpenRA.Mods.Common/Activities/Air/HeliReturnToBase.cs +++ b/OpenRA.Mods.Common/Activities/Air/HeliReturnToBase.cs @@ -47,9 +47,9 @@ namespace OpenRA.Mods.Common.Activities .ClosestTo(self); 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 - return Util.SequenceActivities(new HeliFly(self, Target.FromActor(nearestHpad))); + return ActivityUtils.SequenceActivities(new HeliFly(self, Target.FromActor(nearestHpad))); } heli.MakeReservation(dest); @@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Activities var exit = dest.Info.TraitInfos().FirstOrDefault(); var offset = (exit != null) ? exit.SpawnOffset : WVec.Zero; - return Util.SequenceActivities( + return ActivityUtils.SequenceActivities( new HeliFly(self, Target.FromPos(dest.CenterPosition + offset)), new Turn(self, initialFacing), new HeliLand(self, false), diff --git a/OpenRA.Mods.Common/Activities/Air/ResupplyAircraft.cs b/OpenRA.Mods.Common/Activities/Air/ResupplyAircraft.cs index e961afeb3b..5dcfb334a8 100644 --- a/OpenRA.Mods.Common/Activities/Air/ResupplyAircraft.cs +++ b/OpenRA.Mods.Common/Activities/Air/ResupplyAircraft.cs @@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Activities if (host == null) return NextActivity; - return Util.SequenceActivities( + return ActivityUtils.SequenceActivities( aircraft.GetResupplyActivities(host).Append(NextActivity).ToArray()); } } diff --git a/OpenRA.Mods.Common/Activities/Air/ReturnToBase.cs b/OpenRA.Mods.Common/Activities/Air/ReturnToBase.cs index e38ecc08e4..bbbf7c66d2 100644 --- a/OpenRA.Mods.Common/Activities/Air/ReturnToBase.cs +++ b/OpenRA.Mods.Common/Activities/Air/ReturnToBase.cs @@ -106,12 +106,12 @@ namespace OpenRA.Mods.Common.Activities self.CancelActivity(); 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 return new FlyCircle(self); } - return Util.SequenceActivities( + return ActivityUtils.SequenceActivities( new Fly(self, Target.FromPos(w1)), new Fly(self, Target.FromPos(w2)), new Fly(self, Target.FromPos(w3)), diff --git a/OpenRA.Mods.Common/Activities/Attack.cs b/OpenRA.Mods.Common/Activities/Attack.cs index 06dc9b83d5..94df1d1af8 100644 --- a/OpenRA.Mods.Common/Activities/Attack.cs +++ b/OpenRA.Mods.Common/Activities/Attack.cs @@ -78,11 +78,11 @@ namespace OpenRA.Mods.Common.Activities // Try to move within range 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; 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); diff --git a/OpenRA.Mods.Common/Activities/DeliverResources.cs b/OpenRA.Mods.Common/Activities/DeliverResources.cs index bffbddee68..d92cb2e7a1 100644 --- a/OpenRA.Mods.Common/Activities/DeliverResources.cs +++ b/OpenRA.Mods.Common/Activities/DeliverResources.cs @@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Activities // No refineries exist; check again after delay defined in Harvester. 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 iao = proc.Trait(); @@ -68,7 +68,7 @@ namespace OpenRA.Mods.Common.Activities foreach (var n in notify) 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) @@ -77,7 +77,7 @@ namespace OpenRA.Mods.Common.Activities iao.OnDock(self, this); } - return Util.SequenceActivities(new Wait(10), this); + return ActivityUtils.SequenceActivities(new Wait(10), this); } // Cannot be cancelled diff --git a/OpenRA.Mods.Common/Activities/Enter.cs b/OpenRA.Mods.Common/Activities/Enter.cs index f10fb91376..aed350dd4a 100644 --- a/OpenRA.Mods.Common/Activities/Enter.cs +++ b/OpenRA.Mods.Common/Activities/Enter.cs @@ -252,10 +252,10 @@ namespace OpenRA.Mods.Common.Activities Activity CanceledTick(Actor self) { if (inner == null) - return Util.RunActivity(self, NextActivity); + return ActivityUtils.RunActivity(self, NextActivity); inner.Cancel(self); inner.Queue(NextActivity); - return Util.RunActivity(self, inner); + return ActivityUtils.RunActivity(self, inner); } public override Activity Tick(Actor self) @@ -272,7 +272,7 @@ namespace OpenRA.Mods.Common.Activities return CanceledTick(self); // 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 (inner == null && nextState == State.Done) diff --git a/OpenRA.Mods.Common/Activities/ExternalCaptureActor.cs b/OpenRA.Mods.Common/Activities/ExternalCaptureActor.cs index 49b747b9c1..b049f71176 100644 --- a/OpenRA.Mods.Common/Activities/ExternalCaptureActor.cs +++ b/OpenRA.Mods.Common/Activities/ExternalCaptureActor.cs @@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Activities var nearest = target.Actor.OccupiesSpace.NearestCellTo(mobile.ToCell); 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) capturable.BeginCapture(self); diff --git a/OpenRA.Mods.Common/Activities/FindResources.cs b/OpenRA.Mods.Common/Activities/FindResources.cs index cc2de5b390..2fe14e0451 100644 --- a/OpenRA.Mods.Common/Activities/FindResources.cs +++ b/OpenRA.Mods.Common/Activities/FindResources.cs @@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Activities var deliver = new DeliverResources(self); if (harv.IsFull) - return Util.SequenceActivities(deliver, NextActivity); + return ActivityUtils.SequenceActivities(deliver, NextActivity); var closestHarvestablePosition = ClosestHarvestablePos(self); @@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Activities } 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 { @@ -90,7 +90,7 @@ namespace OpenRA.Mods.Common.Activities if (territory != null) { 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: @@ -104,7 +104,7 @@ namespace OpenRA.Mods.Common.Activities foreach (var n in notify) 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); } } diff --git a/OpenRA.Mods.Common/Activities/HarvestResource.cs b/OpenRA.Mods.Common/Activities/HarvestResource.cs index e65941369d..9972782d11 100644 --- a/OpenRA.Mods.Common/Activities/HarvestResource.cs +++ b/OpenRA.Mods.Common/Activities/HarvestResource.cs @@ -21,12 +21,14 @@ namespace OpenRA.Mods.Common.Activities readonly IFacing facing; readonly ResourceClaimLayer territory; readonly ResourceLayer resLayer; + readonly BodyOrientation body; public HarvestResource(Actor self) { harv = self.Trait(); harvInfo = self.Info.TraitInfo(); facing = self.Trait(); + body = self.Trait(); territory = self.World.WorldActor.TraitOrDefault(); resLayer = self.World.WorldActor.Trait(); } @@ -53,9 +55,9 @@ namespace OpenRA.Mods.Common.Activities if (harvInfo.HarvestFacings != 0) { var current = facing.Facing; - var desired = Util.QuantizeFacing(current, harvInfo.HarvestFacings) * (256 / harvInfo.HarvestFacings); + var desired = body.QuantizeFacing(current, harvInfo.HarvestFacings); 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); @@ -71,7 +73,7 @@ namespace OpenRA.Mods.Common.Activities foreach (var t in self.TraitsImplementing()) t.Harvested(self, resource); - return Util.SequenceActivities(new Wait(harvInfo.LoadTicksPerBale), this); + return ActivityUtils.SequenceActivities(new Wait(harvInfo.LoadTicksPerBale), this); } } } diff --git a/OpenRA.Mods.Common/Activities/HarvesterDockSequence.cs b/OpenRA.Mods.Common/Activities/HarvesterDockSequence.cs index d7cbc8565c..84457c61b1 100644 --- a/OpenRA.Mods.Common/Activities/HarvesterDockSequence.cs +++ b/OpenRA.Mods.Common/Activities/HarvesterDockSequence.cs @@ -53,8 +53,8 @@ namespace OpenRA.Mods.Common.Activities case State.Turn: dockingState = State.Dock; if (IsDragRequired) - return Util.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), new Drag(self, StartDrag, EndDrag, DragLength), this); + return ActivityUtils.SequenceActivities(new Turn(self, DockAngle), this); case State.Dock: if (Refinery.IsInWorld && !Refinery.IsDead) foreach (var nd in Refinery.TraitsImplementing()) @@ -73,7 +73,7 @@ namespace OpenRA.Mods.Common.Activities Harv.LastLinkedProc = Harv.LinkedProc; Harv.LinkProc(self, null); if (IsDragRequired) - return Util.SequenceActivities(new Drag(self, EndDrag, StartDrag, DragLength), NextActivity); + return ActivityUtils.SequenceActivities(new Drag(self, EndDrag, StartDrag, DragLength), NextActivity); return NextActivity; } diff --git a/OpenRA.Mods.Common/Activities/Hunt.cs b/OpenRA.Mods.Common/Activities/Hunt.cs index e9b61f37b9..6afe203315 100644 --- a/OpenRA.Mods.Common/Activities/Hunt.cs +++ b/OpenRA.Mods.Common/Activities/Hunt.cs @@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Activities if (target == null) return this; - return Util.SequenceActivities( + return ActivityUtils.SequenceActivities( new AttackMoveActivity(self, new Move(self, target.Location, WDist.FromCells(2))), new Wait(25), this); diff --git a/OpenRA.Mods.Common/Activities/Move/AttackMoveActivity.cs b/OpenRA.Mods.Common/Activities/Move/AttackMoveActivity.cs index f8fe4b0dbb..05048ee7d0 100644 --- a/OpenRA.Mods.Common/Activities/Move/AttackMoveActivity.cs +++ b/OpenRA.Mods.Common/Activities/Move/AttackMoveActivity.cs @@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Activities if (inner == null) return NextActivity; - inner = Util.RunActivity(self, inner); + inner = ActivityUtils.RunActivity(self, inner); return this; } diff --git a/OpenRA.Mods.Common/Activities/Move/Follow.cs b/OpenRA.Mods.Common/Activities/Move/Follow.cs index ba43d65562..e40738a11b 100644 --- a/OpenRA.Mods.Common/Activities/Move/Follow.cs +++ b/OpenRA.Mods.Common/Activities/Move/Follow.cs @@ -41,10 +41,10 @@ namespace OpenRA.Mods.Common.Activities if (target.IsInRange(self.CenterPosition, maxRange) && !target.IsInRange(self.CenterPosition, minRange)) { 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); } } } diff --git a/OpenRA.Mods.Common/Activities/Move/Move.cs b/OpenRA.Mods.Common/Activities/Move/Move.cs index 1721220b7c..6e1fc960d7 100644 --- a/OpenRA.Mods.Common/Activities/Move/Move.cs +++ b/OpenRA.Mods.Common/Activities/Move/Move.cs @@ -182,7 +182,7 @@ namespace OpenRA.Mods.Common.Activities if (firstFacing != mobile.Facing) { path.Add(nextCell.Value.First); - return Util.SequenceActivities(new Turn(self, firstFacing), this); + return ActivityUtils.SequenceActivities(new Turn(self, firstFacing), this); } else { diff --git a/OpenRA.Mods.Common/Activities/Move/MoveAdjacentTo.cs b/OpenRA.Mods.Common/Activities/Move/MoveAdjacentTo.cs index 94dc28cd43..caa1f4e7bf 100644 --- a/OpenRA.Mods.Common/Activities/Move/MoveAdjacentTo.cs +++ b/OpenRA.Mods.Common/Activities/Move/MoveAdjacentTo.cs @@ -90,7 +90,7 @@ namespace OpenRA.Mods.Common.Activities inner.Cancel(self); 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. @@ -129,7 +129,7 @@ namespace OpenRA.Mods.Common.Activities } // Ticks the inner move activity to actually move the actor. - inner = Util.RunActivity(self, inner); + inner = ActivityUtils.RunActivity(self, inner); return this; } diff --git a/OpenRA.Mods.Common/Activities/UnloadCargo.cs b/OpenRA.Mods.Common/Activities/UnloadCargo.cs index 2c152d9a6f..8a313680b8 100644 --- a/OpenRA.Mods.Common/Activities/UnloadCargo.cs +++ b/OpenRA.Mods.Common/Activities/UnloadCargo.cs @@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Activities { self.NotifyBlocker(BlockedExitCells(actor)); - return Util.SequenceActivities(new Wait(10), this); + return ActivityUtils.SequenceActivities(new Wait(10), this); } cargo.Unload(self); diff --git a/OpenRA.Mods.Common/Activities/WaitForTransport.cs b/OpenRA.Mods.Common/Activities/WaitForTransport.cs index 791b36f38a..91a3b403ec 100644 --- a/OpenRA.Mods.Common/Activities/WaitForTransport.cs +++ b/OpenRA.Mods.Common/Activities/WaitForTransport.cs @@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Activities return NextActivity; } - inner = Util.RunActivity(self, inner); + inner = ActivityUtils.RunActivity(self, inner); return this; } diff --git a/OpenRA.Mods.Common/Effects/AreaBeam.cs b/OpenRA.Mods.Common/Effects/AreaBeam.cs index fdfab6b91e..5e56cd5fd0 100644 --- a/OpenRA.Mods.Common/Effects/AreaBeam.cs +++ b/OpenRA.Mods.Common/Effects/AreaBeam.cs @@ -115,7 +115,7 @@ namespace OpenRA.Mods.Common.Effects target = args.PassiveTarget; 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; target += WVec.FromPDF(world.SharedRandom, 2) * maxOffset / 1024; } diff --git a/OpenRA.Mods.Common/Effects/Bullet.cs b/OpenRA.Mods.Common/Effects/Bullet.cs index 16f7a2fb0e..f9681648de 100644 --- a/OpenRA.Mods.Common/Effects/Bullet.cs +++ b/OpenRA.Mods.Common/Effects/Bullet.cs @@ -116,8 +116,8 @@ namespace OpenRA.Mods.Common.Effects target = args.PassiveTarget; if (info.Inaccuracy.Length > 0) { - var inaccuracy = OpenRA.Traits.Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers); - var range = OpenRA.Traits.Util.ApplyPercentageModifiers(args.Weapon.Range.Length, args.RangeModifiers); + var inaccuracy = Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers); + var range = Util.ApplyPercentageModifiers(args.Weapon.Range.Length, args.RangeModifiers); var maxOffset = inaccuracy * (target - pos).Length / range; target += WVec.FromPDF(world.SharedRandom, 2) * maxOffset / 1024; } diff --git a/OpenRA.Mods.Common/Effects/Missile.cs b/OpenRA.Mods.Common/Effects/Missile.cs index 0822fe791f..729b9a2923 100644 --- a/OpenRA.Mods.Common/Effects/Missile.cs +++ b/OpenRA.Mods.Common/Effects/Missile.cs @@ -14,6 +14,7 @@ using System.Linq; using OpenRA.Effects; using OpenRA.GameRules; using OpenRA.Graphics; +using OpenRA.Mods.Common; using OpenRA.Mods.Common.Graphics; using OpenRA.Mods.Common.Traits; using OpenRA.Traits; @@ -200,7 +201,7 @@ namespace OpenRA.Mods.Common.Effects 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; } @@ -723,8 +724,8 @@ namespace OpenRA.Mods.Common.Effects desiredHFacing = hFacing; // Compute new direction the projectile will be facing - hFacing = OpenRA.Traits.Util.TickFacing(hFacing, desiredHFacing, info.HorizontalRateOfTurn); - vFacing = OpenRA.Traits.Util.TickFacing(vFacing, desiredVFacing, info.VerticalRateOfTurn); + hFacing = Util.TickFacing(hFacing, desiredHFacing, info.HorizontalRateOfTurn); + vFacing = Util.TickFacing(vFacing, desiredVFacing, info.VerticalRateOfTurn); // Compute the projectile's guided displacement return new WVec(0, -1024 * speed, 0) diff --git a/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs b/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs index b008fa7fce..024d25ae86 100644 --- a/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs +++ b/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs @@ -237,7 +237,7 @@ namespace OpenRA.Mods.Common.Graphics 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) f = (Facings - f) % Facings; diff --git a/OpenRA.Mods.Common/Graphics/VoxelRenderable.cs b/OpenRA.Mods.Common/Graphics/VoxelRenderable.cs index 5268e46edc..d6ea10794d 100644 --- a/OpenRA.Mods.Common/Graphics/VoxelRenderable.cs +++ b/OpenRA.Mods.Common/Graphics/VoxelRenderable.cs @@ -144,19 +144,19 @@ namespace OpenRA.Mods.Common.Graphics // Draw voxel bounding box var draw = voxel.voxels.Where(v => v.DisableFunc == null || !v.DisableFunc()); - var scaleTransform = Util.ScaleMatrix(voxel.scale, voxel.scale, voxel.scale); - var cameraTransform = Util.MakeFloatMatrix(voxel.camera.AsMatrix()); + var scaleTransform = OpenRA.Graphics.Util.ScaleMatrix(voxel.scale, voxel.scale, voxel.scale); + var cameraTransform = OpenRA.Graphics.Util.MakeFloatMatrix(voxel.camera.AsMatrix()); foreach (var v in draw) { var bounds = v.Voxel.Bounds(v.FrameFunc()); 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; wr.ScreenVectorComponents(v.OffsetFunc(), out sx, out sy, out sz); 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); } } @@ -171,7 +171,7 @@ namespace OpenRA.Mods.Common.Graphics for (var i = 0; i < 8; i++) { 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]); } @@ -192,8 +192,8 @@ namespace OpenRA.Mods.Common.Graphics { var pxOrigin = wr.ScreenPosition(voxel.pos); var draw = voxel.voxels.Where(v => v.DisableFunc == null || !v.DisableFunc()); - var scaleTransform = Util.ScaleMatrix(voxel.scale, voxel.scale, voxel.scale); - var cameraTransform = Util.MakeFloatMatrix(voxel.camera.AsMatrix()); + var scaleTransform = OpenRA.Graphics.Util.ScaleMatrix(voxel.scale, voxel.scale, voxel.scale); + var cameraTransform = OpenRA.Graphics.Util.MakeFloatMatrix(voxel.camera.AsMatrix()); var minX = float.MaxValue; var minY = float.MaxValue; @@ -203,17 +203,17 @@ namespace OpenRA.Mods.Common.Graphics { var bounds = v.Voxel.Bounds(v.FrameFunc()); 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; wr.ScreenVectorComponents(v.OffsetFunc(), out sx, out sy, out sz); 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++) { 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]); minY = Math.Min(minY, pxPos.Y + screen[1]); maxX = Math.Max(maxX, pxPos.X + screen[0]); diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 3ba155026b..50bd7c0bb0 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -730,6 +730,7 @@ + diff --git a/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs b/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs index dff98deb88..d762c73dbe 100644 --- a/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs +++ b/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs @@ -15,7 +15,7 @@ using OpenRA.Graphics; using OpenRA.Mods.Common.Graphics; using OpenRA.Mods.Common.Traits; using OpenRA.Primitives; -using Util = OpenRA.Traits.Util; +using OpenRA.Traits; namespace OpenRA.Mods.Common.Orders { diff --git a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs index 18f237e054..c6b9a08a77 100644 --- a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs +++ b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs @@ -424,7 +424,7 @@ namespace OpenRA.Mods.Common.Traits if (IsPlane) 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) @@ -439,11 +439,11 @@ namespace OpenRA.Mods.Common.Traits { // TODO: Ignore repulsion when moving if (IsPlane) - return Util.SequenceActivities( + return ActivityUtils.SequenceActivities( new CallFunc(() => SetVisualPosition(self, fromPos)), 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))); } @@ -538,7 +538,7 @@ namespace OpenRA.Mods.Common.Traits if (IsPlane) { - self.QueueActivity(order.Queued, Util.SequenceActivities( + self.QueueActivity(order.Queued, ActivityUtils.SequenceActivities( new ReturnToBase(self, order.TargetActor), new ResupplyAircraft(self))); } diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackCharge.cs b/OpenRA.Mods.Common/Traits/Attack/AttackCharge.cs index b50adaf8a2..18f4968dd9 100644 --- a/OpenRA.Mods.Common/Traits/Attack/AttackCharge.cs +++ b/OpenRA.Mods.Common/Traits/Attack/AttackCharge.cs @@ -107,7 +107,7 @@ namespace OpenRA.Mods.Common.Traits if (!string.IsNullOrEmpty(attack.info.ChargeAudio)) 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); - return Util.SequenceActivities(new Wait(attack.info.ChargeDelay), this); + return ActivityUtils.SequenceActivities(new Wait(attack.info.ChargeDelay), this); } } } diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs b/OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs index 1984a212d2..39957d4f0f 100644 --- a/OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs +++ b/OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs @@ -95,7 +95,7 @@ namespace OpenRA.Mods.Common.Traits attack.Target = target; 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; diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackGarrisoned.cs b/OpenRA.Mods.Common/Traits/Attack/AttackGarrisoned.cs index ca088c5ba0..fe9d8ae00e 100644 --- a/OpenRA.Mods.Common/Traits/Attack/AttackGarrisoned.cs +++ b/OpenRA.Mods.Common/Traits/Attack/AttackGarrisoned.cs @@ -159,7 +159,7 @@ namespace OpenRA.Mods.Common.Traits var sequence = a.Info.MuzzleSequence; 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, () => PortOffset(self, port), diff --git a/OpenRA.Mods.Common/Traits/BodyOrientation.cs b/OpenRA.Mods.Common/Traits/BodyOrientation.cs index e7a8287ed4..3418f4362f 100644 --- a/OpenRA.Mods.Common/Traits/BodyOrientation.cs +++ b/OpenRA.Mods.Common/Traits/BodyOrientation.cs @@ -42,12 +42,17 @@ namespace OpenRA.Mods.Common.Traits return orientation; // 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 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); } } @@ -97,5 +102,15 @@ namespace OpenRA.Mods.Common.Traits { 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); + } } } diff --git a/OpenRA.Mods.Common/Traits/Mobile.cs b/OpenRA.Mods.Common/Traits/Mobile.cs index 668c060235..739d2536ea 100644 --- a/OpenRA.Mods.Common/Traits/Mobile.cs +++ b/OpenRA.Mods.Common/Traits/Mobile.cs @@ -682,7 +682,7 @@ namespace OpenRA.Mods.Common.Traits var notifyBlocking = new CallFunc(() => self.NotifyBlocker(cellInfo.Cell)); var waitFor = new WaitFor(() => CanEnterCell(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}", self.ActorID, self.Location, cellInfo.Cell); @@ -797,7 +797,7 @@ namespace OpenRA.Mods.Common.Traits var delta = toPos - fromPos; 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) diff --git a/OpenRA.Mods.Common/Traits/Render/WithMuzzleOverlay.cs b/OpenRA.Mods.Common/Traits/Render/WithMuzzleOverlay.cs index 5fb5e2d606..117f3911df 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithMuzzleOverlay.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithMuzzleOverlay.cs @@ -84,7 +84,7 @@ namespace OpenRA.Mods.Common.Traits return; 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) return; diff --git a/OpenRA.Mods.Common/Traits/Repairable.cs b/OpenRA.Mods.Common/Traits/Repairable.cs index 59e51c879f..e1293e6d55 100644 --- a/OpenRA.Mods.Common/Traits/Repairable.cs +++ b/OpenRA.Mods.Common/Traits/Repairable.cs @@ -94,7 +94,7 @@ namespace OpenRA.Mods.Common.Traits self.SetTargetLine(target, Color.Green); 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))))); TryCallTransport(self, target, new CallFunc(() => AfterReachActivities(self, order, movement))); diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs index 00741b47c6..f21dbc123f 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs @@ -58,7 +58,7 @@ namespace OpenRA.Mods.Common.Traits var info = Info as AirstrikePowerInfo; 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().CruiseAltitude.Length; var attackRotation = WRot.FromFacing(attackFacing); diff --git a/OpenRA.Mods.Common/Traits/Turreted.cs b/OpenRA.Mods.Common/Traits/Turreted.cs index c23ae24c35..246da505e2 100644 --- a/OpenRA.Mods.Common/Traits/Turreted.cs +++ b/OpenRA.Mods.Common/Traits/Turreted.cs @@ -133,7 +133,7 @@ namespace OpenRA.Mods.Common.Traits // Quantize orientation to match a rendered sprite // 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)); } diff --git a/OpenRA.Mods.Common/Traits/World/CrateSpawner.cs b/OpenRA.Mods.Common/Traits/World/CrateSpawner.cs index f848b7a63c..0295682166 100644 --- a/OpenRA.Mods.Common/Traits/World/CrateSpawner.cs +++ b/OpenRA.Mods.Common/Traits/World/CrateSpawner.cs @@ -108,7 +108,7 @@ namespace OpenRA.Mods.Common.Traits if (info.DeliveryAircraft != null) { 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 altitude = self.World.Map.Rules.Actors[info.DeliveryAircraft].TraitInfo().CruiseAltitude.Length; diff --git a/OpenRA.Mods.Common/Traits/World/EditorActorLayer.cs b/OpenRA.Mods.Common/Traits/World/EditorActorLayer.cs index 56df270a66..41f2f696ad 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorActorLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorActorLayer.cs @@ -190,14 +190,14 @@ namespace OpenRA.Mods.Common.Traits void UpdateNeighbours(IReadOnlyDictionary footprint) { // 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))) p.ReplaceInit(new RuntimeNeighbourInit(NeighbouringPreviews(p.Footprint))); } Dictionary NeighbouringPreviews(IReadOnlyDictionary 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()); } diff --git a/OpenRA.Game/Traits/Util.cs b/OpenRA.Mods.Common/Util.cs similarity index 71% rename from OpenRA.Game/Traits/Util.cs rename to OpenRA.Mods.Common/Util.cs index 7d8d86641d..032772049d 100644 --- a/OpenRA.Game/Traits/Util.cs +++ b/OpenRA.Mods.Common/Util.cs @@ -10,12 +10,11 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; -using OpenRA.Activities; using OpenRA.Support; +using OpenRA.Traits; -namespace OpenRA.Traits +namespace OpenRA.Mods.Common { public static class Util { @@ -54,45 +53,6 @@ namespace OpenRA.Traits 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 */ public static IEnumerable Shuffle(this IEnumerable ts, MersenneTwister random) { diff --git a/OpenRA.Mods.D2k/Activities/DeliverUnit.cs b/OpenRA.Mods.D2k/Activities/DeliverUnit.cs index 75f058452c..c213220765 100644 --- a/OpenRA.Mods.D2k/Activities/DeliverUnit.cs +++ b/OpenRA.Mods.D2k/Activities/DeliverUnit.cs @@ -9,6 +9,7 @@ #endregion using OpenRA.Activities; +using OpenRA.Mods.Common; using OpenRA.Mods.Common.Activities; using OpenRA.Mods.Common.Traits; using OpenRA.Mods.D2k.Traits; @@ -86,7 +87,7 @@ namespace OpenRA.Mods.D2k.Activities case State.Transport: var targetl = GetLocationToDrop(carryable.Destination); state = State.Land; - return Util.SequenceActivities(movement.MoveTo(targetl, 0), this); + return ActivityUtils.SequenceActivities(movement.MoveTo(targetl, 0), this); case State.Land: if (!CanDropHere()) @@ -98,7 +99,7 @@ namespace OpenRA.Mods.D2k.Activities if (HeliFly.AdjustAltitude(self, aircraft, aircraft.Info.LandAltitude)) return this; state = State.Release; - return Util.SequenceActivities(new Wait(15), this); + return ActivityUtils.SequenceActivities(new Wait(15), this); case State.Release: if (!CanDropHere()) diff --git a/OpenRA.Mods.D2k/Activities/PickupUnit.cs b/OpenRA.Mods.D2k/Activities/PickupUnit.cs index 52131bcb77..45c0fd4460 100644 --- a/OpenRA.Mods.D2k/Activities/PickupUnit.cs +++ b/OpenRA.Mods.D2k/Activities/PickupUnit.cs @@ -9,6 +9,7 @@ #endregion using OpenRA.Activities; +using OpenRA.Mods.Common; using OpenRA.Mods.Common.Activities; using OpenRA.Mods.Common.Traits; using OpenRA.Mods.D2k.Traits; @@ -54,7 +55,7 @@ namespace OpenRA.Mods.D2k.Activities { case State.Intercept: 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: // Last check @@ -75,13 +76,13 @@ namespace OpenRA.Mods.D2k.Activities 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 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; - 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: // Remove our carryable from world diff --git a/OpenRA.Mods.RA/Activities/LayMines.cs b/OpenRA.Mods.RA/Activities/LayMines.cs index d3b343b07b..0ed4f2d5c4 100644 --- a/OpenRA.Mods.RA/Activities/LayMines.cs +++ b/OpenRA.Mods.RA/Activities/LayMines.cs @@ -52,7 +52,7 @@ namespace OpenRA.Mods.RA.Activities if (rearmTarget == null) return new Wait(20); - return Util.SequenceActivities( + return ActivityUtils.SequenceActivities( new MoveAdjacentTo(self, Target.FromActor(rearmTarget)), movement.MoveTo(self.World.Map.CellContaining(rearmTarget.CenterPosition), rearmTarget), new Rearm(self), @@ -63,7 +63,7 @@ namespace OpenRA.Mods.RA.Activities if (minelayer.Minefield.Contains(self.Location) && ShouldLayMine(self, self.Location)) { 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) @@ -73,7 +73,7 @@ namespace OpenRA.Mods.RA.Activities { var p = minelayer.Minefield.Random(self.World.SharedRandom); if (ShouldLayMine(self, p)) - return Util.SequenceActivities(movement.MoveTo(p, 0), this); + return ActivityUtils.SequenceActivities(movement.MoveTo(p, 0), this); } } diff --git a/OpenRA.Mods.RA/Traits/SupportPowers/ParatroopersPower.cs b/OpenRA.Mods.RA/Traits/SupportPowers/ParatroopersPower.cs index 9eec3c8d3f..813ef805f5 100644 --- a/OpenRA.Mods.RA/Traits/SupportPowers/ParatroopersPower.cs +++ b/OpenRA.Mods.RA/Traits/SupportPowers/ParatroopersPower.cs @@ -70,7 +70,7 @@ namespace OpenRA.Mods.RA.Traits var info = Info as ParatroopersPowerInfo; 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().CruiseAltitude.Length; var dropRotation = WRot.FromFacing(dropFacing);