Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: Slot persistence #1352

Merged
merged 17 commits into from
Apr 18, 2022
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 =BTC=co@30_Hearts_and_Minds.Altis/core/def/mission.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ if (isServer) then {
//Respawn
btc_respawn_tickets = createHashMap;

btc_slots_serialized = createHashMap;

//Delay
btc_delay_agent = 0.1;
btc_delay_unit = 0.2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ btc_tags_server = btc_tags_server - [objNull];
(_city getVariable ["btc_civ_flowers", []]) call CBA_fnc_deleteEntity;

if (btc_debug_log) then {
[format ["data units = %1", _data_units], __FILE__, [false]] call btc_debug_fnc_message;
[format ["data animals = %1", _data_animals], __FILE__, [false]] call btc_debug_fnc_message;
[format ["data tags = %1", _data_tags], __FILE__, [false]] call btc_debug_fnc_message;
[format ["count data_units = %1", count _data_units], __FILE__, [false]] call btc_debug_fnc_message;
[format ["count data_animals = %1", count _data_animals], __FILE__, [false]] call btc_debug_fnc_message;
[format ["count data_tags = %1", count _data_tags], __FILE__, [false]] call btc_debug_fnc_message;
};

_city setVariable ["has_suicider", _has_suicider];
Expand Down
8 changes: 8 additions & 0 deletions =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/compile.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ if (isServer) then {

//EH
btc_eh_fnc_server = compileScript ["core\fnc\eh\server.sqf"];
btc_eh_fnc_playerConnected = compileScript ["core\fnc\eh\playerConnected.sqf"];

//IED
btc_ied_fnc_boom = compileScript ["core\fnc\ied\boom.sqf"];
Expand Down Expand Up @@ -149,6 +150,10 @@ if (isServer) then {
btc_patrol_fnc_eh = compileScript ["core\fnc\patrol\eh.sqf"];
btc_patrol_fnc_addEH = compileScript ["core\fnc\patrol\addEH.sqf"];

//SLOT
btc_slot_fnc_serializeState = compileScript ["core\fnc\slot\serializeState.sqf"];
btc_slot_fnc_deserializeState_s = compileScript ["core\fnc\slot\deserializeState_s.sqf"];

//REP
btc_rep_fnc_call_militia = compileScript ["core\fnc\rep\call_militia.sqf"];
btc_rep_fnc_change = compileScript ["core\fnc\rep\change.sqf"];
Expand Down Expand Up @@ -415,6 +420,9 @@ if (!isDedicated) then {
btc_tow_fnc_hitch_points = compileScript ["core\fnc\tow\hitch_points.sqf"];
btc_tow_fnc_unhook = compileScript ["core\fnc\tow\unhook.sqf"];
btc_tow_fnc_check = compileScript ["core\fnc\tow\check.sqf"];

//SLOT
btc_slot_fnc_deserializeState = compileScript ["core\fnc\slot\deserializeState.sqf"];
};

/////////////////////HEADLESS\\\\\\\\\\\\\\\\\\\\\
Expand Down
1 change: 1 addition & 0 deletions =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/db/delete.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ profileNamespace setVariable [format ["btc_hm_%1_objs", _name], nil];
profileNamespace setVariable [format ["btc_hm_%1_tags", _name], nil];
profileNamespace setVariable [format ["btc_hm_%1_respawnTickets", _name], nil];
profileNamespace setVariable [format ["btc_hm_%1_deadBodyPlayers", _name], nil];
profileNamespace setVariable [format ["btc_hm_%1_slotsSerialized", _name], nil];
profileNamespace setVariable [format ["btc_hm_%1_markers", _name], nil];
profileNamespace setVariable [format ["btc_hm_%1_db", _name], nil];

Expand Down
28 changes: 26 additions & 2 deletions =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/db/load.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,16 @@ private _cities_status = +(profileNamespace getVariable [format ["btc_hm_%1_citi
};
};
if (btc_debug_log) then {
[format ["ID: %1 - IsOccupied %2", _id, _occupied], __FILE__, [false]] call btc_debug_fnc_message;
[format ["data_city: %1", _x], __FILE__, [false]] call btc_debug_fnc_message;
[format [
"ID: %1 - _initialized %2 _spawn_more %3 _occupied %4 count _data_units %5 _has_ho %6",
_id, _initialized, _spawn_more,
_occupied, count _data_units, _has_ho
], __FILE__, [false]] call btc_debug_fnc_message;
[format [
"ID: %1 - _ho_units_spawned %2 count _ieds %3 _has_suicider %4 count _data_animals %5 count _data_tags %6 count _civKilled %7",
_id, _ho_units_spawned, count _ieds, _has_suicider,
count _data_animals, count _data_tags, count _civKilled
], __FILE__, [false]] call btc_debug_fnc_message;
};
} forEach _cities_status;

Expand Down Expand Up @@ -250,6 +258,21 @@ if (btc_p_respawn_ticketsAtStart >= 0) then {
deleteGroup _group;
};

//Player slots
private _slots_serialized = +(profileNamespace getVariable [format ["btc_hm_%1_slotsSerialized", _name], createHashMap]);
[{
{
private _objtClass = _y select 6;
if (_objtClass isEqualTo "") then {
_objtClass = objNull;
} else {
_objtClass = nearestObject [ASLToATL (_y select 0), _objtClass];
};
_y set [6, _objtClass];
} forEach _this;
}, _slots_serialized] call CBA_fnc_execNextFrame; // Need to wait for vehicle creation
btc_slots_serialized = _slots_serialized;

//Player Markers
private _markers_properties = +(profileNamespace getVariable [format ["btc_hm_%1_markers", _name], []]);
{
Expand All @@ -266,6 +289,7 @@ private _markers_properties = +(profileNamespace getVariable [format ["btc_hm_%1
_marker setMarkerAlpha _markerAlpha;
_marker setMarkerBrush _markerBrush;
_marker setMarkerDir _markerDir;

_marker setMarkerShape _markerShape;
if (_markerPolyline isNotEqualTo []) then {
_marker setMarkerPolyline _markerPolyline;
Expand Down
11 changes: 11 additions & 0 deletions =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/db/save.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,17 @@ if (btc_p_respawn_ticketsAtStart >= 0) then {
profileNamespace setVariable [format ["btc_hm_%1_deadBodyPlayers", _name], +_deadBodyPlayers];
};

//Player slots
{_x call btc_slot_fnc_serializeState} forEach (allPlayers - entities "HeadlessClient_F");
private _slots_serialized = +btc_slots_serialized;
{
if (btc_debug_log) then {
[format ["btc_slots_serialized %1", _y], __FILE__, [false]] call btc_debug_fnc_message;
};
_y set [6, typeOf (_y select 6)];
} forEach _slots_serialized;
profileNamespace setVariable [format ["btc_hm_%1_slotsSerialized", _name], +_slots_serialized];

//Player Markers
private _player_markers = allMapMarkers select {"_USER_DEFINED" in _x};
private _markers_properties = _player_markers apply {
Expand Down
2 changes: 2 additions & 0 deletions =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/eh/player.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ _player addEventHandler ["WeaponAssembled", btc_civ_fnc_add_leaflets];
[_player, "WeaponAssembled", {[_thisType, _this] call btc_fob_fnc_rallypointAssemble;}] call CBA_fnc_addBISEventHandler;
[_player, "WeaponDisassembled", {[_thisType, _this] call btc_fob_fnc_rallypointAssemble;}] call CBA_fnc_addBISEventHandler;
_player addEventHandler ["GetInMan", btc_ied_fnc_deleteLoop];
_player addEventHandler ["GetInMan", {_this remoteExecCall ["btc_slot_fnc_serializeState", 2]}];
_player addEventHandler ["GetOutMan", {
if (btc_ied_deleteOn > -1) then {
[btc_ied_deleteOn] call CBA_fnc_removePerFrameHandler;
btc_ied_deleteOn = -1;
};
_this remoteExecCall ["btc_slot_fnc_serializeState", 2];
}];
_player addEventHandler ["WeaponAssembled", {
params ["_player", "_static"];
Expand Down
30 changes: 30 additions & 0 deletions =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/eh/playerConnected.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

/* ----------------------------------------------------------------------------
Function: btc_eh_fnc_playerConnected

Description:
Fire the event playerConnected.

Parameters:

Returns:

Examples:
(begin example)
[] call btc_eh_fnc_playerConnected;
(end)

Author:
Vdauphin

---------------------------------------------------------------------------- */

params ["_id", "_uid", "_name", "_jip", "_owner", "_idstr"];

if (_name isEqualTo "__SERVER__") exitWith {};

[{
!isNull ((_this select 1) call BIS_fnc_getUnitByUID)
}, {
["btc_playerConnected", [(_this select 1) call BIS_fnc_getUnitByUID, _this]] call CBA_fnc_localEvent;
}, _this, 4 * 60] call CBA_fnc_waitUntilAndExecute;
24 changes: 20 additions & 4 deletions =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/eh/server.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ addMissionEventHandler ["BuildingChanged", btc_rep_fnc_buildingchanged];
["btc_respawn_player", {
params ["", "_player"];
[btc_rep_malus_player_respawn, _player] call btc_rep_fnc_change;
btc_slots_serialized set [
_player getVariable ["btc_slot_name", [0, 0, 0]],
[] // Reset serialized data if slot died
];
}] call CBA_fnc_addEventHandler;

["ace_explosives_detonate", {
Expand All @@ -57,12 +61,24 @@ addMissionEventHandler ["BuildingChanged", btc_rep_fnc_buildingchanged];
] call CBA_fnc_waitAndExecute;
}] call CBA_fnc_addEventHandler;

addMissionEventHandler ["PlayerConnected", btc_eh_fnc_playerConnected];
addMissionEventHandler ["HandleDisconnect", {
params ["_headless"];
if (_headless in (entities "HeadlessClient_F")) then {
deleteVehicle _headless;
params ["_player"];
if (_player in (entities "HeadlessClient_F")) then {
deleteVehicle _player;
};
if (alive _player) then {
_player call btc_slot_fnc_serializeState;
};
false
}];
["ace_unconscious", btc_slot_fnc_serializeState] call CBA_fnc_addEventHandler;
["btc_playerConnected", {
params ["_player"];
private _slotName = position _player;
_player setVariable ["btc_slot_name", _slotName];
[_player, _slotName] call btc_slot_fnc_deserializeState_s;
}] call CBA_fnc_addEventHandler;
if (btc_p_auto_db) then {
addMissionEventHandler ["HandleDisconnect", {
if ((allPlayers - entities "HeadlessClient_F") isEqualTo []) then {
Expand Down Expand Up @@ -108,7 +124,7 @@ if (btc_p_respawn_ticketsAtStart >= 0) then {
["ace_placedInBodyBag", btc_body_fnc_setBodyBag] call CBA_fnc_addEventHandler;

if !(btc_p_respawn_ticketsShare) then {
addMissionEventHandler ["PlayerConnected", btc_respawn_fnc_playerConnected];
["btc_playerConnected", btc_respawn_fnc_playerConnected] call CBA_fnc_addEventHandler;
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,11 @@ Author:

---------------------------------------------------------------------------- */

params ["_id", "_uid", "_name", "_jip", "_owner", "_idstr"];

if (_name isEqualTo "__SERVER__") exitWith {};

[{
!isNull (_this call BIS_fnc_getUnitByUID)
}, {
private _tickets = btc_respawn_tickets getOrDefault [_this, btc_p_respawn_ticketsAtStart];
if (_tickets isEqualTo 0) then {
_tickets = -1;
};
[
_this call BIS_fnc_getUnitByUID,
_tickets
] call BIS_fnc_respawnTickets;
}, _uid, 4 * 60] call CBA_fnc_waitUntilAndExecute;
params ["_player", "_info"];
_info params ["_id", "_uid", "_name", "_jip", "_owner", "_idstr"];

private _tickets = btc_respawn_tickets getOrDefault [_uid, btc_p_respawn_ticketsAtStart];
if (_tickets isEqualTo 0) then {
_tickets = -1;
};
[_player, _tickets] call BIS_fnc_respawnTickets;
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

/* ----------------------------------------------------------------------------
Function: btc_slot_fnc_deserializeState

Description:
Deserialize player slot.

Parameters:
_previousPos - Position of the player. [Array]
_dir - Direction of the player. [Number]
_loadout - Loadout of the player. [Array]
_flagTexture - Flag raised. [String]
_isContaminated - Chemically contaminated. [Boolean]
_medicalDeserializeState - Medical ACE state. [String]
_vehicle - Vehicle occupied by player. [Object]
_field_rations - Thirst and hunger player's. [Array]

Returns:

Examples:
(begin example)
(btc_slots_serialized getOrDefault [(keys btc_slots_serialized)#0, []]) remoteExecCall ["btc_slot_fnc_deserializeState", allPlayers#0];
(end)

Author:
Vdauphin

---------------------------------------------------------------------------- */

[{!isNull player}, {
params [
"_previousPos",
"_dir",
"_loadout",
"_flagTexture",
"_isContaminated",
"_medicalDeserializeState",
["_vehicle", objNull, [objNull]],
["_field_rations", [], [[]]]
];

if (
player distance ASLToAGL _previousPos > 50 || // Don't set loadout when near main base
btc_p_autoloadout isEqualTo 0
) then {
[{player setUnitLoadout _this;}, _loadout] call CBA_fnc_execNextFrame;
};
if ((isNull _vehicle) || {!(player moveInAny _vehicle)}) then {
player setPosASL _previousPos;
};
player setDir _dir;
player forceFlagTexture _flagTexture;
[player, _medicalDeserializeState] call ace_medical_fnc_deserializeState;

if (_isContaminated) then {
player call btc_chem_fnc_damageLoop;
};

_field_rations params [["_thirst", 0, [0]], ["_hunger", 0, [0]]];
player setVariable ["acex_field_rations_thirst", _thirst];
player setVariable ["acex_field_rations_hunger", _hunger];

}, _this] call CBA_fnc_waitUntilAndExecute;
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

/* ----------------------------------------------------------------------------
Function: btc_slot_fnc_deserializeState_s

Description:
Deserialize player slot.

Parameters:
_player - Player. [Object]
_slotName - Slot name use by the player. [String, Array]

Returns:

Examples:
(begin example)
[allPlayers#0, (keys btc_slots_serialized)#0] call btc_slot_fnc_deserializeState_s;
(end)

Author:
Vdauphin

---------------------------------------------------------------------------- */

params [
["_player", objNull, [objNull]],
["_slotName", "", ["", []]]
];

private _data = btc_slots_serialized getOrDefault [_slotName, []];
if (_data isEqualTo []) exitWith {};
if (_data select 4) then {
if ((btc_chem_contaminated pushBackUnique _player) > -1) then {
publicVariable "btc_chem_contaminated";
};
};
_data remoteExecCall ["btc_slot_fnc_deserializeState", _player];
Loading