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

(Ready) Adds more laser functionality to aircraft #7509

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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('Laserdesignator' in weapons ACE_player);
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably want something like getNumber (configFile >> "CfgWeapons" >> (typeOf binocular ACE_PLAYER) >> QGVAR(whateverconfigname)) == 1 so that mods can add functionality without a headache

statement = QUOTE( ARR_1(ACE_player) call FUNC(toggleMarkerHand));
showDisabled = 0;
exceptions[] = {"isNotSwimming"};
};
};
};
};
};
5 changes: 5 additions & 0 deletions addons/laser/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@

PREP(addLaserTarget);
PREP(dev_drawVisibleLaserTargets);
PREP(drawLaserLine);
PREP(findLaserSource);
PREP(handleLaserTargetCreation);
PREP(keyLaserCodeChange);
PREP(laserOff);
PREP(laserOn);
PREP(laserPointTrack);
PREP(laserTargetPFH);
PREP(onLaserDesignatorDraw);
PREP(rotateVectLine);
Expand All @@ -14,3 +16,6 @@ PREP(seekerFindLaserSpot);
PREP(shootCone);
PREP(shootRay);
PREP(showVehicleHud);
PREP(toggleLST);
PREP(toggleMarker);
PREP(toggleMarkerHand);
67 changes: 66 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 Down Expand Up @@ -47,6 +47,71 @@ if (hasInterface) then {
};
}] call CBA_fnc_addEventHandler;


["ace_laserOn", {
params ["_uuid", "_args"];
private _vehicle = _args select 0;
if (hasPilotCamera _vehicle) then {
[_vehicle] call FUNC(laserPointTrack);
};
}] call CBA_fnc_addEventHandler;

["AllVehicles", "init", {
params ["_vehicle"];
private _hasPilotCamera = hasPilotCamera _vehicle;
private _hasLaserSensor = isClass (configfile >> "CfgVehicles" >> (typeOf _vehicle) >> "Components" >> "SensorsManagerComponent" >> "Components" >> "LaserSensorComponent");


if ( (_hasPilotCamera) && (_hasLaserSensor) ) then {
_vehicle setVariable [QGVAR(hasLaserSpotTracker), true];
_vehicle 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;
[_vehicle, 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;
[_vehicle, 1, ["ACE_SelfActions"], _actionOn] call ace_interact_menu_fnc_addActionToObject;
};

private _foundLaser = 0;
private _weapons = weapons _vehicle;
{
_weapons = _weapons + (_vehicle weaponsTurret _x);
} forEach (allTurrets _vehicle);

if (_weapons find "Laserdesignator_mounted" > -1) then {
_foundLaser = 1;
};
if (_weapons find "Laserdesignator_pilotCamera" > -1) then {
_foundLaser = 2;
};

if (_foundlaser == 0) exitWith {};
_vehicle setVariable [QGVAR(hasMarkerLaser), true];
_vehicle setVariable [QGVAR(laserMarkerOn), false];

private _actionOff = ["LaserMarkerOff", localize LSTRING(laserMarkOff), "", {[_this select 0] call FUNC(toggleMarker)}, {(_this select 0) getVariable [QGVAR(laserMarkerOn), false]}] call ace_interact_menu_fnc_createAction;
[_vehicle, 1, ["ACE_SelfActions"], _actionOff] call ace_interact_menu_fnc_addActionToObject;
private _actionOn = ["LaserMarkerOn", localize LSTRING(laserMarkOn), "", {[_this select 0] call FUNC(toggleMarker)}, {!((_this select 0) getVariable [QGVAR(laserMarkerOn), false])}] call ace_interact_menu_fnc_createAction;
[_vehicle, 1, ["ACE_SelfActions"], _actionOn] call ace_interact_menu_fnc_addActionToObject;

}, nil, nil, true] call CBA_fnc_addClassEventHandler;


["CAManBase", "init", {
params ["_unit"];
findDisplay 46 displayAddEventHandler ["KeyDown", {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not savegame compatible.

params ["_displayorcontrol", "_key", "_shift", "_ctrl", "_alt"];
if (_ctrl) then {_key = _key + 486539264};
if (_shift) then {_key = _key + 704643072};
if (_alt) then {_key = _key + 939524096};
private _lightKeys = actionKeys "headlights";
Copy link
Contributor

Choose a reason for hiding this comment

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

This does not work. Floats too big. actionKeys command is unusable. This method cannot be saved. Rethink it from the beginning.

if (_lightKeys find _key > -1) then {
if ( ((currentWeapon player) == "Laserdesignator")) then {
[player] call FUNC(toggleMarkerHand);
};
};
}];
}, nil, nil, 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
27 changes: 27 additions & 0 deletions addons/laser/functions/fnc_drawLaserLine.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "script_component.hpp"
/*
* Author: LorenLuke
* Used to draw laser line across all clients
*
* Arguments:
* 0: start pos (AGL) <ARRAY>
* 1: end pos (AGL) <ARRAY>
* 2: 4 element color <ARRAY>
*
* Return Value:
* Nothing
*
* Example:
* [getpos Player, getpos (laserTarget Player), [1,1,1,1]] call ace_laser_fnc_drawLaserLine
*
* Public: No
*/

params ["_list"];

if ((currentVisionMode ACE_player) > 0) then {
{
_x params ["_start", "_end", "_color"];
drawLine3D [_start, _end, _color];
} forEach _list;
};
16 changes: 12 additions & 4 deletions addons/laser/functions/fnc_keyLaserCodeChange.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ params [["_codeChange", 0, [0]]];

TRACE_1("params",_codeChange);

if ((!alive ACE_player) || {!([ACE_player, vehicle ACE_player, []] call EFUNC(common,canInteractWith))}) exitWith {false};
if (( !alive ACE_player) || {!([ACE_player, vehicle ACE_player, []] call EFUNC(common,canInteractWith))}) exitWith {false};
Copy link
Contributor

Choose a reason for hiding this comment

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

stray space added?


private _currentShooter = objNull;
private _currentWeapon = "";
Expand All @@ -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 = format ["%1<br/>", _LSTmessage];
Copy link
Contributor

Choose a reason for hiding this comment

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

I would say format is probably more expensive than +

Suggested change
_string = format ["%1<br/>", _LSTmessage];
_string = _LSTmessage + "<br/>";

};
_string = format ["%1%2: %3", _string, localize LSTRING(laserCode), _newLaserCode];
[_string] call EFUNC(common,displayTextStructured);

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

[_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 {
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 ( !((getPilotCameraTarget _vehicle) select 0)) exitWith {
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);
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
_vehicle setPilotCameraTarget getPosASL(laserTarget _vehicle);
_vehicle setPilotCameraTarget getPosASL (laserTarget _vehicle);

};
};
};
}, 0, [_vehicle]] call CBA_fnc_addPerFrameHandler;


15 changes: 11 additions & 4 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 {
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(isNil "_ignoreBy") then {
if (isNil "_ignoreBy") then {

_ignoreBy = objNull;
};

_dir = vectorNormalized _dir;
_seekerWavelengths params ["_seekerWavelengthMin", "_seekerWavelengthMax"];
Expand Down Expand Up @@ -79,7 +84,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 {
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(_owner != _ignoreBy) then {
if (_owner != _ignoreBy) then {

_spots pushBack [_testPoint, _owner];
};
};
} forEach _resultPositions;
} else {
Expand Down Expand Up @@ -142,7 +149,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
66 changes: 66 additions & 0 deletions addons/laser/functions/fnc_toggleLST.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#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 {
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 ( !(_vehicle getVariable [QGVAR(laserSpotTrackerOn), false]) || ( !alive _vehicle)) exitWith {
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))];
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
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 _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;
Loading