Skip to content

Commit

Permalink
Merge pull request Apricot-ale#20 from moistbois/extravehiclesave
Browse files Browse the repository at this point in the history
Save fuel, cargo fuel and damage of the vehicles
  • Loading branch information
carlmylo authored Mar 24, 2024
2 parents ad55290 + 2b14df8 commit d90e347
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
12 changes: 9 additions & 3 deletions Missionframework/functions/fn_getSaveData.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private ["_fobPos", "_fobObjects", "_grpUnits", "_fobMines"];
} forEach KPLIB_sectors_fob;

// Save all fetched objects
private ["_savedPos", "_savedVecDir", "_savedVecUp", "_class", "_hasCrew", "_inventory"];
private ["_savedPos", "_savedVecDir", "_savedVecUp", "_class", "_hasCrew", "_inventory", "_fuel", "_fuelCargo", "_damages"];
{
// Position data
_savedPos = getPosWorld _x;
Expand All @@ -170,9 +170,15 @@ private ["_savedPos", "_savedVecDir", "_savedVecUp", "_class", "_hasCrew", "_inv

// Serialize inventory
_inventory = [_x] call fnc_serializeCargo;

_objectsToSave pushBack [_class, _savedPos, _savedVecDir, _savedVecUp, _hasCrew, _inventory];

_fuel = fuel _x;
_fuelCargo = _x call ace_refuel_fnc_getFuel;
_damages = getAllHitPointsDamage _x;

_objectsToSave pushBack [_class, _savedPos, _savedVecDir, _savedVecUp, _hasCrew, _inventory, _fuel, _fuelCargo, _damages];
};


} forEach _allObjects;

// Save all storages and resources
Expand Down
31 changes: 29 additions & 2 deletions Missionframework/scripts/server/game/save_manager.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ if (!isNil "_saveData") then {
private _object = objNull;
{
// Fetch data of saved object
_x params ["_class", "_pos", "_vecDir", "_vecUp", ["_hasCrew", false], ["_inventory", []]];
_x params ["_class", "_pos", "_vecDir", "_vecUp", ["_hasCrew", false], ["_inventory", []], "_fuel", "_fuelCargo", "_damages"];

// This will be removed if we reach a 0.96.7 due to more released Arma 3 DLCs until we finish 0.97.0
if !(((_saveData select 0) select 0) isEqualType 0) then {
Expand Down Expand Up @@ -437,6 +437,32 @@ if (!isNil "_saveData") then {
// Reposition spawned object
_object setPosWorld _pos;
_object setVectorDirAndUp [_vecDir, _vecUp];

// Persistent fuel
if (!isNil "_fuel") then { _object setFuel _fuel; };
if (!isNil "_fuelCargo") then { [_object, _fuelCargo] call ace_refuel_fnc_setFuel; };

// Persistent damage
if (!isNil "_damages") then
{
__cnt = count (_damages select 0);
if (__cnt > 0) then
{
_object allowdamage true; // dmg enabled otherwise seHitPointDamage won't do anything

for "__i" from 0 to __cnt - 1 do
{
__part = (_damages select 0) select __i;
__hp = (_damages select 2) select __i;

if (!isNil "__part" && !isNil "__hp") then
{
// [format ["Set HP %1 - %2", __part, __hp], "SAVE"] call KPLIB_fnc_log;
_object setHitPointDamage [__part, __hp];
};
};
};
};

// Process KP object init
[_object] call KPLIB_fnc_addObjectInit;
Expand Down Expand Up @@ -468,13 +494,14 @@ if (!isNil "_saveData") then {
if ((count _inventory) == 4) then {
[_object, _inventory] call fnc_loadCustomCargo;
};

};
} forEach _objectsToSave;

// Re-enable physics on the spawned objects
{
_x enableSimulation true;
_x setdamage 0;
// _x setdamage 0; // needs to be removed or it will overwrite damage loaded ffrom savefile
_x allowdamage true;
} forEach _spawnedObjects;
["Saved buildings and vehicles placed", "SAVE"] call KPLIB_fnc_log;
Expand Down

0 comments on commit d90e347

Please sign in to comment.