-
-
Notifications
You must be signed in to change notification settings - Fork 153
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
Add UI and supporting code to set custom loadouts for rebel troops #3392
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copy-paste of an inactive code path (the function is never called on units with weapons at the moment), so I won't be touching it for now. The code's quite wrong for other reasons because it doesn't consider magazine wells. Not sure how I missed removeMagazineGlobal though. |
||||||||||||
_unit removeWeapon (primaryWeapon _unit); | ||||||||||||
}; | ||||||||||||
|
||||||||||||
private _categories = _weapon call A3A_fnc_equipmentClassToCategories; | ||||||||||||
|
||||||||||||
if ("GrenadeLaunchers" in _categories && {"Rifles" in _categories} ) then { | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
In my testing, the old seemed to average 20ms, while the new 15. Also the new one is way cleaner. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's wrong though. Should be comparing to -1 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I only just now realized that mistake, which you beat me to. I keep forgetting this thing doesn't return boolean. Fixed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still wrong. It's an AND, while findAny can only do an OR. |
||||||||||||
// 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) }; |
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"); |
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"; |
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.
// TODO: Localize
Or just localize it yourself.