Merge pull request #12004 from reaperrr/projectile-cleanup2

More projectile property streamlining and cleanups
This commit is contained in:
Paul Chote
2016-10-29 14:21:29 +01:00
committed by GitHub
20 changed files with 134 additions and 47 deletions

View File

@@ -0,0 +1,70 @@
#region Copyright & License Information
/*
* Copyright 2007-2016 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 System;
using System.Linq;
using OpenRA.Mods.Common.Projectiles;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Lint
{
class CheckAngle : ILintRulesPass
{
public void Run(Action<string> emitError, Action<string> emitWarning, Ruleset rules)
{
foreach (var weaponInfo in rules.Weapons)
{
var missile = weaponInfo.Value.Projectile as MissileInfo;
if (missile != null)
{
var minAngle = missile.MinimumLaunchAngle.Angle;
var maxAngle = missile.MaximumLaunchAngle.Angle;
// If both angles are identical, we only need to test one of them
var testMaxAngle = minAngle != maxAngle;
CheckLaunchAngles(weaponInfo.Key, minAngle, testMaxAngle, maxAngle, emitError);
}
var bullet = weaponInfo.Value.Projectile as BulletInfo;
if (bullet != null)
{
var minAngle = bullet.LaunchAngle[0].Angle;
var maxAngle = bullet.LaunchAngle.Length > 1 ? bullet.LaunchAngle[1].Angle : minAngle;
// If both angles are identical, we only need to test one of them
var testMaxAngle = minAngle != maxAngle;
CheckLaunchAngles(weaponInfo.Key, minAngle, testMaxAngle, maxAngle, emitError);
}
}
}
static bool InvalidAngle(int value)
{
return value > 255 && value < 769;
}
static void CheckLaunchAngles(string weaponInfo, int minAngle, bool testMaxAngle, int maxAngle, Action<string> emitError)
{
if (InvalidAngle(minAngle))
emitError("Weapon `{0}`: Projectile minimum LaunchAngle must not exceed (-)255!".F(weaponInfo));
if (testMaxAngle && InvalidAngle(maxAngle))
emitError("Weapon `{0}`: Projectile maximum LaunchAngle must not exceed (-)255!".F(weaponInfo));
if ((minAngle < 256) && (maxAngle < 256) && (minAngle > maxAngle))
emitError("Weapon `{0}`: Projectile minimum LaunchAngle must not exceed maximum LaunchAngle!".F(weaponInfo));
if ((minAngle > 768) && (maxAngle > 768) && (minAngle > maxAngle))
emitError("Weapon `{0}`: Projectile minimum LaunchAngle must not exceed maximum LaunchAngle!".F(weaponInfo));
if ((minAngle < 256) && (maxAngle > 768))
emitError("Weapon `{0}`: Projectile minimum LaunchAngle must not exceed maximum LaunchAngle!".F(weaponInfo));
}
}
}

View File

@@ -168,6 +168,7 @@
<Compile Include="HitShapes\Capsule.cs" />
<Compile Include="HitShapes\Circle.cs" />
<Compile Include="Lint\CheckBuildingFootprint.cs" />
<Compile Include="Lint\CheckAngle.cs" />
<Compile Include="Lint\CheckSequences.cs" />
<Compile Include="Lint\CheckPalettes.cs" />
<Compile Include="Lint\CheckPlayers.cs" />

View File

@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Projectiles
public readonly WDist TargetExtraSearchRadius = new WDist(1536);
[Desc("Arc in WAngles, two values indicate variable arc.")]
public readonly WAngle[] Angle = { WAngle.Zero };
public readonly WAngle[] LaunchAngle = { WAngle.Zero };
[Desc("Interval in ticks between each spawned Trail animation.")]
public readonly int TrailInterval = 2;
@@ -97,11 +97,11 @@ namespace OpenRA.Mods.Common.Projectiles
string trailPalette;
[Sync] WPos pos, target;
[Sync] int length;
int length;
[Sync] int facing;
[Sync] int ticks, smokeTicks;
int ticks, smokeTicks;
[Sync] public Actor SourceActor { get { return args.SourceActor; } }
public Actor SourceActor { get { return args.SourceActor; } }
public Bullet(BulletInfo info, ProjectileArgs args)
{
@@ -111,10 +111,10 @@ namespace OpenRA.Mods.Common.Projectiles
var world = args.SourceActor.World;
if (info.Angle.Length > 1)
angle = new WAngle(world.SharedRandom.Next(info.Angle[0].Angle, info.Angle[1].Angle));
if (info.LaunchAngle.Length > 1)
angle = new WAngle(world.SharedRandom.Next(info.LaunchAngle[0].Angle, info.LaunchAngle[1].Angle));
else
angle = info.Angle[0];
angle = info.LaunchAngle[0];
if (info.Speed.Length > 1)
speed = new WDist(world.SharedRandom.Next(info.Speed[0].Length, info.Speed[1].Length));

View File

@@ -159,6 +159,11 @@ namespace OpenRA.Mods.Common.Projectiles
readonly Animation anim;
readonly WVec gravity;
readonly int minLaunchSpeed;
readonly int maxLaunchSpeed;
readonly int maxSpeed;
readonly WAngle minLaunchAngle;
readonly WAngle maxLaunchAngle;
int ticks;
@@ -201,6 +206,11 @@ namespace OpenRA.Mods.Common.Projectiles
gravity = new WVec(0, 0, -info.Gravity);
targetPosition = args.PassiveTarget;
rangeLimit = info.RangeLimit != WDist.Zero ? info.RangeLimit : args.Weapon.Range;
minLaunchSpeed = info.MinimumLaunchSpeed.Length > -1 ? info.MinimumLaunchSpeed.Length : info.Speed.Length;
maxLaunchSpeed = info.MaximumLaunchSpeed.Length > -1 ? info.MaximumLaunchSpeed.Length : info.Speed.Length;
maxSpeed = info.Speed.Length;
minLaunchAngle = info.MinimumLaunchAngle;
maxLaunchAngle = info.MaximumLaunchAngle;
var world = args.SourceActor.World;
@@ -248,13 +258,11 @@ namespace OpenRA.Mods.Common.Projectiles
void DetermineLaunchSpeedAndAngleForIncline(int predClfDist, int diffClfMslHgt, int relTarHorDist,
out int speed, out int vFacing)
{
var minLaunchSpeed = info.MinimumLaunchSpeed.Length > -1 ? info.MinimumLaunchSpeed.Length : info.Speed.Length;
var maxLaunchSpeed = info.MaximumLaunchSpeed.Length > -1 ? info.MaximumLaunchSpeed.Length : info.Speed.Length;
speed = info.MaximumLaunchSpeed.Length > -1 ? info.MaximumLaunchSpeed.Length : info.Speed.Length;
speed = maxLaunchSpeed;
// 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
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
// to hit the target without passing it by (and thus having to do horizontal loops)
@@ -282,8 +290,8 @@ namespace OpenRA.Mods.Common.Projectiles
// Find least vertical facing that will allow the missile to climb
// terrAltDiff w-units within hHeightChange w-units
// all the while ending the ascent with vertical facing 0
vFacing = BisectionSearch(System.Math.Max((sbyte)(info.MinimumLaunchAngle.Angle >> 2), (sbyte)0),
(sbyte)(info.MaximumLaunchAngle.Angle >> 2),
vFacing = BisectionSearch(System.Math.Max((sbyte)(minLaunchAngle.Angle >> 2), (sbyte)0),
(sbyte)(maxLaunchAngle.Angle >> 2),
vFac => !WillClimbWithinDistance(vFac, loopRadius, predClfDist, diffClfMslHgt)) + 1;
}
}
@@ -291,7 +299,7 @@ namespace OpenRA.Mods.Common.Projectiles
// TODO: Double check Launch parameter determination
void DetermineLaunchSpeedAndAngle(World world, out int speed, out int vFacing)
{
speed = info.MaximumLaunchSpeed.Length > -1 ? info.MaximumLaunchSpeed.Length : info.Speed.Length;
speed = maxLaunchSpeed;
loopRadius = LoopRadius(speed, info.VerticalRateOfTurn);
// Compute current distance from target position
@@ -309,8 +317,8 @@ namespace OpenRA.Mods.Common.Projectiles
DetermineLaunchSpeedAndAngleForIncline(predClfDist, diffClfMslHgt, relTarHorDist, out speed, out vFacing);
else if (lastHt != 0)
{
vFacing = System.Math.Max((sbyte)(info.MinimumLaunchAngle.Angle >> 2), (sbyte)0);
speed = info.MaximumLaunchSpeed.Length > -1 ? info.MaximumLaunchSpeed.Length : info.Speed.Length;
vFacing = System.Math.Max((sbyte)(minLaunchAngle.Angle >> 2), (sbyte)0);
speed = maxLaunchSpeed;
}
else
{
@@ -324,8 +332,8 @@ namespace OpenRA.Mods.Common.Projectiles
vFacing = 0;
// Make sure the chosen vertical facing adheres to prescribed bounds
vFacing = vFacing.Clamp((sbyte)(info.MinimumLaunchAngle.Angle >> 2),
(sbyte)(info.MaximumLaunchAngle.Angle >> 2));
vFacing = vFacing.Clamp((sbyte)(minLaunchAngle.Angle >> 2),
(sbyte)(maxLaunchAngle.Angle >> 2));
}
}
@@ -404,7 +412,7 @@ namespace OpenRA.Mods.Common.Projectiles
void ChangeSpeed(int sign = 1)
{
speed = (speed + sign * info.Acceleration.Length).Clamp(0, info.Speed.Length);
speed = (speed + sign * info.Acceleration.Length).Clamp(0, maxSpeed);
// Compute the vertical loop radius
loopRadius = LoopRadius(speed, info.VerticalRateOfTurn);
@@ -415,7 +423,7 @@ namespace OpenRA.Mods.Common.Projectiles
// Compute the projectile's freefall displacement
var move = velocity + gravity / 2;
velocity += gravity;
var velRatio = info.Speed.Length * 1024 / velocity.Length;
var velRatio = maxSpeed * 1024 / velocity.Length;
if (velRatio < 1024)
velocity = velocity * velRatio / 1024;

View File

@@ -497,6 +497,13 @@ namespace OpenRA.Mods.Common.UtilityCommands
node.Key = "Duration";
}
// Rename Bullet Angle to LaunchAngle
if (engineVersion < 20161016)
{
if (node.Key == "Angle")
node.Key = "LaunchAngle";
}
UpgradeWeaponRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
}
}