Skip to content

Commit

Permalink
Rework vehicle classification system to not rely on EN translations
Browse files Browse the repository at this point in the history
  • Loading branch information
theace0296 committed Nov 12, 2021
1 parent d4d60ea commit 3571b6d
Show file tree
Hide file tree
Showing 10 changed files with 209 additions and 243 deletions.
85 changes: 85 additions & 0 deletions RandFramework/Global/common/fn_getVehicleType.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// private _fnc_scriptName = "TRGM_GLOBAL_fnc_getVehicleType";
params [["_type", "", [""]]];


private _configPath = (configFile >> "CfgVehicles" >> _type);
private _vehData = [_configPath] call TRGM_GLOBAL_fnc_getVehicleData;
_vehData params ["_className", "_dispName", "_rawDispName", "_calloutName", "_rawCalloutName", "_editorSubcategory", "_category", "_rawCategory", "_isTransport", "_isArmed"];

private _returnType = "UnarmedCars";
if (isNil "_className" || isNil "_dispName" || isNil "_calloutName" || isNil "_rawCategory" || [_configPath] call TRGM_GLOBAL_fnc_ignoreVehicle) then {
_returnType = "UnarmedCars";
} else {
if (_calloutName isEqualTo "mortar" || _className isKindOf "StaticMortar") then {
_returnType = "Mortars";
} else {
if (_className isKindOf "StaticMGWeapon" || _className isKindOf "StaticGrenadeLauncher") then {
_returnType = "Turrets";
} else {
private _typeFound = false;
private _returnTypeMap = [
["Cars", ["car", "truck", "mrap", "bike", "bicycle"]],
["Mortars", ["mortar"]],
["Turrets", ["turret", "static"]],
["Boats", ["boat", "ship"]],
["Artillery", ["artillery", "arty"]],
["AntiAir", ["_aa", "radar", "air defence"]],
["Planes", ["plane"]],
["APCs", ["apc", "ifv"]],
["Tanks", ["tank", "armor"]],
["Helos", ["helicopter"]]
];
if (!_typeFound) then {
{
private _searchText = _x;
if ([_searchText, _rawCategory] call BIS_fnc_inString) exitWith {
_typeFound = true;
private _mapIndex = _returnTypeMap findIf { _searchText in (_x select 1) };
_returnType = (_returnTypeMap select _mapIndex) select 0;
if (_returnType in ["Cars", "Helos"]) then {
if (_isArmed && !_isTransport) then {
_returnType = "Armed" + _returnType;
} else {
_returnType = "Unarmed" + _returnType;
};
};
};
} forEach (flatten (_returnTypeMap apply { _x select 1}));
};
if (!_typeFound) then {
{
private _searchText = _x;
if ([_searchText, _rawCalloutName] call BIS_fnc_inString) exitWith {
_typeFound = true;
private _mapIndex = _returnTypeMap findIf { _searchText in (_x select 1) };
_returnType = (_returnTypeMap select _mapIndex) select 0;
if (_returnType in ["Cars", "Helos"]) then {
if (_isArmed && !_isTransport) then {
_returnType = "Armed" + _returnType;
} else {
_returnType = "Unarmed" + _returnType;
};
};
};
} forEach (flatten (_returnTypeMap apply { _x select 1}));
};
};
};
};

// Possible return types are:
// [
// "UnarmedCars",
// "ArmedCars",
// "Mortars",
// "Turrets",
// "Boats",
// "Artillery",
// "AntiAir",
// "Planes",
// "APCs",
// "Tanks",
// "ArmedHelos",
// "UnarmedHelos",
// ]
_returnType;
65 changes: 17 additions & 48 deletions RandFramework/Global/factions/fn_getFactionVehicle.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
params [["_vehClassName", "", [objNull, ""]], ["_side", WEST]];
format[localize "STR_TRGM2_debugFunctionString", _fnc_scriptName, _fnc_scriptNameParent, (["Client", "Server"] select isServer)] call TRGM_GLOBAL_fnc_log;



switch (typeName _vehClassName) do {
case ("OBJECT") : {_vehClassName = typeOf _vehClassName};
};
Expand Down Expand Up @@ -71,50 +69,21 @@ switch (_side) do {
};
};

[_vehClassName, getText(_configPath >> "displayName"), getText(_configPath >> "textSingular"), getText(configfile >> "CfgEditorSubcategories" >> getText(_configPath >> "editorSubcategory") >> "displayName"), (configName _configPath) call TRGM_GLOBAL_fnc_isTransport, (configName _configPath) call TRGM_GLOBAL_fnc_isArmed] params [["_className", ""], ["_dispName", ""], ["_calloutName", ""], ["_category", ""], ["_isTransport", false], ["_isArmed", false]];

if (isNil "_className" || isNil "_dispName" || isNil "_calloutName" || isNil "_category") then {

} else {
if (["GMG", _dispName] call BIS_fnc_inString || ["Quadbike", _className] call BIS_fnc_inString || ["Designator", _className] call BIS_fnc_inString || ["Radar", _className] call BIS_fnc_inString || ["SAM", _className] call BIS_fnc_inString) then {
_returnVeh = _UnarmedCars;
} else {
if ([" (", _category] call BIS_fnc_inString) then {
_category = (_category splitString " (") select 0
};
if (_calloutName isEqualTo "mortar" || _className isKindOf "StaticMortar") then {
_returnVeh = _Mortars;
} else {
if (_className isKindOf "StaticMGWeapon" || _className isKindOf "StaticGrenadeLauncher") then {
_returnVeh = _Turrets;
} else {
switch (_category) do {
case "Turrets": { _returnVeh = _Turrets; };
case "Boats": { _returnVeh = _Boats; };
case "Boat": { _returnVeh = _Boats; };
case "Artillery": { _returnVeh = _Artillery; };
case "Anti-Air": { _returnVeh = _AntiAir; };
case "Anti-aircraft": { _returnVeh = _AntiAir; };
case "Planes": { _returnVeh = _Planes; };
case "Plane": { _returnVeh = _Planes; };
case "APCs": { _returnVeh = _APCs; };
case "APC": { _returnVeh = _APCs; };
case "IFV": { _returnVeh = _APCs; };
case "Tanks": { _returnVeh = _Tanks; };
case "Tank": { _returnVeh = _Tanks; };
case "Helicopters": { if (_isArmed && !_isTransport) then { _returnVeh = _ArmedHelos; } else { _returnVeh = _UnarmedHelos; }; };
case "Helicopter": { if (_isArmed && !_isTransport) then { _returnVeh = _ArmedHelos; } else { _returnVeh = _UnarmedHelos; }; };
case "Cars": { if (_isArmed && !_isTransport) then { _returnVeh = _ArmedCars; } else { _returnVeh = _UnarmedCars; }; };
case "Car": { if (_isArmed && !_isTransport) then { _returnVeh = _ArmedCars; } else { _returnVeh = _UnarmedCars; }; };
case "Bikes": { if (_isArmed && !_isTransport) then { _returnVeh = _ArmedCars; } else { _returnVeh = _UnarmedCars; }; };
case "MRAP": { if (_isArmed && !_isTransport) then { _returnVeh = _ArmedCars; } else { _returnVeh = _UnarmedCars; }; };
case "Truck": { if (_isArmed && !_isTransport) then { _returnVeh = _ArmedCars; } else { _returnVeh = _UnarmedCars; }; };
case "Trucks": { if (_isArmed && !_isTransport) then { _returnVeh = _ArmedCars; } else { _returnVeh = _UnarmedCars; }; };
default { };
};
};
};
};
private _vehType = [_vehClassName] call TRGM_GLOBAL_fnc_getVehicleType;
switch (_vehType) do {
case "UnarmedCars": { _returnVeh = _UnarmedCars; };
case "ArmedCars": { _returnVeh = _ArmedCars; };
case "Mortars": { _returnVeh = _Mortars; };
case "Turrets": { _returnVeh = _Turrets; };
case "Boats": { _returnVeh = _Boats; };
case "Artillery": { _returnVeh = _Artillery; };
case "AntiAir": { _returnVeh = _AntiAir; };
case "Planes": { _returnVeh = _Planes; };
case "APCs": { _returnVeh = _APCs; };
case "Tanks": { _returnVeh = _Tanks; };
case "ArmedHelos": { _returnVeh = _ArmedHelos; };
case "UnarmedHelos": { _returnVeh = _UnarmedHelos; };
default { _returnVeh = _UnarmedCars; };
};

private _fallbackReturnVeh = _returnVeh;
Expand All @@ -135,11 +104,11 @@ if (_vehClassName call TRGM_GLOBAL_fnc_isMedical && ({_x call TRGM_GLOBAL_fnc_is
_returnVeh = _returnVeh select {_x call TRGM_GLOBAL_fnc_isAmmo};
if (isNil "_returnVeh" || { _returnVeh isEqualTo []}) exitWith {_vehClassName};
} else {
if (_isArmed && ({_x call TRGM_GLOBAL_fnc_isArmed} count _returnVeh) > 0) then {
if (_vehClassName call TRGM_GLOBAL_fnc_isArmed && ({_x call TRGM_GLOBAL_fnc_isArmed} count _returnVeh) > 0) then {
_returnVeh = _returnVeh select {_x call TRGM_GLOBAL_fnc_isArmed};
if (isNil "_returnVeh" || { _returnVeh isEqualTo []}) exitWith {_vehClassName};
} else {
if (_isTransport && ({_x call TRGM_GLOBAL_fnc_isTransport} count _returnVeh) > 0) then {
if (_vehClassName call TRGM_GLOBAL_fnc_isTransport && ({_x call TRGM_GLOBAL_fnc_isTransport} count _returnVeh) > 0) then {
_returnVeh = _returnVeh select {_x call TRGM_GLOBAL_fnc_isTransport};
if (isNil "_returnVeh" || { _returnVeh isEqualTo []}) exitWith {_vehClassName};
};
Expand Down
Loading

0 comments on commit 3571b6d

Please sign in to comment.