moving Actor.Location onto the appropriate traits (bob)

This commit is contained in:
Chris Forbes
2010-06-19 14:37:06 +12:00
parent db465e1fdd
commit 66adbee2a6
25 changed files with 218 additions and 103 deletions

View File

@@ -27,28 +27,19 @@ using OpenRA.Mods.RA.Activities;
namespace OpenRA.Mods.RA
{
class HelicopterInfo : ITraitInfo
class HelicopterInfo : AircraftInfo
{
public readonly string[] RepairBuildings = { "fix" };
public readonly string[] RearmBuildings = { "hpad" };
public readonly int CruiseAltitude = 20;
public readonly int IdealSeparation = 40;
public readonly bool LandWhenIdle = true;
public object Create(ActorInitializer init) { return new Helicopter(init.self); }
public override object Create( ActorInitializer init ) { return new Helicopter( init ); }
}
class Helicopter : ITick, IIssueOrder, IResolveOrder, IMovement
class Helicopter : Aircraft, IIssueOrder, IResolveOrder
{
public IDisposable reservation;
public Helicopter(Actor self) {}
static bool HeliCanEnter(Actor self, Actor a)
{
if (self.Info.Traits.Get<HelicopterInfo>().RearmBuildings.Contains(a.Info.Name)) return true;
if (self.Info.Traits.Get<HelicopterInfo>().RepairBuildings.Contains(a.Info.Name)) return true;
return false;
}
public Helicopter( ActorInitializer init ) : base( init ) { }
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
{
@@ -60,7 +51,7 @@ namespace OpenRA.Mods.RA
return new Order("Move", self, xy);
}
if (HeliCanEnter(self, underCursor)
if (AircraftCanEnter(self, underCursor)
&& underCursor.Owner == self.Owner
&& !Reservable.IsReserved(underCursor))
return new Order("Enter", self, underCursor);
@@ -113,13 +104,13 @@ namespace OpenRA.Mods.RA
var rawSpeed = .2f * Util.GetEffectiveSpeed(self, UnitMovementType.Fly);
var otherHelis = self.World.FindUnitsInCircle(self.CenterLocation, self.Info.Traits.Get<HelicopterInfo>().IdealSeparation)
.Where(a => a.traits.Contains<Helicopter>());
var f = otherHelis
.Select(h => self.traits.Get<Helicopter>().GetRepulseForce(self, h))
.Aggregate(float2.Zero, (a, b) => a + b);
self.CenterLocation += rawSpeed * f;
self.Location = ((1 / 24f) * self.CenterLocation).ToInt2();
Location = ((1 / 24f) * self.CenterLocation).ToInt2();
}
const float Epsilon = .5f;
@@ -135,9 +126,6 @@ namespace OpenRA.Mods.RA
if (d.LengthSquared < Epsilon)
return float2.FromAngle((float)self.World.SharedRandom.NextDouble() * 3.14f);
return (5 / d.LengthSquared) * d;
}
public UnitMovementType GetMovementType() { return UnitMovementType.Fly; }
public bool CanEnterCell(int2 location) { return true; }
}
}
}