Skip to content

Commit

Permalink
Load fuel, cargo fuel and all hitpoints damages
Browse files Browse the repository at this point in the history
Vehicle fuel handled via BI functions, cargo fuel handled via ACE refuel
API. Vehicle damage saved as list of hit points damages and then set one
by one on load.

This will require thorough testing due to changes in the savefile
structure + enabling damage on some objects earlier during load
procedure.
  • Loading branch information
doxus committed Mar 24, 2024
1 parent b0a34b3 commit 2b14df8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Missionframework/functions/fn_getSaveData.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private ["_savedPos", "_savedVecDir", "_savedVecUp", "_class", "_hasCrew", "_inv
_inventory = [_x] call fnc_serializeCargo;

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

_objectsToSave pushBack [_class, _savedPos, _savedVecDir, _savedVecUp, _hasCrew, _inventory, _fuel, _fuelCargo, _damages];
Expand Down
29 changes: 26 additions & 3 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 @@ -439,7 +439,30 @@ if (!isNil "_saveData") then {
_object setVectorDirAndUp [_vecDir, _vecUp];

// Persistent fuel
_object setFuel _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 @@ -478,7 +501,7 @@ if (!isNil "_saveData") then {
// 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 2b14df8

Please sign in to comment.