Skip to content

Commit

Permalink
Merge pull request #3372 from jaj22/nerf-divebomb-vs-infantry
Browse files Browse the repository at this point in the history
Make dive bomb runs less accurate against infantry targets
  • Loading branch information
Bob-Murphy authored Aug 11, 2024
2 parents 54cee95 + fca6268 commit 1a685ae
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions A3A/addons/core/functions/Supports/fn_SUP_CASDiveBombRun.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ private _group = group driver _plane;

(_plane getVariable "diveParams") params ["_startAlt", "_endAlt", "_diveSpeed", "_diveAngle", "_turnRate", "_bombDrag"];

// Reduce accuracy against foot troops
private _targetOffset = [0,0,0];
if (_target isKindOf "Man") then { _targetOffset getPos [random 100, random 360]; _targetOffset set [2, 0] };

// Delay on loop until we're in the correct position
private _inPosition = false;
Expand All @@ -28,6 +31,7 @@ while {true} do {
// Target lead calc
private _timeToTarget = 1.1 * (_plane distance _target) / _diveSpeed;
private _targetPos = eyePos _target vectorAdd (velocity _target vectorMultiply _timeToTarget); // posASL
_targetPos = _targetPos vectorAdd _targetOffset;

private _targDirFwd = getPosASL _plane vectorFromTo _targetPos;
_targDirFwd = vectorNormalized [_targDirFwd#0, _targDirFwd#1, 0];
Expand Down Expand Up @@ -65,7 +69,7 @@ _plane setVariable ["A3A_diveLastDir", vectorDir _plane];
_plane setVariable ["A3A_diveLastPos", getPosASL _plane];

private _ehID = addMissionEventHandler ["EachFrame", {
_thisArgs params ["_plane", "_target", "_endAlt", "_diveSpeed", "_turnRate", "_bombDrag"];
_thisArgs params ["_plane", "_target", "_endAlt", "_diveSpeed", "_turnRate", "_bombDrag", "_targetOffset"];

if (!alive _target or !canMove _plane or isNull driver _plane) exitWith {
Debug("EachFrame handler abandoned due to target or plane damage");
Expand All @@ -78,6 +82,7 @@ private _ehID = addMissionEventHandler ["EachFrame", {
private _bombOffset = _bombOffset vectorAdd (vectorNormalized [_dir#1, -(_dir#0), 0] vectorMultiply (_bombDrag#1));
private _timeToTarget = (_plane distance _target) / _diveSpeed;
private _targetPos = getPosASL _target vectorAdd (velocity _target vectorMultiply _timeToTarget) vectorAdd _bombOffset;
_targetPos = _targetPos vectorAdd _targetOffset;
private _targetDir = getPosASL _plane vectorFromTo _targetPos;

// heading adjustment
Expand All @@ -103,7 +108,7 @@ private _ehID = addMissionEventHandler ["EachFrame", {
_plane setVectorDirAndUp [_dir, _dir vectorCrossProduct [0,0,1] vectorCrossProduct _dir];
_plane setVelocity (_dir vectorMultiply _diveSpeed);

if (getPosATL _plane#2 < _endAlt) exitWith {
if (getPosASL _plane#2 - getPosASL _target#2 < _endAlt) exitWith {
removeMissionEventHandler ["EachFrame", _thisEventHandler];
driver _plane enableAI "All";
if (_targetDir vectorDotProduct vectorDir _plane < 0.9) exitWith {
Expand All @@ -126,7 +131,7 @@ private _ehID = addMissionEventHandler ["EachFrame", {
_plane setVariable ["bombsDropped", true];
};

}, [_plane, _target, _endAlt, _diveSpeed, _turnRate, _bombDrag]];
}, [_plane, _target, _endAlt, _diveSpeed, _turnRate, _bombDrag, _targetOffset]];

waitUntil { sleep 1; !(getEventHandlerInfo ["EachFrame", _ehID] # 0) };

Expand Down

0 comments on commit 1a685ae

Please sign in to comment.