From 6b24db54c253c77ff54bb6f39ca227ecd68b49fe Mon Sep 17 00:00:00 2001 From: Tapawingo Date: Thu, 23 May 2024 16:18:05 +0200 Subject: [PATCH] Fix Orbat names and ToE --- .../organization/functions/fn_ToE.sqf | 135 +++++++++--------- .../organization/functions/fn_roster.sqf | 102 ++----------- framework/rsc/organization/orbat.sqf | 16 +-- 3 files changed, 82 insertions(+), 171 deletions(-) diff --git a/framework/components/organization/functions/fn_ToE.sqf b/framework/components/organization/functions/fn_ToE.sqf index 8ca873b..6a93dea 100644 --- a/framework/components/organization/functions/fn_ToE.sqf +++ b/framework/components/organization/functions/fn_ToE.sqf @@ -21,62 +21,60 @@ addMissionEventHandler ["Map", { params ["_mapIsOpened"]; - if (!_mapIsOpened) then { - /* Remove outdated roster */ - { - player removeDiaryRecord ["cmf_toe", _x select 8] - } forEach (player allDiaryRecords "cmf_toe"); - } else { - /* Add Each of the highest level groups */ - private _groupHash = [GVAR(groups), side cmf_player, []] call CBA_fnc_hashGet; - private _levels = [_groupHash] call CBA_fnc_hashKeys; - if (count _levels isEqualTo 0) exitWith { cmf_player createDiaryRecord ["cmf_toe", ["No Registered Groups.", ""]] }; - - { - cmf_player removeDiaryRecord ["cmf_toe", _x select 8]; - } forEach (cmf_player allDiaryRecords "cmf_toe"); - - _levels sort false; - private _topLevelGroups = [_groupHash, _levels select 0, []] call CBA_fnc_hashGet; - reverse _topLevelGroups; - - FUNC(ToE_recursiveCheck) = { - params ["_group", ["_indent", ""], ["_vehicle", objNull]]; + if (!_mapIsOpened) exitWith { + { player removeDiaryRecord ["cmf_toe", _x select 8] } forEach (player allDiaryRecords "cmf_toe"); + }; - private _formattedString = ""; + /* Add Each of the highest level groups */ + private _groupHash = [GVAR(groups), side cmf_player, []] call CBA_fnc_hashGet; + private _levels = [_groupHash] call CBA_fnc_hashKeys; + if (count _levels isEqualTo 0) exitWith { cmf_player createDiaryRecord ["cmf_toe", ["No Registered Groups.", ""]] }; - private _formatGroupHeader = { format ["%1
", _this] }; + { + cmf_player removeDiaryRecord ["cmf_toe", _x select 8]; + } forEach (cmf_player allDiaryRecords "cmf_toe"); - private _groupNames = _group getVariable [QGVAR(groupName), ["UNKNOWN", "UNKNOWN"]]; - private _groupVehicle = _group getVariable [QGVAR(vehicle), objNull]; - private _groupData = [_group] call FUNC(groupGetData); - private _units = units _group; - _groupData params ["_level", "_type", "", "_children"]; + _levels sort false; + private _topLevelGroups = [_groupHash, _levels select 0, []] call CBA_fnc_hashGet; + reverse _topLevelGroups; + FUNC(ToE_recursiveCheck) = { + params ["_group", ["_indent", ""], ["_vehicle", objNull]]; - if (count _units isNotEqualTo 0) then { - if (count _children > 0 || _level isEqualTo 1) then { - _formattedString = _formattedString + "
" + _indent + ((_groupNames select 1) call _formatGroupHeader); - _indent = _indent + " "; - }; + private _formattedString = ""; - if (_type isEqualTo "INF") then { - _formattedString = _formattedString + _indent + ((_groupNames select 0) call _formatGroupHeader); - }; + private _formatGroupHeader = { format ["%1
", _this] }; - if (_groupVehicle isNotEqualTo _vehicle) then { - private _vehicleName = [configFile >> "CfgVehicles" >> typeof _groupVehicle] call BIS_fnc_displayName; - _formattedString = _formattedString + _indent + format [" %1
", _vehicleName]; - _vehicle = _groupVehicle; - }; + private _groupNames = _group getVariable [QGVAR(groupName), ["UNKNOWN", "UNKNOWN"]]; + private _groupVehicle = _group getVariable [QGVAR(vehicle), objNull]; + private _groupData = [_group] call FUNC(groupGetData); + private _units = units _group; + _groupData params ["_level", "_type", "", "_children"]; + if (_type isNotEqualTo "ZEUS") then { + if (count _children > 0 || _level isEqualTo 1) then { + _formattedString = _formattedString + "
" + _indent + ((_groupNames select 1) call _formatGroupHeader); + _indent = _indent + " "; + }; + + if (_type isEqualTo "INF") then { + _formattedString = _formattedString + _indent + ((_groupNames select 0) call _formatGroupHeader); + }; + + if (_groupVehicle isNotEqualTo _vehicle) then { + private _vehicleName = [configFile >> "CfgVehicles" >> typeof _groupVehicle] call BIS_fnc_displayName; + _formattedString = _formattedString + _indent + format [" %1
", _vehicleName]; + _vehicle = _groupVehicle; + }; + + if (count units _group isNotEqualTo 0) then { { if (isPlayer _x) then { private _roleDescription = "None"; if (roleDescription _x != "") then { _roleDescription = (roleDescription _x splitString "@") select 0; }; - + _formattedString = _formattedString + _indent + format [" %1, %2
", name _x, _roleDescription]; } else { private _role = [_x] call EFUNC(kosherAI,getRole); @@ -90,43 +88,46 @@ ["MG", "Machinegunner"], ["MAR", "Marksman"], ["SL", "Leader"] - ] getOrDefault [_role, "Rifleman"]; - + ] getOrDefault [_role, _role]; + _formattedString = _formattedString + _indent + format [" [AI] %1, %2
", name _x, _roleDescription]; }; } forEach units _group; + } else { + _formattedString = _formattedString + _indent + " Empty
"; }; + }; - /* Sort children */ - _children = [_children, [], { - private _group = _x; - private _groupData = [_group] call FUNC(groupGetData); - private _groupNames = _group getVariable [QGVAR(groupName), ["UNKNOWN", "UNKNOWN"]]; - _groupData params ["", "_type", "", "_children"]; + /* Sort children */ + _children = [_children, [], { + private _group = _x; + _groupData = [_group] call FUNC(groupGetData); + _groupNames = _group getVariable [QGVAR(groupName), ["UNKNOWN", "UNKNOWN"]]; + _groupData params ["", "_type", "", "_children"]; - private _childrenCount = count _children; - private _alphabetOrder = GVAR(phoneticAlphabet) findIf { (_x select [0, 1]) isEqualTo (_groupNames select [0, 1]) }; + private _childrenCount = count _children; + private _alphabetOrder = GVAR(phoneticAlphabet) findIf { (_x select [0, 1]) isEqualTo (_groupNames select [0, 1]) }; - ([_childrenCount + 1000, _alphabetOrder] select (_type isEqualTo "INF")) - }, "DESCEND"] call BIS_fnc_sortBy; + ([_childrenCount + 1000, _alphabetOrder] select (_type isEqualTo "INF")) + }, "ASCEND"] call BIS_fnc_sortBy; - { - _formattedString = _formattedString + ([_x, _indent, _vehicle] call FUNC(ToE_recursiveCheck)); - } forEach _children; + { + _formattedString = _formattedString + ([_x, _indent, _vehicle] call FUNC(ToE_recursiveCheck)); + } forEach _children; - _formattedString; - }; + _formattedString; + }; - { - private _group = _x; - private _groupNames = _group getVariable [QGVAR(groupName), ["UNKNOWN", "UNKNOWN"]]; - private _formattedString = "
"; + { + private _group = _x; - _formattedString = _formattedString + ([_group] call FUNC(ToE_recursiveCheck)); + private _groupNames = _group getVariable [QGVAR(groupName), ["UNKNOWN", "UNKNOWN"]]; + private _formattedString = "
"; - cmf_player createDiaryRecord ["cmf_toe", [(_groupNames select 1), _formattedString]]; - } forEach _topLevelGroups; - }; + _formattedString = _formattedString + ([_group] call FUNC(ToE_recursiveCheck)); + + cmf_player createDiaryRecord ["cmf_toe", [(_groupNames select 1), _formattedString]]; + } forEach _topLevelGroups; }]; }] call CBA_fnc_waitUntilAndExecute; \ No newline at end of file diff --git a/framework/components/organization/functions/fn_roster.sqf b/framework/components/organization/functions/fn_roster.sqf index 2b67862..9357cc2 100644 --- a/framework/components/organization/functions/fn_roster.sqf +++ b/framework/components/organization/functions/fn_roster.sqf @@ -15,108 +15,30 @@ * Public: No */ -// @TODO: also get unassigned players from outside the dynamic group system [{ !isNull player && { alive player } }, { player createDiarySubject ["cmf_roster", "Player Roster"]; addMissionEventHandler ["Map", { params ["_mapIsOpened"]; - if (!_mapIsOpened) then { - /* Remove outdated roster */ - { - player removeDiaryRecord ["cmf_roster", _x select 8] - } forEach (player allDiaryRecords "cmf_roster"); - } else { - /* Add Each of the highest level groups */ - private _groupHash = [GVAR(groups), side cmf_player, []] call CBA_fnc_hashGet; - private _levels = [_groupHash] call CBA_fnc_hashKeys; - if (count _levels isEqualTo 0) exitWith { cmf_player createDiaryRecord ["cmf_roster", ["No Registered Groups.", ""]] }; - - { - cmf_player removeDiaryRecord ["cmf_roster", _x select 8]; - } forEach (cmf_player allDiaryRecords "cmf_roster"); - - _levels sort false; - private "_topLevelGroups"; - { - private _groups = [_groupHash, _x, []] call CBA_fnc_hashGet; - - if (_groups findIf { units _x findIf { isPlayer _x } > -1 } > -1) exitWith { - _topLevelGroups = _groups; - }; - } forEach _levels; - - if (isNil "_topLevelGroups") exitWith { cmf_player createDiaryRecord ["cmf_roster", ["No Registered Groups.", ""]] }; - - reverse _topLevelGroups; - - FUNC(ToE_recursiveCheck) = { - params ["_group", ["_indent", ""]]; - - private _formattedString = ""; - - private _formatGroupHeader = { format ["%1
", _this] }; - - private _groupNames = _group getVariable [QGVAR(groupName), ["UNKNOWN", "UNKNOWN"]]; - private _groupData = [_group] call FUNC(groupGetData); - private _units = units _group; - _groupData params ["_level", "", "", "_children"]; - - if (count _units isNotEqualTo 0) then { - if (count _children > 0) then { - _formattedString = _formattedString + "
" + _indent + ((_groupNames select 1) call _formatGroupHeader); - _indent = _indent + " "; - }; - + if (!_mapIsOpened) exitWith { + { player removeDiaryRecord ["cmf_roster", _x select 8] } forEach (player allDiaryRecords "cmf_roster"); + }; - _formattedString = _formattedString + _indent + ((_groupNames select 0) call _formatGroupHeader); - { - if (isPlayer _x) then { - private _roleDescription = "None"; - if (roleDescription _x != "") then { - _roleDescription = (roleDescription _x splitString "@") select 0; - }; + private _formattedString = "

Player Roster
"; - _formattedString = _formattedString + _indent + format [" %1, %2
", name _x, _roleDescription]; - }; - } forEach units _group; + { + if (isPlayer _x) then { + private _roleDescription = "None"; + if (roleDescription _x != "") then { + _roleDescription = (roleDescription _x splitString "@") select 0; }; - /* Sort children */ - _children = [_children, [], { - private _group = _x; - private _groupData = [_group] call FUNC(groupGetData); - private _groupNames = _group getVariable [QGVAR(groupName), ["UNKNOWN", "UNKNOWN"]]; - _groupData params ["", "_type", "", "_children"]; - - private _childrenCount = count _children; - private _alphabetOrder = GVAR(phoneticAlphabet) findIf { (_x select [0, 1]) isEqualTo (_groupNames select [0, 1]) }; - - _childrenCount + ([1000, -_alphabetOrder] select (_type isEqualTo "INF")) - }, "DESCEND"] call BIS_fnc_sortBy; - - { - if (units _x findIf { isPlayer _x } > -1) then { - _formattedString = _formattedString + ([_x, _indent] call FUNC(ToE_recursiveCheck)); - } - } forEach _children; - - _formattedString; + _formattedString = _formattedString + format [" %1, %2
", name _x, _roleDescription]; }; + } forEach allPlayers; - { - private _group = _x; - if (units _group findIf { isPlayer _x } > -1) then { - private _groupNames = _group getVariable [QGVAR(groupName), ["UNKNOWN", "UNKNOWN"]]; - private _formattedString = "
"; - - _formattedString = _formattedString + ([_group] call FUNC(ToE_recursiveCheck)); - - cmf_player createDiaryRecord ["cmf_roster", [(_groupNames select 1), _formattedString]]; - } - } forEach _topLevelGroups; - }; + cmf_player createDiaryRecord ["cmf_roster", ["Player Roster", _formattedString]]; }]; }] call CBA_fnc_waitUntilAndExecute; \ No newline at end of file diff --git a/framework/rsc/organization/orbat.sqf b/framework/rsc/organization/orbat.sqf index 61856dc..ee3758a 100644 --- a/framework/rsc/organization/orbat.sqf +++ b/framework/rsc/organization/orbat.sqf @@ -12,11 +12,10 @@ _fireteamNaming = { private "_index"; if (!isNull _parent) then { private _parentData = [_parent] call FUNC(groupGetData); - private _siblings = (_parentData select 3) select { count units _x > 0 }; + private _siblings = (_parentData select 3); _index = _siblings find _group; } else { private _siblings = ([_groupsHash, _level, []] call CBA_fnc_hashGet) select { (([_x] call FUNC(groupGetData)) select 1) isEqualTo _type }; - _siblings = _siblings select { count units _x > 0 }; _index = _siblings find _group; }; @@ -31,7 +30,6 @@ _fireteamNaming = { if (isNil "_names") then { private _siblings = ([_groupsHash, (_parentData select 0), []] call CBA_fnc_hashGet) select { (([_x] call FUNC(groupGetData)) select 1) isEqualTo (_parentData select 1) }; - _siblings = _siblings select { count units _x > 0 }; private _index = _siblings find _parent; if ((_parentData select 0) isEqualTo _level + 1) then { @@ -78,7 +76,6 @@ private _squadNaming = { private _groupsHash = [GVAR(groups), side _group, [] call CBA_fnc_hashCreate] call CBA_fnc_hashGet; private _siblings = ([_groupsHash, _level, []] call CBA_fnc_hashGet) select { (([_x] call FUNC(groupGetData)) select 1) isEqualTo _type }; // @TODO: Try to get siblings from parent first - _siblings = _siblings select { count units _x > 0 }; private _index = _siblings find _group; private _name = [GVAR(phoneticAlphabet) select _index, "ZULU"] select (count GVAR(phoneticAlphabet) < _index); @@ -92,7 +89,6 @@ private _squadNaming = { if (isNil "_names") then { private _siblings = ([_groupsHash, (_parentData select 0), []] call CBA_fnc_hashGet) select { (([_x] call FUNC(groupGetData)) select 1) isEqualTo (_parentData select 1) }; - _siblings = _siblings select { count units _x > 0 }; private _index = _siblings find _parent; _names = [_index]; }; @@ -121,7 +117,6 @@ private _platoonNaming = { private _groupsHash = [GVAR(groups), side _group, [] call CBA_fnc_hashCreate] call CBA_fnc_hashGet; private _siblings = ([_groupsHash, _level, []] call CBA_fnc_hashGet) select { (([_x] call FUNC(groupGetData)) select 1) isEqualTo _type }; - _siblings = _siblings select { count units _x > 0 }; private _index = _siblings find _group; private _parentIDs = []; @@ -134,7 +129,6 @@ private _platoonNaming = { if (isNil "_names") then { private _siblings = ([_groupsHash, (_parentData select 0), []] call CBA_fnc_hashGet) select { (([_x] call FUNC(groupGetData)) select 1) isEqualTo (_parentData select 1) }; - _siblings = _siblings select { count units _x > 0 }; private _index = _siblings find _parent; _names = [_index]; }; @@ -156,7 +150,6 @@ private _companyNaming = { private _groupsHash = [GVAR(groups), side _group, [] call CBA_fnc_hashCreate] call CBA_fnc_hashGet; private _siblings = ([_groupsHash, _level, []] call CBA_fnc_hashGet) select { (([_x] call FUNC(groupGetData)) select 1) isEqualTo _type }; - _siblings = _siblings select { count units _x > 0 }; private _index = _siblings find _group; private _name = [GVAR(phoneticAlphabet) select _index, "ZULU"] select (count GVAR(phoneticAlphabet) < _index); @@ -170,7 +163,6 @@ private _companyNaming = { if (isNil "_names") then { private _siblings = ([_groupsHash, (_parentData select 0), []] call CBA_fnc_hashGet) select { (([_x] call FUNC(groupGetData)) select 1) isEqualTo (_parentData select 1) }; - _siblings = _siblings select { count units _x > 0 }; private _index = _siblings find _parent; _names = [_index]; }; @@ -192,11 +184,10 @@ _vehicleSquadNaming = { private "_index"; if (!isNull _parent) then { private _parentData = [_parent] call FUNC(groupGetData); - private _siblings = (_parentData select 3) select { count units _x > 0 }; + private _siblings = (_parentData select 3); _index = _siblings find _group; } else { private _siblings = ([_groupsHash, _level, []] call CBA_fnc_hashGet) select { (([_x] call FUNC(groupGetData)) select 1) isEqualTo _type }; - _siblings = _siblings select { count units _x > 0 }; _index = _siblings find _group; }; @@ -211,7 +202,6 @@ _vehicleSquadNaming = { if (isNil "_names") then { private _siblings = ([_groupsHash, (_parentData select 0), []] call CBA_fnc_hashGet) select { (([_x] call FUNC(groupGetData)) select 1) isEqualTo (_parentData select 1) }; - _siblings = _siblings select { count units _x > 0 }; private _index = _siblings find _parent; if ((_parentData select 0) isEqualTo _level + 1) then { @@ -259,7 +249,6 @@ private _specialNaming = { private _groupsHash = [GVAR(groups), side _group, [] call CBA_fnc_hashCreate] call CBA_fnc_hashGet; private _siblings = ([_groupsHash, _level, []] call CBA_fnc_hashGet) select { (([_x] call FUNC(groupGetData)) select 1) isEqualTo _type }; - _siblings = _siblings select { count units _x > 0 }; private _index = _siblings find _group; private _parentIDs = []; @@ -272,7 +261,6 @@ private _specialNaming = { if (isNil "_names") then { private _siblings = [_groupsHash, (_parentData select 0), []] call CBA_fnc_hashGet; - _siblings = _siblings select { count units _x > 0 }; private _index = _siblings find _parent; _names = [_index]; };