Fix TakeOffOnCreation
This commit is contained in:
committed by
Matthias Mailänder
parent
c009f58980
commit
60a446123b
@@ -286,6 +286,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public bool RequireForceMove;
|
public bool RequireForceMove;
|
||||||
|
|
||||||
readonly int creationActivityDelay;
|
readonly int creationActivityDelay;
|
||||||
|
readonly CPos[] creationRallyPoint;
|
||||||
|
|
||||||
bool notify = true;
|
bool notify = true;
|
||||||
|
|
||||||
@@ -320,6 +321,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
Facing = init.GetValue<FacingInit, WAngle>(Info.InitialFacing);
|
Facing = init.GetValue<FacingInit, WAngle>(Info.InitialFacing);
|
||||||
creationActivityDelay = init.GetValue<CreationActivityDelayInit, int>(0);
|
creationActivityDelay = init.GetValue<CreationActivityDelayInit, int>(0);
|
||||||
|
creationRallyPoint = init.GetOrDefault<RallyPointInit>()?.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WDist LandAltitude
|
public WDist LandAltitude
|
||||||
@@ -1219,19 +1221,21 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
Activity ICreationActivity.GetCreationActivity()
|
Activity ICreationActivity.GetCreationActivity()
|
||||||
{
|
{
|
||||||
return new AssociateWithAirfieldActivity(self, creationActivityDelay);
|
return new AssociateWithAirfieldActivity(self, creationActivityDelay, creationRallyPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class AssociateWithAirfieldActivity : Activity
|
sealed class AssociateWithAirfieldActivity : Activity
|
||||||
{
|
{
|
||||||
readonly Aircraft aircraft;
|
readonly Aircraft aircraft;
|
||||||
readonly int delay;
|
readonly int delay;
|
||||||
|
readonly CPos[] rallyPoint;
|
||||||
|
|
||||||
public AssociateWithAirfieldActivity(Actor self, int delay = 0)
|
public AssociateWithAirfieldActivity(Actor self, int delay, CPos[] rallyPoint)
|
||||||
{
|
{
|
||||||
aircraft = self.Trait<Aircraft>();
|
aircraft = self.Trait<Aircraft>();
|
||||||
IsInterruptible = false;
|
IsInterruptible = false;
|
||||||
this.delay = delay;
|
this.delay = delay;
|
||||||
|
this.rallyPoint = rallyPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnFirstRun(Actor self)
|
protected override void OnFirstRun(Actor self)
|
||||||
@@ -1253,8 +1257,14 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition).Length <= aircraft.LandAltitude.Length)
|
if (rallyPoint != null && aircraft.Info.TakeOffOnCreation)
|
||||||
QueueChild(new TakeOff(self));
|
{
|
||||||
|
foreach (var cell in rallyPoint)
|
||||||
|
self.QueueActivity(new AttackMoveActivity(self, () => aircraft.MoveTo(cell, 1, evaluateNearestMovableCell: true, targetLineColor: Color.OrangeRed)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if (self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition).Length <= aircraft.LandAltitude.Length)
|
||||||
|
QueueChild(new TakeOff(self));
|
||||||
|
|
||||||
aircraft.UnReserve();
|
aircraft.UnReserve();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -177,6 +177,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
readonly bool returnToCellOnCreation;
|
readonly bool returnToCellOnCreation;
|
||||||
readonly bool returnToCellOnCreationRecalculateSubCell = true;
|
readonly bool returnToCellOnCreationRecalculateSubCell = true;
|
||||||
readonly int creationActivityDelay;
|
readonly int creationActivityDelay;
|
||||||
|
readonly CPos[] creationRallypoint;
|
||||||
|
|
||||||
#region IMove CurrentMovementTypes
|
#region IMove CurrentMovementTypes
|
||||||
MovementType movementTypes;
|
MovementType movementTypes;
|
||||||
@@ -298,6 +299,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
|
|
||||||
creationActivityDelay = init.GetValue<CreationActivityDelayInit, int>(0);
|
creationActivityDelay = init.GetValue<CreationActivityDelayInit, int>(0);
|
||||||
|
creationRallypoint = init.GetOrDefault<RallyPointInit>()?.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Created(Actor self)
|
protected override void Created(Actor self)
|
||||||
@@ -967,9 +969,38 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class LeaveProductionActivity : Activity
|
||||||
|
{
|
||||||
|
readonly Mobile mobile;
|
||||||
|
readonly int delay;
|
||||||
|
readonly CPos[] rallyPoint;
|
||||||
|
readonly ReturnToCellActivity returnToCell;
|
||||||
|
|
||||||
|
public LeaveProductionActivity(Actor self, int delay, CPos[] rallyPoint, ReturnToCellActivity returnToCell)
|
||||||
|
{
|
||||||
|
mobile = self.Trait<Mobile>();
|
||||||
|
IsInterruptible = false;
|
||||||
|
this.delay = delay;
|
||||||
|
this.rallyPoint = rallyPoint;
|
||||||
|
this.returnToCell = returnToCell;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnFirstRun(Actor self)
|
||||||
|
{
|
||||||
|
if (returnToCell != null)
|
||||||
|
self.QueueActivity(returnToCell);
|
||||||
|
else if (delay > 0)
|
||||||
|
self.QueueActivity(new Wait(delay));
|
||||||
|
|
||||||
|
if (rallyPoint != null)
|
||||||
|
foreach (var cell in rallyPoint)
|
||||||
|
self.QueueActivity(new AttackMoveActivity(self, () => mobile.MoveTo(cell, 1, evaluateNearestMovableCell: true, targetLineColor: Color.OrangeRed)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Activity ICreationActivity.GetCreationActivity()
|
Activity ICreationActivity.GetCreationActivity()
|
||||||
{
|
{
|
||||||
return returnToCellOnCreation ? new ReturnToCellActivity(self, creationActivityDelay, returnToCellOnCreationRecalculateSubCell) : null;
|
return new LeaveProductionActivity(self, creationActivityDelay, creationRallypoint, returnToCellOnCreation ? new ReturnToCellActivity(self, creationActivityDelay, returnToCellOnCreationRecalculateSubCell) : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class MoveOrderTargeter : IOrderTargeter
|
sealed class MoveOrderTargeter : IOrderTargeter
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using OpenRA.Mods.Common.Activities;
|
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
@@ -82,18 +81,15 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
td.Add(new CenterPositionInit(spawn));
|
td.Add(new CenterPositionInit(spawn));
|
||||||
td.Add(new FacingInit(initialFacing));
|
td.Add(new FacingInit(initialFacing));
|
||||||
if (exitinfo != null)
|
if (exitinfo != null)
|
||||||
|
{
|
||||||
td.Add(new CreationActivityDelayInit(exitinfo.ExitDelay));
|
td.Add(new CreationActivityDelayInit(exitinfo.ExitDelay));
|
||||||
|
td.Add(new RallyPointInit(exitLocations.ToArray()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.World.AddFrameEndTask(w =>
|
self.World.AddFrameEndTask(w =>
|
||||||
{
|
{
|
||||||
var newUnit = self.World.CreateActor(producee.Name, td);
|
var newUnit = self.World.CreateActor(producee.Name, td);
|
||||||
|
|
||||||
var move = newUnit.TraitOrDefault<IMove>();
|
|
||||||
if (exitinfo != null && move != null)
|
|
||||||
foreach (var cell in exitLocations)
|
|
||||||
newUnit.QueueActivity(new AttackMoveActivity(newUnit, () => move.MoveTo(cell, 1, evaluateNearestMovableCell: true, targetLineColor: Color.OrangeRed)));
|
|
||||||
|
|
||||||
if (!self.IsDead)
|
if (!self.IsDead)
|
||||||
foreach (var t in self.TraitsImplementing<INotifyProduction>())
|
foreach (var t in self.TraitsImplementing<INotifyProduction>())
|
||||||
t.UnitProduced(self, newUnit, exit);
|
t.UnitProduced(self, newUnit, exit);
|
||||||
@@ -143,4 +139,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
mobileInfo.CanEnterCell(self.World, self, self.Location + s.ExitCell, ignoreActor: self);
|
mobileInfo.CanEnterCell(self.World, self, self.Location + s.ExitCell, ignoreActor: self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class RallyPointInit : ValueActorInit<CPos[]>, ISingleInstanceInit
|
||||||
|
{
|
||||||
|
public RallyPointInit(CPos[] value)
|
||||||
|
: base(value) { }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user