Browse Source

Add stitch, bandage, and progress bar to medical facility, deploy now adds interacts

m3ales 4 years ago
parent
commit
d0e963ba66

+ 4 - 1
addons - Copy/RD501_Main/XEH_postinit.sqf

@@ -46,4 +46,7 @@ rd501_flip_vehicle_validBackpacks = ["RD501_JLTS_Clone_Flip_backpack"];
 call macro_fnc_name(fortify_tool);
 
 // Medical CCP Building
-rd501_medical_ccp_building = "Land_Medevac_house_V1_F";
+rd501_medical_ccp_building = "Land_Medevac_house_V1_F";
+rd501_medical_ccp_bandage_treatmentTime = 1;
+rd501_medical_ccp_stitch_treatmentTime = 1;
+rd501_medical_ccp_classes = ["Land_Medevac_house_V1_F"];

+ 12 - 2
addons - Copy/RD501_Main/XEH_preInit.sqf

@@ -115,5 +115,15 @@ macro_prep_xeh(external_reload\fnc_canReloadExternal.sqf,canReloadExternal)
 macro_prep_xeh(external_reload\fnc_reloadExternal.sqf,reloadExternal)
 macro_prep_xeh(external_reload\fnc_onReloadExternalHandler.sqf,onReloadExternalHandler)
 
-// Deploy Medic CCP
-macro_prep_xeh(medical_ccp\fnc_deployCcp.sqf,deployCcp)
+// Medical CCP
+macro_prep_xeh(medical_ccp\fnc_deployCCP.sqf,deployCCP)
+macro_prep_xeh(medical_ccp\fnc_stitchAllWounds.sqf,stitchAllWounds)
+macro_prep_xeh(medical_ccp\fnc_bandageAllWounds.sqf,bandageAllWounds)
+macro_prep_xeh(medical_ccp\fnc_checkInsideCCP.sqf,checkInsideCCP)
+macro_prep_xeh(medical_ccp\fnc_stitchAllWoundsNearbyCCP.sqf,stitchAllWoundsNearbyCCP)
+macro_prep_xeh(medical_ccp\fnc_bandageAllNearbyCCP.sqf,bandageAllNearbyCCP)
+macro_prep_xeh(medical_ccp\fnc_valueProgressBar.sqf,valueProgressBar)
+macro_prep_xeh(medical_ccp\fnc_incrementBandageProgress.sqf,incrementBandageProgress)
+macro_prep_xeh(medical_ccp\fnc_incrementStitchProgress.sqf,incrementStitchProgress)
+
+diag_log "RD501 PREP Complete";

+ 102 - 0
addons - Copy/RD501_Main/functions/medical_ccp/fnc_bandageAllNearbyCCP.sqf

@@ -0,0 +1,102 @@
+/*
+ * Author: M3ales
+ *
+ * Arguments:
+ * Healer
+ * Origin To Search from
+ * Radius To Search Around for People
+ * Return Value:
+ * Nothing
+ *
+ * Example:
+ * [player, cursorTarget] call rd501_fnc_bandageAllNearbyCCP
+ *
+ * Public: No
+ */
+
+params["_healer", "_origin", "_radius"];
+
+private _nearbyPatients = _origin nearEntities ["CAManBase", _radius] select {
+	[_x] call rd501_fnc_checkInsideCCP &&
+	{
+		count (_x getVariable ["ace_medical_openWounds", []]) > 0
+	}
+};
+
+private _args = [_healer, _nearbyPatients, _origin];
+
+if(count _nearbyPatients == 0) exitWith {
+	["Nobody to Bandage Inside CCP", true, 2, 0] call ace_common_fnc_displayText;
+};
+
+[format["Bandaging %1 Patient(s)", count _nearbyPatients], false, 10, 0] call ace_common_fnc_displayText;
+
+private _onFinish = {
+    (_this select 0) params ["_player", "_patients", "_building"];
+	{
+		if([_x] call rd501_fnc_checkInsideCCP) then {
+			[_player, _x] call rd501_fnc_bandageAllWounds;
+		};
+	} forEach (_patients);
+    _building setVariable ["rd501_medical_ccp_bandageProgress", -1, true];
+    _building setVariable["rd501_medical_ccp_bandageMembers", [], true];
+	[_player, "", 1] call ace_common_fnc_doAnimation;
+};
+
+private _onFailure = {
+    params["_args", "_progress", "_errorCode"];
+    _args params["_healer","_nearbyPatients", "_building"];
+    [_healer, "AmovPknlMstpSrasWrflDnon", 1] call ace_common_fnc_doAnimation;
+    _bandagers = _building getVariable ["rd501_medical_ccp_bandageMembers", []];
+    systemChat format["_bandagers %1", _bandagers];
+    if(count _bandagers <= 1) then {
+        _building setVariable ["rd501_medical_ccp_bandageProgress", -1, true];
+        _building setVariable["rd501_medical_ccp_bandageMembers", [], true];
+    }
+    else
+    {
+        _newArr = _bandagers deleteAt (_bandagers findIf { _x isEqualTo ([] call CBA_fnc_currentUnit)}) select 1;
+        _building setVariable["rd501_medical_ccp_bandageMembers", _newArr, true];
+    }
+};
+
+private _condition = {
+    params["_args", "_progress", "_errorCode"];
+    _args params["_healer","_nearbyPatients", "_building"];
+    if(_progress == -1) exitWith {false};
+    if(_healer getVariable ["ACE_Unconscious", false]) exitWith {false};
+    alive _healer && alive _building
+};
+
+if(_origin getVariable ["rd501_medical_ccp_bandageProgress", -1] == -1) then {
+    _origin setVariable ["rd501_medical_ccp_bandageProgress", 0, true];
+    _origin setVariable ["rd501_medical_ccp_bandageMembers", [player], true];
+}
+else
+{
+    _bandageMembers = _origin getVariable ["rd501_medical_ccp_bandageMembers", []];
+    _bandageMembers append [player];
+    _origin setVariable ["rd501_medical_ccp_bandageMembers", _bandageMembers, true];
+};
+
+[
+    {
+        params ["_args", "_handle"];
+        _args params ["_healer", "_nearbyPatients", "_origin"];
+        _progress = _origin getVariable ["rd501_medical_ccp_bandageProgress", -1];
+        if(_progress > 100 || _progress < 0) exitWith {
+            systemChat "EH Exit";
+            [_handle] call CBA_fnc_removePerFrameHandler;
+        };
+        if!(_healer getVariable ["ACE_Unconscious", false]) exitWith {
+            systemChat "EH Increment";
+            [_origin, _healer] call rd501_fnc_incrementBandageProgress;
+        };
+    }, 
+    0.5,
+    _args
+] call CBA_fnc_addPerFrameHandler;
+
+[_healer, "AinvPknlMstpSnonWnonDr_medic5", 0] call ace_common_fnc_doAnimation;
+
+[_origin, _args, _onFinish, _onFailure, "Bandaging All Patients Inside CCP", _condition] call rd501_fnc_valueProgressBar;

+ 27 - 0
addons - Copy/RD501_Main/functions/medical_ccp/fnc_bandageAllWounds.sqf

@@ -0,0 +1,27 @@
+#include "../../ace_medical_macros.hpp"
+/*
+ * Author: M3ales
+ *
+ * Arguments:
+ * Healer
+ * Patient
+ * Return Value:
+ * Nothing
+ *
+ * Example:
+ * [player, cursorTarget] call rd501_fnc_bandageAllWounds
+ *
+ * Public: No
+ */
+
+params ["_healer", "_patient"];
+
+private _openWounds = (_patient getVariable ["ace_medical_openWounds", []]);
+if (_openWounds isEqualTo []) exitWith {};
+_patient setVariable ["ace_medical_openWounds", [], true];
+
+[_patient] call ace_medical_status_fnc_updateWoundBloodLoss;
+[_patient] call ace_medical_engine_fnc_updateDamageEffects;
+
+private _nearPlayers = (_patient nearEntities ["CAManBase", 6]) select {_x call ace_common_fnc_isPlayer};
+["ace_interact_menu_clearConditionCaches", [], _nearPlayers] call CBA_fnc_targetEvent;

+ 6 - 0
addons - Copy/RD501_Main/functions/medical_ccp/fnc_canBandageNearbyCCP.sqf

@@ -0,0 +1,6 @@
+params [
+	"_target", 
+	"_player", 
+	"_params"
+];
+

+ 6 - 0
addons - Copy/RD501_Main/functions/medical_ccp/fnc_canStitchNearbyCCP.sqf

@@ -0,0 +1,6 @@
+params [
+	"_target", 
+	"_player", 
+	"_params"
+];
+

+ 18 - 0
addons - Copy/RD501_Main/functions/medical_ccp/fnc_checkInsideCCP.sqf

@@ -0,0 +1,18 @@
+params ["_unit"];
+
+private _fnc_check = {
+    private _position = _unit modelToWorldVisual [0, 0, eyePos _unit select 2];
+     
+    (
+        (lineIntersectsWith [_position, _position vectorAdd [0, 0, 10], _unit]) findIf {
+            typeOf _x in rd501_medical_ccp_classes || {_x getVariable ["rd501_medical_ccp_inside", false]}
+        } != -1
+    )
+    || {
+        ((_unit nearObjects 7.5) findIf {
+            typeOf _x in rd501_medical_ccp_classes || {_x getVariable ["rd501_medical_ccp_inside", false]}
+        } != -1)
+    }
+};
+
+[[], _fnc_check, _unit, "rd501_medical_ccp_insideCache", 1] call ace_common_fnc_cachedCall;

+ 16 - 12
addons - Copy/RD501_Main/functions/medical_ccp/fnc_deployCcp.sqf

@@ -1,18 +1,22 @@
 params [
-	["_target"], 
-	["_player"], 
-	["_params"]
+	"_target", 
+	"_player", 
+	"_params"
 ];
 
 _position = position _target;
 deleteVehicle _target;
+_spawner = rd501_medical_ccp_building createVehicle _position;
+systemChat format["Deployed CCP"];
 
-[
-	{
-		params["_position"];
-		systemChat format["Deploying CCP"];
-		_spawner = rd501_medical_ccp_building createVehicle _position;
-	},
-	[_position],
-	0.1
-] call CBA_fnc_waitAndExecute;
+_action = ["rd501_medical_ccp_bandageAll", "Bandage All Patients", "", {
+	params ["_target", "_player", "_params"];
+		[_player, _target, 20] call rd501_fnc_bandageAllNearbyCCP;
+	}, {true}] call ace_interact_menu_fnc_createAction;
+[_spawner, 0, ["ACE_MainActions"], _action] call ace_interact_menu_fnc_addActionToObject;
+
+_action = ["rd501_medical_ccp_stitchAll", "Stitch All Patients", "", {
+	params ["_target", "_player", "_params"];
+		[_this select 0, _this select 1, 20] call rd501_fnc_stitchAllWoundsNearbyCCP;
+	}, {true}] call ace_interact_menu_fnc_createAction;
+[_spawner, 0, ["ACE_MainActions"], _action] call ace_interact_menu_fnc_addActionToObject;

+ 6 - 0
addons - Copy/RD501_Main/functions/medical_ccp/fnc_incrementBandageProgress.sqf

@@ -0,0 +1,6 @@
+params["_origin", "_healer"];
+_progress = _origin getVariable["rd501_medical_ccp_bandageProgress", -1];
+systemChat format["Incrementing %1 --- %2", _this, _progress];
+if(_progress >= 0) then {
+	_origin setVariable["rd501_medical_ccp_bandageProgress", _progress + 2.5, true];
+};

+ 6 - 0
addons - Copy/RD501_Main/functions/medical_ccp/fnc_incrementStitchProgress.sqf

@@ -0,0 +1,6 @@
+params["_origin", "_healer"];
+_progress = _origin getVariable["rd501_medical_ccp_stitchProgress", -1];
+systemChat format["Incrementing %1 --- %2", _this, _progress];
+if(_progress >= 0) then {
+	_origin setVariable["rd501_medical_ccp_stitchProgress", _progress + 2.5, true];
+};

+ 8 - 0
addons - Copy/RD501_Main/functions/medical_ccp/fnc_stitchAllWounds.sqf

@@ -0,0 +1,8 @@
+
+params["_healer","_patient"];
+
+private _bandagedWounds = _patient getVariable ["ace_medical_bandagedWounds", []];
+private _stitchedWounds = _patient getVariable ["ace_medical_stitchedWounds", []];
+_patient setVariable ["ace_medical_bandagedWounds", [], true];
+_patient setVariable ["ace_medical_stitchedWounds", _stitchedWounds, true];
+[_patient] call ace_medical_engine_fnc_updateDamageEffects; 

+ 117 - 0
addons - Copy/RD501_Main/functions/medical_ccp/fnc_stitchAllWoundsNearbyCCP.sqf

@@ -0,0 +1,117 @@
+/*
+ * Author: M3ales
+ *
+ * Arguments:
+ * Healer
+ * Origin To Search from
+ * Radius To Search Around for People
+ * Return Value:
+ * Nothing
+ *
+ * Example:
+ * [player, cursorTarget] call rd501_fnc_stitchAllNearbyCCP
+ *
+ * Public: No
+ */
+/*
+ * Author: M3ales
+ *
+ * Arguments:
+ * Healer
+ * Origin To Search from
+ * Radius To Search Around for People
+ * Return Value:
+ * Nothing
+ *
+ * Example:
+ * [player, cursorTarget] call rd501_fnc_stitchAllNearbyCCP
+ *
+ * Public: No
+ */
+
+params["_healer", "_origin", "_radius"];
+
+private _nearbyPatients = _origin nearEntities ["CAManBase", _radius] select {
+	[_x] call rd501_fnc_checkInsideCCP &&
+	{
+		count (_x getVariable ["ace_medical_openWounds", []]) > 0
+	}
+};
+
+private _args = [_healer, _nearbyPatients, _origin];
+
+if(count _nearbyPatients == 0) exitWith {
+	["Nobody to Stitch Inside CCP", true, 2, 0] call ace_common_fnc_displayText;
+};
+
+[format["Bandaging %1 Patient(s)", count _nearbyPatients], false, 10, 0] call ace_common_fnc_displayText;
+
+private _onFinish = {
+    (_this select 0) params ["_player", "_patients", "_building"];
+	{
+		if([_x] call rd501_fnc_checkInsideCCP) then {
+			[_player, _x] call rd501_fnc_stitchAllWounds;
+		};
+	} forEach (_patients);
+    _building setVariable ["rd501_medical_ccp_stitchProgress", -1, true];
+    _building setVariable["rd501_medical_ccp_stitchMembers", [], true];
+	[_player, "", 1] call ace_common_fnc_doAnimation;
+};
+
+private _onFailure = {
+    params["_args", "_progress", "_errorCode"];
+    _args params["_healer","_nearbyPatients", "_building"];
+    [_healer, "AmovPknlMstpSrasWrflDnon", 1] call ace_common_fnc_doAnimation;
+    _stitchers = _building getVariable ["rd501_medical_ccp_stitchMembers", []];
+    systemChat format["_stitchers %1", _stitchers];
+    if(count _stitchers <= 1) then {
+        _building setVariable ["rd501_medical_ccp_stitchProgress", -1, true];
+        _building setVariable["rd501_medical_ccp_stitchMembers", [], true];
+    }
+    else
+    {
+        _newArr = _stitchers deleteAt (_stitchers findIf { _x isEqualTo ([] call CBA_fnc_currentUnit)}) select 1;
+        _building setVariable["rd501_medical_ccp_stitchMembers", _newArr, true];
+    }
+};
+
+private _condition = {
+    params["_args", "_progress", "_errorCode"];
+    _args params["_healer","_nearbyPatients", "_building"];
+    if(_progress == -1) exitWith {false};
+    if(_healer getVariable ["ACE_Unconscious", false]) exitWith {false};
+    alive _healer && alive _building
+};
+
+if(_origin getVariable ["rd501_medical_ccp_stitchProgress", -1] == -1) then {
+    _origin setVariable ["rd501_medical_ccp_stitchProgress", 0, true];
+    _origin setVariable ["rd501_medical_ccp_stitchMembers", [player], true];
+}
+else
+{
+    _stitchMembers = _origin getVariable ["rd501_medical_ccp_stitchMembers", []];
+    _stitchMembers append [player];
+    _origin setVariable ["rd501_medical_ccp_stitchMembers", _stitchMembers, true];
+};
+
+[
+    {
+        params ["_args", "_handle"];
+        _args params ["_healer", "_nearbyPatients", "_origin"];
+        _progress = _origin getVariable ["rd501_medical_ccp_stitchProgress", -1];
+        if(_progress > 100 || _progress < 0) exitWith {
+            systemChat "EH Exit";
+            [_handle] call CBA_fnc_removePerFrameHandler;
+        };
+        if!(_healer getVariable ["ACE_Unconscious", false]) exitWith {
+            systemChat "EH Increment";
+            [_origin, _healer] call rd501_fnc_incrementStitchProgress;
+        };
+    }, 
+    0.5,
+    _args
+] call CBA_fnc_addPerFrameHandler;
+
+[_healer, "AinvPknlMstpSnonWnonDr_medic5", 0] call ace_common_fnc_doAnimation;
+
+[_origin, _args, _onFinish, _onFailure, "Bandaging All Patients Inside CCP", _condition] call rd501_fnc_valueProgressBar;

+ 99 - 0
addons - Copy/RD501_Main/functions/medical_ccp/fnc_valueProgressBar.sqf

@@ -0,0 +1,99 @@
+/*
+ * Author: commy2, Glowbal, PabstMirror
+ * Modified by: Mirror
+ * Draw progress bar and execute given function if succesful.
+ * Finish/Failure/Conditional are all passed [_args, _elapsedTime, _totalTime, _errorCode]
+ *
+ * Arguments:
+ * 0: Progress Variable Func: 0-100 representation of how complete the bar should be.
+ * 1: Arguments, passed to condition, fail and finish <ARRAY>
+ * 2: On Finish: Code called or STRING raised as event. <CODE, STRING>
+ * 3: On Failure: Code called or STRING raised as event. <CODE, STRING>
+ * 4: (Optional) Localized Title <STRING>
+ * 5: Code to check each frame (Optional) <CODE>
+ * 6: Exceptions for checking EFUNC(common,canInteractWith) (Optional)<ARRAY>
+ *
+ * Return Value:
+ * None
+ *
+ * Example:
+ * [5, [], {Hint "Finished!"}, {hint "Failure!"}, "My Title"] call ace_common_fnc_progressBar
+ *
+ * Public: Yes
+ */
+
+params ["_building", "_args", "_onFinish", "_onFail", ["_localizedTitle", ""], ["_condition", {true}], ["_exceptions", []]];
+
+private _player = ACE_player;
+
+//Open Dialog and set the title
+closeDialog 0;
+createDialog "ace_common_ProgressBar_Dialog";
+
+(uiNamespace getVariable "ace_common_ctrlProgressBarTitle") ctrlSetText _localizedTitle;
+
+//Adjust position based on user setting:
+private _ctrlPos = ctrlPosition (uiNamespace getVariable "ace_common_ctrlProgressBarTitle");
+_ctrlPos set [1, ((0 + 29 * ace_common_settingProgressBarLocation) * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + (safezoneY + (safezoneH - (((safezoneW / safezoneH) min 1.2) / 1.2))/2))];
+
+(uiNamespace getVariable "ace_common_ctrlProgressBG") ctrlSetPosition _ctrlPos;
+(uiNamespace getVariable "ace_common_ctrlProgressBG") ctrlCommit 0;
+(uiNamespace getVariable "ace_common_ctrlProgressBar") ctrlSetPosition _ctrlPos;
+(uiNamespace getVariable "ace_common_ctrlProgressBar") ctrlCommit 0;
+(uiNamespace getVariable "ace_common_ctrlProgressBarTitle") ctrlSetPosition _ctrlPos;
+(uiNamespace getVariable "ace_common_ctrlProgressBarTitle") ctrlCommit 0;
+
+[{
+    (_this select 0) params ["_args", "_onFinish", "_onFail", "_condition", "_player", "_building", "_exceptions"];
+
+    private _progress = _building getVariable["rd501_medical_ccp_bandageProgress", -1];
+    private _errorCode = -1;
+
+    // this does not check: target fell unconscious, target died, target moved inside vehicle / left vehicle, target moved outside of players range, target moves at all.
+    if (isNull (uiNamespace getVariable ["ace_common_ctrlProgressBar", controlNull])) then {
+        _errorCode = 1;
+    } else {
+        if (ACE_player != _player || !alive _player) then {
+            _errorCode = 2;
+        } else {
+            if !([_args, _progress, _errorCode] call _condition) then {
+                _errorCode = 3;
+            } else {
+                if !([_player, objNull, _exceptions] call ace_common_fnc_canInteractWith) then {
+                    _errorCode = 4;
+                } else {
+                    if (_progress >= 100) then {
+                        _errorCode = 0;
+                    };
+                };
+            };
+        };
+    };
+
+    if (_errorCode != -1) then {
+        //Error or Success, close dialog and remove PFEH
+
+        //Only close dialog if it's the progressBar:
+        if (!isNull (uiNamespace getVariable ["ace_common_ctrlProgressBar", controlNull])) then {
+            closeDialog 0;
+        };
+
+        [_this select 1] call CBA_fnc_removePerFrameHandler;
+
+        if (_errorCode == 0) then {
+            if (_onFinish isEqualType "") then {
+                [_onFinish, [_args, _errorCode]] call CBA_fnc_localEvent;
+            } else {
+                [_args, _errorCode] call _onFinish;
+            };
+        } else {
+            if (_onFail isEqualType "") then {
+                [_onFail, [_args, _progress, _errorCode]] call CBA_fnc_localEvent;
+            } else {
+                [_args, _progress, _errorCode] call _onFail;
+            };
+        };
+    } else {
+        (uiNamespace getVariable "ace_common_ctrlProgressBar") progressSetPosition _progress / 100;
+    };
+}, 0, [_args, _onFinish, _onFail, _condition, _player, _building, _exceptions]] call CBA_fnc_addPerFrameHandler;