Cache Missile LaunchAngles in constructor

To have one central place for the info look-ups. Makes it a little easier to rename the properties or merge them into a single Angle[] property.
This commit is contained in:
reaperrr
2016-09-09 13:59:55 +02:00
parent 0b7fdc411b
commit 8ba9afdb16

View File

@@ -162,6 +162,8 @@ namespace OpenRA.Mods.Common.Projectiles
readonly int minLaunchSpeed; readonly int minLaunchSpeed;
readonly int maxLaunchSpeed; readonly int maxLaunchSpeed;
readonly int maxSpeed; readonly int maxSpeed;
readonly WAngle minLaunchAngle;
readonly WAngle maxLaunchAngle;
int ticks; int ticks;
@@ -207,6 +209,8 @@ namespace OpenRA.Mods.Common.Projectiles
minLaunchSpeed = info.MinimumLaunchSpeed.Length > -1 ? info.MinimumLaunchSpeed.Length : info.Speed.Length; minLaunchSpeed = info.MinimumLaunchSpeed.Length > -1 ? info.MinimumLaunchSpeed.Length : info.Speed.Length;
maxLaunchSpeed = info.MaximumLaunchSpeed.Length > -1 ? info.MaximumLaunchSpeed.Length : info.Speed.Length; maxLaunchSpeed = info.MaximumLaunchSpeed.Length > -1 ? info.MaximumLaunchSpeed.Length : info.Speed.Length;
maxSpeed = info.Speed.Length; maxSpeed = info.Speed.Length;
minLaunchAngle = info.MinimumLaunchAngle;
maxLaunchAngle = info.MaximumLaunchAngle;
var world = args.SourceActor.World; var world = args.SourceActor.World;
@@ -258,7 +262,7 @@ namespace OpenRA.Mods.Common.Projectiles
// Find smallest vertical facing, for which the missile will be able to climb terrAltDiff w-units // Find smallest vertical facing, for which the missile will be able to climb terrAltDiff w-units
// within hHeightChange w-units all the while ending the ascent with vertical facing 0 // within hHeightChange w-units all the while ending the ascent with vertical facing 0
vFacing = info.MaximumLaunchAngle.Angle >> 2; vFacing = maxLaunchAngle.Angle >> 2;
// Compute minimum speed necessary to both be able to face directly upwards and have enough space // Compute minimum speed necessary to both be able to face directly upwards and have enough space
// to hit the target without passing it by (and thus having to do horizontal loops) // to hit the target without passing it by (and thus having to do horizontal loops)
@@ -286,8 +290,8 @@ namespace OpenRA.Mods.Common.Projectiles
// Find least vertical facing that will allow the missile to climb // Find least vertical facing that will allow the missile to climb
// terrAltDiff w-units within hHeightChange w-units // terrAltDiff w-units within hHeightChange w-units
// all the while ending the ascent with vertical facing 0 // all the while ending the ascent with vertical facing 0
vFacing = BisectionSearch(System.Math.Max((sbyte)(info.MinimumLaunchAngle.Angle >> 2), (sbyte)0), vFacing = BisectionSearch(System.Math.Max((sbyte)(minLaunchAngle.Angle >> 2), (sbyte)0),
(sbyte)(info.MaximumLaunchAngle.Angle >> 2), (sbyte)(maxLaunchAngle.Angle >> 2),
vFac => !WillClimbWithinDistance(vFac, loopRadius, predClfDist, diffClfMslHgt)) + 1; vFac => !WillClimbWithinDistance(vFac, loopRadius, predClfDist, diffClfMslHgt)) + 1;
} }
} }
@@ -313,7 +317,7 @@ namespace OpenRA.Mods.Common.Projectiles
DetermineLaunchSpeedAndAngleForIncline(predClfDist, diffClfMslHgt, relTarHorDist, out speed, out vFacing); DetermineLaunchSpeedAndAngleForIncline(predClfDist, diffClfMslHgt, relTarHorDist, out speed, out vFacing);
else if (lastHt != 0) else if (lastHt != 0)
{ {
vFacing = System.Math.Max((sbyte)(info.MinimumLaunchAngle.Angle >> 2), (sbyte)0); vFacing = System.Math.Max((sbyte)(minLaunchAngle.Angle >> 2), (sbyte)0);
speed = maxLaunchSpeed; speed = maxLaunchSpeed;
} }
else else
@@ -328,8 +332,8 @@ namespace OpenRA.Mods.Common.Projectiles
vFacing = 0; vFacing = 0;
// Make sure the chosen vertical facing adheres to prescribed bounds // Make sure the chosen vertical facing adheres to prescribed bounds
vFacing = vFacing.Clamp((sbyte)(info.MinimumLaunchAngle.Angle >> 2), vFacing = vFacing.Clamp((sbyte)(minLaunchAngle.Angle >> 2),
(sbyte)(info.MaximumLaunchAngle.Angle >> 2)); (sbyte)(maxLaunchAngle.Angle >> 2));
} }
} }