From c82cef1b28926f2f45b6774962f491959f914043 Mon Sep 17 00:00:00 2001
From: esteldunedain <nicolas.d.badano@gmail.com>
Date: Fri, 3 Apr 2015 12:43:41 -0300
Subject: [PATCH 1/2] - self designate capabilities read from config - add
 designator on/off actions to the interact_menu

---
 .../laser_selfdesignate/CfgEventhandlers.hpp  | 16 ++-----
 addons/laser_selfdesignate/XEH_pre_init.sqf   |  9 ++--
 addons/laser_selfdesignate/config.cpp         |  2 +-
 .../functions/fnc_initDesignatorActions.sqf   | 47 +++++++++++++++++++
 .../functions/fnc_onGetin.sqf                 | 13 -----
 .../functions/fnc_onGetout.sqf                | 10 ----
 .../functions/fnc_unitTurretHasDesignator.sqf | 21 +++++++++
 addons/laser_selfdesignate/stringtable.xml    | 12 +++++
 8 files changed, 89 insertions(+), 41 deletions(-)
 create mode 100644 addons/laser_selfdesignate/functions/fnc_initDesignatorActions.sqf
 delete mode 100644 addons/laser_selfdesignate/functions/fnc_onGetin.sqf
 delete mode 100644 addons/laser_selfdesignate/functions/fnc_onGetout.sqf
 create mode 100644 addons/laser_selfdesignate/functions/fnc_unitTurretHasDesignator.sqf
 create mode 100644 addons/laser_selfdesignate/stringtable.xml

diff --git a/addons/laser_selfdesignate/CfgEventhandlers.hpp b/addons/laser_selfdesignate/CfgEventhandlers.hpp
index e75b3b674b..4cef7be4a3 100644
--- a/addons/laser_selfdesignate/CfgEventhandlers.hpp
+++ b/addons/laser_selfdesignate/CfgEventhandlers.hpp
@@ -10,18 +10,10 @@ class Extended_PostInit_EventHandlers {
     };
 };
 
-class Extended_GetIn_EventHandlers {
-    class B_Heli_Attack_01_F {
+class Extended_Init_EventHandlers {
+    class Helicopter {
         class ADDON {
-            clientGetIn = QUOTE(_this call FUNC(onGetIn));
+            init = QUOTE(_this call DFUNC(initDesignatorActions));
         };
     };
-};
-
-class Extended_GetOut_EventHandlers {
-    class B_Heli_Attack_01_F {
-        class ADDON {
-            clientGetOut = QUOTE(_this call FUNC(onGetOut));
-        };
-    };
-};
+};
\ No newline at end of file
diff --git a/addons/laser_selfdesignate/XEH_pre_init.sqf b/addons/laser_selfdesignate/XEH_pre_init.sqf
index 4e98fce7ec..a8d4b1779d 100644
--- a/addons/laser_selfdesignate/XEH_pre_init.sqf
+++ b/addons/laser_selfdesignate/XEH_pre_init.sqf
@@ -1,12 +1,11 @@
 #include "script_component.hpp"
 
-PREP(onGetIn);
-PREP(onGetOut);
-
+PREP(initDesignatorActions);
 PREP(laserHudDesignateOn);
 PREP(laserHudDesignateOff);
+PREP(unitTurretHasDesignator);
 
 GVAR(laser) = nil;
-GVAR(laserActive) = false; 
+GVAR(laserActive) = false;
 
-FUNC(getPosASL) = {visiblePositionASL (_this select 0)};
\ No newline at end of file
+FUNC(getPosASL) = {visiblePositionASL (_this select 0)};
diff --git a/addons/laser_selfdesignate/config.cpp b/addons/laser_selfdesignate/config.cpp
index e19e438da0..ff9c269989 100644
--- a/addons/laser_selfdesignate/config.cpp
+++ b/addons/laser_selfdesignate/config.cpp
@@ -5,7 +5,7 @@ class CfgPatches {
         units[] = {};
         weapons[] = {};
         requiredVersion = REQUIRED_VERSION;
-        requiredAddons[] = {"ace_main", "ace_laser"};
+        requiredAddons[] = {"ace_interaction", "ace_laser"};
         version = VERSION;
     };
 };
diff --git a/addons/laser_selfdesignate/functions/fnc_initDesignatorActions.sqf b/addons/laser_selfdesignate/functions/fnc_initDesignatorActions.sqf
new file mode 100644
index 0000000000..2216fe6e71
--- /dev/null
+++ b/addons/laser_selfdesignate/functions/fnc_initDesignatorActions.sqf
@@ -0,0 +1,47 @@
+/*
+ * Author: esteldunedain
+ * Initializes the actions for turning on/off the laser for vehicles that have them
+ *
+ * Argument:
+ * 0: Vehicle <OBJECT>
+ *
+ * Return value:
+ * NONE.
+ */
+#include "script_component.hpp"
+
+EXPLODE_1_PVT(_this,_vehicle);
+
+{
+    private ["_turretConfig","_onAction","_offAction"];
+    _turretConfig = [configFile >> "CfgVehicles" >> typeOf _vehicle, _x] call EFUNC(common,getTurretConfigPath);
+
+    if (getNumber (_turretConfig >> QGVAR(Enabled)) == 1) exitWith {
+        // @todo: Add the state variables to the vehicle, instead of to the client
+        // e.g.: _vehicle setVariable [format ["%1_%2", QGVAR(laserActive),  _x], false];
+
+        // Add actions
+        _onAction = [QGVAR(LaserOn), localize "STR_ACE_Laser_SelfDesignate_DesignatorOn", "",
+        {
+            // Statement
+            _this call FUNC(laserHudDesignateOn)
+        },
+        {
+            // Condition
+            !GVAR(laserActive) && {[ACE_player] call FUNC(unitTurretHasDesignator)}
+        }] call EFUNC(interact_menu,createAction);
+
+        _offAction = [QGVAR(LaserOff), localize "STR_ACE_Laser_SelfDesignate_DesignatorOff", "",
+        {
+            // Statement
+            _this call FUNC(laserHudDesignateOff)
+        },
+        {
+            // Condition
+            GVAR(laserActive) && {[ACE_player] call FUNC(unitTurretHasDesignator)}
+        }] call EFUNC(interact_menu,createAction);
+
+        [typeOf _vehicle, 1, ["ACE_SelfActions"], _onAction] call EFUNC(interact_menu,addActionToClass);
+        [typeOf _vehicle, 1, ["ACE_SelfActions"], _offAction] call EFUNC(interact_menu,addActionToClass);
+    };
+} forEach allTurrets _vehicle;
diff --git a/addons/laser_selfdesignate/functions/fnc_onGetin.sqf b/addons/laser_selfdesignate/functions/fnc_onGetin.sqf
deleted file mode 100644
index dc62f72e95..0000000000
--- a/addons/laser_selfdesignate/functions/fnc_onGetin.sqf
+++ /dev/null
@@ -1,13 +0,0 @@
-//#define DEBUG_MODE_FULL
-#include "script_component.hpp"
-// TODO: we should do this differently eventually
-private["_onActionId", "_offActionId"];
-TRACE_1("ENTER", _this);
-
-// TODO: THIS SHOULD NOT BE ACTIONS EVENTUALLY
-
-_onActionId = player addAction ["Laser Designator On", { _this call FUNC(laserHudDesignateOn) }, [], 1, false, false, "", QUOTE( (gunner (vehicle player)) == player && !GVAR(laserActive))];
-player setVariable[QGVAR(onActionId), _onActionId, false];
-
-_offActionId = player addAction ["Laser Designator Off", { _this call FUNC(laserHudDesignateOff) }, [], 1, false, false, "", QUOTE( (gunner (vehicle player)) == player && GVAR(laserActive))];
-player setVariable[QGVAR(offActionId), _offActionId, false];
\ No newline at end of file
diff --git a/addons/laser_selfdesignate/functions/fnc_onGetout.sqf b/addons/laser_selfdesignate/functions/fnc_onGetout.sqf
deleted file mode 100644
index 2a32403c19..0000000000
--- a/addons/laser_selfdesignate/functions/fnc_onGetout.sqf
+++ /dev/null
@@ -1,10 +0,0 @@
-#include "script_component.hpp"
-
-_onActionId = player getVariable[QGVAR(onActionId), -1];
-_offActionId = player getVariable[QGVAR(offActionId), -1];
-
-player removeAction _onActionId;
-player removeAction _offActionId;
-
-player setVariable[QGVAR(onActionId), -1, false];
-player setVariable[QGVAR(offActionId), -1, false];
\ No newline at end of file
diff --git a/addons/laser_selfdesignate/functions/fnc_unitTurretHasDesignator.sqf b/addons/laser_selfdesignate/functions/fnc_unitTurretHasDesignator.sqf
new file mode 100644
index 0000000000..291deb5015
--- /dev/null
+++ b/addons/laser_selfdesignate/functions/fnc_unitTurretHasDesignator.sqf
@@ -0,0 +1,21 @@
+/*
+ * Author: esteldunedain
+ * Checks if the turret occupied by the given unit has a laser designator
+ *
+ * Argument:
+ * 0: Unit <OBJECT>
+ *
+ * Return value:
+ * Has designator? <BOOL>
+ */
+#include "script_component.hpp"
+
+EXPLODE_1_PVT(_this,_unit);
+
+// Get the player turret path
+private ["_turret","_config","_turretConfig"];
+_turret = [_unit] call EFUNC(common,getTurretIndex);
+_config = configFile >> "CfgVehicles" >> typeOf vehicle _unit;
+_turretConfig = [_config, _turret] call EFUNC(common,getTurretConfigPath);
+
+getNumber (_turretConfig >> QGVAR(Enabled)) > 0
diff --git a/addons/laser_selfdesignate/stringtable.xml b/addons/laser_selfdesignate/stringtable.xml
new file mode 100644
index 0000000000..70f8912cfe
--- /dev/null
+++ b/addons/laser_selfdesignate/stringtable.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Edited with tabler - 2015-04-03 -->
+<Project name="ACE">
+  <Package name="Laser_SelfDesignate">
+    <Key ID="STR_ACE_Laser_SelfDesignate_DesignatorOn">
+      <English>Laser&lt;br/&gt;Designator On</English>
+    </Key>
+    <Key ID="STR_ACE_Laser_SelfDesignate_DesignatorOff">
+      <English>Laser&lt;br/&gt;Designator Off</English>
+    </Key>
+  </Package>
+</Project>
\ No newline at end of file

From b7e3a9446212936ff8ba003d6d283143371c51d8 Mon Sep 17 00:00:00 2001
From: esteldunedain <nicolas.d.badano@gmail.com>
Date: Fri, 3 Apr 2015 12:44:09 -0300
Subject: [PATCH 2/2] Add designator to the comanche's gunner

---
 addons/laser_selfdesignate/CfgVehicles.hpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/addons/laser_selfdesignate/CfgVehicles.hpp b/addons/laser_selfdesignate/CfgVehicles.hpp
index 5b2fdd7d28..1c30e3d1e7 100644
--- a/addons/laser_selfdesignate/CfgVehicles.hpp
+++ b/addons/laser_selfdesignate/CfgVehicles.hpp
@@ -23,7 +23,8 @@ class CfgVehicles {
     class B_Heli_Attack_01_F: Heli_Attack_01_base_F {
         class Turrets: Turrets {
             class MainTurret: MainTurret {
-                stabilizedInAxes = 4;       // This stablizes the turret a bit more for laser designation
+                GVAR(Enabled) = 1;      // Enable laser self-designation
+                stabilizedInAxes = 4;   // This stablizes the turret a bit more for laser designation
             };
         };
     };