Skip to content
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

CSW - Handle turret locality safer #10272

Merged
merged 4 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/common/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ if (isServer) then {
[QGVAR(switchMove), {(_this select 0) switchMove (_this select 1)}] call CBA_fnc_addEventHandler;
[QGVAR(setVectorDirAndUp), {(_this select 0) setVectorDirAndUp (_this select 1)}] call CBA_fnc_addEventHandler;
[QGVAR(addWeaponItem), {(_this select 0) addWeaponItem [(_this select 1), (_this select 2)]}] call CBA_fnc_addEventHandler;
[QGVAR(addMagazineTurret), {(_this select 0) addMagazineTurret (_this select 1)}] call CBA_fnc_addEventHandler;
[QGVAR(removeMagazinesTurret), {(_this select 0) removeMagazinesTurret [_this select 1, _this select 2]}] call CBA_fnc_addEventHandler;
[QGVAR(triggerAmmo), {triggerAmmo _this}] call CBA_fnc_addEventHandler;

Expand Down
5 changes: 5 additions & 0 deletions addons/csw/functions/fnc_proxyWeapon.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
params ["_vehicle", "_turret", "_needed", "_emptyWeapon"];
TRACE_4("proxyWeapon",_vehicle,_turret,_needed,_emptyWeapon);

// addWeaponTurret/removeWeaponTurret need to be executed where turret is local
if !(_vehicle turretLocal _turret) exitWith {
WARNING_2("[%1]'s turret [%2] isn't local, skipping proxy weapon change",_vehicle,_turret);
};

if (_vehicle getVariable [format [QGVAR(proxyHandled_%1), _turret], false]) exitWith { TRACE_1("already handled",typeOf _vehicle); };

private _proxyWeapon = getText (configOf _vehicle >> QUOTE(ADDON) >> "proxyWeapon");
Expand Down
8 changes: 5 additions & 3 deletions addons/csw/functions/fnc_staticWeaponInit_unloadExtraMags.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ private _containerMagazineCount = [];

TRACE_1("Remove all loaded magazines",_magsToRemove);
{
_vehicle removeMagazinesTurret _x;
[QEGVAR(common,removeMagazinesTurret), [_vehicle, _x select 0, _x select 1], _vehicle, _x select 1] call CBA_fnc_turretEvent;

if ((_loadedMagazineInfo select [0,2]) isEqualTo _x) then {
TRACE_1("Re-add the starting mag",_loadedMagazineInfo);
_vehicle addMagazineTurret _loadedMagazineInfo;

[QEGVAR(common,addMagazineTurret), [_vehicle, _loadedMagazineInfo], _vehicle, _x select 1] call CBA_fnc_turretEvent;
};
} forEach _magsToRemove;

Expand All @@ -83,7 +85,7 @@ if (_secondaryWeaponMagazines isNotEqualTo []) then {

// If the magazine can be added to the static weapon, do it now
if (_vehicleMag in _compatibleMagazinesTurret) then {
_vehicle addMagazineTurret [_vehicleMag, _turret, _x select 1];
[QEGVAR(common,addMagazineTurret), [_vehicle, [_vehicleMag, _turret, _x select 1]], _vehicle, _turret] call CBA_fnc_turretEvent;
} else {
// Find a suitable container to place items in if necessary
if (isNull _container) then {
Expand Down