fix aircraft desync
This commit is contained in:
@@ -27,6 +27,8 @@ namespace OpenRA
|
|||||||
public static int2 operator *(int2 b, int a) { return new int2(a * b.X, a * b.Y); }
|
public static int2 operator *(int2 b, int a) { return new int2(a * b.X, a * b.Y); }
|
||||||
public static int2 operator /(int2 a, int b) { return new int2(a.X / b, a.Y / b); }
|
public static int2 operator /(int2 a, int b) { return new int2(a.X / b, a.Y / b); }
|
||||||
|
|
||||||
|
public static int2 operator -(int2 a) { return new int2(-a.X, -a.Y); }
|
||||||
|
|
||||||
public static bool operator ==(int2 me, int2 other) { return (me.X == other.X && me.Y == other.Y); }
|
public static bool operator ==(int2 me, int2 other) { return (me.X == other.X && me.Y == other.Y); }
|
||||||
public static bool operator !=(int2 me, int2 other) { return !(me == other); }
|
public static bool operator !=(int2 me, int2 other) { return !(me == other); }
|
||||||
|
|
||||||
|
|||||||
@@ -33,32 +33,27 @@ namespace OpenRA.Mods.RA.Air
|
|||||||
{
|
{
|
||||||
protected readonly Actor self;
|
protected readonly Actor self;
|
||||||
[Sync]
|
[Sync]
|
||||||
public int2 Location { get { return Util.CellContaining( center.ToInt2() ); } }
|
|
||||||
[Sync]
|
|
||||||
public int Facing { get; set; }
|
public int Facing { get; set; }
|
||||||
[Sync]
|
[Sync]
|
||||||
public int Altitude { get; set; }
|
public int Altitude { get; set; }
|
||||||
|
[Sync]
|
||||||
|
public int2 SubPxPosition;
|
||||||
|
public int2 PxPosition { get { return new int2( SubPxPosition.X / 1024, SubPxPosition.Y / 1024 ); } }
|
||||||
|
public int2 TopLeft { get { return Util.CellContaining( PxPosition ); } }
|
||||||
|
|
||||||
public float2 center;
|
readonly AircraftInfo Info;
|
||||||
|
|
||||||
AircraftInfo Info;
|
|
||||||
|
|
||||||
public Aircraft( ActorInitializer init , AircraftInfo info)
|
public Aircraft( ActorInitializer init , AircraftInfo info)
|
||||||
{
|
{
|
||||||
this.self = init.self;
|
this.self = init.self;
|
||||||
if( init.Contains<LocationInit>() )
|
if( init.Contains<LocationInit>() )
|
||||||
this.center = Util.CenterOfCell( init.Get<LocationInit, int2>() );
|
this.SubPxPosition = 1024 * Util.CenterOfCell( init.Get<LocationInit, int2>() );
|
||||||
|
|
||||||
this.Facing = init.Contains<FacingInit>() ? init.Get<FacingInit,int>() : info.InitialFacing;
|
this.Facing = init.Contains<FacingInit>() ? init.Get<FacingInit,int>() : info.InitialFacing;
|
||||||
this.Altitude = init.Contains<AltitudeInit>() ? init.Get<AltitudeInit,int>() : 0;
|
this.Altitude = init.Contains<AltitudeInit>() ? init.Get<AltitudeInit,int>() : 0;
|
||||||
Info = info;
|
Info = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int2 TopLeft
|
|
||||||
{
|
|
||||||
get { return Location; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public int ROT { get { return Info.ROT; } }
|
public int ROT { get { return Info.ROT; } }
|
||||||
|
|
||||||
public int InitialFacing { get { return Info.InitialFacing; } }
|
public int InitialFacing { get { return Info.InitialFacing; } }
|
||||||
@@ -70,7 +65,7 @@ namespace OpenRA.Mods.RA.Air
|
|||||||
|
|
||||||
public void SetPxPosition( Actor self, int2 px )
|
public void SetPxPosition( Actor self, int2 px )
|
||||||
{
|
{
|
||||||
center = px;
|
SubPxPosition = px * 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AircraftCanEnter(Actor a)
|
public bool AircraftCanEnter(Actor a)
|
||||||
@@ -82,26 +77,31 @@ namespace OpenRA.Mods.RA.Air
|
|||||||
|
|
||||||
public bool CanEnterCell(int2 location) { return true; }
|
public bool CanEnterCell(int2 location) { return true; }
|
||||||
|
|
||||||
public float MovementSpeed
|
public int MovementSpeed
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var modifier = self
|
//var modifier = self
|
||||||
.TraitsImplementing<ISpeedModifier>()
|
// .TraitsImplementing<ISpeedModifier>()
|
||||||
.Select( t => t.GetSpeedModifier() )
|
// .Select( t => t.GetSpeedModifier() )
|
||||||
.Product();
|
// .Product();
|
||||||
return Info.Speed * modifier;
|
return Info.Speed;// *modifier;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int2[] noCells = new int2[] { };
|
int2[] noCells = new int2[] { };
|
||||||
public IEnumerable<int2> OccupiedCells() { return noCells; }
|
public IEnumerable<int2> OccupiedCells() { return noCells; }
|
||||||
public int2 PxPosition { get { return center.ToInt2(); } }
|
|
||||||
|
|
||||||
public void TickMove( float speed, int facing )
|
public void TickMove( int speed, int facing )
|
||||||
{
|
{
|
||||||
var angle = facing / 128f * Math.PI;
|
var rawspeed = speed * 7 / (32 * 1024);
|
||||||
center += speed * -float2.FromAngle((float)angle);
|
SubPxPosition += rawspeed * -SubPxVector( facing );
|
||||||
|
}
|
||||||
|
|
||||||
|
int2 SubPxVector( int facing )
|
||||||
|
{
|
||||||
|
var angle = facing * Math.PI / 128.0;
|
||||||
|
return new int2( (int)Math.Truncate( 1024 * Math.Sin( angle ) ), (int)Math.Truncate( 1024 * Math.Cos( angle ) ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,8 +57,7 @@ namespace OpenRA.Mods.RA.Air
|
|||||||
public static void Fly(Actor self, int desiredAltitude )
|
public static void Fly(Actor self, int desiredAltitude )
|
||||||
{
|
{
|
||||||
var aircraft = self.Trait<Aircraft>();
|
var aircraft = self.Trait<Aircraft>();
|
||||||
var speed = .2f * aircraft.MovementSpeed;
|
aircraft.TickMove( 1024 * aircraft.MovementSpeed, aircraft.Facing );
|
||||||
aircraft.TickMove( speed, aircraft.Facing );
|
|
||||||
aircraft.Altitude += Math.Sign(desiredAltitude - aircraft.Altitude);
|
aircraft.Altitude += Math.Sign(desiredAltitude - aircraft.Altitude);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,10 +42,9 @@ namespace OpenRA.Mods.RA.Air
|
|||||||
|
|
||||||
var desiredFacing = Util.GetFacing(dist, aircraft.Facing);
|
var desiredFacing = Util.GetFacing(dist, aircraft.Facing);
|
||||||
aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.ROT);
|
aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.ROT);
|
||||||
var rawSpeed = .2f * aircraft.MovementSpeed;
|
|
||||||
|
if( !float2.WithinEpsilon( float2.Zero, dist, range * Game.CellSize ) )
|
||||||
if (!float2.WithinEpsilon(float2.Zero, dist, range * Game.CellSize))
|
aircraft.TickMove( 1024 * aircraft.MovementSpeed, desiredFacing );
|
||||||
aircraft.center += (rawSpeed / dist.Length) * dist;
|
|
||||||
|
|
||||||
attack.DoAttack( self, target );
|
attack.DoAttack( self, target );
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ namespace OpenRA.Mods.RA.Air
|
|||||||
{
|
{
|
||||||
class HeliFly : CancelableActivity
|
class HeliFly : CancelableActivity
|
||||||
{
|
{
|
||||||
public readonly float2 Dest;
|
public readonly int2 Dest;
|
||||||
public HeliFly(float2 dest)
|
public HeliFly(int2 dest)
|
||||||
{
|
{
|
||||||
Dest = dest;
|
Dest = dest;
|
||||||
}
|
}
|
||||||
@@ -35,19 +35,16 @@ namespace OpenRA.Mods.RA.Air
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
var dist = Dest - self.CenterLocation;
|
var dist = Dest - aircraft.PxPosition;
|
||||||
if (float2.WithinEpsilon(float2.Zero, dist, 2))
|
if (float2.WithinEpsilon(float2.Zero, dist, 2))
|
||||||
{
|
{
|
||||||
aircraft.center = Dest;
|
aircraft.SubPxPosition = Dest * 1024;
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
}
|
}
|
||||||
|
|
||||||
var desiredFacing = Util.GetFacing(dist, aircraft.Facing);
|
var desiredFacing = Util.GetFacing(dist, aircraft.Facing);
|
||||||
aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing,
|
aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.ROT);
|
||||||
aircraft.ROT);
|
aircraft.TickMove( 1024 * aircraft.MovementSpeed, desiredFacing );
|
||||||
|
|
||||||
var rawSpeed = .2f * aircraft.MovementSpeed;
|
|
||||||
aircraft.center += (rawSpeed / dist.Length) * dist;
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,10 +43,10 @@ namespace OpenRA.Mods.RA.Air
|
|||||||
self.Trait<Helicopter>().reservation = res.Reserve(self);
|
self.Trait<Helicopter>().reservation = res.Reserve(self);
|
||||||
|
|
||||||
var exit = dest.Info.Traits.WithInterface<ExitInfo>().FirstOrDefault();
|
var exit = dest.Info.Traits.WithInterface<ExitInfo>().FirstOrDefault();
|
||||||
var offset = exit != null ? exit.SpawnOffset : float2.Zero;
|
var offset = exit != null ? exit.SpawnOffset : int2.Zero;
|
||||||
|
|
||||||
return Util.SequenceActivities(
|
return Util.SequenceActivities(
|
||||||
new HeliFly(dest.CenterLocation + offset),
|
new HeliFly(dest.Trait<IHasLocation>().PxPosition + offset),
|
||||||
new Turn(initialFacing),
|
new Turn(initialFacing),
|
||||||
new HeliLand(false),
|
new HeliLand(false),
|
||||||
new Rearm(),
|
new Rearm(),
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA.Air
|
|||||||
{
|
{
|
||||||
class HelicopterInfo : AircraftInfo
|
class HelicopterInfo : AircraftInfo
|
||||||
{
|
{
|
||||||
public readonly float InstabilityMagnitude = 2.0f;
|
public readonly int InstabilityMagnitude = 1024;
|
||||||
public readonly int InstabilityTicks = 5;
|
public readonly int InstabilityTicks = 5;
|
||||||
public readonly int IdealSeparation = 40;
|
public readonly int IdealSeparation = 40;
|
||||||
public readonly bool LandWhenIdle = true;
|
public readonly bool LandWhenIdle = true;
|
||||||
@@ -105,7 +105,7 @@ namespace OpenRA.Mods.RA.Air
|
|||||||
reservation = res.Reserve(self);
|
reservation = res.Reserve(self);
|
||||||
|
|
||||||
var exit = order.TargetActor.Info.Traits.WithInterface<ExitInfo>().FirstOrDefault();
|
var exit = order.TargetActor.Info.Traits.WithInterface<ExitInfo>().FirstOrDefault();
|
||||||
var offset = exit != null ? exit.SpawnOffset : float2.Zero;
|
var offset = exit != null ? exit.SpawnOffset : int2.Zero;
|
||||||
|
|
||||||
if (self.Owner == self.World.LocalPlayer)
|
if (self.Owner == self.World.LocalPlayer)
|
||||||
self.World.AddFrameEndTask(w =>
|
self.World.AddFrameEndTask(w =>
|
||||||
@@ -118,7 +118,7 @@ namespace OpenRA.Mods.RA.Air
|
|||||||
});
|
});
|
||||||
|
|
||||||
self.CancelActivity();
|
self.CancelActivity();
|
||||||
self.QueueActivity(new HeliFly(order.TargetActor.CenterLocation + offset));
|
self.QueueActivity(new HeliFly(order.TargetActor.Trait<IHasLocation>().PxPosition + offset));
|
||||||
self.QueueActivity(new Turn(Info.InitialFacing));
|
self.QueueActivity(new Turn(Info.InitialFacing));
|
||||||
self.QueueActivity(new HeliLand(false));
|
self.QueueActivity(new HeliLand(false));
|
||||||
self.QueueActivity(Info.RearmBuildings.Contains(order.TargetActor.Info.Name)
|
self.QueueActivity(Info.RearmBuildings.Contains(order.TargetActor.Info.Name)
|
||||||
@@ -133,7 +133,6 @@ namespace OpenRA.Mods.RA.Air
|
|||||||
if (aircraft.Altitude <= 0)
|
if (aircraft.Altitude <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var rawSpeed = .2f * aircraft.MovementSpeed;
|
|
||||||
var otherHelis = self.World.FindUnitsInCircle(self.CenterLocation, Info.IdealSeparation)
|
var otherHelis = self.World.FindUnitsInCircle(self.CenterLocation, Info.IdealSeparation)
|
||||||
.Where(a => a.HasTrait<Helicopter>());
|
.Where(a => a.HasTrait<Helicopter>());
|
||||||
|
|
||||||
@@ -141,16 +140,26 @@ namespace OpenRA.Mods.RA.Air
|
|||||||
.Select(h => self.Trait<Helicopter>().GetRepulseForce(self, h, h.Trait<Helicopter>()))
|
.Select(h => self.Trait<Helicopter>().GetRepulseForce(self, h, h.Trait<Helicopter>()))
|
||||||
.Aggregate(float2.Zero, (a, b) => a + b);
|
.Aggregate(float2.Zero, (a, b) => a + b);
|
||||||
|
|
||||||
aircraft.center += rawSpeed * f;
|
RepulsionFacing = Util.GetFacing( f, -1 );
|
||||||
|
if( RepulsionFacing != -1 )
|
||||||
|
aircraft.TickMove( 1024 * aircraft.MovementSpeed, RepulsionFacing );
|
||||||
|
|
||||||
if (--offsetTicks <= 0)
|
if (--offsetTicks <= 0)
|
||||||
{
|
{
|
||||||
aircraft.center += Info.InstabilityMagnitude * self.World.SharedRandom.Gauss2D(5);
|
InstabilityFacing = Util.GetFacing( self.World.SharedRandom.Gauss2D( 5 ), -1 );
|
||||||
|
if( InstabilityFacing != -1 )
|
||||||
|
aircraft.TickMove( Info.InstabilityMagnitude, InstabilityFacing );
|
||||||
|
|
||||||
aircraft.Altitude += (int)(Info.InstabilityMagnitude * self.World.SharedRandom.Gauss1D(5));
|
aircraft.Altitude += (int)(Info.InstabilityMagnitude * self.World.SharedRandom.Gauss1D(5));
|
||||||
offsetTicks = Info.InstabilityTicks;
|
offsetTicks = Info.InstabilityTicks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Sync]
|
||||||
|
int RepulsionFacing;
|
||||||
|
[Sync]
|
||||||
|
int InstabilityFacing;
|
||||||
|
|
||||||
const float Epsilon = .5f;
|
const float Epsilon = .5f;
|
||||||
public float2 GetRepulseForce(Actor self, Actor h, Aircraft hAir)
|
public float2 GetRepulseForce(Actor self, Actor h, Aircraft hAir)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -38,9 +38,7 @@ namespace OpenRA.Mods.RA.Air
|
|||||||
|
|
||||||
var desiredFacing = Util.GetFacing(d, aircraft.Facing);
|
var desiredFacing = Util.GetFacing(d, aircraft.Facing);
|
||||||
aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.ROT);
|
aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.ROT);
|
||||||
var speed = .2f * aircraft.MovementSpeed;
|
aircraft.TickMove( 1024 * aircraft.MovementSpeed, aircraft.Facing );
|
||||||
|
|
||||||
aircraft.TickMove( speed, aircraft.Facing );
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user