Add Aircraft.MakeReservation.

This provides a simpler method for making reservations and also ensures the previous reservation is definitely unreserved before being discarded.
This commit is contained in:
RoosterDragon
2015-10-27 22:15:56 +00:00
parent e2dd967757
commit b4180615a8
3 changed files with 18 additions and 37 deletions

View File

@@ -92,11 +92,11 @@ namespace OpenRA.Mods.Common.Traits
readonly Actor self;
UpgradeManager um;
IDisposable reservation;
[Sync] public int Facing { get; set; }
[Sync] public WPos CenterPosition { get; private set; }
public CPos TopLeft { get { return self.World.Map.CellContaining(CenterPosition); } }
public IDisposable Reservation;
public int ROT { get { return Info.ROT; } }
bool airborne;
@@ -257,22 +257,24 @@ namespace OpenRA.Mods.Common.Traits
if (afld == null)
return;
var res = afld.TraitOrDefault<Reservable>();
MakeReservation(afld);
}
if (res != null)
{
UnReserve();
Reservation = res.Reserve(afld, self, this);
}
public void MakeReservation(Actor target)
{
UnReserve();
var reservable = target.TraitOrDefault<Reservable>();
if (reservable != null)
reservation = reservable.Reserve(target, self, this);
}
public void UnReserve()
{
if (Reservation != null)
{
Reservation.Dispose();
Reservation = null;
}
if (reservation == null)
return;
reservation.Dispose();
reservation = null;
}
public bool AircraftCanEnter(Actor a)
@@ -448,12 +450,7 @@ namespace OpenRA.Mods.Common.Traits
if (target.Positions.Any(p => self.World.ActorMap.GetActorsAt(self.World.Map.CellContaining(p)).Any(a => a != self && a != target.Actor)))
return false;
var res = target.Actor.TraitOrDefault<Reservable>();
if (res == null)
return true;
UnReserve();
Reservation = res.Reserve(target.Actor, self, this);
MakeReservation(target.Actor);
return true;
}
@@ -541,12 +538,7 @@ namespace OpenRA.Mods.Common.Traits
}
else
{
var res = order.TargetActor.TraitOrDefault<Reservable>();
if (res != null)
{
UnReserve();
Reservation = res.Reserve(order.TargetActor, self, this);
}
MakeReservation(order.TargetActor);
Action enter = () =>
{