Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions addons/fuel/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
PREP(applyFuelStates);
PREP(grabFuelStates);
PREP(initFuelPumps);
PREP(initRefuelRestrictions);
PREP(processFuelCan);
Expand Down
38 changes: 38 additions & 0 deletions addons/fuel/functions/fnc_applyFuelStates.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "..\script_component.hpp"
/*
* Author: TenuredCLOUD
* Applies saved ACE fuel station states from stored hashmap
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* [] call misery_fuel_fnc_applyFuelStates;
*/

if (!isServer) exitWith {};

private _masterFuelMap = missionNamespace getVariable [QGVAR(pumpStates), createHashMap];

if (count _masterFuelMap isEqualTo 0) exitWith {};

private _activePumps = missionNamespace getVariable [QGVAR(activeFuelPumps), []];

if (count _activePumps isEqualTo 0) exitWith {};

{
private _pump = _x;
private _pumpPos = getPosASL _pump;

{
_y params ["_className", "_savedFuel", "_savedPosASL"];

if ((typeOf _pump isEqualTo _className) && (_pumpPos distance _savedPosASL < 2)) exitWith {

_pump setVariable [QGVAR(litreCargo), _savedFuel, true];
};
} forEach _masterFuelMap;
} forEach _activePumps;
46 changes: 46 additions & 0 deletions addons/fuel/functions/fnc_grabFuelStates.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "..\script_component.hpp"
/*
* Author: TenuredCLOUD
* Server side fuel station state grabber for ACE Refuel persistence
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* [] call misery_fuel_fnc_grabFuelStates;
*/

if (!isServer) exitWith {};

private _activePumps = missionNamespace getVariable [QGVAR(activeFuelPumps), []];

private _masterFuelMap = createHashMap;

{
private _pump = _x;


if (!isNull _pump && {alive _pump}) then {

private _currentFuel = _pump getVariable [QGVAR(litreCargo), -1];
private _aceFuel = _pump getVariable [QACEGVAR(refuel,currentFuelCargo), -1];

if (_aceFuel isNotEqualTo -1 && ([_pump] call AE3FUNC(power,getPowerState) isNotEqualTo "Off")) then {
_currentFuel = _aceFuel;
};

if (_currentFuel isEqualTo -1) then {
private _capacity = [MACRO_FUELSTATION_CAPACITIES];
private _index = _capacity findIf { (_x select 0) isEqualTo typeOf _pump };
_currentFuel = [1000, (_capacity select _index) select 1] select (_index isNotEqualTo -1);
};

private _key = _pump call BIS_fnc_objectVar;
_masterFuelMap set [_key, [typeOf _pump, _currentFuel, getPosASL _pump, [vectorDir _pump, vectorUp _pump]]];
};
} forEach _activePumps;

missionNamespace setVariable [QGVAR(pumpStates), _masterFuelMap, true];
2 changes: 2 additions & 0 deletions addons/fuel/functions/fnc_processTerrainPumps.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ if (isClass (missionConfigFile >> "CfgGradPersistence")) then {
[_x] call GRADFUNC(persistence,blacklistObjects);
} forEach _replacementPumps;
};

missionNamespace setVariable [QGVAR(activeFuelPumps), _replacementPumps, true];
6 changes: 6 additions & 0 deletions addons/fuel/functions/fnc_turnOffPump.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@

params ["_source"];

if (EGVAR(persistence,saveACEFuelStations)) then {
private _remainingFuel = _source getVariable [QACEGVAR(refuel,currentFuelCargo), 0];

_source setVariable [QGVAR(litreCargo), _remainingFuel, true];
};

[_source, 0] call ACEFUNC(refuel,makeSource);

true
18 changes: 17 additions & 1 deletion addons/fuel/functions/fnc_turnOnPump.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,23 @@ params ["_source"];
[{
params ["_source"];

[_source, -10] call ACEFUNC(refuel,makeSource);
if (EGVAR(persistence,saveACEFuelStations)) then {

private _currentFuel = _source getVariable [QGVAR(litreCargo), -1];

if (_currentFuel isEqualTo -1) then {
private _capacity = [MACRO_FUELSTATION_CAPACITIES];
private _index = _capacity findIf { (_x select 0) isEqualTo typeOf _source };

_currentFuel = [1000, (_capacity select _index) select 1] select (_index isNotEqualTo -1);

_source setVariable [QGVAR(litreCargo), _currentFuel, true];
};

[_source, _currentFuel] call ACEFUNC(refuel,makeSource);
} else {
[_source, -10] call ACEFUNC(refuel,makeSource);
};
}, [_source], 1] call CBA_fnc_waitAndExecute;

true
15 changes: 15 additions & 0 deletions addons/main/script_macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,21 @@
// Crafting stations / Fuel stations
#define MACRO_FUELSTATIONS_LAND "Land_fs_feed_F", "Land_FuelStation_Feed_F", "Land_FuelStation_03_pump_F", "Land_Ind_TankSmall2", "Land_Ind_TankSmall2_EP1", "Land_A_FuelStation_Feed", "Land_fuelstation", "Land_Ind_FuelStation_Feed_EP1"
#define MACRO_FUELSTATIONS_AIR "B_Slingload_01_Fuel_F", "StorageBladder_01_fuel_forest_F", "StorageBladder_01_fuel_sand_F", "Land_Pod_Heli_Transport_04_fuel_F"

#define MACRO_FUELSTATION_CAPACITIES \
["Land_fs_feed_F", 10000], \
["Land_FuelStation_Feed_F", 10000], \
["Land_FuelStation_03_pump_F", 10000], \
["Land_Ind_TankSmall2", 15000], \
["Land_Ind_TankSmall2_EP1", 15000], \
["Land_A_FuelStation_Feed", 10000], \
["Land_fuelstation", 10000], \
["Land_Ind_FuelStation_Feed_EP1", 10000], \
["B_Slingload_01_Fuel_F", 4000], \
["StorageBladder_01_fuel_forest_F", 2500], \
["StorageBladder_01_fuel_sand_F", 2500], \
["Land_Pod_Heli_Transport_04_fuel_F", 3000]

#define MACRO_CRAFTINGSTATIONS "Land_Workbench_01_F", "Land_PortableDesk_01_olive_F"

// Radios
Expand Down
3 changes: 3 additions & 0 deletions addons/persistence/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ PREP(clientDataGet);
PREP(clientDataSet);
PREP(formatSaveName);
PREP(gradSave);
PREP(handleGrad);
PREP(init);
PREP(loadData);
PREP(multiplayerDataLoad);
PREP(multiplayerDataSave);
PREP(newPlayer);
PREP(restoreCargo);
PREP(saveGame);
PREP(syncCargo);
37 changes: 37 additions & 0 deletions addons/persistence/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,43 @@ GVAR(saveName) = call FUNC(formatSaveName);
if (isServer) then {
[QGVAR(saveDataToServer), FUNC(multiplayerDataSave)] call CBA_fnc_addEventHandler;
[QGVAR(loadDataFromServer), FUNC(multiplayerDataLoad)] call CBA_fnc_addEventHandler;

[QGVAR(saveWorldState), {[GVAR(gradWarning), 0] call GRADFUNC(persistence,saveMission)}] call CBA_fnc_addEventHandler;
[QGVAR(wipeWorldState), {[GVAR(gradPersistenceTag)] call GRADFUNC(persistence,clearMissionData)}] call CBA_fnc_addEventHandler;

if (GVAR(saveAE3States)) then {
[QGVAR(grabAE3Devices), {call EFUNC(power,grabDeviceStates)}] call CBA_fnc_addEventHandler;

[{
call EFUNC(power,applyStates);
}, [], 0.2] call CBA_fnc_waitAndExecute;
};

if (GVAR(saveACECargo)) then {
[QCLASSACE(cargoLoaded), {
params ["_item", "_vehicle"];
_item setVariable [QGVAR(isCargo), true, true];
}] call CBA_fnc_addEventHandler;

[QCLASSACE(cargoUnloaded), {
params ["_item", "_vehicle"];
_item setVariable [QGVAR(isCargo), false, true];
}] call CBA_fnc_addEventHandler;

[QGVAR(grabCargo), {call FUNC(syncCargo)}] call CBA_fnc_addEventHandler;

[{
call FUNC(restoreCargo);
}, [], 0.2] call CBA_fnc_waitAndExecute;
};

if (GVAR(saveACEFuelStations)) then {
[QGVAR(grabFuelStationLitres), {call EFUNC(fuel,grabFuelStates)}] call CBA_fnc_addEventHandler;

[{
call EFUNC(fuel,applyFuelStates);
}, [], 0.2] call CBA_fnc_waitAndExecute;
};
};

[QGVAR(loadDataFromServerCallback), {
Expand Down
2 changes: 1 addition & 1 deletion addons/persistence/functions/fnc_gradSave.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
[] call FUNC(gradSave);
}, [], GVAR(gradAutosaveTimer)] call CBA_fnc_waitAndExecute;

[GVAR(gradWarning), 0] call GRADFUNC(persistence,saveMission);
[1] call FUNC(handleGrad);

41 changes: 41 additions & 0 deletions addons/persistence/functions/fnc_handleGrad.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "..\script_component.hpp"
/*
* Author: TenuredCLOUD
* Handles GRAD saving / wipes
* Processes other data handles prior to GRAD
*
* Arguments:
* 0: Type of process <NUMBER>
*
* Return Value:
* None
*
* Example:
* [] call misery_persistence_fnc_handleGrad
*/

params ["_type"];

if (_type isEqualTo 1) then {

if (GVAR(saveAE3States)) then {
[QGVAR(grabAE3Devices)] call CBA_fnc_serverEvent;
};

if (GVAR(saveACECargo)) then {
[QGVAR(grabCargo)] call CBA_fnc_serverEvent;
};

if (GVAR(saveACEFuelStations)) then {
[QGVAR(grabFuelStationLitres)] call CBA_fnc_serverEvent;
};

[{
// Slight delay to ensure other persistence frameworks are cached for GRAD write
[QGVAR(saveWorldState)] call CBA_fnc_serverEvent;
}, [], 0.02] call CBA_fnc_waitAndExecute;
} else {
[QGVAR(wipeWorldState)] call CBA_fnc_serverEvent;
};


3 changes: 3 additions & 0 deletions addons/persistence/functions/fnc_init.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ if (isMultiplayer) exitWith {
params ["", "_key"];
if (_key isEqualTo 1) then {
call FUNC(saveGame);
if (GVAR(gradESCSave)) then {
[1] call FUNC(handleGrad);
};
};
}];
}] call CBA_fnc_waitUntilAndExecute;
Expand Down
82 changes: 82 additions & 0 deletions addons/persistence/functions/fnc_restoreCargo.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include "..\script_component.hpp"
/*
* Author: TenuredCLOUD
* ACE Cargo API restore handle
* Also restores AE3 items states stored in Cargo
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* [] call misery_persistence_fnc_restoreCargo
*/

if (!isServer) exitWith {};

private _masterCargoMap = missionNamespace getVariable [QGVAR(cargoStates), createHashMap];

if (count _masterCargoMap isEqualTo 0) exitWith {};

{
_y params ["_vehicleClass", "_savedPosASL", "_savedCargoArray"];

private _nearVehicles = nearestObjects [ASLToAGL _savedPosASL, [_vehicleClass], 8];
if (_nearVehicles isEqualTo []) then { continue };

private _vehicle = _nearVehicles select 0;

if (!isNull _vehicle) then {
{
_x params ["_className", "_powerData"];
_powerData params ["_powerValue", "_powerType", "_damageValue"];

private _spawnPos = (getPosWorld _vehicle) vectorAdd [0, 0, -100];

private _cargoObject = createVehicle [_className, _spawnPos, [], 0, "CAN_COLLIDE"];

if (_damageValue > 0) then {
_cargoObject setDamage _damageValue;
};

switch (_powerType) do {
case 0: {
if (_powerValue isNotEqualTo -1) then {
[{private _dummy = _this select 0 getVariable [QAE3GVAR(power,internal), objNull]; (!isNull _dummy) && {alive _dummy}},
{
params ["_object", "_battery"];

private _dummy = _object getVariable [QAE3GVAR(power,internal), objNull];
if (!isNull _dummy) then {
_dummy setVariable [QAE3GVAR(power,batteryLevel), _battery, true];
};
}, [_cargoObject, _powerValue], 0.5] call CBA_fnc_waitUntilAndExecute;
};
};
case 1: {
[{
params ["_object", "_battery"];
_object setVariable [QAE3GVAR(power,batteryLevel), _battery, true];
}, [_cargoObject, _powerValue], 0.2] call CBA_fnc_waitAndExecute;
};
case 2: {
[{
params ["_object", "_fuelVal"];
_object setFuel _fuelVal;
}, [_cargoObject, _powerValue], 0.2] call CBA_fnc_waitAndExecute;
};
};

[{
params ["_object", "_vehicle"];

if (!isNull _object && !isNull _vehicle) then {
[_object, _vehicle, true] call ACEFUNC(cargo,loadItem);
};
}, [_cargoObject, _vehicle], 0.25] call CBA_fnc_waitAndExecute;

} forEach _savedCargoArray;
};
} forEach _masterCargoMap;
Loading
Loading