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

Laser guidance for all designators #3308

Merged
merged 16 commits into from
Oct 8, 2016
Merged
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
2 changes: 1 addition & 1 deletion addons/common/functions/fnc_getTurretDirection.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ if (_pov == "pip0_pos") then {

_povDir = _gunBeginPos vectorDiff _gunEndPos;
};

_povDir = vectorNormalized _povDir;
[_povPos, _povDir]
7 changes: 7 additions & 0 deletions addons/laser/ACE_Settings.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ACE_Settings {
class GVAR(dispersionCount) {
value = 2;
typeName = "SCALAR";
displayName = CSTRING(dispersionCount_displayName);
};
};
12 changes: 2 additions & 10 deletions addons/laser/CfgEventhandlers.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preStart));
Expand All @@ -7,20 +6,13 @@ class Extended_PreStart_EventHandlers {

class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_pre_init));
init = QUOTE(call COMPILE_FILE(XEH_preInit));
};
};

class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_post_init));
init = QUOTE(call COMPILE_FILE(XEH_postInit));
};
};

class Extended_Init_EventHandlers {
class LaserTargetBase {
class ADDON {
init = QUOTE(_this call DFUNC(laser_init));
};
};
};
41 changes: 14 additions & 27 deletions addons/laser/CfgVehicles.hpp
Original file line number Diff line number Diff line change
@@ -1,44 +1,31 @@
class CfgVehicles {
class All;

class LaserTarget: All {
// @TODO: Changing the model and simulation hides it, but THEN IT DOESNT SPAWN WTF!?
model = "\A3\Weapons_F\empty.p3d";
destrType = "DestructNo";
simulation = "LaserTarget";
// model = "\A3\Weapons_F\empty.p3d";

class EventHandlers {
init = QUOTE(_this call FUNC(laser_init));
class ADDON {
init = QUOTE(_this call FUNC(handleLaserTargetCreation));
};
};
};

// Visual laserTarget override
class ACE_LaserTarget_Visual : LaserTarget {
simulation = "LaserTarget";
model = "\A3\Weapons_f\laserTgt.p3d";
};

// Vehicle lockable configurations

class AllVehicles;
class Air: AllVehicles {
class Turrets;
// laserTarget fails if the turret does not have "primaryGunner" config
// This only effects the indfor strider who's commander is not the primaryGunner
class LandVehicle;
class Car: LandVehicle {
class NewTurret;
};

class Helicopter: Air {
class Car_F: Car {
class Turrets {
class MainTurret;
class MainTurret: NewTurret {};
};
};

class Helicopter_Base_F: Helicopter {};

class Heli_Attack_01_base_F: Helicopter_Base_F {};

class B_Heli_Attack_01_F: Heli_Attack_01_base_F {
class MRAP_03_base_F: Car_F {
class Turrets: Turrets {
class MainTurret: MainTurret {
GVAR(CanLockLaser) = 1; // Enable laser locking selection
class CommanderTurret: MainTurret {
primaryGunner = 1;
};
};
};
Expand Down
2 changes: 2 additions & 0 deletions addons/laser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ The people responsible for merging changes to this component or answering potent

- [walterpearce](https://github.com/walterpearce)
- [NouberNou](https://github.com/NouberNou)
- [esteldunedain](https://github.com/esteldunedain)
- [PabstMirror](https://github.com/PabstMirror)
35 changes: 12 additions & 23 deletions addons/laser/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@

PREP(rotateVectLineGetMap);
PREP(rotateVectLine);
PREP(shootRay);
PREP(shootCone);
PREP(checkLos);

PREP(findStrongestRay);

PREP(onLaserDesignatorDraw);

PREP(seekerFindLaserSpot);
PREP(laserOn);
PREP(addLaserTarget);
PREP(dev_drawVisibleLaserTargets);
PREP(findLaserSource);
PREP(handleLaserTargetCreation);
PREP(keyLaserCodeChange);
PREP(laserOff);
PREP(handleLaserOn);
PREP(handleLaserOff);

PREP(drawVisibleLaserTargets);

PREP(laser_init);
PREP(vanillaLaserSeekerHandler);
PREP(laserOn);
PREP(laserTargetPFH);

PREP(unitTurretCanLockLaser);
PREP(keyLaserCodeUp);
PREP(keyLaserCodeDown);
PREP(onLaserDesignatorDraw);
PREP(rotateVectLine);
PREP(rotateVectLineGetMap);
PREP(seekerFindLaserSpot);
PREP(shootCone);
PREP(shootRay);
23 changes: 23 additions & 0 deletions addons/laser/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "script_component.hpp"

#include "initKeybinds.sqf"

// Global Laser EHs
["ace_laserOn", {
params ["_uuid", "_args"];
TRACE_2("ace_laserOn eh",_uuid,_args);
[GVAR(laserEmitters), _uuid, _args] call CBA_fnc_hashSet;
}] call CBA_fnc_addEventHandler;

["ace_laserOff", {
params ["_uuid"];
TRACE_1("ace_laserOn eh",_uuid);
if ([GVAR(laserEmitters), _uuid] call CBA_fnc_hashHasKey) then {
[GVAR(laserEmitters), _uuid] call CBA_fnc_hashRem;
};
}] call CBA_fnc_addEventHandler;

// Shows detector and mine posistions in 3d when debug is on
#ifdef DRAW_LASER_INFO
addMissionEventHandler ["Draw3D", {_this call FUNC(dev_drawVisibleLaserTargets)}];
#endif
7 changes: 0 additions & 7 deletions addons/laser/XEH_post_init.sqf

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ ADDON = false;

#include "XEH_PREP.hpp"

GVAR(VanillaLasers) = [];

// Laser default variables
ACE_DEFAULT_LASER_CODE = 1001;
ACE_DEFAULT_LASER_CODE = 1111;
ACE_DEFAULT_LASER_WAVELENGTH = 1550;
ACE_DEFAULT_LASER_BEAMSPREAD = 1;

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

ADDON = true;
1 change: 1 addition & 0 deletions addons/laser/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class CfgPatches {
};
};

#include "ACE_Settings.hpp"
#include "CfgEventhandlers.hpp"
#include "CfgVehicles.hpp"
#include "CfgWeapons.hpp"
Expand Down
59 changes: 59 additions & 0 deletions addons/laser/functions/fnc_addLaserTarget.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Author: esteldunedain
* Adds a vanilla laser target to the tracker PFH and globaly turns it on
*
* Argument:
* 0: TargetObject (vanilla laser) <OBJECT>
* 1: Vehicle <OBJECT>
*
* Return value:
* None
*
* Example:
* [laserTarget player, player] call ace_laser_fnc_addLaserTarget;
*
* Public: No
*/
#include "script_component.hpp"

params ["_targetObject", "_vehicle"];
TRACE_2("params",_targetObject,_vehicle);

// Get the designator variables, or use defaults
private _waveLength = _vehicle getVariable [QEGVAR(laser,waveLength), ACE_DEFAULT_LASER_WAVELENGTH];
private _laserCode = _vehicle getVariable [QEGVAR(laser,code), ACE_DEFAULT_LASER_CODE];
private _beamSpread = _vehicle getVariable [QEGVAR(laser,beamSpread), ACE_DEFAULT_LASER_BEAMSPREAD];
TRACE_3("codes",_waveLength,_laserCode,_beamSpread);

// Laser method is the method ACE_Laser will use to determine from where to where it should project the designator cone
_vehicle setVariable [QGVAR(targetObject), _targetObject, true];

private _laserMethod = QFUNC(findLaserSource);

private _vehicleSourceSelection = "";
if (_vehicle isKindOf "CaManBase") then {
_vehicleSourceSelection = "pilot";
} else {
{ // Go through turrets on vehicle and find the laser
private _turretPath = _x;
{
if ((getNumber (configFile >> "CfgWeapons" >> _x >> "laser")) > 0) exitWith {
_vehicleSourceSelection = getText (([_vehicle, _turretPath] call CBA_fnc_getTurret) >> "memoryPointGunnerOptics");
TRACE_3("",_turretPath,_x,_vehicleSourceSelection);
};
} forEach (_vehicle weaponsTurret _turretPath);
} forEach (allTurrets [_vehicle, true]);
};

private _methodArgs = [_vehicleSourceSelection];

TRACE_6("Laser on:",_vehicle,_laserMethod,_waveLength,_laserCode,_beamSpread,_methodArgs);
private _laserUuid = [_vehicle, _vehicle, _laserMethod, _waveLength, _laserCode, _beamSpread, _methodArgs] call FUNC(laserOn);

GVAR(trackedLaserTargets) pushBack [_targetObject, _vehicle, _laserUuid];
TRACE_1("",GVAR(trackedLaserTargets));

if (GVAR(pfehID) == -1) then {
TRACE_1("starting pfeh",count GVAR(trackedLaserTargets));
GVAR(pfehID) = [DFUNC(laserTargetPFH), 0, []] call CBA_fnc_addPerFrameHandler;
};
28 changes: 0 additions & 28 deletions addons/laser/functions/fnc_checkLos.sqf

This file was deleted.

61 changes: 61 additions & 0 deletions addons/laser/functions/fnc_dev_drawVisibleLaserTargets.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Dev Debug Function
// Displays lasers and attempts to lock on to codes 1111 and 1112 from a target vehicle's view
// On Screen Debug:
// Red - Vanilla Laser Targets
// Yellow - Array (vehicle pos/weapon) Laser Targets
// Green - Rays
// Blue - Seeker Locks

#include "script_component.hpp"

// Try searching for lasers from a given vehicle position [BLUE]:
private _seekerVehicle = vehicle ace_player;
private _testSeekerPosASL = AGLtoASL (_seekerVehicle modelToWorldVisual [0,0,1]);
private _testSeekerDir = vectorDirVisual _seekerVehicle;
{
private _code = _x;
private _results = [_testSeekerPosASL, _testSeekerDir, 45, [1550,1550], _code, _seekerVehicle] call FUNC(seekerFindLaserSpot);
private _resultPos = _results select 0;
if (!isNil "_resultPos") then {
// Draw lock results
drawLine3D [ASLtoAGL _testSeekerPosASL, ASLtoAGL _resultPos, [0,0,1,1]];
drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\select_target_ca.paa", [0,0,1,1], (ASLtoAGL _resultPos), 1.5, 1.5, 45, format ["%1 from %2", _code, _results select 1], 0.5, 0.025, "TahomaB"];
};
} forEach [1111, 1112]; // Scan at codes 1111 and 1112


// Draw all lasers
[GVAR(laserEmitters), {
// TRACE_2("",_key,_value);
_value params ["_obj", "_owner", "_laserMethod", "_waveLength", "_laserCode", "_beamSpread"];

// Draw vanila lasers [RED]
if (_laserMethod isEqualTo QFUNC(findLaserSource)) then { // Normal vanilla laserTarget func
private _targetObject = _obj getVariable [QGVAR(targetObject), objNull];
private _targetPosASL = getPosASL _targetObject;
drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\select_target_ca.paa", [1,0,0,1], (ASLtoAGL _targetPosASL), 0.5, 0.5, 0, "", 0.5, 0.025, "TahomaB"];

(_value call FUNC(findLaserSource)) params ["_laserPosASL", "_laserDir"];
private _resultsRay = [_laserPosASL, _laserDir, _obj] call FUNC(shootRay);

private _rayPos = _resultsRay select 0;
if (isNil "_rayPos") then {
drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\select_target_ca.paa", [1,0,0,1], (ASLtoAGL _targetPosASL), 2, 2, 0, "Nil Ray", 0.5, 0.025, "TahomaB"];
} else {
private _diff = _rayPos vectorDistance (getPosASL _targetObject); // Diff from ray position compared to actual
drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\select_target_ca.paa", [1,0,0,1], (ASLtoAGL _rayPos), 2, 2, 0, format ["Diff %1",_diff], 0.5, 0.025, "TahomaB"];
};
};
// Draw array weapon lasers [YELLOW]
if ((_laserMethod isEqualType []) && {(count _laserMethod) == 2}) then {
_laserMethod params ["_modelPosition", "_weaponName"];
private _laserPosASL = AGLtoASL (_obj modelToWorldVisual _modelPosition);
drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\select_target_ca.paa", [1,1,0,1], (ASLtoAGL _laserPosASL), 0.5, 0.5, 0, _weaponName, 0.5, 0.025, "TahomaB"];
private _laserDir = _obj weaponDirection _weaponName;
private _resultsRay = [_laserPosASL, _laserDir, _obj] call FUNC(shootRay);
private _rayPos = _resultsRay select 0;
if (!isNil "_rayPos") then {
drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\select_target_ca.paa", [1,1,0,1], (ASLtoAGL _rayPos), 2, 2, 0, _weaponName, 0.5, 0.025, "TahomaB"];
};
};
}] call CBA_fnc_hashEachPair;
9 changes: 0 additions & 9 deletions addons/laser/functions/fnc_drawVisibleLaserTargets.sqf

This file was deleted.

Loading