diff options
Diffstat (limited to 'Common/Module/CIPHER')
| -rw-r--r-- | Common/Module/CIPHER/CIPHER_Init.sqf | 91 | ||||
| -rw-r--r-- | Common/Module/CIPHER/CIPHER_Sort.sqf | 63 |
2 files changed, 154 insertions, 0 deletions
diff --git a/Common/Module/CIPHER/CIPHER_Init.sqf b/Common/Module/CIPHER/CIPHER_Init.sqf new file mode 100644 index 0000000..05866ba --- /dev/null +++ b/Common/Module/CIPHER/CIPHER_Init.sqf @@ -0,0 +1,91 @@ +/*
+ * Cipher Module
+ * Author: Benny.
+ * Description: Alphabetical functions such as sorting and string compare.
+ */
+
+
+/* Compare whether string A is greater than string B */
+CIPHER_CompareString = {
+ Private ["_aisgreater","_stringA","_stringB"];
+ _stringA = toArray(_this select 0);
+ _stringB = toArray(_this select 1);
+
+ _aisgreater = false;
+
+ for '_i' from 0 to count(_stringA)-1 do {
+ if (_i > count(_stringB)-1) exitWith {_aisgreater = true};
+ if ((_stringA select _i) != (_stringB select _i)) exitWith {
+ _aisgreater = if ((_stringA select _i) > (_stringB select _i)) then {true} else {false};
+ };
+ };
+
+ _aisgreater;
+};
+
+/* Swap Element A with Element B in an array. */
+CIPHER_ArraySwap = {
+ Private ["_array","_elea","_eleb","_posa","_posb"];
+ _array = _this select 0;
+ _posa = _this select 1;
+ _posb = _this select 2;
+
+ _elea = _array select _posa;
+ _eleb = _array select _posb;
+
+ _array set [_posa, _eleb];
+ _array set [_posb, _elea];
+
+ _array;
+};
+
+/* Reverse an array */
+CIPER_ArrayReverse = {
+ Private ["_array","_reversed","_u"];
+ _array = _this;
+ _reversed = [];
+
+ _u = 0;
+ for '_i' from count(_array)-1 step -1 to 0 do {
+ _reversed set [_u, _array select _i];
+ _u = _u + 1;
+ };
+
+ _reversed
+};
+
+/* Sort an array by alphabetical order, selection sort. */
+CIPHER_SortArray = {
+ Private['_auxArray','_list','_min','_reverse'];
+
+ _list = _this select 0;
+ _reverse = _this select 1;
+ _auxArray = if (count _this > 2) then {+(_this select 2)} else {[]};
+
+ if (count _list == 0) exitWith {[]};
+ _isString = if (typeName(_list select 0) == typeName "") then {true} else {false};
+
+ for '_i' from 0 to (count _list)-1 do {
+ _min = _i;
+
+ for '_j' from _i+1 to (count _list)-1 do {
+ if (_isString) then {
+ if !([_list select _j, _list select _min] Call CIPHER_CompareString) then {_min = _j}
+ } else {
+ if ((_list select _j) < (_list select _min)) then {_min = _j};
+ };
+ };
+
+ if (_min != _i) then {
+ _list = [_list, _i, _min] Call CIPHER_ArraySwap;
+ if (count _auxArray > 0) then {_auxArray = [_auxArray, _i, _min] Call CIPHER_ArraySwap};
+ };
+ };
+
+ if (_reverse) then {
+ _list = (_list) Call CIPER_ArrayReverse;
+ if (count _auxArray > 0) then {_auxArray = (_auxArray) Call CIPER_ArrayReverse};
+ };
+
+ [_list, _auxArray]
+};
\ No newline at end of file diff --git a/Common/Module/CIPHER/CIPHER_Sort.sqf b/Common/Module/CIPHER/CIPHER_Sort.sqf new file mode 100644 index 0000000..0ae438b --- /dev/null +++ b/Common/Module/CIPHER/CIPHER_Sort.sqf @@ -0,0 +1,63 @@ +/* Elements to sort etc ... */
+
+_preformat = {
+ Private ["_get","_output","_units"];
+ _units = _this;
+ _output = [];
+
+ for '_i' from 0 to count(_units)-1 do {
+ _get = (_units select _i) Call GetNamespace;
+ if !(isNil "_get") then {
+ _output set [_i, _get select QUERYUNITLABEL];
+ } else {
+ _output set [_i, (_units select _i)];
+ };
+ };
+
+ _output
+};
+
+_preformat_gear = {
+ Private ["_content","_get","_output"];
+ _content = _this;
+ _output = [];
+
+ for '_i' from 0 to count(_content)-1 do {
+ _get = (_content select _i) Call GetNamespace;
+ if !(isNil "_get") then {
+ _output set [_i, _get select QUERYGEARLABEL];
+ } else {
+ _output set [_i, (_content select _i)];
+ };
+ };
+
+ _output
+};
+
+//--- Sort Factions.
+{
+ _content = Format["WFBE_%1%2FACTIONS",sideJoinedText,_x] Call GetNamespace;
+ _sorted = ([_content, false] Call CIPHER_SortArray) select 0;
+ [Format['WFBE_%1%2FACTIONS',sideJoinedText,_x], _sorted, true] Call SetNamespace;
+
+ //--- While we're at it we set the default selected faction.
+ _content = Format["WFBE_%1%2FACTIONS",sideJoinedText,_x] Call GetNamespace;
+ _find = _content find (Format["WFBE_%1DEFAULTFACTION",sideJoinedText] Call GetNamespace);
+ if (_find != -1) then {
+ [Format["WFBE_%1%2CURRENTFACTIONSELECTED",sideJoinedText,_x], _find] Call SetNamespace;
+ };
+} forEach ["BARRACKS","LIGHT","HEAVY","AIRCRAFT","AIRPORT","DEPOT"];
+
+//--- Sort Purchases (Default, name - asc).
+{
+ _content = Format['WFBE_%1%2UNITS',sideJoinedText,_x] Call GetNamespace;
+ _sorted = ([(_content) Call _preformat,false,_content] Call CIPHER_SortArray) select 1;
+ [Format['WFBE_%1%2UNITS',sideJoinedText,_x], _sorted, true] Call SetNamespace;
+} forEach ["BARRACKS","LIGHT","HEAVY","AIRCRAFT","AIRPORT","DEPOT"];
+
+//--- Sort Gear.
+{
+ _content = WF_Logic getVariable Format ["%1Classes",_x];
+ _sorted = ([(_content) Call _preformat_gear,false,_content] Call CIPHER_SortArray) select 1;
+ WF_Logic setVariable [Format ["%1Classes",_x], _sorted];
+} forEach ["primary","secondary","sidearm","misc"];
\ No newline at end of file |
