Skip to content

(Ready) Adds more laser functionality to aircraft #7509

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

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions addons/laser/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,19 @@ class CfgVehicles {
};
};
};

class Man;
class CAManBase: Man {
class ACE_SelfActions {
class ACE_Equipment {
class ACE_ToggleMarkerLaser {
displayName = CSTRING(laserMarkToggle);
condition = QUOTE(getNumber (configFile >> 'CfgWeapons' >> (currentWeapon ACE_player) >> QUOTE(QUOTE(ADDON)) >> 'markerEnabled') > 0);
statement = QUOTE( ARR_1(ACE_player) call FUNC(toggleMarker));
showDisabled = 0;
exceptions[] = {"isNotSwimming"};
};
};
};
};
};
7 changes: 0 additions & 7 deletions addons/laser/CfgWeapons.hpp

This file was deleted.

2 changes: 2 additions & 0 deletions addons/laser/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ PREP(handleLaserTargetCreation);
PREP(keyLaserCodeChange);
PREP(laserOff);
PREP(laserOn);
PREP(laserPointTrack);
PREP(laserTargetPFH);
PREP(onLaserDesignatorDraw);
PREP(rotateVectLine);
Expand All @@ -14,3 +15,4 @@ PREP(seekerFindLaserSpot);
PREP(shootCone);
PREP(shootRay);
PREP(showVehicleHud);
PREP(toggleLST);
19 changes: 18 additions & 1 deletion addons/laser/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if (hasInterface) then {
["ACE_controlledUAV", {
params ["_UAV", "_seatAI", "_turret", "_position"];
TRACE_4("ACE_controlledUAV EH",_UAV,_seatAI,_turret,_position);
if (!isNull _seatAI) then {
if ( !isNull _seatAI) then {
[_seatAI] call FUNC(showVehicleHud);
} else {
[ace_player] call FUNC(showVehicleHud);
Expand All @@ -27,6 +27,10 @@ if (hasInterface) then {
params ["_uuid", "_args"];
TRACE_2("ace_laserOn eh",_uuid,_args);
[GVAR(laserEmitters), _uuid, _args] call CBA_fnc_hashSet;
private _unit = _args select 0;
if (hasPilotCamera _unit) then {
[_unit] call FUNC(laserPointTrack);
};
}] call CBA_fnc_addEventHandler;

["ace_laserOff", {
Expand All @@ -37,6 +41,7 @@ if (hasInterface) then {
};
}] call CBA_fnc_addEventHandler;


[QGVAR(updateCode), {
params ["_uuid", "_newCode"];
TRACE_2("ace_laser_updateCode eh",_uuid,_newCode);
Expand All @@ -47,6 +52,18 @@ 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)}];
Expand Down
1 change: 1 addition & 0 deletions addons/laser/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ACE_DEFAULT_LASER_BEAMSPREAD = 1;

GVAR(laserEmitters) = [] call CBA_fnc_hashCreate;
GVAR(trackedLaserTargets) = [];
GVAR(laserMarkers) = [];
GVAR(pfehID) = -1;

ADDON = true;
1 change: 0 additions & 1 deletion addons/laser/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class CfgPatches {
#include "ACE_Settings.hpp"
#include "CfgEventhandlers.hpp"
#include "CfgVehicles.hpp"
#include "CfgWeapons.hpp"


class RscControlsGroup;
Expand Down
14 changes: 11 additions & 3 deletions addons/laser/functions/fnc_keyLaserCodeChange.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ 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;
Expand All @@ -61,6 +63,12 @@ TRACE_2("",_oldLaserCode,_newLaserCode);
if (_oldLaserCode != _newLaserCode) then {
_currentShooter setVariable [QGVAR(code), _newLaserCode, true];
};
[format ["%1: %2", localize LSTRING(laserCode), _newLaserCode]] call EFUNC(common,displayTextStructured);
private _string = "";
if (_currentShooter getVariable [QGVAR(hasLaserSpotTracker), false]) then {
private _LSTmessage = localize ([LSTRING(LSTOff), LSTRING(LSTOn)] select (_currentShooter getVariable [QGVAR(laserSpotTrackerOn), false]));
_string = _LSTmessage + "<br/>";
};
_string = format ["%1%2: %3", _string, localize LSTRING(laserCode), _newLaserCode];
[_string] call EFUNC(common,displayTextStructured);

true
45 changes: 45 additions & 0 deletions addons/laser/functions/fnc_laserPointTrack.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#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"];

GVAR(TrackerpfID) = [{
params ["_args", "_pfID"];
_args params ["_vehicle"];
if (!(hasPilotCamera _vehicle)) exitWith {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!(hasPilotCamera _vehicle)) exitWith {
if (!(hasPilotCamera _vehicle) || {isNull (laserTarget _vehicle)}) exitWith {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ehhhhhh... While that works within the scope of how things are currently, I want to keep the lines separate because of how the laser point system works for weird edge cases like the blackfish, which don't return a laserTarget.

[_pfID] call CBA_fnc_removePerFrameHandler;
};
if (isNull(laserTarget _vehicle)) exitWith {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (isNull(laserTarget _vehicle)) exitWith {
if (isNull (laserTarget _vehicle)) exitWith {

[_pfID] call CBA_fnc_removePerFrameHandler;
};
if (!((getPilotCameraTarget _vehicle) select 0)) exitWith {
};
if (isNull((getPilotCameraTarget _vehicle) select 2)) then {
private _distance = ((getPilotCameraTarget _vehicle) select 1) distance getPosASL (laserTarget _vehicle);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the line above you didn't put parenthesis around getPilotCameraTarget, why do it here?

if (_distance > 0.15) then {
private _vehPos = getPosASL _vehicle;
private _vectorToLaser = _vehPos vectorFromTo (getPosASL (laserTarget _vehicle));
private _vectorToSpot = _vehPos vectorFromTo ((getPilotCameraTarget _vehicle) select 1);
if (acos(_vectorToLaser vectorCos _vectorToSpot) < 0.025) then {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (acos(_vectorToLaser vectorCos _vectorToSpot) < 0.025) then {
if (acos (_vectorToLaser vectorCos _vectorToSpot) < 0.025) then {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have me deleting extra spaces all around, why would there need to be one between acos and the parentheses (considering that my formatting is like a single-argument method)?

_vehicle setPilotCameraTarget getPosASL (laserTarget _vehicle);
};
};
};
}, 0, [_vehicle]] call CBA_fnc_addPerFrameHandler;


16 changes: 11 additions & 5 deletions addons/laser/functions/fnc_seekerFindLaserSpot.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,24 @@
* 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. Player's vehicle) <OBJECT> (default: objNull)
*
* Return Value:
* [Strongest compatible laser spot ASL pos, owner object] Nil array values if nothing found <ARRAY>
*
* Example:
* [getPosASL player, [0,1,0], 90, [1500, 1500], 1111, player] call ace_laser_fnc_seekerFindLaserSpot
* [getPosASL player, [0,1,0], 90, [1500, 1500], 1111, player, vehiclePlayer] call ace_laser_fnc_seekerFindLaserSpot
*
* Public: No
*/

BEGIN_COUNTER(seekerFindLaserSpot);

params ["_posASL", "_dir", "_seekerFov", "_seekerMaxDistance", "_seekerWavelengths", "_seekerCode", ["_ignoreObj1", objNull]];
params ["_posASL", "_dir", "_seekerFov", "_seekerMaxDistance", "_seekerWavelengths", "_seekerCode", "_ignoreObj", "_ignoreBy"];

if (isNil "_ignoreBy") then {
_ignoreBy = objNull;
};

_dir = vectorNormalized _dir;
_seekerWavelengths params ["_seekerWavelengthMin", "_seekerWavelengthMax"];
Expand All @@ -44,7 +49,6 @@ private _finalOwner = objNull;
TRACE_6("laser",_obj,_owner,_laserMethod,_emitterWavelength,_laserCode,_divergence);

if (alive _obj && {_emitterWavelength >= _seekerWavelengthMin} && {_emitterWavelength <= _seekerWavelengthMax} && {_laserCode == _seekerCode}) then {

private _laser = [];
// Find laser pos and dir of the laser depending on type
if (IS_STRING(_laserMethod)) then {
Expand Down Expand Up @@ -79,7 +83,9 @@ private _finalOwner = objNull;
private _testPointVector = _posASL vectorFromTo _testPoint;
private _testDotProduct = _dir vectorDotProduct _testPointVector;
if ((_testDotProduct > _seekerCos) && {(_testPoint vectorDistanceSqr _posASL) < _seekerMaxDistSq}) then {
_spots pushBack [_testPoint, _owner];
if (_owner != _ignoreBy) then {
_spots pushBack [_testPoint, _owner];
};
};
} forEach _resultPositions;
} else {
Expand Down Expand Up @@ -142,7 +148,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, _ignoreObj, objNull];
if ([] isEqualTo _testIntersections) then {
_bucketList pushBack _x;
};
Expand Down
69 changes: 69 additions & 0 deletions addons/laser/functions/fnc_toggleLST.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#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);

GVAR(TrackerpfID) = [{
params ["_args", "_pfID"];
_args params ["_vehicle"];

if (!(_vehicle getVariable [QGVAR(laserSpotTrackerOn), false]) || (!alive _vehicle)) exitWith {
[_pfID] call CBA_fnc_removePerFrameHandler;
};

private _pos = _vehicle modelToWorldWorld [0,0,0];
private _pilotCameraPos = getPilotCameraPosition _vehicle;
private _pilotCameraRotation = getPilotCameraRotation _vehicle;
private _laserCode = _vehicle getVariable [QEGVAR(laser,code), ACE_DEFAULT_LASER_CODE];
private _angle = 30;

if ((getPilotCameraTarget _vehicle) select 0) then {
_angle = 0.75;
};

private _pilotCameraLookPos = [
sin(-deg(_pilotCameraRotation select 0)) * cos(-deg(_pilotCameraRotation select 1)),
cos(-deg(_pilotCameraRotation select 0)) * cos(-deg(_pilotCameraRotation select 1)),
sin(-deg(_pilotCameraRotation select 1))
];

private _pilotCameraVector = _pos vectorFromTo (_vehicle modelToWorldWorld _pilotCameraLookPos);
private _laserSource = _vehicle modelToWorldWorld _pilotCameraPos;
private _laserResult = [_laserSource, _pilotCameraVector, _angle, 5000, [ACE_DEFAULT_LASER_WAVELENGTH,ACE_DEFAULT_LASER_WAVELENGTH], _laserCode, _vehicle, _vehicle] call FUNC(seekerFindLaserSpot);
private _foundTargetPos = _laserResult select 0;

if ((getPilotCameraTarget _vehicle) select 0) then {
private _distance = ((getPilotCameraTarget _vehicle) select 1) distance _foundTargetPos;
if (_distance > 0.75) then {
_vehicle setPilotCameraTarget _foundTargetPos;
};
} else {
_vehicle setPilotCameraTarget _foundTargetPos;
};
}, 0, [_vehicle]] call CBA_fnc_addPerFrameHandler;
6 changes: 6 additions & 0 deletions addons/laser/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,11 @@
<Chinesesimp>雷射 - 循环切换雷射码 下</Chinesesimp>
<Chinese>雷射 - 循環切換雷射碼 下</Chinese>
</Key>
<Key ID="STR_ACE_Laser_LSTOn">
<English>Laser Spot Tracker: On</English>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure there is already a vanilla translation for On/Off that could be reused here, and get rid of the mostly duplicate entries here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where would I find it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either unpack and search the vanilla stringtables dta/languagecore.pbo or
https://synixebrett.github.io/stringtables/
STR_ACTION_LASER_OFF
is a allcaps OFF
STR_3DEN_Attributes_Radar_RadarOff_text
is a normal Off

Meh... Can't find a "On" though

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<Key ID="STR_ACE_Map_Action_NVGOn">

Here are On and Off, but I see the german translation for example wouldn't fit here as it doesn't mean "enabled/on" but more like "one" the number.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<Key ID="STR_ACE_ViewDistance_object_off">

Same...
<Key ID="STR_ACE_MicroDAGR_settingOff">

same... did we just copy the same On/Off translations into multiple components? 🤔

</Key>
<Key ID="STR_ACE_Laser_LSTOff">
<English>Laser Spot Tracker: Off</English>
</Key>
</Package>
</Project>