2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2016-10-12 22:35:24 +00:00
|
|
|
/*
|
|
|
|
* Author: jaynus / nou
|
|
|
|
* Fired event handler, starts guidance if enabled for ammo
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Shooter (Man/Vehicle) <OBJECT>
|
|
|
|
* 4: Ammo <STRING>
|
|
|
|
* 6: Projectile <OBJECT>
|
|
|
|
*
|
|
|
|
* Return Value:
|
2017-06-08 13:31:51 +00:00
|
|
|
* None
|
2016-10-12 22:35:24 +00:00
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [player, "", "", "", "ACE_Javelin_FGM148", "", theMissile] call ace_missileguidance_fnc_onFired;
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2019-01-31 04:11:01 +00:00
|
|
|
params ["_shooter","_weapon","","_mode","_ammo","","_projectile"];
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
// Bail on not missile
|
2024-06-18 14:08:03 +00:00
|
|
|
if !(_ammo isKindOf "MissileBase") exitWith {};
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
// Bail if guidance is disabled for this ammo
|
|
|
|
if ((getNumber (configFile >> "CfgAmmo" >> _ammo >> QUOTE(ADDON) >> "enabled")) != 1) exitWith {};
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
// Bail on locality of the projectile, it should be local to us
|
|
|
|
if (GVAR(enabled) < 1 || {!local _projectile} ) exitWith {};
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
// Bail if shooter isn't player AND system not enabled for AI:
|
|
|
|
if ( !isPlayer _shooter && { GVAR(enabled) < 2 } ) exitWith {};
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
// Verify ammo has explicity added guidance config (ignore inheritances)
|
|
|
|
private _configs = configProperties [(configFile >> "CfgAmmo" >> _ammo), QUOTE(configName _x == QUOTE(QUOTE(ADDON))), false];
|
|
|
|
if ((count _configs) < 1) exitWith {};
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
// MissileGuidance is enabled for this shot
|
|
|
|
TRACE_4("enabled",_shooter,_ammo,_projectile,typeOf _shooter);
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
private _config = configFile >> "CfgAmmo" >> _ammo >> QUOTE(ADDON);
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
private _target = _shooter getVariable [QGVAR(target), nil];
|
|
|
|
private _targetPos = _shooter getVariable [QGVAR(targetPosition), nil];
|
|
|
|
private _seekerType = _shooter getVariable [QGVAR(seekerType), nil];
|
|
|
|
private _attackProfile = _shooter getVariable [QGVAR(attackProfile), nil];
|
2019-01-31 04:11:01 +00:00
|
|
|
if ((getNumber (configFile >> "CfgAmmo" >> _ammo >> QUOTE(ADDON) >> "useModeForAttackProfile")) == 1) then {
|
|
|
|
_attackProfile = getText (configFile >> "CfgWeapons" >> _weapon >> _mode >> QGVAR(attackProfile))
|
|
|
|
};
|
2016-10-12 22:35:24 +00:00
|
|
|
private _lockMode = _shooter getVariable [QGVAR(lockMode), nil];
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
private _laserCode = _shooter getVariable [QEGVAR(laser,code), ACE_DEFAULT_LASER_CODE];
|
|
|
|
private _laserInfo = [_laserCode, ACE_DEFAULT_LASER_WAVELENGTH, ACE_DEFAULT_LASER_WAVELENGTH];
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
TRACE_6("getVars",_target,_targetPos,_seekerType,_attackProfile,_lockMode,_laserCode);
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
private _launchPos = getPosASL (vehicle _shooter);
|
2016-05-30 16:37:03 +00:00
|
|
|
|
|
|
|
if (isNil "_seekerType" || {!(_seekerType in (getArray (_config >> "seekerTypes")))}) then {
|
|
|
|
_seekerType = getText (_config >> "defaultSeekerType");
|
|
|
|
};
|
|
|
|
if (isNil "_attackProfile" || {!(_attackProfile in (getArray (_config >> "attackProfiles")))}) then {
|
|
|
|
_attackProfile = getText (_config >> "defaultAttackProfile");
|
|
|
|
};
|
|
|
|
if (isNil "_lockMode" || {!(_lockMode in (getArray (_config >> "seekerLockModes")))}) then {
|
|
|
|
_lockMode = getText (_config >> "defaultSeekerLockMode");
|
|
|
|
};
|
|
|
|
|
|
|
|
// If we didn't get a target, try to fall back on tab locking
|
2016-10-12 22:35:24 +00:00
|
|
|
if (isNil "_target") then {
|
|
|
|
if (!isPlayer _shooter) then {
|
2016-05-30 16:37:03 +00:00
|
|
|
// This was an AI shot, lets still guide it on the AI target
|
2016-10-12 22:35:24 +00:00
|
|
|
_target = _shooter getVariable [QGVAR(vanilla_target), nil];
|
2024-02-05 17:04:24 +00:00
|
|
|
TRACE_1("Detected AI Shooter!",_target);
|
2016-05-30 16:37:03 +00:00
|
|
|
} else {
|
2016-10-12 22:35:24 +00:00
|
|
|
private _canUseLock = getNumber (_config >> "canVanillaLock");
|
2016-05-30 16:37:03 +00:00
|
|
|
// @TODO: Get vanilla target
|
2016-10-12 22:35:24 +00:00
|
|
|
if (_canUseLock > 0 || difficulty < 1) then {
|
|
|
|
private _vanillaTarget = cursorTarget;
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2024-02-05 17:04:24 +00:00
|
|
|
TRACE_1("Using Vanilla Locking",_vanillaTarget);
|
2016-10-12 22:35:24 +00:00
|
|
|
if (!isNil "_vanillaTarget") then {
|
2016-05-30 16:37:03 +00:00
|
|
|
_target = _vanillaTarget;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
// Array for seek last target position
|
|
|
|
private _seekLastTargetPos = (getNumber ( _config >> "seekLastTargetPos")) == 1;
|
|
|
|
private _lastKnownPosState = [_seekLastTargetPos];
|
|
|
|
if (_seekLastTargetPos && {!isNil "_target"}) then {
|
|
|
|
_lastKnownPosState set [1, (getPosASL _target)];
|
|
|
|
} else {
|
|
|
|
_lastKnownPosState set [1, [0,0,0]];
|
|
|
|
};
|
|
|
|
|
2016-05-30 16:37:03 +00:00
|
|
|
TRACE_4("Beginning ACE guidance system",_target,_ammo,_seekerType,_attackProfile);
|
2016-10-12 22:35:24 +00:00
|
|
|
private _args = [_this,
|
|
|
|
[ _shooter,
|
2016-05-30 16:37:03 +00:00
|
|
|
[_target, _targetPos, _launchPos],
|
|
|
|
_seekerType,
|
|
|
|
_attackProfile,
|
|
|
|
_lockMode,
|
|
|
|
_laserInfo
|
|
|
|
],
|
|
|
|
[
|
|
|
|
getNumber ( _config >> "minDeflection" ),
|
|
|
|
getNumber ( _config >> "maxDeflection" ),
|
|
|
|
getNumber ( _config >> "incDeflection" )
|
|
|
|
],
|
|
|
|
[
|
|
|
|
getNumber ( _config >> "seekerAngle" ),
|
|
|
|
getNumber ( _config >> "seekerAccuracy" ),
|
2019-06-08 04:48:37 +00:00
|
|
|
getNumber ( _config >> "seekerMaxRange" ),
|
|
|
|
getNumber ( _config >> "seekerMinRange" )
|
2016-05-30 16:37:03 +00:00
|
|
|
],
|
2016-10-12 22:35:24 +00:00
|
|
|
[ diag_tickTime, [], [], _lastKnownPosState]
|
2016-05-30 16:37:03 +00:00
|
|
|
];
|
|
|
|
|
2019-06-08 04:48:37 +00:00
|
|
|
private _onFiredFunc = getText (configFile >> QGVAR(SeekerTypes) >> _seekerType >> "onFired");
|
|
|
|
TRACE_1("",_onFiredFunc);
|
|
|
|
if (_onFiredFunc != "") then {
|
|
|
|
_args call (missionNamespace getVariable _onFiredFunc);
|
|
|
|
};
|
2019-12-17 02:01:30 +00:00
|
|
|
|
2019-06-08 04:48:37 +00:00
|
|
|
_onFiredFunc = getText (configFile >> QGVAR(AttackProfiles) >> _attackProfile >> "onFired");
|
2017-06-02 21:51:20 +00:00
|
|
|
TRACE_1("",_onFiredFunc);
|
|
|
|
if (_onFiredFunc != "") then {
|
|
|
|
_args call (missionNamespace getVariable _onFiredFunc);
|
|
|
|
};
|
2019-12-17 02:01:30 +00:00
|
|
|
|
2019-06-08 04:48:37 +00:00
|
|
|
// Run the "onFired" function passing the full guidance args array
|
|
|
|
_onFiredFunc = getText (_config >> "onFired");
|
|
|
|
TRACE_1("",_onFiredFunc);
|
|
|
|
if (_onFiredFunc != "") then {
|
|
|
|
_args call (missionNamespace getVariable _onFiredFunc);
|
|
|
|
};
|
2019-12-17 02:01:30 +00:00
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
// Reverse:
|
|
|
|
// _args params ["_firedEH", "_launchParams", "_flightParams", "_seekerParams", "_stateParams"];
|
|
|
|
// _firedEH params ["_shooter","","","","_ammo","","_projectile"];
|
|
|
|
// _launchParams params ["_shooter","_targetLaunchParams","_seekerType","_attackProfile","_lockMode","_laserInfo"];
|
|
|
|
// _targetLaunchParams params ["_target", "_targetPos", "_launchPos"];
|
|
|
|
// _stateParams params ["_lastRunTime", "_seekerStateParams", "_attackProfileStateParams", "_lastKnownPosState"];
|
2019-12-17 02:01:30 +00:00
|
|
|
// _seekerParams params ["_seekerAngle", "_seekerAccuracy", "_seekerMaxRange", "_seekerMinRange"];
|
2016-10-12 22:35:24 +00:00
|
|
|
|
2024-03-28 18:57:23 +00:00
|
|
|
[LINKFUNC(guidancePFH), 0, _args ] call CBA_fnc_addPerFrameHandler;
|
2016-10-12 22:35:24 +00:00
|
|
|
|
2016-05-30 16:37:03 +00:00
|
|
|
|
|
|
|
/* Clears locking settings
|
|
|
|
(vehicle _shooter) setVariable [QGVAR(target), nil];
|
|
|
|
(vehicle _shooter) setVariable [QGVAR(seekerType), nil];
|
|
|
|
(vehicle _shooter) setVariable [QGVAR(attackProfile), nil];
|
|
|
|
(vehicle _shooter) setVariable [QGVAR(lockMode), nil];
|
2016-10-12 22:35:24 +00:00
|
|
|
*/
|