Browse Source

Merge pull request #117 from 501st-Aux-Mod-Team/magclamp_refuel

Magclamp refuel
Erliens 4 years ago
parent
commit
5ae5ea87e3

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

@@ -67,6 +67,9 @@ macro_prep_xeh(nightvision.sqf,nightvision)
 
 //magclamp
 macro_prep_xeh(magclamp\magclamp.sqf,magclamp)
+macro_prep_xeh(magclamp\fnc_startRefuel.sqf,mc_startRefuel)
+macro_prep_xeh(magclamp\fnc_canRefuel.sqf,mc_canRefuel)
+macro_prep_xeh(magclamp\fnc_canStopRefuel.sqf,mc_canStopRefuel)
 
 //HUD color
 macro_prep_xeh(hud_color_change.sqf,change_hud_color)

+ 7 - 0
addons - Copy/RD501_Main/functions/magclamp/fnc_canRefuel.sqf

@@ -0,0 +1,7 @@
+params["_vehicle"];
+
+if (!(driver _vehicle == player)) exitWith{false};
+if (!alive _vehicle) exitWith{false};
+if (isNull (_vehicle getVariable["RD501_mc_attached_large", objNull])) exitWith{false};
+if (_vehicle getVariable["RD501_mc_lastRefuelTick", -1] != -1) exitWith{false};
+true

+ 7 - 0
addons - Copy/RD501_Main/functions/magclamp/fnc_canStopRefuel.sqf

@@ -0,0 +1,7 @@
+params["_vehicle"];
+
+if (!(driver _vehicle == player)) exitWith{false};
+if (!alive _vehicle) exitWith{false};
+if (isNull (_vehicle getVariable["RD501_mc_attached_large", objNull])) exitWith{false};
+if (_vehicle getVariable["RD501_mc_lastRefuelTick", -1] == -1) exitWith{false};
+true

+ 97 - 0
addons - Copy/RD501_Main/functions/magclamp/fnc_startRefuel.sqf

@@ -0,0 +1,97 @@
+params["_vehicle"];
+
+private _rate = 10;
+
+private _attached = _vehicle getVariable["RD501_mc_attached_large", objNull];
+_vehicle setVariable["RD501_mc_stop_refuel", false, true];
+
+_maxFuelSource = getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "fuelCapacity");
+_maxFuelTarget = getNumber (configFile >> "CfgVehicles" >> typeOf _attached >> "fuelCapacity");
+
+private _firstTick = 0;
+if (isMultiplayer) then
+{
+    _firstTick = serverTime;
+} else
+{
+    _firstTick = time;
+};
+
+hint "Refueling started";
+
+_vehicle setVariable["RD501_mc_lastRefuelTick", _firstTick, true];
+_vehicle setVariable["RD501_mc_nextRefuelUpdate", 0.1, true];
+
+[{
+    params ["_args", "_pfID"];
+    _args params ["_target", "_source", "_rate", "_maxFuelSource", "_maxFuelTarget"];
+
+    if (!alive _source || {!alive _sink}) then 
+    {
+        _source setVariable["RD501_mc_lastRefuelTick", nil, true];
+        _source setVariable["RD501_mc_nextRefuelUpdate", nil, true];
+        _source setVariable["RD501_mc_lastTargetFuelAmount", nil, true];
+        [_pfID] call CBA_fnc_removePerFrameHandler;
+    };
+
+    if (_source getVariable["RD501_mc_stop_refuel", false]) then
+    {
+        hint "Refueling stopped";
+        _source setVariable["RD501_mc_lastRefuelTick", nil, true];
+        _source setVariable["RD501_mc_nextRefuelUpdate", nil, true];
+        _source setVariable["RD501_mc_lastTargetFuelAmount", nil, true];
+        [_pfID] call CBA_fnc_removePerFrameHandler;
+    };
+
+    private _currentTime = 0;
+    if (isMultiplayer) then
+    {
+        _currentTime = serverTime;
+    } else
+    {
+        _currentTime = time;
+    };
+    
+    private _target_fuel = (fuel _target) * _maxFuelTarget;
+    private _source_fuel = (fuel _source) * _maxFuelSource;
+
+    // if last ticks have not been applied yet, act as if they have
+    private _last_target_fuel = (_source getVariable["RD501_mc_lastTargetFuelAmount", 0]) * _maxFuelTarget;
+    if (_last_target_fuel > _target_fuel) then
+    {
+        _target_fuel = _last_target_fuel;
+    };
+
+    private _deltaT = _currentTime - (_source getVariable["RD501_mc_lastRefuelTick", 0]);
+    private _transfer = _rate * _deltaT;
+
+    private _target_new_fuel = ((_target_fuel + _transfer) / _maxFuelTarget);
+    private _source_new_fuel = ((_source_fuel - _transfer) / _maxFuelSource);
+
+    private _last_update = _source getVariable["RD501_mc_nextRefuelUpdate", 0];
+
+    if (_target_new_fuel >= 1.0) then
+    {
+        _target_new_fuel = 1.0;
+        hint "Refueling complete";
+        _source setVariable["RD501_mc_lastRefuelTick", nil, true];
+        _source setVariable["RD501_mc_nextRefuelUpdate", nil, true];
+        _source setVariable["RD501_mc_lastTargetFuelAmount", nil, true];
+        [_pfID] call CBA_fnc_removePerFrameHandler;
+    } else 
+    {
+        if (_target_new_fuel >= _last_update) then
+        {
+            _last_update = round(_target_new_fuel * 10) / 10;
+            hint format ["Refueling at %1 percent", str (_last_update*100)];
+            _source setVariable["RD501_mc_nextRefuelUpdate", _last_update+0.1, true];
+        };
+    };
+
+    ["RD501_mc_set_fuel", _target_new_fuel, _target] call CBA_fnc_targetEvent;
+    _source setVariable["RD501_mc_lastTargetFuelAmount", _target_new_fuel, true];
+
+    _source setFuel _source_new_fuel;
+    _source setVariable["RD501_mc_lastRefuelTick", _currentTime, true];
+
+}, 1, [_attached, _vehicle, _rate, _maxFuelSource, _maxFuelTarget]] call CBA_fnc_addPerFrameHandler;

+ 16 - 3
addons - Copy/RD501_Main/functions/magclamp/magclamp.sqf

@@ -20,13 +20,15 @@ macro_grp_fnc_name(magclamp,handle_universal) = {
 	    private _is_attached = _target getVariable["RD501_mc_is_attached",false];
 	    private _cant_be_clamped = (configFile >> "CfgVehicles" >> (typeOf _target) >> _forbid_param) call BIS_fnc_getCfgDataBool;
 
-	    while {_target isKindOf "Man" || isPlayer _target || _is_attached || _cant_be_clamped} do {
+	    while {_target == _vehicle || _target isKindOf "Man" || _is_attached || _cant_be_clamped} do {
 	        _target_index = _target_index + 1;
 	        _target = _objects select _target_index;
 	        _is_attached = _target getVariable["RD501_mc_is_attached",false];
 	        _cant_be_clamped = (configFile >> "CfgVehicles" >> (typeOf _target) >> _forbid_param) call BIS_fnc_getCfgDataBool;
         };
 
+        if (isNull _target) exitWith {};
+
 	    private _offset = (configFile >> "CfgVehicles" >> (typeOf _target) >> _offset_param) call BIS_fnc_getCfgDataArray;
 	    if (count _offset == 3) then {
 	        _position = [(_position select 0) + (_offset select 0), (_position select 1) + (_offset select 1), (_position select 2) + (_offset select 2)];
@@ -38,6 +40,10 @@ macro_grp_fnc_name(magclamp,handle_universal) = {
 	} else {
 	    detach _attached;
 	    _vehicle setVariable[_attached_var,objNull,true];
+        if (_mc_pos == "RD501_magclamp_large") then
+        {
+            _vehicle setVariable["RD501_mc_stop_refuel",true,true];
+        };
 	    _attached setVariable["RD501_mc_is_attached",false,true];
 	};
 };
@@ -76,6 +82,7 @@ macro_grp_fnc_name(magclamp,handle_drop_all) = {
     _attached = _vehicle getVariable["RD501_mc_attached_large",objNull];
     if(isNull _attached) then {} else {
 	    detach _attached;
+        _vehicle setVariable["RD501_mc_stop_refuel",true,true];
 	    _vehicle setVariable["RD501_mc_attached_large",objNull,true];
 	    _attached setVariable["RD501_mc_is_attached",false,true];
     };
@@ -87,8 +94,7 @@ macro_grp_fnc_name(magclamp,handle_drop_all) = {
     };
 };
 
-
-//add keybinds
+// add keybinds
 ["RD501 Magclamp","small_1",["First Small Clamp (Laat/I, Laat/C Left)","Activate/Deactivate left Magclamp on Laat/C or main Magclamp on Laat/I"],{
     [player] call macro_grp_fnc_name(magclamp,handle_small_1_pressed);
 },"",[DIK_7,[false,false,false]],false] call cba_fnc_addKeybind;
@@ -101,3 +107,10 @@ macro_grp_fnc_name(magclamp,handle_drop_all) = {
 ["RD501 Magclamp","detach_all",["Detach All","Detach all clamped vehicles"],{
     [player] call macro_grp_fnc_name(magclamp,handle_drop_all);
 },"",[DIK_0,[false,false,false]],false] call cba_fnc_addKeybind;
+
+// refuel target function
+["RD501_mc_set_fuel", {
+    _vehicle = (vehicle this);
+    if (isNull _vehicle) exitWith {};
+    _vehicle setFuel _this;
+}, []] call CBA_fnc_addEventHandlerArgs;

+ 9 - 6
addons - Copy/RD501_Vehicles/air/LAAT/common_stuff_swop.hpp

@@ -1,13 +1,16 @@
 class EventHandlers : DefaultEventhandlers 
-	{
-		fired = "_this call (uinamespace getvariable 'BIS_fnc_effectFired');";
-		init = "[_this select 0] execVM 'RD501_Main\functions\autocrate\autocrate.sqf';";
-	};
-	
+{
+	fired = "_this call (uinamespace getvariable 'BIS_fnc_effectFired');";
+	init = "[_this select 0] execVM 'RD501_Main\functions\autocrate\autocrate.sqf';";
+};
+
+RD501_magclamp_small_forbidden=1;
+RD501_magclamp_large_offset[]={0.0,2.0,-3.7};
+
 	faction = macro_republic_faction
 	editorSubcategory = macro_editor_cat_air(Republic_heli)
 	vehicleClass = macro_editor_vehicle_type_air(Republic)
-	
+
 	maximumLoad = 5000000000;
 	slingLoadMaxCargoMass = 5000000000;
 

+ 4 - 1
addons - Copy/RD501_Vehicles/air/LAAT/common_stuff_tcw.hpp

@@ -5,13 +5,16 @@ class EventHandlers : DefaultEventhandlers
 };
 
 scope=2;
-author="RD501"
+author="RD501";
 forceInGarage = 1;
 
 faction = macro_republic_faction
 editorSubcategory = macro_editor_cat_air(Republic_heli)
 vehicleClass = macro_editor_vehicle_type_air(Republic)
 
+RD501_magclamp_small_forbidden=1;
+RD501_magclamp_large_offset[]={0.0,1.6,-7.3};
+
 weapons[] = {
 	macro_basic_air_weapons,
 	macro_new_weapon(generic,green_dual_aircraft_laser),

+ 26 - 0
addons - Copy/RD501_Vehicles/air/LAAT/config.cpp

@@ -467,6 +467,8 @@ class CfgVehicles
 		RD501_magclamp_small_1[] = {-7.0,-2.0,-2.5};
 		RD501_magclamp_large[] = {0.0,-2.0,-2.0};
 		RD501_magclamp_small_2[] = {7.0,-2.0,-2.5};
+		RD501_magclamp_small_forbidden=1;
+		RD501_magclamp_large_offset[]={0.0,1.0,-4.5};
 
 		class ACE_SelfActions
 		{		
@@ -481,6 +483,30 @@ class CfgVehicles
 		class UserActions
 		{
 			#include "user_action.hpp"
+			class StartRefuel
+			{
+				displayName = "<t color='#07CC0C'>[Start Refueling]</t>";
+				displayNameDefault = "<t color='#07CC0C'>[Start Refueling]</t>";
+				textToolTip = "<t color='#07CC0C'>[Start Refueling]</t>";
+				position = "pilotview";
+				radius = 20;
+				priority = 21;
+				onlyForPlayer = 1;
+				condition = "this call RD501_fnc_mc_canRefuel";
+				statement = "this call RD501_fnc_mc_startRefuel;";
+			};
+			class StopRefuel
+			{
+				displayName = "<t color='#BC0404'>[Stop Refueling]</t>";
+				displayNameDefault = "<t color='#BC0404'>[Stop Refueling]</t>";
+				textToolTip = "<t color='#BC0404'>[Stop Refueling]</t>";
+				position = "pilotview";
+				radius = 20;
+				priority = 21;
+				onlyForPlayer = 1;
+				condition = "this call RD501_fnc_mc_canStopRefuel";
+				statement = "_vehicle setVariable['RD501_mc_stop_refuel',true,true];";
+			};
 		};
 		class EventHandlers : DefaultEventhandlers {
 			fired = "_this call (uinamespace getvariable 'BIS_fnc_effectFired');";

+ 9 - 3
addons - Copy/RD501_Weapons/_mag/config.cpp

@@ -27,7 +27,10 @@ class CfgMagazines
 	class SWOP_termDet_Gm;
 	class SWOP_BCCKtermimploder_G;
 	class RPG32_F;
-	///Rifle/Pistol Magazines
+
+	////////////////////////////////////////////////////
+	/////////////Rifle/Pistol Magazines/////////////////
+	////////////////////////////////////////////////////
 	class macro_new_mag(2mw,30) : 3AS_45Rnd_EC50_Mag
 	{
 		displayName="30 Round 2MW Cell";
@@ -192,6 +195,7 @@ class CfgMagazines
 		count=5;
 		picture="\MRC\JLTS\weapons\Core\data\ui\stun_mag_ui_ca";
 	};
+
 	////////////////////////////////////////////////////
 	/////////Grenade Launcher Magazines/////////////////
 	////////////////////////////////////////////////////
@@ -309,7 +313,8 @@ class CfgMagazines
 		ammo = "F_40mm_White";
 		descriptionShort = "6Rd White Flare RGL6 Grenade";
 	};
-	/////////////////////////////////////////////////////
+
+	////////////////////////////////////////////////////
 	/////////////Grenades Magazines/////////////////////
 	////////////////////////////////////////////////////
 	class macro_new_mag(imploder,1):SWOP_BCCKtermimploder_G
@@ -330,7 +335,8 @@ class CfgMagazines
 		ammo = macro_new_ammo(thermaldet)
 		descriptionShort = "Republic Thermal Detonator";
 	};
-	/////////////////////////////////////////////////////
+
+	////////////////////////////////////////////////////
 	/////////////Missile  Magazines/////////////////////
 	////////////////////////////////////////////////////
 	class macro_new_mag(rps1,1):RPG32_F