Replace MoveIntoWorld with ReturnToCell/AssociateWithAirfield.
This commit is contained in:
@@ -191,7 +191,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
WPos? initialTargetPosition = null, Color? targetLineColor = null) { return null; }
|
WPos? initialTargetPosition = null, Color? targetLineColor = null) { return null; }
|
||||||
public Activity MoveFollow(Actor self, Target target, WDist minRange, WDist maxRange,
|
public Activity MoveFollow(Actor self, Target target, WDist minRange, WDist maxRange,
|
||||||
WPos? initialTargetPosition = null, Color? targetLineColor = null) { return null; }
|
WPos? initialTargetPosition = null, Color? targetLineColor = null) { return null; }
|
||||||
public Activity MoveIntoWorld(Actor self, int delay = 0) { return null; }
|
public Activity ReturnToCell(Actor self) { return null; }
|
||||||
public Activity MoveToTarget(Actor self, Target target,
|
public Activity MoveToTarget(Actor self, Target target,
|
||||||
WPos? initialTargetPosition = null, Color? targetLineColor = null) { return null; }
|
WPos? initialTargetPosition = null, Color? targetLineColor = null) { return null; }
|
||||||
public Activity MoveIntoTarget(Actor self, Target target) { return null; }
|
public Activity MoveIntoTarget(Actor self, Target target) { return null; }
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
case EnterState.Exiting:
|
case EnterState.Exiting:
|
||||||
{
|
{
|
||||||
QueueChild(move.MoveIntoWorld(self));
|
QueueChild(move.ReturnToCell(self));
|
||||||
lastState = EnterState.Finished;
|
lastState = EnterState.Finished;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,13 +24,13 @@ namespace OpenRA.Mods.Common
|
|||||||
public int Value(World world) { return value; }
|
public int Value(World world) { return value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MoveIntoWorldDelayInit : IActorInit<int>
|
public class CreationActivityDelayInit : IActorInit<int>
|
||||||
{
|
{
|
||||||
[FieldFromYamlKey]
|
[FieldFromYamlKey]
|
||||||
readonly int value = 0;
|
readonly int value = 0;
|
||||||
|
|
||||||
public MoveIntoWorldDelayInit() { }
|
public CreationActivityDelayInit() { }
|
||||||
public MoveIntoWorldDelayInit(int init) { value = init; }
|
public CreationActivityDelayInit(int init) { value = init; }
|
||||||
public int Value(World world) { return value; }
|
public int Value(World world) { return value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
var pos = Self.CenterPosition;
|
var pos = Self.CenterPosition;
|
||||||
mobile.SetPosition(Self, cell);
|
mobile.SetPosition(Self, cell);
|
||||||
mobile.SetVisualPosition(Self, pos);
|
mobile.SetVisualPosition(Self, pos);
|
||||||
Self.QueueActivity(mobile.MoveIntoWorld(Self));
|
Self.QueueActivity(mobile.ReturnToCell(Self));
|
||||||
}
|
}
|
||||||
|
|
||||||
[ScriptActorPropertyActivity]
|
[ScriptActorPropertyActivity]
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Eluant;
|
||||||
using OpenRA.Mods.Common.Activities;
|
using OpenRA.Mods.Common.Activities;
|
||||||
using OpenRA.Mods.Common.Traits;
|
using OpenRA.Mods.Common.Traits;
|
||||||
using OpenRA.Scripting;
|
using OpenRA.Scripting;
|
||||||
@@ -35,7 +36,13 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
public int PassengerCount { get { return cargo.Passengers.Count(); } }
|
public int PassengerCount { get { return cargo.Passengers.Count(); } }
|
||||||
|
|
||||||
[Desc("Teleport an existing actor inside this transport.")]
|
[Desc("Teleport an existing actor inside this transport.")]
|
||||||
public void LoadPassenger(Actor a) { cargo.Load(Self, a); }
|
public void LoadPassenger(Actor a)
|
||||||
|
{
|
||||||
|
if (!a.IsIdle)
|
||||||
|
throw new LuaException("LoadPassenger requires the passenger to be idle.");
|
||||||
|
|
||||||
|
cargo.Load(Self, a);
|
||||||
|
}
|
||||||
|
|
||||||
[Desc("Remove the first actor from the transport. This actor is not added to the world.")]
|
[Desc("Remove the first actor from the transport. This actor is not added to the world.")]
|
||||||
public Actor UnloadPassenger() { return cargo.Unload(Self); }
|
public Actor UnloadPassenger() { return cargo.Unload(Self); }
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
IEnumerable<CPos> landingCells = Enumerable.Empty<CPos>();
|
IEnumerable<CPos> landingCells = Enumerable.Empty<CPos>();
|
||||||
bool requireForceMove;
|
bool requireForceMove;
|
||||||
int moveIntoWorldDelay;
|
int creationActivityDelay;
|
||||||
|
|
||||||
public static WPos GroundPosition(Actor self)
|
public static WPos GroundPosition(Actor self)
|
||||||
{
|
{
|
||||||
@@ -251,7 +251,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
SetPosition(self, init.Get<CenterPositionInit, WPos>());
|
SetPosition(self, init.Get<CenterPositionInit, WPos>());
|
||||||
|
|
||||||
Facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : Info.InitialFacing;
|
Facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : Info.InitialFacing;
|
||||||
moveIntoWorldDelay = init.Contains<MoveIntoWorldDelayInit>() ? init.Get<MoveIntoWorldDelayInit, int>() : 0;
|
|
||||||
|
if (init.Contains<CreationActivityDelayInit>())
|
||||||
|
creationActivityDelay = init.Get<CreationActivityDelayInit, int>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public WDist LandAltitude
|
public WDist LandAltitude
|
||||||
@@ -841,18 +843,15 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
initialTargetPosition, targetLineColor);
|
initialTargetPosition, targetLineColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Activity MoveIntoWorld(Actor self, int delay = 0)
|
public Activity ReturnToCell(Actor self) { return null; }
|
||||||
{
|
|
||||||
return new MoveIntoWorldActivity(self, delay);
|
|
||||||
}
|
|
||||||
|
|
||||||
class MoveIntoWorldActivity : Activity
|
class AssociateWithAirfieldActivity : Activity
|
||||||
{
|
{
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
readonly Aircraft aircraft;
|
readonly Aircraft aircraft;
|
||||||
readonly int delay;
|
readonly int delay;
|
||||||
|
|
||||||
public MoveIntoWorldActivity(Actor self, int delay = 0)
|
public AssociateWithAirfieldActivity(Actor self, int delay = 0)
|
||||||
{
|
{
|
||||||
this.self = self;
|
this.self = self;
|
||||||
aircraft = self.Trait<Aircraft>();
|
aircraft = self.Trait<Aircraft>();
|
||||||
@@ -1164,7 +1163,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
Activity ICreationActivity.GetCreationActivity()
|
Activity ICreationActivity.GetCreationActivity()
|
||||||
{
|
{
|
||||||
return MoveIntoWorld(self, moveIntoWorldDelay);
|
return new AssociateWithAirfieldActivity(self, creationActivityDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AircraftMoveOrderTargeter : IOrderTargeter
|
public class AircraftMoveOrderTargeter : IOrderTargeter
|
||||||
|
|||||||
@@ -406,11 +406,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
// If not initialized then this will be notified in the first tick
|
// If not initialized then this will be notified in the first tick
|
||||||
if (initialized)
|
if (initialized)
|
||||||
{
|
{
|
||||||
foreach (var npe in self.TraitsImplementing<INotifyPassengerEntered>())
|
|
||||||
npe.OnPassengerEntered(self, a);
|
|
||||||
|
|
||||||
foreach (var nec in a.TraitsImplementing<INotifyEnteredCargo>())
|
foreach (var nec in a.TraitsImplementing<INotifyEnteredCargo>())
|
||||||
nec.OnEnteredCargo(a, self);
|
nec.OnEnteredCargo(a, self);
|
||||||
|
|
||||||
|
foreach (var npe in self.TraitsImplementing<INotifyPassengerEntered>())
|
||||||
|
npe.OnPassengerEntered(self, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
var p = a.Trait<Passenger>();
|
var p = a.Trait<Passenger>();
|
||||||
@@ -507,11 +507,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
c.Trait<Passenger>().Transport = self;
|
c.Trait<Passenger>().Transport = self;
|
||||||
|
|
||||||
foreach (var npe in self.TraitsImplementing<INotifyPassengerEntered>())
|
|
||||||
npe.OnPassengerEntered(self, c);
|
|
||||||
|
|
||||||
foreach (var nec in c.TraitsImplementing<INotifyEnteredCargo>())
|
foreach (var nec in c.TraitsImplementing<INotifyEnteredCargo>())
|
||||||
nec.OnEnteredCargo(c, self);
|
nec.OnEnteredCargo(c, self);
|
||||||
|
|
||||||
|
foreach (var npe in self.TraitsImplementing<INotifyPassengerEntered>())
|
||||||
|
npe.OnPassengerEntered(self, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
|||||||
@@ -143,7 +143,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
readonly Lazy<IEnumerable<int>> speedModifiers;
|
readonly Lazy<IEnumerable<int>> speedModifiers;
|
||||||
readonly int moveIntoWorldDelay;
|
|
||||||
|
readonly bool returnToCellOnCreation;
|
||||||
|
readonly bool returnToCellOnCreationRecalculateSubCell = true;
|
||||||
|
readonly int creationActivityDelay;
|
||||||
|
|
||||||
#region IMove CurrentMovementTypes
|
#region IMove CurrentMovementTypes
|
||||||
MovementType movementTypes;
|
MovementType movementTypes;
|
||||||
@@ -228,7 +231,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
ToSubCell = FromSubCell = info.LocomotorInfo.SharesCell ? init.World.Map.Grid.DefaultSubCell : SubCell.FullCell;
|
ToSubCell = FromSubCell = info.LocomotorInfo.SharesCell ? init.World.Map.Grid.DefaultSubCell : SubCell.FullCell;
|
||||||
if (init.Contains<SubCellInit>())
|
if (init.Contains<SubCellInit>())
|
||||||
|
{
|
||||||
FromSubCell = ToSubCell = init.Get<SubCellInit, SubCell>();
|
FromSubCell = ToSubCell = init.Get<SubCellInit, SubCell>();
|
||||||
|
returnToCellOnCreationRecalculateSubCell = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (init.Contains<LocationInit>())
|
if (init.Contains<LocationInit>())
|
||||||
{
|
{
|
||||||
@@ -238,12 +244,16 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
Facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : info.InitialFacing;
|
Facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : info.InitialFacing;
|
||||||
|
|
||||||
// Sets the visual position to WPos accuracy
|
// Sets the initial visual position
|
||||||
// Use LocationInit if you want to insert the actor into the ActorMap!
|
// Unit will move into the cell grid (defined by LocationInit) as its initial activity
|
||||||
if (init.Contains<CenterPositionInit>())
|
if (init.Contains<CenterPositionInit>())
|
||||||
|
{
|
||||||
SetVisualPosition(self, init.Get<CenterPositionInit, WPos>());
|
SetVisualPosition(self, init.Get<CenterPositionInit, WPos>());
|
||||||
|
returnToCellOnCreation = true;
|
||||||
|
}
|
||||||
|
|
||||||
moveIntoWorldDelay = init.Contains<MoveIntoWorldDelayInit>() ? init.Get<MoveIntoWorldDelayInit, int>() : 0;
|
if (init.Contains<CreationActivityDelayInit>())
|
||||||
|
creationActivityDelay = init.Get<CreationActivityDelayInit, int>();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Created(Actor self)
|
protected override void Created(Actor self)
|
||||||
@@ -568,27 +578,27 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return WrapMove(new Follow(self, target, minRange, maxRange, initialTargetPosition, targetLineColor));
|
return WrapMove(new Follow(self, target, minRange, maxRange, initialTargetPosition, targetLineColor));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Activity MoveIntoWorld(Actor self, int delay = 0)
|
public Activity ReturnToCell(Actor self)
|
||||||
{
|
{
|
||||||
return new MoveIntoWorldActivity(self, delay);
|
return new ReturnToCellActivity(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
class MoveIntoWorldActivity : Activity
|
class ReturnToCellActivity : Activity
|
||||||
{
|
{
|
||||||
readonly Actor self;
|
|
||||||
readonly Mobile mobile;
|
readonly Mobile mobile;
|
||||||
|
readonly bool recalculateSubCell;
|
||||||
|
|
||||||
CPos cell;
|
CPos cell;
|
||||||
SubCell subCell;
|
SubCell subCell;
|
||||||
WPos pos;
|
WPos pos;
|
||||||
int delay;
|
int delay;
|
||||||
|
|
||||||
public MoveIntoWorldActivity(Actor self, int delay = 0)
|
public ReturnToCellActivity(Actor self, int delay = 0, bool recalculateSubCell = false)
|
||||||
{
|
{
|
||||||
this.self = self;
|
|
||||||
mobile = self.Trait<Mobile>();
|
mobile = self.Trait<Mobile>();
|
||||||
IsInterruptible = false;
|
IsInterruptible = false;
|
||||||
this.delay = delay;
|
this.delay = delay;
|
||||||
|
this.recalculateSubCell = recalculateSubCell;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnFirstRun(Actor self)
|
protected override void OnFirstRun(Actor self)
|
||||||
@@ -604,7 +614,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
cell = mobile.ToCell;
|
cell = mobile.ToCell;
|
||||||
subCell = mobile.ToSubCell;
|
subCell = mobile.ToSubCell;
|
||||||
|
|
||||||
if (subCell == SubCell.Any)
|
if (recalculateSubCell)
|
||||||
subCell = mobile.Info.LocomotorInfo.SharesCell ? self.World.ActorMap.FreeSubCell(cell, subCell) : SubCell.FullCell;
|
subCell = mobile.Info.LocomotorInfo.SharesCell ? self.World.ActorMap.FreeSubCell(cell, subCell) : SubCell.FullCell;
|
||||||
|
|
||||||
// TODO: solve/reduce cell is full problem
|
// TODO: solve/reduce cell is full problem
|
||||||
@@ -898,7 +908,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
Activity ICreationActivity.GetCreationActivity()
|
Activity ICreationActivity.GetCreationActivity()
|
||||||
{
|
{
|
||||||
return MoveIntoWorld(self, moveIntoWorldDelay);
|
return returnToCellOnCreation ? new ReturnToCellActivity(self, creationActivityDelay, returnToCellOnCreationRecalculateSubCell) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
class MoveOrderTargeter : IOrderTargeter
|
class MoveOrderTargeter : IOrderTargeter
|
||||||
|
|||||||
@@ -131,6 +131,16 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (specificCargoToken == ConditionManager.InvalidConditionToken && Info.CargoConditions.TryGetValue(cargo.Info.Name, out specificCargoCondition))
|
if (specificCargoToken == ConditionManager.InvalidConditionToken && Info.CargoConditions.TryGetValue(cargo.Info.Name, out specificCargoCondition))
|
||||||
specificCargoToken = conditionManager.GrantCondition(self, specificCargoCondition);
|
specificCargoToken = conditionManager.GrantCondition(self, specificCargoCondition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Allow scripted / initial actors to move from the unload point back into the cell grid on unload
|
||||||
|
// This is handled by the RideTransport activity for player-loaded cargo
|
||||||
|
if (self.IsIdle)
|
||||||
|
{
|
||||||
|
// IMove is not used anywhere else in this trait, there is no benefit to caching it from Created.
|
||||||
|
var move = self.TraitOrDefault<IMove>();
|
||||||
|
if (move != null)
|
||||||
|
self.QueueActivity(move.ReturnToCell(self));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyExitedCargo.OnExitedCargo(Actor self, Actor cargo)
|
void INotifyExitedCargo.OnExitedCargo(Actor self, Actor cargo)
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ 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 MoveIntoWorldDelayInit(exitinfo.ExitDelay));
|
td.Add(new CreationActivityDelayInit(exitinfo.ExitDelay));
|
||||||
}
|
}
|
||||||
|
|
||||||
self.World.AddFrameEndTask(w =>
|
self.World.AddFrameEndTask(w =>
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
td.Add(new LocationInit(exit));
|
td.Add(new LocationInit(exit));
|
||||||
td.Add(new CenterPositionInit(spawn));
|
td.Add(new CenterPositionInit(spawn));
|
||||||
td.Add(new FacingInit(initialFacing));
|
td.Add(new FacingInit(initialFacing));
|
||||||
td.Add(new MoveIntoWorldDelayInit(exitinfo.ExitDelay));
|
td.Add(new CreationActivityDelayInit(exitinfo.ExitDelay));
|
||||||
}
|
}
|
||||||
|
|
||||||
self.World.AddFrameEndTask(w =>
|
self.World.AddFrameEndTask(w =>
|
||||||
|
|||||||
@@ -435,7 +435,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
WPos? initialTargetPosition = null, Color? targetLineColor = null);
|
WPos? initialTargetPosition = null, Color? targetLineColor = null);
|
||||||
Activity MoveToTarget(Actor self, Target target,
|
Activity MoveToTarget(Actor self, Target target,
|
||||||
WPos? initialTargetPosition = null, Color? targetLineColor = null);
|
WPos? initialTargetPosition = null, Color? targetLineColor = null);
|
||||||
Activity MoveIntoWorld(Actor self, int delay = 0);
|
Activity ReturnToCell(Actor self);
|
||||||
Activity MoveIntoTarget(Actor self, Target target);
|
Activity MoveIntoTarget(Actor self, Target target);
|
||||||
Activity VisualMove(Actor self, WPos fromPos, WPos toPos);
|
Activity VisualMove(Actor self, WPos fromPos, WPos toPos);
|
||||||
int EstimatedMoveDuration(Actor self, WPos fromPos, WPos toPos);
|
int EstimatedMoveDuration(Actor self, WPos fromPos, WPos toPos);
|
||||||
|
|||||||
Reference in New Issue
Block a user