forked from Bob-Murphy/A3-Antistasi-1.4
-
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add UI and supporting code to set custom loadouts for rebel troops (#…
…3392) * Add UI and supporting code to set custom loadouts for rebel troops * Fix recruit-spam bug
- Loading branch information
Showing
20 changed files
with
660 additions
and
129 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
68 changes: 68 additions & 0 deletions
68
A3A/addons/core/functions/Ammunition/fn_addPrimaryAndMags.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,68 @@ | ||
/* | ||
Equip rebel unit with primary weapon or handgun | ||
Adds magazines by mass. Uses default magazine of selected weapon | ||
Parameters: | ||
0. <OBJECT> Rebel unit to equip with primary weapon. | ||
1. <STRING> Weapon classname | ||
2. <STRING> Optic type preference ("OpticsClose", "OpticsMid", "OpticsLong") | ||
3. <NUMBER> Total mass of primary magazines to add to inventory. | ||
4. <NUMBER> Optional: Number of GL mags to add if secondary. | ||
Returns: | ||
Nothing | ||
Environment: | ||
Scheduled, any machine | ||
*/ | ||
|
||
#include "..\..\script_component.hpp" | ||
FIX_LINE_NUMBERS() | ||
|
||
params ["_unit", "_weapon", "_opticType", "_totalMagWeight", ["_glMags", 5]]; | ||
|
||
call A3A_fnc_fetchRebelGear; // Send current version of rebelGear from server if we're out of date | ||
|
||
// Probably shouldn't ever be executed | ||
if !(primaryWeapon _unit isEqualTo "") then { | ||
if (_weapon == primaryWeapon _unit) exitWith {}; | ||
private _magazines = getArray (configFile / "CfgWeapons" / (primaryWeapon _unit) / "magazines"); | ||
{_unit removeMagazines _x} forEach _magazines; // Broken, doesn't remove mags globally. Pain to fix. | ||
_unit removeWeapon (primaryWeapon _unit); | ||
}; | ||
|
||
private _categories = _weapon call A3A_fnc_equipmentClassToCategories; | ||
|
||
if ("GrenadeLaunchers" in _categories && {"Rifles" in _categories} ) then { | ||
// lookup real underbarrel GL magazine, because not everything is 40mm | ||
private _config = configFile >> "CfgWeapons" >> _weapon; | ||
private _glmuzzle = getArray (_config >> "muzzles") select 1; // guaranteed by category | ||
_glmuzzle = configName (_config >> _glmuzzle); // bad-case fix. compatibleMagazines is case-sensitive as of 2.12 | ||
private _glmag = compatibleMagazines [_weapon, _glmuzzle] select 0; | ||
_unit addMagazines [_glmag, 5]; | ||
}; | ||
|
||
private _magazine = compatibleMagazines _weapon select 0; | ||
private _magweight = 5 max getNumber (configFile >> "CfgMagazines" >> _magazine >> "mass"); | ||
|
||
_unit addWeapon _weapon; | ||
if ("Handguns" in _categories) then { | ||
_unit addHandgunItem _magazine; | ||
} else { | ||
_unit addPrimaryWeaponItem _magazine; | ||
}; | ||
_unit addMagazines [_magazine, round (random 0.5 + _totalMagWeight / _magWeight)]; | ||
|
||
|
||
private _compatOptics = A3A_rebelOpticsCache get _weapon; | ||
if (isNil "_compatOptics") then { | ||
private _compatItems = compatibleItems _weapon; | ||
|
||
_compatOptics = _compatItems arrayIntersect (A3A_rebelGear get _opticType); | ||
if (_compatOptics isEqualTo [] and _opticType != "OpticsClose") then { | ||
private _fallbackType = ["OpticsClose", "OpticsMid"] select (_opticType == "OpticsLong"); | ||
_compatOptics = _compatItems arrayIntersect (A3A_rebelGear get _fallbackType); | ||
}; | ||
A3A_rebelOpticsCache set [_weapon, _compatOptics]; | ||
}; | ||
if (_compatOptics isNotEqualTo []) then { _unit addPrimaryWeaponItem (selectRandom _compatOptics) }; |
31 changes: 21 additions & 10 deletions
31
A3A/addons/core/functions/Ammunition/fn_fetchRebelGear.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 |
---|---|---|
@@ -1,24 +1,35 @@ | ||
/* | ||
Ensures A3A_rebelGear and related caches are valid and updated for equipping rebel AIs | ||
Ensures A3A_rebelGear, A3A_rebelLoadouts and related caches are locally valid and updated for equipping rebel AIs | ||
Parameters: | ||
None, returns nothing | ||
Environment: | ||
Scheduled, executed anywhere | ||
Scheduled, executed locally | ||
*/ | ||
|
||
#include "..\..\script_component.hpp" | ||
FIX_LINE_NUMBERS() | ||
|
||
// Send current version of rebelGear from server if we're out of date | ||
if (!isNil "A3A_rebelGear" and { A3A_rebelGear get "Version" == A3A_rebelGearVersion}) exitWith {}; | ||
private _updateGear = isNil "A3A_rebelGear" or { A3A_rebelGear get "Version" != A3A_rebelGearVersion }; | ||
private _updateLoadouts = isNil "A3A_rebelLoadouts" or { A3A_rebelLoadouts get "Version" != A3A_rebelLoadoutsVersion }; | ||
if !(_updateGear or _updateLoadouts) exitWith {}; | ||
|
||
Info("Fetching new version of rebelGear data..."); | ||
[clientOwner, "A3A_rebelGear"] remoteExecCall ["publicVariableClient", 2]; | ||
waitUntil { sleep 1; !isNil "A3A_rebelGear" and { A3A_rebelGear get "Version" == A3A_rebelGearVersion } }; | ||
Info("New version of rebelGear data received"); | ||
if (_updateGear) then { | ||
// Create/clear local accessory-compatibility caches | ||
A3A_rebelOpticsCache = createHashMap; | ||
A3A_rebelFlashlightsCache = createHashMap; | ||
|
||
// Create/clear local accessory-compatibility caches | ||
A3A_rebelOpticsCache = createHashMap; | ||
A3A_rebelFlashlightsCache = createHashMap; | ||
Info("Fetching new version of rebelGear data..."); | ||
[clientOwner, "A3A_rebelGear"] remoteExecCall ["publicVariableClient", 2]; | ||
}; | ||
if (_updateLoadouts) then { | ||
Info("Fetching new version of rebelLoadouts data..."); | ||
[clientOwner, "A3A_rebelLoadouts"] remoteExecCall ["publicVariableClient", 2]; | ||
}; | ||
waitUntil { sleep 0.5; | ||
!isNil "A3A_rebelGear" and { A3A_rebelGear get "Version" == A3A_rebelGearVersion } | ||
and !isNil "A3A_rebelLoadouts" and { A3A_rebelLoadouts get "Version" == A3A_rebelLoadoutsVersion }; | ||
}; | ||
Info("New version of rebelGear data received"); |
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
17 changes: 17 additions & 0 deletions
17
A3A/addons/core/functions/Ammunition/fn_setRebelLoadouts.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,17 @@ | ||
/* | ||
Writes custom rebel loadouts structure & updates version number | ||
Parameters: | ||
<HASHMAP> Custom rebel loadouts structure | ||
Environment: | ||
Unscheduled, server | ||
*/ | ||
|
||
params ["_newLoadouts"]; | ||
|
||
A3A_rebelLoadoutsVersion = time; | ||
_newLoadouts set ["Version", A3A_rebelLoadoutsVersion]; | ||
A3A_rebelLoadouts = _newLoadouts; | ||
|
||
publicVariable "A3A_rebelLoadoutsVersion"; |
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
Oops, something went wrong.