Skip to content
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

Make dive bomb runs less accurate against infantry targets #3372

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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