Tweak helicopter movement / attack

This commit is contained in:
Paul Chote
2010-06-13 11:34:33 +12:00
parent a7f5c4b03a
commit b50ad94efb
5 changed files with 40 additions and 9 deletions

View File

@@ -21,6 +21,7 @@
using System;
using OpenRA.GameRules;
using OpenRA.Traits;
using System.Linq;
namespace OpenRA.Mods.RA.Activities
{
@@ -48,8 +49,16 @@ namespace OpenRA.Mods.RA.Activities
unit.Altitude += Math.Sign(info.CruiseAltitude - unit.Altitude);
return this;
}
var dist = Dest - self.CenterLocation;
// Prevent multiple units from stacking together
var otherHelis = self.World.FindUnitsInCircle(self.CenterLocation, info.IdealSeparation)
.Where(a => a.traits.Contains<Helicopter>());
var f = otherHelis
.Select(h => GetRepulseForce(self, h))
.Aggregate(float2.Zero, (a, b) => a + b);
var dist = Dest - self.CenterLocation + f;
if (float2.WithinEpsilon(float2.Zero, dist, 2))
{
self.CenterLocation = Dest;
@@ -67,6 +76,19 @@ namespace OpenRA.Mods.RA.Activities
return this;
}
// Todo: Duplicated from HeliAttack
const float Epsilon = .5f;
float2 GetRepulseForce(Actor self, Actor h)
{
if (self == h)
return float2.Zero;
var d = self.CenterLocation - h.CenterLocation;
if (d.LengthSquared < Epsilon)
return float2.FromAngle((float)self.World.SharedRandom.NextDouble() * 3.14f);
return (2 / d.LengthSquared) * d;
}
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
}