Fix units from transports appearing at load point.

This commit is contained in:
tovl
2019-08-12 00:46:54 +02:00
committed by abcdefg30
parent 70459b311e
commit 2d394f33b8
22 changed files with 186 additions and 86 deletions

View File

@@ -219,6 +219,7 @@ namespace OpenRA.Mods.Common.Traits
public bool ForceLanding { get; private set; }
IEnumerable<CPos> landingCells = Enumerable.Empty<CPos>();
bool requireForceMove;
int moveIntoWorldDelay;
public static WPos GroundPosition(Actor self)
{
@@ -229,7 +230,6 @@ namespace OpenRA.Mods.Common.Traits
bool airborne;
bool cruising;
bool firstTick = true;
int airborneToken = ConditionManager.InvalidConditionToken;
int cruisingToken = ConditionManager.InvalidConditionToken;
@@ -250,6 +250,7 @@ namespace OpenRA.Mods.Common.Traits
SetPosition(self, init.Get<CenterPositionInit, WPos>());
Facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : Info.InitialFacing;
moveIntoWorldDelay = init.Contains<MoveIntoWorldDelayInit>() ? init.Get<MoveIntoWorldDelayInit, int>() : 0;
}
public WDist LandAltitude
@@ -307,6 +308,8 @@ namespace OpenRA.Mods.Common.Traits
notifyMoving = self.TraitsImplementing<INotifyMoving>().ToArray();
positionOffsets = self.TraitsImplementing<IAircraftCenterPositionOffset>().ToArray();
overrideAircraftLanding = self.TraitOrDefault<IOverrideAircraftLanding>();
self.QueueActivity(MoveIntoWorld(self, moveIntoWorldDelay));
}
void INotifyAddedToWorld.AddedToWorld(Actor self)
@@ -346,20 +349,6 @@ namespace OpenRA.Mods.Common.Traits
protected virtual void Tick(Actor self)
{
if (firstTick)
{
firstTick = false;
var host = GetActorBelow();
if (host == null)
return;
MakeReservation(host);
if (Info.TakeOffOnCreation)
UnReserve(true);
}
// Add land activity if LandOnCondition resolves to true and the actor can land at the current location.
if (!ForceLanding && landNow.HasValue && landNow.Value && airborne && CanLand(self.Location)
&& !((self.CurrentActivity is Land) || self.CurrentActivity is Turn))
@@ -868,9 +857,46 @@ namespace OpenRA.Mods.Common.Traits
initialTargetPosition, targetLineColor);
}
public Activity MoveIntoWorld(Actor self, CPos cell, SubCell subCell = SubCell.Any)
public Activity MoveIntoWorld(Actor self, int delay = 0)
{
return new Fly(self, Target.FromCell(self.World, cell, subCell));
return new MoveIntoWorldActivity(self, delay);
}
class MoveIntoWorldActivity : Activity
{
readonly Actor self;
readonly Aircraft aircraft;
readonly int delay;
public MoveIntoWorldActivity(Actor self, int delay = 0)
{
this.self = self;
aircraft = self.Trait<Aircraft>();
IsInterruptible = false;
this.delay = delay;
}
protected override void OnFirstRun(Actor self)
{
var host = aircraft.GetActorBelow();
if (host != null)
aircraft.MakeReservation(host);
if (delay > 0)
QueueChild(new Wait(delay));
}
public override bool Tick(Actor self)
{
if (!aircraft.Info.TakeOffOnCreation)
return true;
if (self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition).Length <= aircraft.LandAltitude.Length)
QueueChild(new TakeOff(self));
aircraft.UnReserve();
return true;
}
}
public Activity MoveToTarget(Actor self, Target target,

View File

@@ -29,9 +29,6 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Type tags on this exit.")]
public readonly HashSet<string> ProductionTypes = new HashSet<string>();
[Desc("AttackMove to a RallyPoint or stay where you are spawned.")]
public readonly bool MoveIntoWorld = true;
[Desc("Number of ticks to wait before moving into the world.")]
public readonly int ExitDelay = 0;

View File

@@ -11,6 +11,7 @@
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Traits.Render;
using OpenRA.Primitives;
using OpenRA.Traits;
@@ -106,7 +107,7 @@ namespace OpenRA.Mods.Common.Traits
}
void INotifyParachute.OnParachute(Actor self) { }
void INotifyParachute.OnLanded(Actor self, Actor ignore)
void INotifyParachute.OnLanded(Actor self)
{
// Check whether the crate landed on anything
var landedOn = self.World.ActorMap.GetActorsAt(self.Location)
@@ -237,6 +238,9 @@ namespace OpenRA.Mods.Common.Traits
var cs = self.World.WorldActor.TraitOrDefault<CrateSpawner>();
if (cs != null)
cs.IncrementCrates();
if (self.World.Map.DistanceAboveTerrain(CenterPosition) > WDist.Zero && self.TraitOrDefault<Parachutable>() != null)
self.QueueActivity(new Parachute(self));
}
void INotifyRemovedFromWorld.RemovedFromWorld(Actor self)

View File

@@ -82,11 +82,10 @@ namespace OpenRA.Mods.Common.Traits
self.World.AddFrameEndTask(w =>
{
pilotPositionable.SetPosition(pilot, pilotCell, pilotSubCell);
w.Add(pilot);
var dropPosition = pilot.CenterPosition + new WVec(0, 0, self.CenterPosition.Z - pilot.CenterPosition.Z);
pilotPositionable.SetVisualPosition(pilot, dropPosition);
pilot.QueueActivity(new Parachute(pilot));
w.Add(pilot);
});
Game.Sound.Play(SoundType.World, Info.ChuteSound, cp);

View File

@@ -144,6 +144,7 @@ namespace OpenRA.Mods.Common.Traits
{
readonly Actor self;
readonly Lazy<IEnumerable<int>> speedModifiers;
readonly int moveIntoWorldDelay;
#region IMove CurrentMovementTypes
MovementType movementTypes;
@@ -239,6 +240,8 @@ namespace OpenRA.Mods.Common.Traits
// Use LocationInit if you want to insert the actor into the ActorMap!
if (init.Contains<CenterPositionInit>())
SetVisualPosition(self, init.Get<CenterPositionInit, WPos>());
moveIntoWorldDelay = init.Contains<MoveIntoWorldDelayInit>() ? init.Get<MoveIntoWorldDelayInit, int>() : 0;
}
protected override void Created(Actor self)
@@ -251,6 +254,7 @@ namespace OpenRA.Mods.Common.Traits
Locomotor = self.World.WorldActor.TraitsImplementing<Locomotor>()
.Single(l => l.Info.Name == Info.Locomotor);
self.QueueActivity(MoveIntoWorld(self, moveIntoWorldDelay));
base.Created(self);
}
@@ -563,22 +567,59 @@ namespace OpenRA.Mods.Common.Traits
return WrapMove(new Follow(self, target, minRange, maxRange, initialTargetPosition, targetLineColor));
}
public Activity MoveIntoWorld(Actor self, CPos cell, SubCell subCell = SubCell.Any)
public Activity MoveIntoWorld(Actor self, int delay = 0)
{
var pos = self.CenterPosition;
return new MoveIntoWorldActivity(self, delay);
}
if (subCell == SubCell.Any)
subCell = Info.LocomotorInfo.SharesCell ? self.World.ActorMap.FreeSubCell(cell, subCell) : SubCell.FullCell;
class MoveIntoWorldActivity : Activity
{
readonly Actor self;
readonly Mobile mobile;
// TODO: solve/reduce cell is full problem
if (subCell == SubCell.Invalid)
subCell = self.World.Map.Grid.DefaultSubCell;
CPos cell;
SubCell subCell;
WPos pos;
int delay;
// Reserve the exit cell
SetPosition(self, cell, subCell);
SetVisualPosition(self, pos);
public MoveIntoWorldActivity(Actor self, int delay = 0)
{
this.self = self;
mobile = self.Trait<Mobile>();
IsInterruptible = false;
this.delay = delay;
}
return WrapMove(VisualMove(self, pos, self.World.Map.CenterOfSubCell(cell, subCell), cell));
protected override void OnFirstRun(Actor self)
{
pos = self.CenterPosition;
if (self.World.Map.DistanceAboveTerrain(pos) > WDist.Zero && self.TraitOrDefault<Parachutable>() != null)
QueueChild(new Parachute(self));
}
public override bool Tick(Actor self)
{
pos = self.CenterPosition;
cell = mobile.ToCell;
subCell = mobile.ToSubCell;
if (subCell == SubCell.Any)
subCell = mobile.Info.LocomotorInfo.SharesCell ? self.World.ActorMap.FreeSubCell(cell, subCell) : SubCell.FullCell;
// TODO: solve/reduce cell is full problem
if (subCell == SubCell.Invalid)
subCell = self.World.Map.Grid.DefaultSubCell;
// Reserve the exit cell
mobile.SetPosition(self, cell, subCell);
mobile.SetVisualPosition(self, pos);
if (delay > 0)
QueueChild(new Wait(delay));
QueueChild(mobile.VisualMove(self, pos, self.World.Map.CenterOfSubCell(cell, subCell)));
return true;
}
}
public Activity MoveToTarget(Actor self, Target target,

View File

@@ -105,12 +105,10 @@ namespace OpenRA.Mods.Common.Traits
self.World.AddFrameEndTask(w =>
{
dropPositionable.SetPosition(dropActor, dropCell, dropSubCell);
w.Add(dropActor);
var dropPosition = dropActor.CenterPosition + new WVec(0, 0, self.CenterPosition.Z - dropActor.CenterPosition.Z);
dropPositionable.SetVisualPosition(dropActor, dropPosition);
dropActor.QueueActivity(new Parachute(dropActor));
w.Add(dropActor);
});
Game.Sound.Play(SoundType.World, info.ChuteSound, self.CenterPosition);

View File

@@ -62,6 +62,8 @@ namespace OpenRA.Mods.Common.Traits
readonly ParachutableInfo info;
readonly IPositionable positionable;
public Actor IgnoreActor;
ConditionManager conditionManager;
int parachutingToken = ConditionManager.InvalidConditionToken;
@@ -86,7 +88,7 @@ namespace OpenRA.Mods.Common.Traits
parachutingToken = conditionManager.GrantCondition(self, info.ParachutingCondition);
}
void INotifyParachute.OnLanded(Actor self, Actor ignore)
void INotifyParachute.OnLanded(Actor self)
{
IsInAir = false;
@@ -100,7 +102,7 @@ namespace OpenRA.Mods.Common.Traits
if (positionable.CanEnterCell(cell, self))
return;
if (ignore != null && self.World.ActorMap.GetActorsAt(cell).Any(a => a != ignore))
if (IgnoreActor != null && self.World.ActorMap.GetActorsAt(cell).Any(a => a != IgnoreActor))
return;
var onWater = info.WaterTerrainTypes.Contains(self.World.Map.GetTerrainInfo(cell).Type);

View File

@@ -162,7 +162,7 @@ namespace OpenRA.Mods.Common.Traits
if (!order.Queued)
self.CancelActivity();
self.QueueActivity(new EnterTransport(self, order.Target));
self.QueueActivity(new RideTransport(self, order.Target));
self.ShowTargetLines();
}

View File

@@ -73,6 +73,8 @@ namespace OpenRA.Mods.Common.Traits
td.Add(new LocationInit(exit));
td.Add(new CenterPositionInit(spawn));
td.Add(new FacingInit(initialFacing));
if (exitinfo != null)
td.Add(new MoveIntoWorldDelayInit(exitinfo.ExitDelay));
}
self.World.AddFrameEndTask(w =>
@@ -81,16 +83,7 @@ namespace OpenRA.Mods.Common.Traits
var move = newUnit.TraitOrDefault<IMove>();
if (exitinfo != null && move != null)
{
if (exitinfo.MoveIntoWorld)
{
if (exitinfo.ExitDelay > 0)
newUnit.QueueActivity(new Wait(exitinfo.ExitDelay, false));
newUnit.QueueActivity(move.MoveIntoWorld(newUnit, exit));
newUnit.QueueActivity(new AttackMoveActivity(newUnit, () => move.MoveTo(exitLocation, 1, targetLineColor: Color.OrangeRed)));
}
}
newUnit.QueueActivity(new AttackMoveActivity(newUnit, () => move.MoveTo(exitLocation, 1, targetLineColor: Color.OrangeRed)));
if (!self.IsDead)
foreach (var t in self.TraitsImplementing<INotifyProduction>())

View File

@@ -127,25 +127,17 @@ namespace OpenRA.Mods.Common.Traits
td.Add(new LocationInit(exit));
td.Add(new CenterPositionInit(spawn));
td.Add(new FacingInit(initialFacing));
td.Add(new MoveIntoWorldDelayInit(exitinfo.ExitDelay));
}
self.World.AddFrameEndTask(w =>
{
var newUnit = self.World.CreateActor(producee.Name, td);
newUnit.Trait<Parachutable>().IgnoreActor = self;
newUnit.QueueActivity(new Parachute(newUnit, self));
var move = newUnit.TraitOrDefault<IMove>();
if (move != null)
{
if (exitinfo.MoveIntoWorld)
{
if (exitinfo.ExitDelay > 0)
newUnit.QueueActivity(new Wait(exitinfo.ExitDelay, false));
newUnit.QueueActivity(move.MoveIntoWorld(newUnit, exit));
newUnit.QueueActivity(new AttackMoveActivity(newUnit, () => move.MoveTo(exitLocation, 1, targetLineColor: Color.OrangeRed)));
}
}
newUnit.QueueActivity(new AttackMoveActivity(newUnit, () => move.MoveTo(exitLocation, 1, targetLineColor: Color.OrangeRed)));
if (!self.IsDead)
foreach (var t in self.TraitsImplementing<INotifyProduction>())

View File

@@ -81,7 +81,7 @@ namespace OpenRA.Mods.Common.Traits.Render
void INotifyParachute.OnParachute(Actor self) { }
void INotifyParachute.OnLanded(Actor self, Actor ignore)
void INotifyParachute.OnLanded(Actor self)
{
PlaySequence();
}