Refactor unreserve actions.
This commit is contained in:
@@ -36,8 +36,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
if (self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition).Length >= aircraft.Info.MinAirborneAltitude)
|
if (self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition).Length >= aircraft.Info.MinAirborneAltitude)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// We are taking off, so remove reservation and influence in ground cells.
|
// We are taking off, so remove influence in ground cells.
|
||||||
aircraft.UnReserve();
|
|
||||||
aircraft.RemoveInfluence();
|
aircraft.RemoveInfluence();
|
||||||
|
|
||||||
if (aircraft.Info.TakeoffSounds.Length > 0)
|
if (aircraft.Info.TakeoffSounds.Length > 0)
|
||||||
|
|||||||
@@ -191,6 +191,8 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
QueueChild(move.MoveTo(rp.Location, repairableNear != null ? null : host.Actor));
|
QueueChild(move.MoveTo(rp.Location, repairableNear != null ? null : host.Actor));
|
||||||
else
|
else
|
||||||
QueueChild(new TakeOff(self));
|
QueueChild(new TakeOff(self));
|
||||||
|
|
||||||
|
aircraft.UnReserve();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Aircraft without TakeOffOnResupply remain on the resupplier until something else needs it
|
// Aircraft without TakeOffOnResupply remain on the resupplier until something else needs it
|
||||||
|
|||||||
@@ -506,25 +506,15 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
MayYieldReservation = true;
|
MayYieldReservation = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UnReserve(bool takeOff = false)
|
public void UnReserve()
|
||||||
{
|
{
|
||||||
if (reservation == null)
|
if (reservation == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Move to the host's rally point if it has one
|
|
||||||
var rp = ReservedActor != null ? ReservedActor.TraitOrDefault<RallyPoint>() : null;
|
|
||||||
|
|
||||||
reservation.Dispose();
|
reservation.Dispose();
|
||||||
reservation = null;
|
reservation = null;
|
||||||
ReservedActor = null;
|
ReservedActor = null;
|
||||||
MayYieldReservation = false;
|
MayYieldReservation = false;
|
||||||
|
|
||||||
if (takeOff && self.World.Map.DistanceAboveTerrain(CenterPosition).Length <= LandAltitude.Length)
|
|
||||||
{
|
|
||||||
self.QueueActivity(new TakeOff(self));
|
|
||||||
if (rp != null)
|
|
||||||
self.QueueActivity(new AttackMoveActivity(self, () => MoveTo(rp.Location, null, targetLineColor: Color.OrangeRed)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AircraftCanEnter(Actor a, TargetModifiers modifiers)
|
bool AircraftCanEnter(Actor a, TargetModifiers modifiers)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using OpenRA.Mods.Common.Activities;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
@@ -18,10 +19,16 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Desc("Reserve landing places for aircraft.")]
|
[Desc("Reserve landing places for aircraft.")]
|
||||||
class ReservableInfo : TraitInfo<Reservable> { }
|
class ReservableInfo : TraitInfo<Reservable> { }
|
||||||
|
|
||||||
public class Reservable : ITick, INotifyOwnerChanged, INotifySold, INotifyActorDisposing
|
public class Reservable : ITick, INotifyOwnerChanged, INotifySold, INotifyActorDisposing, INotifyCreated
|
||||||
{
|
{
|
||||||
Actor reservedFor;
|
Actor reservedFor;
|
||||||
Aircraft reservedForAircraft;
|
Aircraft reservedForAircraft;
|
||||||
|
RallyPoint rallyPoint;
|
||||||
|
|
||||||
|
void INotifyCreated.Created(Actor self)
|
||||||
|
{
|
||||||
|
rallyPoint = self.TraitOrDefault<RallyPoint>();
|
||||||
|
}
|
||||||
|
|
||||||
void ITick.Tick(Actor self)
|
void ITick.Tick(Actor self)
|
||||||
{
|
{
|
||||||
@@ -41,7 +48,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public IDisposable Reserve(Actor self, Actor forActor, Aircraft forAircraft)
|
public IDisposable Reserve(Actor self, Actor forActor, Aircraft forAircraft)
|
||||||
{
|
{
|
||||||
if (reservedForAircraft != null && reservedForAircraft.MayYieldReservation)
|
if (reservedForAircraft != null && reservedForAircraft.MayYieldReservation)
|
||||||
reservedForAircraft.UnReserve(true);
|
UnReserve(self);
|
||||||
|
|
||||||
reservedFor = forActor;
|
reservedFor = forActor;
|
||||||
reservedForAircraft = forAircraft;
|
reservedForAircraft = forAircraft;
|
||||||
@@ -71,17 +78,27 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return res == null || res.reservedForAircraft == null || res.reservedForAircraft.MayYieldReservation || res.reservedFor == forActor;
|
return res == null || res.reservedForAircraft == null || res.reservedForAircraft.MayYieldReservation || res.reservedFor == forActor;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UnReserve()
|
void UnReserve(Actor self)
|
||||||
{
|
{
|
||||||
if (reservedForAircraft != null)
|
if (reservedForAircraft != null)
|
||||||
reservedForAircraft.UnReserve(true);
|
{
|
||||||
|
if (reservedForAircraft.GetActorBelow() == self)
|
||||||
|
{
|
||||||
|
if (rallyPoint != null)
|
||||||
|
reservedFor.QueueActivity(reservedForAircraft.MoveTo(rallyPoint.Location, null, targetLineColor: Color.Green));
|
||||||
|
else
|
||||||
|
reservedFor.QueueActivity(new TakeOff(reservedFor));
|
||||||
|
}
|
||||||
|
|
||||||
|
reservedForAircraft.UnReserve();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyActorDisposing.Disposing(Actor self) { UnReserve(); }
|
void INotifyActorDisposing.Disposing(Actor self) { UnReserve(self); }
|
||||||
|
|
||||||
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) { UnReserve(); }
|
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) { UnReserve(self); }
|
||||||
|
|
||||||
void INotifySold.Selling(Actor self) { UnReserve(); }
|
void INotifySold.Selling(Actor self) { UnReserve(self); }
|
||||||
void INotifySold.Sold(Actor self) { UnReserve(); }
|
void INotifySold.Sold(Actor self) { UnReserve(self); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user