Rework paradrop logic to be more robust.
This commit is contained in:
@@ -18,72 +18,45 @@ namespace OpenRA.Mods.Common.Activities
|
||||
public class Parachute : Activity
|
||||
{
|
||||
readonly IPositionable pos;
|
||||
readonly ParachutableInfo para;
|
||||
readonly WVec fallVector;
|
||||
readonly Actor ignore;
|
||||
|
||||
WPos dropPosition;
|
||||
WPos currentPosition;
|
||||
bool triggered = false;
|
||||
int groundLevel;
|
||||
|
||||
public Parachute(Actor self, WPos dropPosition, Actor ignoreActor = null)
|
||||
public Parachute(Actor self, Actor ignoreActor = null)
|
||||
{
|
||||
pos = self.TraitOrDefault<IPositionable>();
|
||||
ignore = ignoreActor;
|
||||
|
||||
// Parachutable trait is a prerequisite for running this activity
|
||||
para = self.Info.TraitInfo<ParachutableInfo>();
|
||||
fallVector = new WVec(0, 0, para.FallRate);
|
||||
this.dropPosition = dropPosition;
|
||||
fallVector = new WVec(0, 0, self.Info.TraitInfo<ParachutableInfo>().FallRate);
|
||||
IsInterruptible = false;
|
||||
}
|
||||
|
||||
Activity FirstTick(Actor self)
|
||||
protected override void OnFirstRun(Actor self)
|
||||
{
|
||||
triggered = true;
|
||||
|
||||
groundLevel = self.World.Map.CenterOfCell(self.Location).Z;
|
||||
foreach (var np in self.TraitsImplementing<INotifyParachute>())
|
||||
np.OnParachute(self);
|
||||
|
||||
// Place the actor and retrieve its visual position (CenterPosition)
|
||||
pos.SetPosition(self, dropPosition);
|
||||
currentPosition = self.CenterPosition;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
Activity LastTick(Actor self)
|
||||
{
|
||||
var dat = self.World.Map.DistanceAboveTerrain(currentPosition);
|
||||
pos.SetPosition(self, currentPosition - new WVec(WDist.Zero, WDist.Zero, dat));
|
||||
|
||||
foreach (var np in self.TraitsImplementing<INotifyParachute>())
|
||||
np.OnLanded(self, ignore);
|
||||
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
{
|
||||
// If this is the first tick
|
||||
if (!triggered)
|
||||
return FirstTick(self);
|
||||
var nextPosition = self.CenterPosition - fallVector;
|
||||
if (nextPosition.Z < groundLevel)
|
||||
return NextActivity;
|
||||
|
||||
currentPosition -= fallVector;
|
||||
|
||||
// If the unit has landed, this will be the last tick
|
||||
if (self.World.Map.DistanceAboveTerrain(currentPosition).Length <= 0)
|
||||
return LastTick(self);
|
||||
|
||||
pos.SetVisualPosition(self, currentPosition);
|
||||
pos.SetVisualPosition(self, nextPosition);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
// Only the last queued activity (given order) is kept
|
||||
public override void Queue(Actor self, Activity activity)
|
||||
protected override void OnLastRun(Actor self)
|
||||
{
|
||||
NextActivity = activity;
|
||||
var centerPosition = self.CenterPosition;
|
||||
pos.SetPosition(self, centerPosition - new WVec(0, 0, groundLevel - centerPosition.Z));
|
||||
|
||||
foreach (var np in self.TraitsImplementing<INotifyParachute>())
|
||||
np.OnLanded(self, ignore);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user