Browse Source

start refuel implementation

thefloff 4 years ago
parent
commit
be279570e2

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

@@ -67,6 +67,8 @@ 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_stopRefuel.sqf,mc_stopRefuel)
 
 //HUD color
 macro_prep_xeh(hud_color_change.sqf,change_hud_color)

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

@@ -0,0 +1,55 @@
+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;
+};
+
+_vehicle setVariable["RD501_mc_lastRefuelTick",_firstTick,true];
+
+[{
+    params ["_args", "_pfID"];
+    _args params ["_target", "_source", "_rate", "_maxFuelSource", "_maxFuelTarget"];
+
+    private _currentTime = 0;
+    if (isMultiplayer) then
+    {
+        _currentTime = serverTime;
+    } else
+    {
+        _currentTime = time;
+    };
+    private _lastTick = _source getVariable["RD501_mc_lastRefuelTick",objNull];
+    private _deltaT = _currentTime - _lastTick;
+
+    private _target_fuel = (fuel _target) * _maxFuelTarget;
+    private _source_fuel = (fuel _source) * _maxFuelSource;
+
+    private _transfer = _rate * _deltaT;
+
+    /*
+     *  REMOTE EXECUTE THIS
+     */
+    _target setFuel ((_target_fuel + _transfer) / _maxFuelTarget);
+
+    _source setFuel ((_source_fuel - _transfer) / _maxFuelSource);
+    _source setVariable["RD501_mc_lastRefuelTick",_currentTime,true];
+
+    private _stop = _source getVariable["RD501_mc_stop_refuel",false];
+    if (_stop) then
+    {
+        [_pfID] call CBA_fnc_removePerFrameHandler;
+    };
+}, 1, [_attached, _vehicle, _rate, _maxFuelSource, _maxFuelTarget]] call CBA_fnc_addPerFrameHandler;

+ 4 - 0
addons - Copy/RD501_Main/functions/magclamp/fnc_stopRefuel.sqf

@@ -0,0 +1,4 @@
+params["_vehicle"];
+
+systemChat "stopping refuel";
+_vehicle setVariable["RD501_mc_stop_refuel",true,true];

+ 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,0.0,-5.0};
+
 	faction = macro_republic_faction
 	editorSubcategory = macro_editor_cat_air(Republic_heli)
 	vehicleClass = macro_editor_vehicle_type_air(Republic)
-	
+
 	maximumLoad = 5000000000;
 	slingLoadMaxCargoMass = 5000000000;
 

+ 3 - 0
addons - Copy/RD501_Vehicles/air/LAAT/common_stuff_tcw.hpp

@@ -12,6 +12,9 @@ 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,0.0,-5.0};
+
 weapons[] = {
 	macro_basic_air_weapons,
 	macro_new_weapon(generic,green_dual_aircraft_laser),

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

@@ -481,6 +481,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 = "((player == driver this) AND (alive this))";
+				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 = "((player == driver this) AND (alive this))";
+				statement = "this call RD501_fnc_mc_stopRefuel;";
+			};
 		};
 		class EventHandlers : DefaultEventhandlers {
 			fired = "_this call (uinamespace getvariable 'BIS_fnc_effectFired');";