Actor previously cached targetable locations for static actors as an optimization. As we can no longer reference the IPositionable interface, move this optimization to HitShape instead. Although we lose some of the efficiency of caching the final result on the actor, we gain some by allowing HitShape to cache the results as long as they have not changed. So instead of being limited to static actors, we can extend the caching to currently stationary actor.
60 lines
1.5 KiB
C#
60 lines
1.5 KiB
C#
#region Copyright & License Information
|
|
/*
|
|
* Copyright 2007-2021 The OpenRA Developers (see AUTHORS)
|
|
* This file is part of OpenRA, which is free software. It is made
|
|
* available to you under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation, either version 3 of
|
|
* the License, or (at your option) any later version. For more
|
|
* information, see COPYING.
|
|
*/
|
|
#endregion
|
|
|
|
using OpenRA.Activities;
|
|
using OpenRA.Mods.Common.Traits;
|
|
|
|
namespace OpenRA.Mods.Common.Activities
|
|
{
|
|
public class Parachute : Activity
|
|
{
|
|
readonly IPositionable pos;
|
|
readonly WVec fallVector;
|
|
|
|
int groundLevel;
|
|
|
|
public Parachute(Actor self)
|
|
{
|
|
pos = self.TraitOrDefault<IPositionable>();
|
|
|
|
fallVector = new WVec(0, 0, self.Info.TraitInfo<ParachutableInfo>().FallRate);
|
|
IsInterruptible = false;
|
|
}
|
|
|
|
protected override void OnFirstRun(Actor self)
|
|
{
|
|
groundLevel = self.World.Map.CenterOfCell(self.Location).Z;
|
|
foreach (var np in self.TraitsImplementing<INotifyParachute>())
|
|
np.OnParachute(self);
|
|
}
|
|
|
|
public override bool Tick(Actor self)
|
|
{
|
|
var nextPosition = self.CenterPosition - fallVector;
|
|
if (nextPosition.Z < groundLevel)
|
|
return true;
|
|
|
|
pos.SetCenterPosition(self, nextPosition);
|
|
|
|
return false;
|
|
}
|
|
|
|
protected override void OnLastRun(Actor self)
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
}
|