-
Notifications
You must be signed in to change notification settings - Fork 158
Common - Add more loadout randomization options #1783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DartRuffian
wants to merge
19
commits into
CBATeam:master
Choose a base branch
from
DartRuffian:loadout-randomization
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
ae3ab2c
Add more loadout randomization
DartRuffian 4592eb6
Remove duplicate checks
DartRuffian af678b7
Fix issues from when moving to CBA
DartRuffian 68555a8
Remove (now) unused defines
DartRuffian 971763c
Fix loadout array
DartRuffian e635116
Change to Init, fix when slot is empty
DartRuffian b80ff6e
Slight rework
DartRuffian d1e2cc5
Add function to set unit's identity in Eden
DartRuffian 00f16cb
Update addons/common/XEH_init3DEN.sqf
DartRuffian a0815aa
Fix function names
DartRuffian ba4abb2
Update addons/common/fnc_setIdentity3DEN.sqf
DartRuffian 51def60
Fix zeus spawned units, remove function only called once
DartRuffian 1b76db6
Formatting
DartRuffian 57326c4
Combine ifs
DartRuffian faac7d9
Fix EH
DartRuffian c817e9b
Fix typo
DartRuffian 6dc1536
Delay eden fixAnimation
DartRuffian ecca769
Remove animation workaround
DartRuffian de22cf7
Deleted too much
DartRuffian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,64 @@ | ||
| #include "script_component.hpp" | ||
| /* ---------------------------------------------------------------------------- | ||
| Function: CBA_fnc_addRandomizedMagazines | ||
|
|
||
| Description: | ||
| Adds the randomized magazines for the weapon(s) added from CBA_fnc_randomizeLoadout. | ||
|
|
||
| Parameters: | ||
| _unit - unit <OBJECT> | ||
|
|
||
| Returns: | ||
| true on success, false on error <BOOLEAN> | ||
|
|
||
| Examples: | ||
| (begin example) | ||
| _unit call CBA_fnc_addRandomizedMagazines; | ||
| (end) | ||
|
|
||
| Author: | ||
| DartRuffian | ||
| ---------------------------------------------------------------------------- */ | ||
|
|
||
| #define INDEX_PRIMARY 0 | ||
| #define INDEX_LAUNCHER 1 | ||
| #define INDEX_HANDGUN 2 | ||
|
|
||
| params [["_unit", objNull, [objNull]]]; | ||
|
|
||
| if (isNull _unit) exitWith { | ||
| WARNING_1("Unit [%1] is null",_unit); | ||
| false | ||
| }; | ||
|
|
||
| // Disabled conditions | ||
| if (!local _unit) exitWith {true}; | ||
|
|
||
| private _cache = _unit call CBA_fnc_getRandomizedEquipment; | ||
|
|
||
| // Exit if unit has no randomization | ||
| if (!(_cache select 0)) exitWith { true }; | ||
| (_unit call CBA_fnc_getLoadout) params ["_loadout", "_extendedInfo"]; | ||
|
|
||
| { | ||
| // Handle mission maker changing weapons of units | ||
| private _weaponSlot = _loadout select _x; | ||
| if (_weaponSlot isEqualTo []) then { continue }; | ||
|
|
||
| private _weaponClass = _weaponSlot select 0; | ||
| private _weaponCache = (_cache select _x + 1); | ||
| if (_weaponCache isEqualTo []) then { continue }; | ||
|
|
||
| private _weaponIndex = _weaponCache findIf { _x param [0, ""] isEqualTo _weaponClass}; | ||
| if (_weaponIndex == -1) then { continue }; | ||
| _weaponCache = _weaponCache select _weaponIndex; | ||
| { | ||
| _x params ["_magazine", "_count"]; | ||
| for "_" from 2 to _count do { // 2 since one magazine is added in Eden | ||
| // Exit if magazine can't be added | ||
| if !([_unit, _magazine] call CBA_fnc_addMagazine) exitWith {}; | ||
| }; | ||
| } forEach (_weaponCache select 1); | ||
| } forEach [INDEX_PRIMARY, INDEX_LAUNCHER, INDEX_HANDGUN]; | ||
|
|
||
| true; |
This file contains hidden or 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,54 @@ | ||
| #include "script_component.hpp" | ||
| /* ---------------------------------------------------------------------------- | ||
| Function: CBA_fnc_getRandomizedEquipment | ||
| Description: | ||
| Gets a unit's randomized items. | ||
|
|
||
| Parameters: | ||
| _unit - Unit <OBJECT> | ||
|
|
||
| Returns: | ||
| Array of randomized items <ARRAY> | ||
|
|
||
| Examples | ||
| (begin example) | ||
| player call CBA_fnc_getRandomizedEquipment | ||
| (end) | ||
|
|
||
| Author: | ||
| DartRuffian | ||
| ---------------------------------------------------------------------------- */ | ||
|
|
||
| params ["_unit"]; | ||
| TRACE_1("fnc_getRandomizedEquipment",_unit); | ||
|
|
||
| CBA_common_randomLoadoutUnits getOrDefaultCall [typeOf _unit, { | ||
| private _unitConfig = configOf _unit; | ||
| private _primaryList = getArray (_unitConfig >> "CBA_primaryList"); | ||
| private _launcherList = getArray (_unitConfig >> "CBA_launcherList"); | ||
| private _handgunList = getArray (_unitConfig >> "CBA_handgunList"); | ||
| private _uniformList = getArray (_unitConfig >> "CBA_uniformList"); | ||
| private _vestList = getArray (_unitConfig >> "CBA_vestList"); | ||
| private _backpackList = getArray (_unitConfig >> "CBA_backpackList"); | ||
| private _headgearList = getArray (_unitConfig >> "CBA_headgearList"); | ||
| private _facewearList = getArray (_unitConfig >> "CBA_facewearList"); | ||
| private _binocularList = getArray (_unitConfig >> "CBA_binocularList"); | ||
| private _nvgList = getArray (_unitConfig >> "CBA_nvgList"); | ||
|
|
||
| // If all arrays are empty, just cache `[false]` to not save a bunch of empty arrays | ||
| if ( | ||
| [ | ||
| _primaryList, _launcherList, _handgunList, | ||
| _uniformList, _vestList, _backpackList, | ||
| _headgearList, _facewearList, _binocularList, | ||
| _nvgList | ||
| ] findIf { _x isEqualTo [] } >= -1 | ||
DartRuffian marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) then { | ||
| [ | ||
| true, _primaryList, _launcherList, | ||
| _handgunList, _uniformList, _vestList, | ||
| _backpackList, _headgearList, _facewearList, | ||
| _binocularList, _nvgList | ||
| ] | ||
| } else { [false] }; | ||
| }, true]; | ||
This file contains hidden or 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,147 @@ | ||
| #include "script_component.hpp" | ||
| /* ---------------------------------------------------------------------------- | ||
| Function: CBA_fnc_randomizeLoadout | ||
|
|
||
| Description: | ||
| Add config defined weighted random weapons, uniforms, vests, headgear, facewear, etc. to a unit. | ||
|
|
||
| CBA_headgearList[] = {}; // default: Use `linkedItems` property | ||
| CBA_headgearList[] = {"H_HelmetHBK_headset_F", 1, "H_HelmetHBK_chops_F", 1}; // 50% headset, 50% chops | ||
|
|
||
| CBA_primaryList[] = { | ||
| // 50% chance for AK-12, with 2 30Rnd magazines and 2 75Rnd magazines | ||
| // 50% chance for hunter shotgun with 3 12 gauge magazines | ||
| {"arifle_AK12_F", {{"30Rnd_762x39_AK12_Mag_F", 2}, {"75Rnd_762x39_Mag_F", 2}}}, 1, | ||
| {"sgun_HunterShotgun_01_F", {{"2Rnd_12Gauge_Pellets", 3}}}, 1 | ||
| }; | ||
|
|
||
| Parameters: | ||
| _unit - unit <OBJECT> | ||
|
|
||
| Returns: | ||
| true on success, false on error <BOOLEAN> | ||
|
|
||
| Examples: | ||
| (begin example) | ||
| [unit] call CBA_fnc_randomizeLoadout; | ||
| (end) | ||
|
|
||
| Author: | ||
| DartRuffian | ||
| ---------------------------------------------------------------------------- */ | ||
|
|
||
| #define INDEX_UNIFORM 3 | ||
| #define INDEX_VEST 4 | ||
| #define INDEX_BACKPACK 5 | ||
| #define INDEX_HELMET 6 | ||
| #define INDEX_FACEWEAR 7 | ||
| #define INDEX_BINOCULARS 8 | ||
| #define INDEX_LINKEDITEMS 9 | ||
|
|
||
| // Note that this is specifically for a loadout array | ||
| #define INDEX_NVG 5 | ||
|
|
||
| params [["_unit", objNull, [objNull]]]; | ||
|
|
||
| if (isNull _unit) exitWith { | ||
| WARNING_1("Unit [%1] is null",_unit); | ||
| false | ||
| }; | ||
|
|
||
| // Disabled conditions | ||
| if (!local _unit) exitWith {true}; | ||
|
|
||
| private _randomizationDisabled = getArray (missionConfigFile >> "disableRandomization") findIf { | ||
| _unit isKindOf _x || {(vehicleVarName _unit) isEqualTo _x} | ||
| } != -1; | ||
DartRuffian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (_randomizationDisabled || {!(_unit getVariable ["BIS_enableRandomization", true])}) exitWith { true }; | ||
|
|
||
| private _cache = _unit call CBA_fnc_getRandomizedEquipment; | ||
|
|
||
| // Exit if unit has no randomization | ||
| if (!(_cache select 0)) exitWith { true }; | ||
| _cache params ["", "_primaryList", "_launcherList", "_handgunList", "_uniformList", "_vestList", "_backpackList", "_headgearList", "_facewearList", "_binocularList", "_nvgList"]; | ||
|
|
||
| (_unit call CBA_fnc_getLoadout) params ["_loadout", "_extendedInfo"]; | ||
|
|
||
| { | ||
| _x params ["_loadoutIndex", "_items"]; | ||
| if (_items isEqualTo []) then { continue }; | ||
|
|
||
| _loadout set [_loadoutIndex, selectRandomWeighted _items]; | ||
| } forEach [ | ||
| [INDEX_HELMET, _headgearList], | ||
| [INDEX_FACEWEAR, _facewearList] | ||
| ]; | ||
|
|
||
| { | ||
| _x params ["_loadoutIndex", "_items"]; | ||
| if (_items isEqualTo []) then { continue }; | ||
|
|
||
| // Handle no item being equipped in the current slot, e.g. ["UniformClass"] would be invalid | ||
| private _section = _loadout select _loadoutIndex; | ||
| if (_section isEqualTo []) then { _section = ["", []] }; | ||
|
|
||
| _section set [0, selectRandomWeighted _items]; | ||
| _loadout set [_loadoutIndex, _section]; | ||
| } forEach [ | ||
| [INDEX_UNIFORM, _uniformList], | ||
| [INDEX_VEST, _vestList], | ||
| [INDEX_BACKPACK, _backpackList] | ||
| ]; | ||
|
|
||
| if (_nvgList isNotEqualTo []) then { | ||
| _loadout select INDEX_LINKEDITEMS set [INDEX_NVG, selectRandomWeighted _nvgList]; | ||
| }; | ||
|
|
||
| // Set loadout and then add weapons to avoid issues with conflicting weapon items | ||
| [_unit, [_loadout, _extendedInfo]] call CBA_fnc_setLoadout; | ||
|
|
||
| if (_binocularList isNotEqualTo []) then { | ||
| private _item = selectRandomWeighted _binocularList; | ||
| private _magazine = (_item call CBA_fnc_compatibleMagazines) param [0, ""]; // For laser designators | ||
| _unit addWeapon _item; | ||
| if (_magazine != "") then { | ||
DartRuffian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| _unit addBinocularItem _magazine | ||
| }; | ||
| }; | ||
|
|
||
| { | ||
| private _items = _x; | ||
| if (_items isEqualTo []) then { continue }; | ||
|
|
||
| // Add a single magazine so the gun is pre-loaded | ||
| // The rest of the magazines are added in PostInit to preserve changes made in Eden | ||
| (selectRandomWeighted _items) params ["_weapon", "_magazineCounts"]; | ||
| [_unit, _magazineCounts select 0 select 0] call CBA_fnc_addMagazine; | ||
| _unit addWeapon _weapon; | ||
| } forEach [ | ||
| _primaryList, | ||
| _launcherList, | ||
| _handgunList | ||
| ]; | ||
|
|
||
| // Immediately select weapon and set animation | ||
| private _fnc_fixAnimation = { | ||
| private _weapons = [primaryWeapon _this, handgunWeapon _this, secondaryWeapon _this]; | ||
| private _weaponIndex = _weapons findIf { _x != "" }; | ||
| if (_weaponIndex != -1) then { | ||
| _this switchMove (["amovpercmstpsraswrfldnon", "amovpercmstpsraswpstdnon", "amovpercmstpsnonwnondnon"] select _weaponIndex); | ||
| _this selectWeapon (_weapons select _weaponIndex); | ||
| }; | ||
| }; | ||
|
|
||
| if (is3DEN) then { | ||
| // CBA's frame functions don't work in Eden | ||
| [_unit, _fnc_fixAnimation] spawn { | ||
| sleep 0.1; | ||
| params ["_unit", "_function"]; | ||
| save3DENInventory [get3DENEntityID _unit]; | ||
| _unit call _function; | ||
| }; | ||
| } else { | ||
| [_fnc_fixAnimation, _unit] call CBA_fnc_execNextFrame; | ||
| }; | ||
DartRuffian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| true; | ||
This file contains hidden or 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,51 @@ | ||
| #include "script_component.hpp" | ||
| /* ---------------------------------------------------------------------------- | ||
| Function: CBA_fnc_setIdentity3DEN | ||
| Description: | ||
| Sets Eden attributes relating to the given identity. | ||
|
|
||
| Parameters: | ||
| _unit - Unit <OBJECT> | ||
| _identity - Class in CfgIdentities (optional, defaults to CBA_identity property in unit's config) <STRING> | ||
|
|
||
| Returns: | ||
| None | ||
|
|
||
| Examples | ||
| (begin example) | ||
| _unit call CBA_fnc_setIdentity3DEN | ||
| (end) | ||
|
|
||
| Author: | ||
| DartRuffian | ||
| ---------------------------------------------------------------------------- */ | ||
|
|
||
| params ["_unit", ["_identity", ""]]; | ||
| TRACE_2("fnc_setIdentity3DEN",_unity,_identity); | ||
|
|
||
| if (_identity == "") then { | ||
DartRuffian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| _identity = getText (configOf _unit >> "CBA_identity"); | ||
| }; | ||
|
|
||
| if (_identity == "") exitWith {}; | ||
DartRuffian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private _identityConfig = configFile >> "CfgIdentities" >> _identity; | ||
| if !(is3DEN && isClass _identityConfig) exitWith {}; | ||
|
|
||
| private _name = getText (_identityConfig >> "name"); | ||
| private _nameSound = getText (_identityConfig >> "nameSound"); | ||
| private _face = getText (_identityConfig >> "face"); | ||
| private _glasses = getText (_identityConfig >> "glasses"); | ||
| private _pitch = getNumber (_identityConfig >> "pitch"); | ||
| private _speaker = getText (_identityConfig >> "speaker"); | ||
|
|
||
| _unit set3DENAttribute ["unitName", _name]; | ||
| _unit set3DENAttribute ["NameSound", _nameSound]; | ||
| _unit set3DENAttribute ["face", _face]; | ||
| _unit set3DENAttribute ["pitch", _pitch]; | ||
| _unit set3DENAttribute ["speaker", _speaker]; | ||
|
|
||
| if (_glasses != "") then { | ||
DartRuffian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| _unit addGoggles _glasses; | ||
| save3DENInventory [get3DENEntityID _unit]; | ||
| }; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if there's a more proper way to do this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
xeh_postInit won't run on 3den (for now at least)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check is so units spawned in Eden don't have their kits randomized again, but units spawned later (e.g. script / zeus) do
Without the missionTime check Eden placed units would have their loadouts randomized on mission start