From fb763a9d57214117292f106be29af3e085c174f3 Mon Sep 17 00:00:00 2001
From: Glowbal <thomasskooi@live.nl>
Date: Sun, 1 Mar 2015 10:44:08 +0100
Subject: [PATCH] Added load and unload actions

---
 addons/medical/XEH_preInit.sqf                |  2 +
 .../medical/functions/fnc_actionLoadUnit.sqf  | 37 +++++++++++++++++++
 .../functions/fnc_actionUnloadUnit.sqf        | 33 +++++++++++++++++
 3 files changed, 72 insertions(+)
 create mode 100644 addons/medical/functions/fnc_actionLoadUnit.sqf
 create mode 100644 addons/medical/functions/fnc_actionUnloadUnit.sqf

diff --git a/addons/medical/XEH_preInit.sqf b/addons/medical/XEH_preInit.sqf
index be6651e198..d052a287d7 100644
--- a/addons/medical/XEH_preInit.sqf
+++ b/addons/medical/XEH_preInit.sqf
@@ -9,6 +9,8 @@ PREP(actionCheckPulseLocal);
 PREP(actionCheckResponse);
 PREP(actionPlaceInBodyBag);
 PREP(actionRemoveTourniquet);
+PREP(actionLoadUnit);
+PREP(actionUnloadUnit);
 PREP(addHeartRateAdjustment);
 PREP(addToInjuredCollection);
 PREP(addToLog);
diff --git a/addons/medical/functions/fnc_actionLoadUnit.sqf b/addons/medical/functions/fnc_actionLoadUnit.sqf
new file mode 100644
index 0000000000..6fad5b0847
--- /dev/null
+++ b/addons/medical/functions/fnc_actionLoadUnit.sqf
@@ -0,0 +1,37 @@
+/*
+ * Author: Glowbal
+ * Action for loading an unconscious or dead unit in the nearest vechile
+ *
+ * Arguments:
+ * 0: The medic <OBJECT>
+ * 1: The patient <OBJECT>
+ *
+ * Return Value:
+ * NONE
+ *
+ * Public: No
+ */
+
+
+#include "script_component.hpp"
+
+
+private ["_caller", "_target","_vehicle", "_loaded"];
+_caller = _this select 0;
+_target = _this select 1;
+
+if ([_target] call EFUNC(common,isAwake)) exitwith {
+	// TODO localization
+    ["displayTextStructured", [_caller], [["This person (%1) is awake and cannot be loaded", [_target] call EFUNC(common,getName)], 1.5, _caller]] call EFUNC(common,targetEvent);
+};
+
+[_caller, objNull] call cse_fnc_carryObj;
+[_target, objNull] call cse_fnc_carryObj;
+
+_vehicle = [_caller, _target] call EFUNC(common,loadPerson);
+if (!isNull _vehicle) then {
+    if (!isnil QGVAR(DROP_ADDACTION)) then {
+        _caller removeAction GVAR(DROP_ADDACTION);
+        GVAR(DROP_ADDACTION) = nil;
+    };
+};
diff --git a/addons/medical/functions/fnc_actionUnloadUnit.sqf b/addons/medical/functions/fnc_actionUnloadUnit.sqf
new file mode 100644
index 0000000000..92c06e176a
--- /dev/null
+++ b/addons/medical/functions/fnc_actionUnloadUnit.sqf
@@ -0,0 +1,33 @@
+/*
+ * Author: Glowbal
+ * Action for unloading an unconscious or dead unit from a vechile
+ *
+ * Arguments:
+ * 0: The medic <OBJECT>
+ * 1: The patient <OBJECT>
+ * 2: Drag after unload <BOOL> <OPTIONAL>
+ *
+ * Return Value:
+ * NONE
+ *
+ * Public: No
+ */
+
+#include "script_component.hpp"
+
+private ["_caller", "_target","_vehicle", "_drag", "_handle"];
+_caller = _this select 0;
+_target = _this select 1;
+_drag = if (count _this > 2) then {_this select 2} else {false};
+
+// cannot unload a unit not in a vehicle.
+if (vehicle _target == _target) exitwith {};
+if (([_target] call cse_fnc_isAwake)) exitwith {};
+
+if ([_caller, _target] call EFUNC(common,unloadPerson)) then {
+    if (_drag) then {
+        if ((vehicle _caller) == _caller) then {
+            [[_caller, _target], QUOTE(DFUNC(actionDragUnit)), _caller, false] call BIS_fnc_MP;
+        };
+    };
+};