Skip to content

Commit

Permalink
Use laser target
Browse files Browse the repository at this point in the history
  • Loading branch information
PabstMirror committed Sep 29, 2024
1 parent d397efe commit 9d87533
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 371 deletions.
4 changes: 0 additions & 4 deletions addons/markinglaser/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
PREP(findTurret);
PREP(getPilotCamVector);
PREP(getTurretVector);
PREP(onAircraftInit);
PREP(onLaserOff);
PREP(onLaserOn);
PREP(renderPFH);
PREP(updatePFH);
58 changes: 26 additions & 32 deletions addons/markinglaser/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -1,45 +1,39 @@
#include "script_component.hpp"
#include "\a3\ui_f\hpp\defineDIKCodes.inc"

// Events
[QGVAR(laserOn), LINKFUNC(onLaserOn)] call CBA_fnc_addEventHandler;
[QGVAR(laserOff), LINKFUNC(onLaserOff)] call CBA_fnc_addEventHandler;
if (!hasInterface) exitWith {};

// Keybinds
["ACE3 Vehicles", QGVAR(toggleLaser), LLSTRING(ToggleLaser), {
// Ignore when in Zeus
if (!isNull curatorCamera) exitWith {};
if (!isNull curatorCamera) exitWith {false};

private _vehicle = cameraOn;
if !(_vehicle getVariable [QGVAR(enabled), false]) exitWith {false};

private _controlledUnit = [ACE_player, ACE_controlledUAV # 1] select (unitIsUAV _vehicle);

private _canTurnOn = if (_vehicle getVariable [QGVAR(useTurret), false]) then {
private _turretInfo = _vehicle getVariable [QGVAR(turretInfo), []];
_controlledUnit == _vehicle turretUnit _turretInfo # 0
} else {
_controlledUnit == driver _vehicle
};

if (_canTurnOn) then {
if (_vehicle getVariable [QGVAR(laserOn), false]) then {
[QGVAR(laserOff), [_vehicle]] call CBA_fnc_globalEvent;
} else {
[QGVAR(laserOn), [_vehicle]] call CBA_fnc_globalEvent;
};

true
} else {
false
};
}, "", [DIK_L, [false, false, true]]] call CBA_fnc_addKeybind;

// JIP init
if (didJIP) then {
{
if (_x getVariable [QGVAR(laserOn), false]) then {
[_x] call FUNC(onLaserOn);
};
} forEach (allMissionObjects "Air");
};
private _turretInfo = _vehicle getVariable [QGVAR(turretInfo), []];
private _canTurnOn = _controlledUnit == _vehicle turretUnit _turretInfo;
if (!_canTurnOn) exitWith { false };

playSound "ACE_Sound_Click";
private _current = _vehicle getVariable [QGVAR(laserOn), false];
_vehicle setVariable [QGVAR(laserOn), !_current, true];
true
}, "", [DIK_L, [false, false, true]]] call CBA_fnc_addKeybind; // ALT-L

["CBA_settingsInitialized", {
TRACE_1("settingsInitialized",1);

GVAR(pfEH) = -1;
["visionMode", LINKFUNC(onLaserOn), true] call CBA_fnc_addPlayerEventHandler;
["ace_laserOn", {
params ["", "_args"];
_args params ["_object"];
if !(_object getVariable [QGVAR(enabled), false]) exitWith {};
_object setVariable [QGVAR(smoothing), []];

[] call LINKFUNC(onLaserOn);
}] call CBA_fnc_addEventHandler;
}] call CBA_fnc_addEventHandler;
5 changes: 0 additions & 5 deletions addons/markinglaser/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,4 @@ PREP_RECOMPILE_END;

#include "initSettings.inc.sqf"

GVAR(lasers) = [];
GVAR(localLasers) = [];
GVAR(renderPFH) = -1;
GVAR(updatePFH) = -1;

ADDON = true;
2 changes: 1 addition & 1 deletion addons/markinglaser/functions/fnc_findTurret.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* 0: Aircraft config <OBJECT>
*
* Return Value:
* None
* <ARRAY>
*
* Example:
* [configOf _plane] call ace_markinglaser_fnc_findTurret
Expand Down
81 changes: 0 additions & 81 deletions addons/markinglaser/functions/fnc_getPilotCamVector.sqf

This file was deleted.

38 changes: 0 additions & 38 deletions addons/markinglaser/functions/fnc_getTurretVector.sqf

This file was deleted.

44 changes: 7 additions & 37 deletions addons/markinglaser/functions/fnc_onAircraftInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

params ["_aircraft"];
TRACE_2("onAircraftInit",_aircraft,typeOf _aircraft);

// Assume enabled by default
if !(_aircraft getVariable [QGVAR(enabled), true]) exitWith {};
Expand All @@ -30,45 +31,14 @@ if ((_turretData isEqualTo []) && {!_hasPilotCamera}) exitWith {
};

_aircraft setVariable [QGVAR(enabled), true];
_aircraft setVariable [QGVAR(smoothing), []];

if (_turretData isEqualTo []) then {
TRACE_1("pilot",_turretData);
// Use pilot camera if no turrets are available
private _origin = getText (_config >> "memoryPointDriverOptics");

// Elevation limits are inverted, possibly because TGPs are usually mounted below the wing
private _limits = [
getNumber (_config >> "PilotCamera" >> "minTurn"),
getNumber (_config >> "PilotCamera" >> "maxTurn"),
-getNumber (_config >> "PilotCamera" >> "maxElev"),
-getNumber (_config >> "PilotCamera" >> "minElev")
];

_aircraft setVariable [QGVAR(useTurret), false];
_aircraft setVariable [QGVAR(laserOrigin), _origin];
_aircraft setVariable [QGVAR(gimbalLimits), _limits];
_aircraft setVariable [QGVAR(turretInfo), [-1]];
} else {
// Use turret of copilot or primary gunner
_turretData params ["_turretPath", "_turretConfig"];

private _origin = getText (_turretConfig >> "memoryPointGunnerOptics");
private _limits = [
getNumber (_turretConfig >> "minTurn"),
getNumber (_turretConfig >> "maxTurn"),
getNumber (_turretConfig >> "minElev"),
getNumber (_turretConfig >> "maxElev")
];

// Animation sources are used to detect direction of turret
private _animationSources = [
getText (_turretConfig >> "animationSourceBody"),
getText (_turretConfig >> "animationSourceGun")
];

// Some helicopter turrets follow the look direction when not in gunner view
private _followFreeLook = (getNumber (_turretConfig >> "turretFollowFreeLook")) > 0;

_aircraft setVariable [QGVAR(useTurret), true];
_aircraft setVariable [QGVAR(laserOrigin), _origin];
_aircraft setVariable [QGVAR(gimbalLimits), _limits];
_aircraft setVariable [QGVAR(turretInfo), [_turretPath, _animationSources, _followFreeLook]];
TRACE_1("turret",_turretData);
_turretData params ["_turretPath"];
_aircraft setVariable [QGVAR(turretInfo), _turretPath];
};
29 changes: 0 additions & 29 deletions addons/markinglaser/functions/fnc_onLaserOff.sqf

This file was deleted.

38 changes: 7 additions & 31 deletions addons/markinglaser/functions/fnc_onLaserOn.sqf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "..\script_component.hpp"
/*
* Author: BaerMitUmlaut
* Handles a plane turning its marking laser off.
* Author: BaerMitUmlaut, PabstMirror
* Starts render PFEH
*
* Arguments:
* 0: Aircraft <OBJECT>
Expand All @@ -10,37 +10,13 @@
* None
*
* Example:
* [plane] call ace_markinglaser_fnc_onLaserOn
* [] call ace_markinglaser_fnc_onLaserOn
*
* Public: No
*/

params ["_aircraft"];
if (GVAR(pfEH) != -1) exitWith {};
if (((currentVisionMode focusOn) != 1) || {EGVAR(laser,laserEmitters) isEqualTo []}) exitWith {};

// Start PFHs if this is the first laser
if (local _aircraft && {GVAR(updatePFH) == -1}) then {
GVAR(updatePFH) = [LINKFUNC(updatePFH), 1, []] call CBA_fnc_addPerFrameHandler;

// Make sure update is called before first render
[] call FUNC(updatePFH);
};

if (hasInterface && {GVAR(renderPFH) == -1}) then {
GVAR(renderPFH) = [LINKFUNC(renderPFH), 0, []] call CBA_fnc_addPerFrameHandler;
};

GVAR(lasers) pushBack _aircraft;
if (local _aircraft) then {
GVAR(localLasers) pushBack _laser;

// Mark aircraft for JIPs
_aircraft setVariable [QGVAR(laserOn), true, true];
};

if (isServer) then {
private _killedEH = _aircraft addMPEventHandler ["MPKilled", {
params ["_aircraft"];
[QGVAR(laserOff), [_aircraft]] call CBA_fnc_globalEvent;
}];
_aircraft setVariable [QGVAR(killedEH), _killedEH];
};
GVAR(pfEH) = [LINKFUNC(renderPFH), 0, []] call CBA_fnc_addPerFrameHandler;
TRACE_1("start PFEH", GVAR(pfEH));
Loading

0 comments on commit 9d87533

Please sign in to comment.