-
Notifications
You must be signed in to change notification settings - Fork 737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Artillery Tables - Add additional extension hooks for shot simulation and solution calculation #9298
Closed
Closed
Artillery Tables - Add additional extension hooks for shot simulation and solution calculation #9298
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d02ebbd
Initial Commit
LorenLuke 880242c
Merge branch 'master' of github.com:acemod/ACE3 into ArtilleryExtension
LorenLuke 1168694
Second Commit.
LorenLuke df8ea11
Incorporate suggestions, clarify variables
LorenLuke 048efff
Push for Rust.
LorenLuke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
TRACE_1("prep",_this); | ||
|
||
PREP(adjustFire); | ||
PREP(firedEH); | ||
PREP(interactMenuOpened); | ||
PREP(rangeTableOpen); | ||
PREP(rangeTableUpdate); | ||
PREP(turretChanged); | ||
PREP(turretPFEH); | ||
|
||
PREP(calculateElevation); | ||
PREP(calculateMuzzleVelocity); | ||
PREP(calculateSolution); | ||
PREP(calculateWinds); | ||
PREP(findMaxRange); | ||
PREP(calculateMaxDistance); | ||
PREP(simulateShot); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "script_component.hpp" | ||
/* | ||
* Author: LorenLuke | ||
* Adjusts a target point using add/drop, left/right, and up/down with an observer direction, | ||
* and recalculates a solution from a gun based on atmospheric conditions | ||
* | ||
* Arguments: | ||
* 0: Gun Position ASL <ARRAY> | ||
* 1: Target Position ASL <ARRAY> | ||
* 2: Observer Direction | ||
* 3: Adjustment in distance (negative is towards observer); meters <NUMBER> | ||
* 4: Adjustment to the right (negative is Left); meters <NUMBER> | ||
* 5: Adjustment vertically (negative is Down); meters <NUMBER> | ||
* 6: Muzzle velocity; meters/second <NUMBER> | ||
* 7: Air Friction; meters^-1 (m/s^2)/(m^2/s^2) <NUMBER> | ||
* 8: High angle boolean (true is high angle) <BOOL> | ||
* 9: Temperature; degrees Celsius <NUMBER> | ||
* 10: Atmospheric Density; kg/(meters^3) <NUMBER> | ||
* 11: Direction of wind; degrees clockwise from north <NUMBER> | ||
* 12: Speed of wind; meters/second <NUMBER> | ||
* | ||
* Return Value: | ||
* Array of returns <ARRAY> | ||
* 0: Angle of shot; Milliradians <NUMBER> | ||
* 1: Angle adjust left or right; Milliradians <NUMBER> | ||
* 2: Time of flight; seconds <NUMBER> | ||
* | ||
* Example: | ||
* [getposASL vehicle player, targetPos, 20, 50, 0, 200, -0.0001, true, 15, 1.225, 225, 5] call ace_artilleryTables_fnc_adjustFire | ||
* | ||
* Public: No | ||
*/ | ||
|
||
params ["_gunPos", "_targetPos", "_observerDir", "_adjustAdd", "_adjustRight", "_adjustUp", "_muzzleVelocity", "_airFriction", ["_highAngle", true], ["_temperature", 15], ["_airDensity", 1.225], ["_windDir", 0], ["_windSpeed", 0]]; | ||
//DEFAULT_AIR_FRICTION == -0.00006 | ||
//MK6_82mm_AIR_FRICTION == -0.0001 | ||
|
||
private _newTargetPos = _targetPos vectorAdd [(_adjustRight * cos(_observerDir)) + (_adjustAdd * sin(_observerDir)), (_adjustAdd * cos(_observerDir)) - (_adjustRight * sin(_observerDir)), _adjustUp]; | ||
private _targetDiff = _targetPos vectorDiff _gunPos; | ||
private _newTargetDiff = _newTargetPos vectorDiff _gunPos; | ||
|
||
private _directionToTarget = (_targetDiff select 0) atan2 (_targetDiff select 1); | ||
private _newDirectionToTarget = (_newTargetDiff select 0) atan2 (_newTargetDiff select 1); | ||
private _windReturns = [_newDirectionToTarget, _windDir, _windSpeed] call FUNC(calculateWinds); | ||
|
||
private _returns = ["_gunPos", "_newTargetPos", "_muzzleVelocity", "_highAngle", "_airFriction", "_temperature", "_airDensity", "_windDir", "_windSpeed"] call FUNC(calculateSolution); | ||
|
||
_returns |
39 changes: 39 additions & 0 deletions
39
addons/artillerytables/functions/fnc_calculateElevation.sqf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include "script_component.hpp" | ||
/* | ||
* Author: LorenLuke | ||
* Adjusts a target point north and east, and recalculates a solution in air based on atmospheric conditions | ||
* | ||
* Arguments: | ||
* 0: Distance to Target; meters <NUMBER> | ||
* 1: Height of target; meters, relative to gun altitude (positive means target higher than gun) <NUMBER> | ||
* 2: Muzzle velocity; meters/second <NUMBER> | ||
* 3: High angle boolean (true is high angle) <BOOL> | ||
* 4: Air Friction; meters^-1 [(m/s^2)/(m^2/s^2)] <NUMBER> | ||
* 5: Temperature; degrees Celsius <NUMBER> | ||
* 6: Atmospheric Density; kg/(meters^3) <NUMBER> | ||
* 7: Cross wind; meters/second (negative is Right to Left) <NUMBER> | ||
* 8: Tail wind; meters/second (negative is flying against the wind) <NUMBER> | ||
* | ||
* Return Value: | ||
* Array of returns <ARRAY> | ||
* 0: Angle of shot; Milliradians <NUMBER> | ||
* 1: Angle adjust left or right; Milliradians <NUMBER> | ||
* 2: Time of flight; seconds <NUMBER> | ||
* | ||
* Example: | ||
* [myPos, 0, 200, true, -0.0001, 15, 1.225, 5, -10] call ace_artilleryTables_fnc_simulateShot | ||
* | ||
* Public: No | ||
*/ | ||
|
||
params ["_targetDistance", "_targetHeight", "_muzzleVelocity", ["_airFriction", 0], ["_highAngle", true], ["_temperature", 15], ["_airDensity", 1.225], ["_crossWind", 0], ["_tailWind", 0]]; | ||
|
||
//DEFAULT_AIR_FRICTION == -0.00006 | ||
//MK6_82mm_AIR_FRICTION == -0.0001 | ||
|
||
private _solutionReturns = parseSimpleArray ("ace_artilleryTables" callExtension ["getSolution", [_targetDistance, _targetHeight, _muzzleVelocity, _airFriction, _highAngle, _crossWind, _tailWind, _temperature, _airDensity/1.225]] select 0); | ||
if (_solutionReturns isEqualTo [-1, -1, -1]) exitWith {_solutionReturns}; | ||
|
||
_solutionReturns params ["_elevation", "_tof", "_azimuthCorrection"]; | ||
|
||
[_elevation * RADTOMILS, _tof, _azimuthCorrection * RADTOMILS] |
28 changes: 28 additions & 0 deletions
28
addons/artillerytables/functions/fnc_calculateMuzzleVelocity.sqf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include "script_component.hpp" | ||
/* | ||
* Author: LorenLuke | ||
* Calculates the muzzleVelocity change with advanced calculations. | ||
* | ||
* Arguments: | ||
* 0: Initial Muzzle velocity; meters/second <NUMBER> | ||
* 1: Temperature; degrees Celsius <NUMBER> | ||
* 2: Atmospheric Density; kg/(meters^3) <NUMBER> | ||
* | ||
* Return Value: | ||
* Adjusted Muzzle Velocity; Meters <NUMBER> | ||
* | ||
* Example: | ||
* [200, 15, 1.225] call ace_artilleryTables_fnc_calculateMuzzleVelocity | ||
* | ||
* Public: No | ||
*/ | ||
|
||
params ["_muzzleVelocity", "_temperature", "_airDensity"]; | ||
|
||
// Calculate air density | ||
private _relativeDensity = _airDensity / 1.225; | ||
private _newMuzzleVelocityCoefficient = (((_temperature + 273.13) / 288.13 - 1) / 40 + 1); | ||
|
||
private _newMuzzleVelocity = _muzzleVelocity * _newMuzzleVelocityCoefficient; | ||
|
||
_newMuzzleVelocity |
44 changes: 44 additions & 0 deletions
44
addons/artillerytables/functions/fnc_calculateSolution.sqf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "script_component.hpp" | ||
/* | ||
* Author: LorenLuke | ||
* Provides fire angle and deflection solutions on a target of set distance and height, including accounting for drag and atmospheric wind conditions. | ||
* | ||
* Arguments: | ||
* 0: Gun Position ASL; <ARRAY> | ||
* 1: Target Position ASL; <ARRAY> | ||
* 2: Muzzle Velocity; meters/second <NUMBER> | ||
* 3: High angle boolean (true is high angle) <BOOL> | ||
* 4: Air Friction; meters^-1 [(m/s^2)/(m^2/s^2)] <NUMBER> | ||
* 5: Temperature; degrees Celsius <NUMBER> | ||
* 6: Atmospheric Density; kg/(meters^3) <NUMBER> | ||
* 7: Direction of wind; degrees clockwise from north <NUMBER> | ||
* 8: Speed of wind; meters/second <NUMBER> | ||
* | ||
* Return Value: | ||
* array of returns <ARRAY> | ||
* 0: Angle of shot; Milliradians <NUMBER> | ||
* 1: Angle adjust left or right; Milliradians <NUMBER> | ||
* 2: Time of flight; seconds <NUMBER> | ||
* | ||
* Example: | ||
* [myPos, targetPos, 200, true, -0.0001, 15, 1.225, 225, 5] call ace_artilleryTables_fnc_calculateSolution | ||
* | ||
* Public: No | ||
*/ | ||
|
||
params ["_ownPos", "_targetPos", "_muzzleVelocity", ["_airFriction", 0], ["_highAngle", true], ["_temperature", 15], ["_airDensity", 1.225], ["_windDir", 0], ["_windSpeed", 0]]; | ||
|
||
//DEFAULT_AIR_FRICTION == -0.00006 | ||
//MK6_82mm_AIR_FRICTION == -0.0001 | ||
|
||
private _relPos = _targetPos vectorDiff _ownPos; | ||
|
||
private _targetDir = (_relpos select 0) atan2 (_relPos select 1); | ||
private _targetDist = sqrt((_relPos select 0)^2 + (_relpos select 1)^2); | ||
private _heightDiff = _relPos select 2; | ||
private _windReturns = [_targetDir, _windDir, _windSpeed] call FUNC(calculateWinds); | ||
_windReturns params ["_crossWind", "_tailWind"]; | ||
|
||
private _solutionReturns = [_ownPos distance2D _targetPos, (_targetPos select 2) - (_ownPos select 2), _muzzleVelocity, _airFriction, _highAngle, _temperature, _airDensity, _crossWind, _tailWind] call FUNC(calculateElevation); | ||
|
||
[_solutionReturns select 0, _solutionReturns select 1, ((_targetDir * DEGTOMILS) + (_solutionReturns select 2) + 360) % 360] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include "script_component.hpp" | ||
/* | ||
* Author: LorenLuke | ||
* Simulates an indirect shot on a target of known height with given drag, wind, and atmospheric conditions | ||
* | ||
* Arguments: | ||
* 0: Gun Elevation Angle; milliradians <NUMBER> | ||
* 1: Relative Target Height; meters, relative to gun altitude (positive means target higher than gun) <NUMBER> | ||
* 2: Muzzle Velocity; meters/second <NUMBER> | ||
* 3: Air Friction; meters^-1 [(m/s^2)/(m^2/s^2)] <NUMBER> | ||
* 4: Cross wind; meters/second (negative is Right to Left) <NUMBER> | ||
* 5: Tail wind; meters/second (negative is flying against the wind) <NUMBER> | ||
* 6: Temperature; degrees Celsius <NUMBER> | ||
* 7: Atmospheric Density; kg/(meters^3) <NUMBER> | ||
* | ||
* Return Value: | ||
* array of returns <ARRAY> | ||
* 0: Deflection Adjustment To Hit; Milliradians (negative is Left) <NUMBER> | ||
* 1: Distance of Shot; meters <NUMBER> | ||
* 2: Time of Flight; seconds <NUMBER> | ||
* | ||
* Example: | ||
* [900, 10, 200, -0.0001, 4, 0, 15, 1.225] call ace_artilleryTables_fnc_simulateShot | ||
* | ||
* Public: No | ||
*/ | ||
|
||
params ["_angle", "_targetHeight", "_muzzleVelocity", ["_airFriction", 0], ["_crossWind", 0], ["_tailWind", 0], ["_temperature", 15], ["_atmosphericDensity", 1.225]]; | ||
|
||
//DEFAULT_AIR_FRICTION == -0.00006 | ||
//MK6_82mm_AIR_FRICTION == -0.0001 | ||
|
||
if (_airFriction != 0) then { | ||
_muzzleVelocity = [_muzzleVelocity, _temperature, _atmosphericDensity] call FUNC(calculateMuzzleVelocity); | ||
}; | ||
|
||
private _atmosphericDensityRatio = _atmosphericDensity / 1.225; | ||
private _radAngle = rad(_angle / DEGTOMILS); | ||
|
||
private _returns = parseSimpleArray (("ace_artilleryTables" callExtension ["simulateShot", [_radAngle, _targetHeight, _muzzleVelocity, _airFriction, _temperature, _atmosphericDensityRatio, _crossWind, _tailWind]]) select 0); | ||
|
||
//[xDeviation, yDistance, timeOfFlight] | ||
_returns |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is intended to be a user-facing function then
_airFriction
should be handled by the function as well, IMO.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with that is that it has to identify it as a mortar versus as an artillery shell, and I feel like that might fall into the weird 'special numbers' case, as it were, if any other mod were to use anything different.
(If you recall the demonstration with the shells falling short of predicted solutions, that was because it automatically added DEFAULT_AIR_FRICTION when I was using the mortar; I'd like to avoid that if possible just by making it enterable, and having some other function determine which value to use, as they were just included here for reference in testing).