Advertisement
Guest User

saveData.sqf - DCG

a guest
Oct 7th, 2016
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 4.33 KB | None | 0 0
  1. /*
  2. Author:
  3. Nicholas Clark (SENSEI)
  4.  
  5. Description:
  6. save data to server profile
  7.  
  8. Arguments:
  9.  
  10. Return:
  11. none
  12. __________________________________________________________________*/
  13. #include "script_component.hpp"
  14. #define PUSHBACK_DATA(ADDONTOSAVE,DATATOSAVE) \
  15.     LOG_DEBUG_2("Saving data for %1 addon: %2.",QUOTE(DOUBLES(PREFIX,ADDONTOSAVE)),DATATOSAVE); \
  16.     GVAR(saveDataCurrent) pushBack [QUOTE(DOUBLES(PREFIX,ADDONTOSAVE)),DATATOSAVE]
  17.  
  18. if (!isServer) exitWith {};
  19.  
  20. private ["_dataProfile"];
  21.  
  22. _dataProfile = DATA_GETVAR; // main data variable
  23. GVAR(saveDataCurrent) = [DATA_MISSION_ID]; // overwrite current data
  24.  
  25. // don't need to check for main addon, it's always enabled
  26. private _data = [];
  27.  
  28. {
  29.     if (!(_x isKindOf "Man") && {!(_x isKindOf "Logic")}) then {
  30.         if (_x getVariable [DATA_OBJVAR,false]) then {
  31.             _data pushBack [typeOf _x,getPosASL _x,getDir _x,vectorUp _x];
  32.         };
  33.     };
  34. } foreach (allMissionObjects "All");
  35.  
  36. PUSHBACK_DATA(main,_data);
  37.  
  38. if (CHECK_ADDON_2(occupy)) then {
  39.     private ["_data","_locations","_infCount","_vehCount","_airCount","_players"];
  40.     _locations = []; // active locations
  41.  
  42.     for "_i" from 0 to count EGVAR(occupy,locations) - 1 do {
  43.         (EGVAR(occupy,locations) select _i) params ["_name","_position","_size","_type"];
  44.         _infCount = 0;
  45.         _vehCount = 0;
  46.         _airCount = 0;
  47.         {
  48.             if ((driver _x) getVariable [QUOTE(TRIPLES(PREFIX,occupy,unit)),false]) then {
  49.                 if (_x isKindOf "Man") exitWith {
  50.                     _infCount = _infCount + 1;
  51.                 };
  52.                 if (_x isKindOf "LandVehicle") exitWith {
  53.                     _vehCount = _vehCount + 1;
  54.                 };
  55.                 if (_x isKindOf "Air") exitWith {
  56.                     _airCount = _airCount + 1;
  57.                 };
  58.             };
  59.             false
  60.         } count (_position nearEntities [["Man","LandVehicle","Air","Ship"],_size*2]);
  61.  
  62.         _locations pushBack [_name,_position,_size,_type,[_infCount,_vehCount,_airCount]];
  63.     };
  64.  
  65.     _data = [_locations];
  66.  
  67.     PUSHBACK_DATA(occupy,_data);
  68. };
  69.  
  70. if (CHECK_ADDON_2(fob)) then {
  71.     private ["_data","_dataObj","_refund"];
  72.     _data = [];
  73.  
  74.     if !(EGVAR(fob,location) isEqualTo locationNull) then {
  75.         _data pushBack (locationPosition EGVAR(fob,location));
  76.         _data pushBack (curatorPoints EGVAR(fob,curator));
  77.         _dataObj = [];
  78.         _refund = 0;
  79.         {
  80.             if (!(_x isKindOf "Man") && {!(_x isKindOf "Logic")} && {count crew _x isEqualTo 0}) then {
  81.                 _dataObj pushBack [typeOf _x,getPosASL _x,getDir _x,vectorUp _x];
  82.             } else {
  83.                 call {
  84.                     if (_x isKindOf "Man") exitWith {
  85.                         _refund = _refund + abs(COST_MAN*EGVAR(fob,deletingMultiplier));
  86.                     };
  87.                     if (_x isKindOf "Car") exitWith {
  88.                         _refund = _refund + abs(COST_CAR*EGVAR(fob,deletingMultiplier));
  89.                     };
  90.                     if (_x isKindOf "Tank") exitWith {
  91.                         _refund = _refund + abs(COST_TANK*EGVAR(fob,deletingMultiplier));
  92.                     };
  93.                     if (_x isKindOf "Air") exitWith {
  94.                         _refund = _refund + abs(COST_AIR*EGVAR(fob,deletingMultiplier));
  95.                     };
  96.                     if (_x isKindOf "Ship") exitWith {
  97.                         _refund = _refund + abs(COST_SHIP*EGVAR(fob,deletingMultiplier));
  98.                     };
  99.                 };
  100.             };
  101.             false
  102.         } count (curatorEditableObjects EGVAR(fob,curator));
  103.  
  104.         _data pushBack _dataObj;
  105.         _refund = ((_data select 1) + _refund) min 1;
  106.         _data set [1,_refund];
  107.         //_data pushBack [EGVAR(fob,AVBonus)];
  108.     };
  109.  
  110.     PUSHBACK_DATA(fob,_data);
  111. };
  112.  
  113. if (CHECK_ADDON_2(weather)) then {
  114.     private ["_data"];
  115.     _data = [overcast,date];
  116.  
  117.     PUSHBACK_DATA(weather,_data);
  118. };
  119.  
  120. if (CHECK_ADDON_2(ied)) then {
  121.     private ["_data"];
  122.     _data = [];
  123.     {
  124.         private "_pos";
  125.         _pos = getPos _x;
  126.         _pos deleteAt 2;
  127.         _data pushBack _pos;
  128.         false
  129.     } count EGVAR(ied,list);
  130.  
  131.     PUSHBACK_DATA(ied,_data);
  132. };
  133.  
  134. if (CHECK_ADDON_2(task)) then {
  135.     private ["_data"];
  136.     _data = [EGVAR(task,primary),EGVAR(task,secondary)];
  137.  
  138.     PUSHBACK_DATA(task,_data);
  139. };
  140.  
  141. if (CHECK_ADDON_2(approval)) then {
  142.     private ["_data"];
  143.     _data = [];
  144.     {
  145.         _data pushBack [_x select 0,missionNamespace getVariable [AV_VAR(_x select 0),AV_MAX*0.1]];
  146.         false
  147.     } count GVAR(locations);
  148.  
  149.     PUSHBACK_DATA(approval,_data);
  150. };
  151.  
  152. // following code must run last
  153. if !(_dataProfile isEqualTo []) then {
  154.     {
  155.         if (toUpper (_x select 0) isEqualTo DATA_MISSION_ID) exitWith {
  156.             _dataProfile set [_forEachIndex,GVAR(saveDataCurrent)];
  157.         };
  158.         _dataProfile pushBack GVAR(saveDataCurrent);
  159.     } forEach _dataProfile;
  160. } else {
  161.     _dataProfile pushBack GVAR(saveDataCurrent);
  162. };
  163.  
  164. DATA_SETVAR(_dataProfile);
  165. saveProfileNamespace;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement