Skip to content

Commit

Permalink
clean up if-then nesting in fnc
Browse files Browse the repository at this point in the history
  • Loading branch information
theace0296 committed Nov 12, 2021
1 parent f19a7b1 commit d4d60ea
Showing 1 changed file with 40 additions and 44 deletions.
84 changes: 40 additions & 44 deletions RandFramework/Global/common/fn_getUnitType.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,50 @@ private _unitData = [_configPath] call TRGM_GLOBAL_fnc_getUnitData;
_unitData params ["_className", "_dispName", "_rawDispName", "_icon", "_calloutName", "_isMedic", "_isEngineer", "_isExpSpecialist", "_isUAVHacker", "_role"];

private _returnType = "riflemen";
if (isNil "_className" || isNil "_dispName" || isNil "_rawDispName" || isNil "_icon" || isNil "_calloutName") then {

if (isNil "_className" || isNil "_dispName" || isNil "_rawDispName" || isNil "_icon" || isNil "_calloutName" || [_configPath] call TRGM_GLOBAL_fnc_ignoreUnit) then {
_returnType = "riflemen";
} else {
if ([_configPath] call TRGM_GLOBAL_fnc_ignoreUnit) then {
_returnType = "riflemen";
} else {
switch (toLower _icon) do {
case "iconmanengineer": { _returnType = "engineers"; };
case "iconmanmedic": { _returnType = "medics"; };
case "iconmanexplosive": { _returnType = "explosivespecs"; };
case "iconmanleader": { _returnType = "leaders"; };
case "iconmanofficer": { _returnType = "leaders"; };
case "iconmanmg": { _returnType = "autoriflemen"; };
case "iconmanat": { _returnType = (["atsoldiers", "aasoldiers"] select (({ ["AA", _x, true] call BIS_fnc_inString } count [_role, _className, _rawDispName] > 0) && !({ ["AT", _x, true] call BIS_fnc_inString } count [_role, _className, _rawDispName] > 0))); };
default {
if (_isEngineer isEqualTo 1) then { _returnType = "engineers"; };
if (_isMedic isEqualTo 1) then { _returnType = "medics"; };
if (_isExpSpecialist isEqualTo 1) then { _returnType = "explosivespecs"; };
if (_isUAVHacker isEqualTo 1) then { _returnType = "uavops"; };
if ([_isEngineer, _isMedic, _isExpSpecialist, _isUAVHacker] isEqualTo [0,0,0,0]) then {
switch (toLower _calloutName) do {
case "pilot": { _returnType = "pilots"; };
case "sniper": { _returnType = "snipers"; };
case "at soldier": { _returnType = (["atsoldiers", "aasoldiers"] select (({ ["AA", _x, true] call BIS_fnc_inString } count [_role, _className, _rawDispName] > 0) && !({ ["AT", _x, true] call BIS_fnc_inString } count [_role, _className, _rawDispName] > 0))); };
case "machinegunner": { _returnType = "autoriflemen"; };
case "officer": { _returnType = "leaders"; };
case "infantry";
default {
if ({ ["pilot", _x] call BIS_fnc_inString } count [_role, _className, _rawDispName] > 0) then {
_returnType = "pilots";
switch (toLower _icon) do {
case "iconmanengineer": { _returnType = "engineers"; };
case "iconmanmedic": { _returnType = "medics"; };
case "iconmanexplosive": { _returnType = "explosivespecs"; };
case "iconmanleader": { _returnType = "leaders"; };
case "iconmanofficer": { _returnType = "leaders"; };
case "iconmanmg": { _returnType = "autoriflemen"; };
case "iconmanat": { _returnType = (["atsoldiers", "aasoldiers"] select (({ ["AA", _x, true] call BIS_fnc_inString } count [_role, _className, _rawDispName] > 0) && !({ ["AT", _x, true] call BIS_fnc_inString } count [_role, _className, _rawDispName] > 0))); };
default {
if (_isEngineer isEqualTo 1) then { _returnType = "engineers"; };
if (_isMedic isEqualTo 1) then { _returnType = "medics"; };
if (_isExpSpecialist isEqualTo 1) then { _returnType = "explosivespecs"; };
if (_isUAVHacker isEqualTo 1) then { _returnType = "uavops"; };
if ([_isEngineer, _isMedic, _isExpSpecialist, _isUAVHacker] isEqualTo [0,0,0,0]) then {
switch (toLower _calloutName) do {
case "pilot": { _returnType = "pilots"; };
case "sniper": { _returnType = "snipers"; };
case "at soldier": { _returnType = (["atsoldiers", "aasoldiers"] select (({ ["AA", _x, true] call BIS_fnc_inString } count [_role, _className, _rawDispName] > 0) && !({ ["AT", _x, true] call BIS_fnc_inString } count [_role, _className, _rawDispName] > 0))); };
case "machinegunner": { _returnType = "autoriflemen"; };
case "officer": { _returnType = "leaders"; };
case "infantry";
default {
if ({ ["pilot", _x] call BIS_fnc_inString } count [_role, _className, _rawDispName] > 0) then {
_returnType = "pilots";
} else {
if ({ ["AT", _x, true] call BIS_fnc_inString } count [_role, _className, _rawDispName] > 0) then {
_returnType = "atsoldiers";
} else {
if ({ ["AT", _x, true] call BIS_fnc_inString } count [_role, _className, _rawDispName] > 0) then {
_returnType = "atsoldiers";
if ({ ["AA", _x, true] call BIS_fnc_inString } count [_role, _className, _rawDispName] > 0) then {
_returnType = "aasoldiers";
} else {
if ({ ["AA", _x, true] call BIS_fnc_inString } count [_role, _className, _rawDispName] > 0) then {
_returnType = "aasoldiers";
} else {
if ({ ["grenadier", _x] call BIS_fnc_inString || ["GL", _x, true] call BIS_fnc_inString } count [_role, _className, _rawDispName] > 0) then {
_returnType = "grenadiers"; }
else {
if ({ ["scout", _x] call BIS_fnc_inString || ["sniper", _x] call BIS_fnc_inString || ["marksman", _x] call BIS_fnc_inString || ["ghillie", _x] call BIS_fnc_inString } count [_role, _className, _rawDispName] > 0) then {
_returnType = "snipers";
if ({ ["grenadier", _x] call BIS_fnc_inString || ["GL", _x, true] call BIS_fnc_inString } count [_role, _className, _rawDispName] > 0) then {
_returnType = "grenadiers"; }
else {
if ({ ["scout", _x] call BIS_fnc_inString || ["sniper", _x] call BIS_fnc_inString || ["marksman", _x] call BIS_fnc_inString || ["ghillie", _x] call BIS_fnc_inString } count [_role, _className, _rawDispName] > 0) then {
_returnType = "snipers";
} else {
if ({ ["machinegunner", _x] call BIS_fnc_inString || ["autorifleman", _x] call BIS_fnc_inString } count [_role, _className, _rawDispName] > 0) then {
_returnType = "autoriflemen";
} else {
if ({ ["machinegunner", _x] call BIS_fnc_inString || ["autorifleman", _x] call BIS_fnc_inString } count [_role, _className, _rawDispName] > 0) then {
_returnType = "autoriflemen";
} else {
_returnType = "riflemen";
};
_returnType = "riflemen";
};
};
};
Expand Down

0 comments on commit d4d60ea

Please sign in to comment.