Browse Source

Add Make Volatile Cargo module

m3ales 3 years ago
parent
commit
2e326a9c37

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

@@ -105,4 +105,13 @@ if(hasInterface) then {
 	["rd501_fired_deployable_soundEnd", {
 		_this call rd501_fnc_fired_deployable_endSoundLocal
 	}] call CBA_fnc_addEventHandler;
-};
+};
+
+// Volatile
+["rd501_volatile_destroy", {
+	_this call rd501_fnc_volatile_destroy;
+}] call CBA_fnc_addEventHandler;
+
+["rd501_volatile_create", {
+	_this call rd501_fnc_volatile_create;
+}] call CBA_fnc_addEventHandler;

+ 5 - 0
addons - Copy/RD501_Main/XEH_preInit.sqf

@@ -162,4 +162,9 @@ macro_prep_xeh(init\deka_shield_init.sqf,deka_shield_init)
 // JLTS Shield
 macro_prep_xeh(jlts_shield\fnc_jlts_shield_aiToggle.sqf,jlts_shield_aiToggle)
 
+// Volatile
+macro_prep_xeh(volatile\fnc_volatile_create.sqf,volatile_create)
+macro_prep_xeh(volatile\fnc_volatile_destroy.sqf,volatile_destroy)
+macro_prep_xeh(volatile\fnc_volatile_handleDamage.sqf,volatile_handleDamage)
+
 diag_log "RD501 PREP Complete";

+ 8 - 0
addons - Copy/RD501_Main/functions/volatile/fnc_volatile_create.sqf

@@ -0,0 +1,8 @@
+params["_target"];
+
+private _ehId = _target addEventHandler["HitPart", {
+	_this call rd501_fnc_volatile_handleDamage;
+}];
+
+_target setVariable ["rd501_volatile_health", 100, true];
+_target setVariable ["rd501_volatile_ehId", _ehId];

+ 11 - 0
addons - Copy/RD501_Main/functions/volatile/fnc_volatile_destroy.sqf

@@ -0,0 +1,11 @@
+params["_target"];
+
+private _position = getPosATL _target;
+private _explosive = createVehicle ["RD501_Explosive_Barrel", _position, [], 0, "CAN_COLLIDE"];
+hideObject _explosive;
+_explosive setPosATL _position;
+_explosive setDamage [1, true];
+[{
+	params["_target"];
+	deleteVehicle _target;
+}, [_target], 0.5] call CBA_fnc_waitAndExecute;

+ 22 - 0
addons - Copy/RD501_Main/functions/volatile/fnc_volatile_handleDamage.sqf

@@ -0,0 +1,22 @@
+(_this select 0) params ["_target", "_shooter", "_projectile", "_position", "_velocity", "_selection", "_ammo", "_vector", "_radius", "_surfaceType", "_isDirect"];
+
+if(_target isEqualTo objNull) exitWith { systemChat "Target is null idk why"; }; 
+
+private _health = _target getVariable ["rd501_volatile_health", false];
+
+if(_health isEqualTo false) exitWith { systemChat "Health not found"; };
+_ammo params ["_directHit", "_indirectHit", "_indirectRange", "_explosionHit", "_ammoClass"];
+private _hit = _directHit + (_indirectHit/(_indirectRange max 0.1)) + _explosionHit;
+private _result = _health - _hit;
+
+if(_result <= 0) then {
+	_target setVariable ["rd501_volatile_health", _result, true];
+	private _ehId = _target getVariable ["rd501_volatile_ehId", -1];
+	["rd501_volatile_destroy", [_target], _target] call cba_fnc_targetEvent;
+	_target  removeEventHandler ["HitPart", _ehId];
+}
+else
+{
+	// Set locally only to reduce network traffic
+	_target setVariable ["rd501_volatile_health", _result];
+};

+ 3 - 1
addons - Copy/RD501_Zeus/XEH_PREP.sqf

@@ -17,4 +17,6 @@
 
 PREP(moduleJammerSettings);
 PREP(ui_jammerSettings);
-PREP(moduleJammerClearAll);
+PREP(moduleJammerClearAll);
+PREP(moduleVolatile);
+PREP(ui_volatileSettings);

+ 18 - 2
addons - Copy/RD501_Zeus/config.cpp

@@ -15,7 +15,8 @@ class CfgPatches
 			macro_new_ordnance(ModuleShadow),
 			macro_new_ordnance(OrbitalLaser),
 			rd501_moduleJammerSettings,
-			rd501_moduleClearAllJammers
+			rd501_moduleClearAllJammers,
+			rd501_moduleVolatileSettings,
 		};
 		weapons[] = {};
 	};
@@ -93,6 +94,21 @@ class CfgVehicles
 		portrait = "RD501_Zeus\ui\jammer_icon.paa";
     };
 
+	class rd501_moduleVolatileSettings: Module_F  {
+		author = "RD501";
+        category = "Ordnance";
+        function = "ace_common_dummy";
+        functionPriority = 1;
+        isGlobal = 1;
+        isTriggerActivated = 0;
+        scope = 1;
+        scopeCurator = 2;
+        curatorCanAttach = 1;
+        displayName = "Make Volatile Cargo";
+        curatorInfoType = "RD501_RscVolatileSettings";
+		portrait = "RD501_Zeus\ui\explosion_zeus_icon_small.paa";
+    };
+
 	class macro_new_ordnance(ModuleSquadShield): ModuleChemlight_F
 	{
 		author = "RD501";
@@ -282,4 +298,4 @@ class Extended_PreInit_EventHandlers
 	};
 };
 
-#include "ui\RscAttributes.hpp"
+#include "ui\RscAttributes.hpp"

+ 11 - 0
addons - Copy/RD501_Zeus/functions/fnc_moduleVolatile.sqf

@@ -0,0 +1,11 @@
+params["_logic"];
+
+if (isNull _logic) exitWith {};
+private _initVars = _logic getVariable ["rd501_ui_volatileInit", [100]];
+private _attach = attachedTo _logic;
+if(isNull _attach) then {
+	deleteVehicle _logic; // Don't spawn without any target obj
+}else
+{
+	["rd501_volatile_create", [_attach], _attach] call CBA_fnc_targetEvent;
+};

+ 49 - 0
addons - Copy/RD501_Zeus/functions/fnc_ui_volatileSettings.sqf

@@ -0,0 +1,49 @@
+params ["_control"];
+
+private _display = ctrlParent _control;
+private _ctrlButtonOK = _display displayCtrl 1;
+private _logic = missionNamespace getVariable ["BIS_fnc_initCuratorAttributes_target",objNull];
+
+_control ctrlRemoveAllEventHandlers "setFocus";
+
+private _fnc_sliderMove = {
+    params ["_slider"];
+    private _idc = ctrlIDC _slider;
+    private _logic = missionNamespace getVariable["BIS_fnc_initCuratorAttributes_target",objNull];
+    if (isNull _logic) exitWith {};
+    private _jammerInit = _logic getVariable ["rd501_ui_volatileInit", [100]];
+    if(_idc == 58502) then {
+        // Health
+        private _curVal = _jammerInit select 0;
+        _slider ctrlSetTooltip format ["%1%3 (default %2%3)", round(sliderPosition _slider), round(_curVal), " hitpoints"];
+    };
+};
+
+private _logic = missionNamespace getVariable["BIS_fnc_initCuratorAttributes_target",objNull];
+private _init = _logic getVariable ["rd501_ui_volatileInit", [100]];
+
+private _slider = _display displayCtrl 58502;
+_slider sliderSetRange [10, 20000];
+_slider sliderSetSpeed [1,100];
+_slider sliderSetPosition (_init select 0);
+_slider ctrlAddEventHandler ["SliderPosChanged", _fnc_sliderMove];
+_slider call _fnc_sliderMove;
+
+private _fnc_onUnload = {
+    private _logic =  missionNamespace getVariable ["BIS_fnc_initCuratorAttributes_target",objNull];
+    if (isNull _logic) exitWith { };
+    deleteVehicle _logic;
+};
+
+private _fnc_onConfirm = {
+    params [["_ctrlButtonOK", controlNull, [controlNull]]];
+    private _display = ctrlparent _ctrlButtonOK;
+    if (isNull _display) exitWith { };
+    private _logic = missionNamespace getVariable["BIS_fnc_initCuratorAttributes_target",objNull];
+    if (isNull _logic) exitWith { };
+    _logic setVariable ["rd501_ui_volatileInit", [sliderPosition (_display displayCtrl 58502)]];
+    [_logic] call rd501_zeus_fnc_moduleVolatile;
+};
+
+_display displayAddEventHandler ["unload", _fnc_onUnload];
+_ctrlButtonOK ctrlAddEventHandler ["buttonclick", _fnc_onConfirm];

+ 43 - 0
addons - Copy/RD501_Zeus/ui/RscAttributes.hpp

@@ -74,4 +74,47 @@ class RD501_RscJammerSettings: RscDisplayAttributes {
         class ButtonOK: ButtonOK {};
         class ButtonCancel: ButtonCancel {};
     };
+};
+
+
+class RD501_RscVolatileSettings: RscDisplayAttributes {
+    onLoad = "['onLoad', _this, ""RD501_RscVolatileSettings""] call ace_zeus_fnc_zeusAttributes";
+    onUnload = "['onUnload', _this, ""RD501_RscVolatileSettings""] call ace_zeus_fnc_zeusAttributes";
+    class Controls: Controls {
+        class Background: Background {};
+        class Title: Title {};
+        class Content: Content {
+            class Controls {
+                class RD501_VolatileSettings: RscControlsGroupNoScrollbars {
+                    onSetFocus = "_this call rd501_zeus_fnc_ui_volatileSettings";
+                    idc = 58501;
+                    x = 0;
+                    y = 0;
+                    w = (26 * (((safezoneW / safezoneH) min 1.2) / 40));
+                    h = (2 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25));
+                    class Controls {
+                        class Title1: RscText {
+                            idc = -1;
+                            text = "Volatile Health";
+                            toolTip = "How many hits to take before exploding";
+                            x = 0;
+                            y = 0;
+                            w = (10 * (((safezoneW / safezoneH) min 1.2) / 40));
+                            h = (1 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25));
+                            colorBackground[] = {0,0,0,0.5};
+                        };
+                        class Volatile_Health: RscXSliderH {
+                            idc = 58502;
+                            x = (10.1 * (((safezoneW / safezoneH) min 1.2) / 40));
+                            y = 0;
+                            w = (15.9 * (((safezoneW / safezoneH) min 1.2) / 40));
+                            h = (1 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25));
+                        };
+                    };
+                };
+            };
+        };
+        class ButtonOK: ButtonOK {};
+        class ButtonCancel: ButtonCancel {};
+    };
 };