Skip to content

Commit

Permalink
Add acceleration.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mailaender committed Apr 26, 2020
1 parent 0ff11fa commit 3c8f25e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
5 changes: 3 additions & 2 deletions OpenRA.Mods.RA2/Activities/BallisticMissileFly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ public class BallisticMissileFly : Activity
readonly BallisticMissile missile;
readonly WPos initPos;
readonly WPos targetPos;
readonly int length;
readonly int facing;

int length;
int ticks;

public BallisticMissileFly(Actor self, Target target, BallisticMissile missile)
{
this.missile = missile;
initPos = self.CenterPosition;
targetPos = target.CenterPosition;
length = Math.Max((targetPos - initPos).Length / missile.Info.Speed, 1);
length = Math.Max((targetPos - initPos).Length / missile.MovementSpeed, 1);
facing = (targetPos - initPos).Yaw.Facing;
missile.Facing = facing;
}
Expand All @@ -50,6 +50,7 @@ public override bool Tick(Actor self)
return true;
}

length = Math.Max((targetPos - initPos).Length / missile.MovementSpeed, 1);
var pos = WPos.LerpQuadratic(initPos, targetPos, missile.Info.LaunchAngle, ticks, length);
missile.SetPosition(self, pos);

Expand Down
16 changes: 11 additions & 5 deletions OpenRA.Mods.RA2/Traits/BallisticMissile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ namespace OpenRA.Mods.RA2.Traits
[Desc("This unit, when ordered to move, will fly in ballistic path then will detonate itself upon reaching target.")]
public class BallisticMissileInfo : ITraitInfo, IMoveInfo, IPositionableInfo, IFacingInfo
{
[Desc("Projectile speed in WDist / tick, two values indicate variable velocity.")]
public readonly int Speed = 17;
[Desc("Initial projectile speed in WDist / tick.")]
public readonly int Speed = 1;

[Desc("In angle. Missile is launched at this pitch and the intial tangential line of the ballistic path will be this.")]
public readonly WAngle LaunchAngle = WAngle.Zero;

[Desc("Minimum altitude where this missile is considered airborne")]
public readonly int MinAirborneAltitude = 5;

[Desc("Speed gain in WDist / tick.")]
public readonly int Acceleration = 3;

[Desc("Types of damage missile explosion is triggered with. Leave empty for no damage types.")]
public readonly BitSet<DamageType> DamageTypes = default(BitSet<DamageType>);

Expand Down Expand Up @@ -78,6 +81,8 @@ public class BallisticMissile : ISync, IFacing, IMove, IPositionable,
bool airborne;
int airborneToken = ConditionManager.InvalidConditionToken;

int acceleration;

public BallisticMissile(ActorInitializer init, BallisticMissileInfo info)
{
Info = info;
Expand Down Expand Up @@ -123,7 +128,7 @@ Pair<CPos, SubCell>[] IOccupySpace.OccupiedCells()

public int MovementSpeed
{
get { return Util.ApplyPercentageModifiers(Info.Speed, speedModifiers); }
get { return Util.ApplyPercentageModifiers(Info.Speed, speedModifiers) + acceleration; }
}

public WVec FlyStep(int facing)
Expand Down Expand Up @@ -163,6 +168,8 @@ public void SetPosition(Actor self, WPos pos)
if (!self.IsInWorld)
return;

acceleration += Info.Acceleration;

self.World.UpdateMaps(self, this);

var altitude = self.World.Map.DistanceAboveTerrain(CenterPosition);
Expand Down Expand Up @@ -228,8 +235,7 @@ public Activity VisualMove(Actor self, WPos fromPos, WPos toPos)

public int EstimatedMoveDuration(Actor self, WPos fromPos, WPos toPos)
{
var speed = MovementSpeed;
return speed > 0 ? (toPos - fromPos).Length / speed : 0;
return MovementSpeed > 0 ? (toPos - fromPos).Length / MovementSpeed : 0;
}

public CPos NearestMoveableCell(CPos cell) { return cell; }
Expand Down

0 comments on commit 3c8f25e

Please sign in to comment.