Laser - Add Aircraft Laser Spot Tracker and Point Locking (#8453)

* Initial commit

* optimize/clean, add ignoreOwners param

* locality, PFH condition

---------

Co-authored-by: LinkIsGrim <salluci.lovi@gmail.com>
This commit is contained in:
LorenLuke 2023-07-27 21:03:02 -07:00 committed by GitHub
parent cd36871f90
commit 2578ead13b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 146 additions and 4 deletions

View File

@ -7,6 +7,7 @@ PREP(handleLaserTargetCreation);
PREP(keyLaserCodeChange);
PREP(laserOff);
PREP(laserOn);
PREP(laserPointTrack);
PREP(laserTargetPFH);
PREP(onLaserDesignatorDraw);
PREP(rotateVectLine);
@ -15,3 +16,4 @@ PREP(seekerFindLaserSpot);
PREP(shootCone);
PREP(shootRay);
PREP(showVehicleHud);
PREP(toggleLST);

View File

@ -33,7 +33,12 @@ if (hasInterface) then {
["ace_laserOn", {
params ["_uuid", "_args"];
TRACE_2("ace_laserOn eh",_uuid,_args);
GVAR(laserEmitters) set [_uuid, _args];
private _unit = _args select 0;
if (local _unit && {hasPilotCamera _unit}) then {
[_unit] call FUNC(laserPointTrack);
};
}] call CBA_fnc_addEventHandler;
["ace_laserOff", {
@ -52,6 +57,19 @@ if (hasInterface) then {
};
}] call CBA_fnc_addEventHandler;
["AllVehicles", "init", {
params ["_unit"];
if (hasPilotCamera _unit) then {
_unit setVariable [QGVAR(hasLaserSpotTracker), true];
_unit setVariable [QGVAR(laserSpotTrackerOn), false];
private _actionOff = ["LSTOff", localize LSTRING(LSTOff), "", {[_this select 0] call FUNC(toggleLST)}, {(_this select 0) getVariable [QGVAR(laserSpotTrackerOn), false]}] call ace_interact_menu_fnc_createAction;
[_unit, 1, ["ACE_SelfActions"], _actionOff] call ace_interact_menu_fnc_addActionToObject;
private _actionOn = ["LSTOn", localize LSTRING(LSTOn), "", {[_this select 0] call FUNC(toggleLST)}, {!((_this select 0) getVariable [QGVAR(laserSpotTrackerOn), false])}] call ace_interact_menu_fnc_createAction;
[_unit, 1, ["ACE_SelfActions"], _actionOn] call ace_interact_menu_fnc_addActionToObject;
};
}, true, [], true] call CBA_fnc_addClassEventHandler;
// Shows detector and mine posistions in 3d when debug is on
#ifdef DRAW_LASER_INFO
addMissionEventHandler ["Draw3D", {_this call FUNC(dev_drawVisibleLaserTargets)}];

View File

@ -40,8 +40,14 @@ if (isNull (ACE_controlledUAV param [0, objNull])) then {
};
TRACE_2("",_currentShooter,_currentWeapon);
if (((getNumber (configFile >> "CfgWeapons" >> _currentWeapon >> "laser")) == 0) &&
{(getNumber (configFile >> "CfgWeapons" >> _currentWeapon >> QGVAR(canSelect))) == 0}) exitWith {false};
private _currentWeaponCfg = configFile >> "CfgWeapons" >> _currentWeapon;
if (
(getNumber (_currentWeaponCfg >> "laser") == 0) &&
{
!(_currentShooter getVariable [QGVAR(hasLaserSpotTracker), false]) &&
{(getNumber (_currentWeaponCfg >> QGVAR(canSelect))) == 0}
}
) exitWith {false};
private _oldLaserCode = _currentShooter getVariable [QGVAR(code), ACE_DEFAULT_LASER_CODE];
private _newLaserCode = _oldLaserCode;

View File

@ -0,0 +1,39 @@
#include "script_component.hpp"
/*
* Author: LorenLuke
* Toggles laser point tracking when a laser is on, for tracking coordinates.
*
* Arguments:
* 0: Vehicle <OBJECT>
*
* Return Value:
* Nothing
*
* Example:
* [vehicle player] call ace_laser_fnc_laserPointTrack
*
* Public: No
*/
params ["_vehicle"];
[{
params ["_args", "_pfhID"];
_args params ["_vehicle"];
if !(alive _vehicle && {local _vehicle} && {hasPilotCamera _vehicle} && {!isNull (laserTarget _vehicle)}) exitWith {
[_pfhID] call CBA_fnc_removePerFrameHandler;
};
(getPilotCameraTarget _vehicle) params ["_isTracking", "_spotPos", "_targetObj"];
if (!_isTracking) exitWith {};
if (isNull _targetObj) then {
private _laserTargetPos = getPosASL laserTarget _vehicle;
private _distance = _spotPos distance _laserTargetPos;
if (_distance > 0.15) then {
private _vehPos = getPosASL _vehicle;
private _vectorToLaser = _vehPos vectorFromTo _laserTargetPos;
private _vectorToSpot = _vehPos vectorFromTo _spotPos;
if (acos (_vectorToLaser vectorCos _vectorToSpot) < 0.025) then {
_vehicle setPilotCameraTarget _laserTargetPos;
};
};
};
}, 0, [_vehicle]] call CBA_fnc_addPerFrameHandler;

View File

@ -12,6 +12,8 @@
* 4: Seeker wavelength sensitivity range, [1550,1550] is common eye safe <ARRAY>
* 5: Seeker laser code. <NUMBER>
* 6: Ignore 1 (e.g. Player's vehicle) <OBJECT> (default: objNull)
* 7: Ignore 2 (e.g. Attached object) <OBJECT> (default: objNull)
* 8: Owners to ignore (e.g. Player's vehicle) <ARRAY of OBJECT> (default: [])
*
* Return Value:
* [Strongest compatible laser spot ASL pos, owner object] Nil array values if nothing found <ARRAY>
@ -24,7 +26,7 @@
BEGIN_COUNTER(seekerFindLaserSpot);
params ["_posASL", "_dir", "_seekerFov", "_seekerMaxDistance", "_seekerWavelengths", "_seekerCode", ["_ignoreObj1", objNull]];
params ["_posASL", "_dir", "_seekerFov", "_seekerMaxDistance", "_seekerWavelengths", "_seekerCode", ["_ignoreObj1", objNull], ["_ignoreObj2", objNull], ["_ignoreOwners", []]];
_dir = vectorNormalized _dir;
_seekerWavelengths params ["_seekerWavelengthMin", "_seekerWavelengthMax"];
@ -43,6 +45,8 @@ private _finalOwner = objNull;
_x params ["_obj", "_owner", "_laserMethod", "_emitterWavelength", "_laserCode", "_divergence"];
TRACE_6("laser",_obj,_owner,_laserMethod,_emitterWavelength,_laserCode,_divergence);
if (_owner in _ignoreOwners) then {continue};
if (alive _obj && {_emitterWavelength >= _seekerWavelengthMin} && {_emitterWavelength <= _seekerWavelengthMax} && {_laserCode == _seekerCode}) then {
private _laser = [];
@ -142,7 +146,7 @@ if ((count _spots) > 0) then {
_bucketList = _finalBuckets select _index;
{
private _testPos = (_x select 0) vectorAdd [0,0,0.05];
private _testIntersections = lineIntersectsSurfaces [_posASL, _testPos, _ignoreObj1];
private _testIntersections = lineIntersectsSurfaces [_posASL, _testPos, _ignoreObj1, _ignoreObj2];
if ([] isEqualTo _testIntersections) then {
_bucketList pushBack _x;
};

View File

@ -0,0 +1,67 @@
#include "script_component.hpp"
/*
* Author: LorenLuke
* Toggles the laser spot tracker for any enabled vehicle.
*
* Arguments:
* 0: Vehicle <OBJECT>
*
* Return Value:
* Nothing
*
* Example:
* [vehicle player] call ace_laser_fnc_toggleLST
*
* Public: No
*/
params ["_vehicle"];
if !(_vehicle getVariable [QGVAR(hasLaserSpotTracker), false]) exitWith {};
private _enabled = _vehicle getVariable [QGVAR(laserSpotTrackerOn), false];
_vehicle setVariable [QGVAR(laserSpotTrackerOn), !_enabled];
private _LSTmessage = if (_vehicle getVariable [QGVAR(laserSpotTrackerOn), false]) then {localize LSTRING(LSTOn)} else {localize LSTRING(LSTOff)};
private _string = format ["%1<br/>", _LSTmessage];
private _laserCode = _vehicle getVariable [QGVAR(code), ACE_DEFAULT_LASER_CODE];
_string = format ["%1%2: %3<br/>",_string, localize LSTRING(laserCode), _laserCode];
[_string] call EFUNC(common,displayTextStructured);
if (_enabled) exitWith {};
[{
params ["_args", "_pfhID"];
_args params ["_vehicle"];
if !(_vehicle getVariable [QGVAR(laserSpotTrackerOn), false] && {alive _vehicle}) exitWith {
[_pfhID] call CBA_fnc_removePerFrameHandler;
};
private _laserCode = _vehicle getVariable [QEGVAR(laser,code), ACE_DEFAULT_LASER_CODE];
private _angle = 25;
private _pos = _vehicle modelToWorldVisualWorld [0,0,0];
private _pilotCameraPos = getPilotCameraPosition _vehicle;
private _pilotCameraVector = _pos vectorFromTo (_vehicle modelToWorldVisualWorld (getPilotCameraDirection _vehicle));
(getPilotCameraTarget _vehicle) params ["_isTracking", "_spotPos"];
if (_isTracking) then {
_angle = 0.25;
};
private _laserSource = _vehicle modelToWorldWorld _pilotCameraPos;
private _laserResult = [_laserSource, _pilotCameraVector, _angle, 5000, [ACE_DEFAULT_LASER_WAVELENGTH,ACE_DEFAULT_LASER_WAVELENGTH], _laserCode, _vehicle, laserTarget _vehicle, [_vehicle]] call FUNC(seekerFindLaserSpot);
private _foundTargetPos = _laserResult select 0;
if (_isTracking) then {
private _distance = _spotPos distance _foundTargetPos;
if (_distance > 0.75) then {
_vehicle setPilotCameraTarget _foundTargetPos;
};
} else {
_vehicle setPilotCameraTarget _foundTargetPos;
};
}, 0, [_vehicle]] call CBA_fnc_addPerFrameHandler;

View File

@ -85,6 +85,12 @@
<Chinese>雷射 - 循環切換雷射碼 下</Chinese>
<Turkish>Lazer - Çevrim Kodu aşağı</Turkish>
</Key>
<Key ID="STR_ACE_Laser_LSTOn">
<English>Laser Spot Tracker: On</English>
</Key>
<Key ID="STR_ACE_Laser_LSTOff">
<English>Laser Spot Tracker: Off</English>
</Key>
<Key ID="STR_ACE_Laser_showLaserOnMap">
<English>Draw Laser on Map</English>
<Japanese>地図上にレーザーを表示する</Japanese>