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

Deep Paste takes headless clients into account now #562

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions addons/common/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ PREP(getArtilleryETA);
PREP(getCargoPositionsCount);
PREP(getDefaultInventory);
PREP(getDLC);
PREP(getFewestGroupsHC);
PREP(getLightingSelections);
PREP(getPhoneticName);
PREP(getPlayers);
Expand Down
2 changes: 1 addition & 1 deletion addons/common/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@
_unit setNameSound _nameSound;
}] call CBA_fnc_addEventHandler;

[QGVAR(deserializeObjects), LINKFUNC(deserializeObjects)] call CBA_fnc_addEventHandler;
[QGVAR(earthquake), LINKFUNC(earthquake)] call CBA_fnc_addEventHandler;
[QGVAR(fireArtillery), LINKFUNC(fireArtillery)] call CBA_fnc_addEventHandler;
[QGVAR(setLampState), LINKFUNC(setLampState)] call CBA_fnc_addEventHandler;
Expand Down Expand Up @@ -390,5 +391,4 @@ if (isServer) then {
} call FUNC(runAfterSettingsInit);

[QGVAR(createZeus), LINKFUNC(createZeus)] call CBA_fnc_addEventHandler;
[QGVAR(deserializeObjects), LINKFUNC(deserializeObjects)] call CBA_fnc_addEventHandler;
};
9 changes: 8 additions & 1 deletion addons/common/functions/fnc_deserializeObjects.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* 1: Center Position <ARRAY>
* 2: Make Editable <BOOL> (default: true)
* 3: Randomization <BOOL> (default: false)
* 4: Use Headless Client <BOOL> (default: true)
ampersand38 marked this conversation as resolved.
Show resolved Hide resolved
*
* Return Value:
* Created Objects <ARRAY>
Expand All @@ -19,9 +20,15 @@
* Public: No
*/

params [["_serializedData", [], [[]]], ["_centerPos", [0, 0, 0], [[]], [2, 3]], ["_makeEditable", true, [true]], ["_enableRandomization", false, [true]]];
params [["_serializedData", [], [[]]], ["_centerPos", [0, 0, 0], [[]], [2, 3]], ["_makeEditable", true, [true]], ["_enableRandomization", false, [true]]]];
ampersand38 marked this conversation as resolved.
Show resolved Hide resolved
_serializedData params [["_objectData", [], [[]]], ["_groupData", [], [[]]]];

// Check for suitable Headless Client
private _hc = [] call FUNC(getFewestGroupsHC);
if (!isNull _hc) exitWith {
[QEGVAR(common,deserializeObjects), _this, _hc] call CBA_fnc_targetEvent;
};

// Set center position to ground level over land and water level over the ocean
// Serialized object data offsets are relative to AGL height 0
_centerPos set [2, 0];
Expand Down
51 changes: 51 additions & 0 deletions addons/common/functions/fnc_getFewestGroupsHC.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "script_component.hpp"
/*
* Author: Ampersand
* Returns HC with fewest groups, if available.
ampersand38 marked this conversation as resolved.
Show resolved Hide resolved
*
* Arguments:
* None
*
* Return Value:
* Headless Client <OBJECT>
*
* Example:
* [] call zen_common_fnc_getFewestGroupsHC
*
* Public: No
*/

if !(isServer) exitWith {objNull};
ampersand38 marked this conversation as resolved.
Show resolved Hide resolved

private _hcs = [];
private _hcIDs = [];
private _hcLoad = [];

{
if (_x isKindOf "HeadlessClient_F") then {
_hcs pushBack _x;
_hcIDs pushBack owner _x;
_hcLoad pushBack 0;
};
} forEach allPlayers;

switch (count _hcIDs) do {
case (0): {
ampersand38 marked this conversation as resolved.
Show resolved Hide resolved
objNull
};
case (1): {
_hcIDs select 0;
ampersand38 marked this conversation as resolved.
Show resolved Hide resolved
};
default {
// Count local groups for each HC
{
private _hcIndex = _hcIDs find groupOwner _x;
if (_hcIndex > -1) then {
ampersand38 marked this conversation as resolved.
Show resolved Hide resolved
private _groupCount = _hcLoad select _hcIndex;
_hcLoad set [_hcIndex, _groupCount + 1];
};
} forEach allGroups;

_hcs select (_hcLoad find selectMin _hcLoad)
};
};
2 changes: 1 addition & 1 deletion addons/editor/initKeybinds.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
[ELSTRING(main,DisplayName), QGVAR(deepPaste), [LSTRING(DeepPaste), LSTRING(DeepPaste_Description)], {
if (!isNull curatorCamera && {!GETMVAR(RscDisplayCurator_search,false)}) then {
private _position = [nil, false] call EFUNC(common,getPosFromScreen);
[QEGVAR(common,deserializeObjects), [GVAR(clipboard), _position, true, GVAR(randomizeCopyPaste)]] call CBA_fnc_serverEvent;
[QEGVAR(common,deserializeObjects), [GVAR(clipboard), _position, true, GVAR(randomizeCopyPaste), GVAR(deepPasteHC)]] call CBA_fnc_serverEvent;

playSound ["RscDisplayCurator_error01", true];

Expand Down
9 changes: 9 additions & 0 deletions addons/editor/initSettings.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@
false
] call CBA_fnc_addSetting;

[
QGVAR(deepPasteHC),
"CHECKBOX",
[LSTRING(DeepPasteHC), LSTRING(DeepPasteHC_Description)],
[ELSTRING(main,DisplayName), LSTRING(DisplayName)],
true,
false
] call CBA_fnc_addSetting;

[
QGVAR(unitRadioMessages),
"LIST",
Expand Down
6 changes: 6 additions & 0 deletions addons/editor/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@
<German>Fügt die derzeitig gespeicherte komplette Kopie ein.</German>
<Polish>Wkleja z schowka obiekty które zostały głęboko skopiowane.</Polish>
</Key>
<Key ID="STR_ZEN_Editor_DeepPasteHC">
<English>Deep Paste On Headless Client</English>
</Key>
<Key ID="STR_ZEN_Editor_DeepPasteHC_Description">
<English>Deep-copied entities will be sent to headless client(s) if available, avoiding subsequent transfer.</English>
</Key>
<Key ID="STR_ZEN_Editor_FocusSearchBar">
<English>Focus Search Bar</English>
<German>Suchfeld fokussieren</German>
Expand Down