Skip to content

Commit

Permalink
Updated and fixed code
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasBrostrom committed Jul 21, 2024
1 parent 89ee0ee commit 5c6da4b
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 43 deletions.
10 changes: 6 additions & 4 deletions addons/infantry/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
PREP(getCallsign);
PREP(getShortDesignation);
PREP(getUnitDesignation);
PREP(setCallsign);
PREP(getBillet);
PREP(getDesignation);
PREP(getUnitCallsign);
PREP(getUnitTeam);
PREP(setUniqCallsign);
PREP(setUnitTeam);
3 changes: 2 additions & 1 deletion addons/infantry/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

if (!hasInterface) exitWith {};

player call FUNC(setCallsign);
[player] call FUNC(setUniqCallsign);
[player] call FUNC(setUnitTeam);
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#include "..\script_component.hpp"
/*
* Author: CPL.Brostrom.A
* This function return a unit designation
* The callsign can also be defined in mission via CfgLoadouts
* Author: SGT.Brostrom.A
* This function return your given unit billet designation.
* If you have a cfgLoadouts in your mission it will be used instead.
*
* Arguments:
* 0: Unit <OBJECT>
* 0: Unit/Classname <OBJECT|STRING>
*
* Return Value:
* Callsign <STRING>
* Unit Billet <STRING> (1/1/C/1-7)
*
* Example:
* _x = [player] call cav_infantry_fnc_getShortDesignation;
* _x = [player] call cav_infantry_fnc_getBillet;
* _x // 1/1/C/1-7
*
* Public: Yes
*/

params [["_unit", objNull, [objNull]]];
params [["_unit", objNull, [objNull,""]]];


private _hashMap = [_unit] call FUNC(getUnitCallsign);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
* HashMap
*
* Example:
* [player] call cav_infantry_fnc_getUnitDesignation;
* [player] call cav_infantry_fnc_getDesignation
*
* Public: No
*/

params [["_unit", objNull, [objNull]]];
params [["_unit", objNull, [objNull, ""]]];

private _classname = typeOf _unit;
if (_unit isEqualType objNull) then {
_unit = typeOf _unit;
};

private _fn_companyLetter = {
params ["_company"];
Expand All @@ -37,24 +39,26 @@ private _fn_companyLetter = {

private _fn_getConfigValue = {
params ["_configKey"];

LOG_1("getDesignation: Looking up key '%1'",_configKey);
private _return = "";
_CfgLoadouts = isClass (missionConfigFile >> "CfgLoadouts");

if (_configKey == "company") then {
if (_configKey in ["company", "regimentName"] ) then {
_configKeyPrefixed = format["cav_%1",_configKey];
_return = getText (configFile >> "CfgVehicles" >> _classname >> _configKeyPrefixed);
_return = getText (configFile >> "CfgVehicles" >> _unit >> _configKeyPrefixed);
if (_CfgLoadouts) then {
if (_CfgLoadouts) then {
_return = getText (missionConfigFile >> "CfgLoadouts" >> _classname >> _configKey);
_return = getText (missionConfigFile >> "CfgLoadouts" >> _unit >> _configKey);
};
};
_return = _return call _fn_companyLetter;
if (_configKey == "company") then {
_return = _return call _fn_companyLetter;
};
} else {
_configKeyPrefixed = format["cav_%1",_configKey];
_return = getNumber (configFile >> "CfgVehicles" >> _classname >> _configKeyPrefixed);
_return = getNumber (configFile >> "CfgVehicles" >> _unit >> _configKeyPrefixed);
if (_CfgLoadouts) then {
_return = getNumber (missionConfigFile >> "CfgLoadouts" >> _classname >> _configKey);
_return = getNumber (missionConfigFile >> "CfgLoadouts" >> _unit >> _configKey);
};
_return = [_return, 0] select (_return <= 0);
_return = str _return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "..\script_component.hpp"
/*
* Author: CPL.Brostrom.A
* This function gets your callsign based on your displayname
* Author: SGT.Brostrom.A
* This function gets your callsign based on your units displayName
* If you have a cfgLoadouts in your mission it will be used instead.
* Exsample: Squad Leader (BADNIT-1) will return BADNIT-1
*
* Arguments:
Expand All @@ -11,17 +12,20 @@
* Unit Callsign <STRING>
*
* Example:
* [player] call cav_infantry_fnc_getCallsign
* [player] call cav_infantry_fnc_getUnitCallsign
*
* Public: No
*/

params [["_unit", objNull, [objNull]]];
params [["_unit", objNull, [objNull, ""]]];

private _classname = typeOf _unit;
_displayName = getText (configFile >> "CfgVehicles" >> _classname >> "displayName");
if (_unit isEqualType objNull) then {
_unit = typeOf _unit;
};

_displayName = getText (configFile >> "CfgVehicles" >> _unit >> "displayName");
if (isClass (missionConfigFile >> "CfgLoadouts")) then {
_displayName = getText (missionConfigFile >> "CfgLoadouts" >> _classname >> "displayName");
_displayName = getText (missionConfigFile >> "CfgLoadouts" >> _unit >> "displayName");
};

private _callsign = _displayName splitString " ";
Expand All @@ -31,9 +35,4 @@ _callsign = _callsign select (count _callsign - 1);
_callsign = _callsign splitString ")";
_callsign = _callsign select (count _callsign - 1);

private _group = group _unit;
private _currentID = groupId group _unit;
if (_currentID == _callsign) exitWith {_currentID};

[_group, _callsign] call CBA_fnc_setCallsign;
_callsign;
33 changes: 33 additions & 0 deletions addons/infantry/functions/fnc_getUnitTeam.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "..\script_component.hpp"
/*
* Author: SGT.Brostrom.A
* This function get team color based on you unit prefix
*
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* Color Name <STRING>
*
* Example:
* [player] call cav_infantry_fnc_getUnitTeam;
*
* Public: No
*/

params [["_unit", objNull, [objNull]]];

private _displayName = getText (configFile >> "CfgVehicles" >> typeOf _unit >> "displayName");
_displayName = _displayName splitString " ";
_team = _displayName#0;
_teamUpper = toUpper _team;

private _color = switch (_teamUpper) do {
case "ALPHA": {"RED"};
case "BRAVO": {"BLUE"};
case "CHARLIE": {"GREEN"};
case "DELTA": {"YELLOW"};
default {"MAIN"};
};

_color;
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,44 @@
* 0: Unit <OBJECT>
*
* Return Value:
* Units new callsign <STRING>
* True or False <BOOLEAN>
*
* Example:
* [player] call cav_infantry_fnc_setCallsign
* [player] call cav_infantry_fnc_setUniqCallsign
*
* Public: No
*/

params [["_unit", objNull, [objNull]]];

if (isNull _unit) exitWith {};

private _classname = typeOf _unit;
private _group = group _unit;
private _currentID = groupId group _unit;

private _hashMap = [_unit] call FUNC(getUnitDesignation);
private _hashMap = [_unit] call FUNC(getDesignation);
private _regiment = _hashMap getOrDefault ["regiment", "0"];
if (_regiment == "0") exitWith {INFO_1("Regiment for %1 is not set, callsign not changed",_unit); false};

INFO_1("Attempting to set callsign for %1",_unit);
private _callsign = [_unit] call FUNC(getCallsign);
private _callsign = [_unit] call FUNC(getUnitCallsign);

// Check if the callsign is structured correctly CALLSIGN-1
private _callsignSplit = _callsign splitString "-";
if (count _callsignSplit != 2 ) exitWith {INFO_1("Uniq callsign not changed for %1",_unit); false};

// Check if your name is already set
if (_currentID == _callsign) exitWith {INFO_1("Uniq callsign for unit allready set %1",_unit); false};
if (_currentID == _callsign) exitWith {INFO_1("Uniq callsign for unit already set %1",_unit); false};

// Check if name correspon to callsign given
private _squad = _callsignSplit#1;
private _expectedSquad = _hashMap getOrDefault ["squad", "0"];

if (_squad != _expectedSquad) exitWith {INFO_1("Expected squad number value %1 don't match config %2",_expectedSquad,_squad); false};
if (_squad != _expectedSquad) exitWith {INFO_2("Expected squad number value %1 don't match config %2",_expectedSquad,_squad); false};

INFO_1("Units group callsign set to '%1'",_callsign);

[_group, _callsign] call CBA_fnc_setCallsign;

true
28 changes: 28 additions & 0 deletions addons/infantry/functions/fnc_setUnitTeam.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "..\script_component.hpp"
/*
* Author: SGT.Brostrom.A
* This function sets your team name based on your units prefix
*
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* Unit Callsign <STRING>
*
* Example:
* [player] call cav_infantry_fnc_setUnitTeam;
*
* Public: No
*/

params [["_unit", objNull, [objNull]]];

private _color = [_unit] call FUNC(getUnitTeam);

if (assignedTeam _unit == _color) exitWith {INFO_1("Team color for unit already set %1",_unit);false};

[_unit, _color] call ace_interaction_fnc_joinTeam;

INFO_2("%1 have joind team %2.", _unit, _color);

Check warning on line 26 in addons/infantry/functions/fnc_setUnitTeam.sqf

View workflow job for this annotation

GitHub Actions / hemtt

padding a macro argument

padding a macro argument

Check warning on line 26 in addons/infantry/functions/fnc_setUnitTeam.sqf

View workflow job for this annotation

GitHub Actions / hemtt

padding a macro argument

padding a macro argument

Check warning on line 26 in addons/infantry/functions/fnc_setUnitTeam.sqf

View workflow job for this annotation

GitHub Actions / hemtt

padding a macro argument

padding a macro argument

Check warning on line 26 in addons/infantry/functions/fnc_setUnitTeam.sqf

View workflow job for this annotation

GitHub Actions / hemtt

padding a macro argument

padding a macro argument

true
6 changes: 3 additions & 3 deletions addons/infantry_charlie_labeled/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CfgVehicles {
// First Platoon
UNIT_CHARLIE(Cav_B_C_PlatoonSergeant_1_5_F,Cav_B_C_PlatoonSergeant_F,1,5);
UNIT_CHARLIE(Cav_B_C_PlatoonLeader_1_6_F,Cav_B_C_PlatoonLeader_F,1,5);
UNIT_CHARLIE(Cav_B_C_PlatoonMedic_1_7_F,Cav_B_C_PlatoonMedic_F,1,5);
UNIT_CHARLIE(Cav_B_C_PlatoonMedic_1_7_F,Cav_B_C_PlatoonMedic_F,1,7);

// Squad 1-1-C-1/7
UNIT_CHARLIE(Cav_B_C_SquadLeader_1_1_F,Cav_B_C_SquadLeader_F,1,1);
Expand Down Expand Up @@ -77,8 +77,8 @@ class CfgVehicles {

// Second Platoon
UNIT_CHARLIE(Cav_B_C_PlatoonSergeant_2_5_F,Cav_B_C_PlatoonSergeant_F,2,5);
UNIT_CHARLIE(Cav_B_C_PlatoonLeader_2_6_F,Cav_B_C_PlatoonLeader_F,2,5);
UNIT_CHARLIE(Cav_B_C_PlatoonMedic_2_7_F,Cav_B_C_PlatoonMedic_F,2,5);
UNIT_CHARLIE(Cav_B_C_PlatoonLeader_2_6_F,Cav_B_C_PlatoonLeader_F,2,6);
UNIT_CHARLIE(Cav_B_C_PlatoonMedic_2_7_F,Cav_B_C_PlatoonMedic_F,2,7);

// Squad 1-2-C-1/7
UNIT_CHARLIE(Cav_B_C_SquadLeader_2_1_F,Cav_B_C_SquadLeader_F,2,1);
Expand Down

0 comments on commit 5c6da4b

Please sign in to comment.