-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] - Add Gearscript ACE gun-bag support. (#102)
* Part 1 - added "SET_GUNBAG_CONTENTS" macro and underlying variable setter. * Full gunbag support including forcing gunbag state onto regular backpacks. Examples placed into default gearscripts. Fixed globals ordering bug (was after preinit config group).
- Loading branch information
Showing
19 changed files
with
217 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "macros.hpp" | ||
|
||
params ["_unit", "_typeofUnit", "_gearVariant"]; | ||
|
||
_gearVariant = toLower _gearVariant; | ||
_typeofUnit = toLower _typeofUnit; | ||
|
||
private _gunbagContents = GUNBAG_ITEM_DYNAMIC(_gearVariant,_typeofUnit); | ||
private _gunbagVariableValue = []; | ||
|
||
if !(_gunbagContents isEqualTo []) then | ||
{ | ||
_gunbagContents params ["_attachments", "_muzzles", "_magazines", "_ammo", "_baseWeapon"]; | ||
|
||
private _gunbagMags = []; | ||
{ | ||
_gunbagMags pushBack [_x, _ammo # _forEachIndex]; | ||
|
||
} forEach _magazines; | ||
|
||
_gunbagVariableValue = | ||
[ | ||
_baseWeapon, | ||
_attachments, | ||
_gunbagMags | ||
]; | ||
}; | ||
|
||
// Wait a short while and apply gunbag contents. Avoids issue on spawn where ACE can potentially override intended value. | ||
[ | ||
// Script | ||
{ | ||
params ["_unit", "_contents"]; | ||
|
||
if (_contents isEqualTo []) then | ||
{ | ||
_contents = nil; | ||
}; | ||
|
||
(backpackContainer _unit) setVariable ["ace_gunbag_gunbagWeapon", _contents, true]; | ||
}, | ||
|
||
// Arguments | ||
[_unit, _gunbagVariableValue], | ||
|
||
// Delay | ||
0.5 | ||
|
||
] call CBA_fnc_waitAndExecute; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
private _keyValues = | ||
[ | ||
["LinkedItemsMuzzle", 0], | ||
["LinkedItemsAcc", 1], | ||
["LinkedItemsOptic", 2], | ||
["LinkedItemsUnder", 3] | ||
]; | ||
|
||
f_arr_gunbagAttachmentsMap = createHashMapFromArray _keyValues; |
32 changes: 32 additions & 0 deletions
32
components/gearScript/gunbag/fn_getWeaponStateFromClassName.sqf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Derived from ace_common_fnc_getWeaponState. Used to get a 'getWeaponState' array from a weapon config string. | ||
// Augments the standard 'getWeaponState' array by returning the base weapon name as a 5th field. | ||
// Currently ignores configured default magazines. Arrays returned from this function will have no ammo. | ||
|
||
params [["_weapon", nil, [""]]]; | ||
if (isNil "_weapon") throw "_weapon must not be nil."; | ||
|
||
private _weaponClass = configFile >> "CfgWeapons" >> _weapon; | ||
if (isNil "_weapon") then {throw format ["_weapon (%1) must be a subclass of CfgWeapons.", _weapon]}; | ||
|
||
private _baseWeapon = getText (_weaponClass >> "baseWeapon"); | ||
|
||
private _attachments = ["","","",""]; | ||
private _linkedItems = _weaponClass >> "LinkedItems"; | ||
private _linkedItemsSubclasses = _linkedItems call BIS_fnc_getCfgSubClasses; | ||
|
||
{ | ||
private _entry = _linkedItems >> _x; | ||
private _index = f_arr_gunbagAttachmentsMap get _x; | ||
|
||
if !(isNil "_index") then | ||
{ | ||
private _attachmentName = getText (_entry >> "item"); | ||
_attachments set [_index, _attachmentName]; | ||
}; | ||
} foreach _linkedItemsSubclasses; | ||
|
||
private _muzzles = _weapon call ace_common_fnc_getWeaponMuzzles; | ||
private _magazines = _muzzles apply {""}; | ||
private _ammo = _muzzles apply {0}; | ||
|
||
[_attachments, _muzzles, _magazines, _ammo, _baseWeapon]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Override of ace_gunbag_fnc_hasGunbag, to allow any backpack to be a gunbag if it has the gunbag variable set. | ||
|
||
params ["_unit"]; | ||
|
||
(getNumber (configFile >> "CfgVehicles" >> (backpack _unit) >> "ace_gunbag") == 1) or | ||
{ | ||
((backpackContainer _unit) getVariable ["ace_gunbag_gunbagWeapon", []]) isNotEqualTo [] | ||
} |
43 changes: 43 additions & 0 deletions
43
components/gearScript/gunbag/fn_setGunbagVariableFromArsenalExport.sqf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include "macros.hpp" | ||
|
||
// Used by gearscript to set the state of a unit's gunbag global variable. | ||
// Provide an ACE Arsenal export array ("Unit Loadout Array"), or a string representing the weapon's CfgWeapons classname. | ||
|
||
params ["_faction", "_unitName", ["_contents", nil, [[], ""]]]; | ||
|
||
if (isNil "_contents") then {throw format ["_contents for gunbag contents must not be nil. (unit %1, side %2).", _unitName, _faction]}; | ||
|
||
if (typeName _contents isEqualTo "STRING") exitWith | ||
{ | ||
[_faction, _unitName, _contents] call f_fnc_setGunbagVariableState; | ||
}; | ||
|
||
if (count _contents < 1) then {throw format ["_contents for gunbag contents is empty. (unit %1, side %2).", _unitName, _faction]}; | ||
|
||
private _rifle = _contents # 0; | ||
|
||
private _isRifleWellFormed = _rifle params | ||
[ | ||
["_rifleClass", nil, [""]], | ||
["_muzzleDevice", nil, [""]], | ||
["_sideRailDevice", nil, [""]], | ||
["_optic", nil, [""]], | ||
["_muzzle1Mag", nil, [[]]], | ||
["_muzzle2Mag", nil, [[]]], | ||
["_bipod", nil, [""]] | ||
]; | ||
|
||
if !(_isRifleWellFormed) then {throw format ["_contents for gunbag contents contained an invalid rifle. Please re-export the loadout. (unit %1, side %2).", _unitName, _faction]}; | ||
|
||
private _magsArray = [_muzzle1Mag, _muzzle2Mag] select {_x isNotEqualTo []}; | ||
|
||
private _contents = | ||
[ | ||
[_muzzleDevice, _sideRailDevice, _optic, _bipod], | ||
_rifleClass call ace_common_fnc_getWeaponMuzzles, | ||
_magsArray apply {_x # 0}, | ||
_magsArray apply {_x # 1}, | ||
_rifleClass | ||
]; | ||
|
||
SET_GUNBAG_CONTENTS(_faction,_unitName,_contents); |
12 changes: 12 additions & 0 deletions
12
components/gearScript/gunbag/fn_setGunbagVariableState.sqf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include "macros.hpp" | ||
|
||
// Used by gearscript to set the state of a unit's gunbag global variable. | ||
// Should a string representing the weapon's CfgWeapons classname. | ||
|
||
params ["_faction", "_unitName", ["_contents", nil, [""]]]; | ||
|
||
if (isNil "_contents") throw "_contents must not be nil."; | ||
|
||
private _weaponState = [_contents] call f_fnc_getWeaponStateFromClassName; | ||
|
||
SET_GUNBAG_CONTENTS(_faction,_unitName,_weaponState); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "../macros.hpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ | |
|
||
LOAD_GLOBALS(miscShared) | ||
|
||
LOAD_GLOBALS(gearScript) | ||
|
||
|
||
// Kill tracker init | ||
#ifdef ENABLE_KILL_TRACKING | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters