From bdc5e54f553250e9d8dfd13a330450a83269e4be Mon Sep 17 00:00:00 2001 From: IngoKauffmann Date: Wed, 19 Aug 2015 17:33:32 +0200 Subject: [PATCH] Fixed turret locality and driver empty magazine issues --- addons/rearm/CfgAmmo.hpp | 2 +- addons/rearm/XEH_preInit.sqf | 3 ++ .../rearm/functions/fnc_addRearmActions.sqf | 11 ++-- .../functions/fnc_getConfigMagazines.sqf | 53 +++++++++++++++++++ .../rearm/functions/fnc_getMaxMagazines.sqf | 32 +---------- .../functions/fnc_getNeedRearmMagazines.sqf | 9 +++- .../fnc_rearmEntireVehicleSuccess.sqf | 16 +++--- .../fnc_rearmEntireVehicleSuccessLocal.sqf | 20 ++++--- addons/rearm/functions/fnc_rearmSuccess.sqf | 8 ++- 9 files changed, 99 insertions(+), 55 deletions(-) create mode 100644 addons/rearm/functions/fnc_getConfigMagazines.sqf diff --git a/addons/rearm/CfgAmmo.hpp b/addons/rearm/CfgAmmo.hpp index e611293164..2e5e0ee7e8 100644 --- a/addons/rearm/CfgAmmo.hpp +++ b/addons/rearm/CfgAmmo.hpp @@ -32,7 +32,7 @@ class CfgAmmo { GVAR(dummy) = QGVAR(Rocket_03_AP_F); }; class M_PG_AT : MissileBase { - GVAR(caliber) = 100; + GVAR(caliber) = 70; GVAR(dummy) = QGVAR(M_PG_AT); }; class Missile_AGM_02_F : MissileBase { diff --git a/addons/rearm/XEH_preInit.sqf b/addons/rearm/XEH_preInit.sqf index e11166c74c..9b01018a2a 100644 --- a/addons/rearm/XEH_preInit.sqf +++ b/addons/rearm/XEH_preInit.sqf @@ -5,6 +5,7 @@ ADDON = false; PREP(addRearmActions); PREP(canPickupAmmo); PREP(canRearm); +PREP(getConfigMagazines); PREP(getMaxMagazines); PREP(getNeedRearmMagazines); PREP(handleKilled); @@ -16,6 +17,8 @@ PREP(pickUpSuccess); PREP(rearm); PREP(rearmEntireVehicle); PREP(rearmEntireVehicleSuccess); +PREP(rearmEntireVehicleSuccessLocal); PREP(rearmSuccess); +PREP(rearmSuccessLocal); ADDON = true; diff --git a/addons/rearm/functions/fnc_addRearmActions.sqf b/addons/rearm/functions/fnc_addRearmActions.sqf index a8bd6b7382..7bcb9b939a 100644 --- a/addons/rearm/functions/fnc_addRearmActions.sqf +++ b/addons/rearm/functions/fnc_addRearmActions.sqf @@ -18,7 +18,7 @@ private ["_vehicleActions", "_actions", "_action", "_vehicles", "_vehicle", "_needToAdd", "_magazineHelper", "_turretPath", "_magazines", "_magazine", "_icon", "_cnt"]; params ["_target"]; -_vehicles = nearestObjects [_target, ["AllVehicles"], 20]; +_vehicles = nearestObjects [_target, ["AllVehicles"], 20]; // FIXME remove players if (count _vehicles < 2) exitWith {false}; // Rearming needs at least 2 vehicles _vehicleActions = []; @@ -27,11 +27,16 @@ _vehicleActions = []; _vehicle = _x; _needToAdd = false; _action = []; - if !(_vehicle == _target) then { + if !((_vehicle == _target) || (_vehicle isKindOf "CAManBase")) then { _magazineHelper = []; { _turretPath = _x; - _magazines = _vehicle magazinesTurret _turretPath; + _magazines = []; + if (_turretPath isEqualTo [-1]) then { + _magazines = [_vehicle, _turretPath] call FUNC(getConfigMagazines); + } else { + _magazines = _vehicle magazinesTurret _turretPath; + }; { _magazine = _x; _cnt = { _x == _magazine } count (_vehicle magazinesTurret _turretPath); diff --git a/addons/rearm/functions/fnc_getConfigMagazines.sqf b/addons/rearm/functions/fnc_getConfigMagazines.sqf new file mode 100644 index 0000000000..de75d24415 --- /dev/null +++ b/addons/rearm/functions/fnc_getConfigMagazines.sqf @@ -0,0 +1,53 @@ +/* + * Author: GitHawk, Jonpas + * Returns all magazines a turret can hold according to config. + * + * Arguments: + * 0: Target + * 1: Turret Path + * + * Return Value: + * Magazine classes in TurretPath + * + * Example: + * [vehicle, [0]] call ace_rearm_fnc_getMaxMagazines + * + * Public: No + */ +#include "script_component.hpp" + +params ["_target", "_turretPath"]; + +if (isNull _target) exitWith {[]}; + +_cfg = configFile >> "CfgVehicles" >> (typeOf _target) >> "Turrets"; + +if (count _turretPath == 1) then { + _turretPath params ["_subPath"]; + + if (_subPath == -1) exitWith { + _cfg = configFile >> "CfgVehicles" >> (typeOf _target); + }; + + if (count _cfg > _subPath) then { + _cfg = _cfg select _subPath; + } else { + _cfg = nil; + }; +} else { + _turretPath params ["", "_subPath"]; + if (count _cfg > 0) then { + _cfg = (_cfg select 0) >> "Turrets"; + if (count _cfg > _subPath) then { + _cfg = _cfg select _subPath; + } else { + _cfg = nil; + }; + } else { + _cfg = nil; + }; +}; + +if !(isClass _cfg) exitWith {[]}; + +getArray (_cfg >> "magazines") diff --git a/addons/rearm/functions/fnc_getMaxMagazines.sqf b/addons/rearm/functions/fnc_getMaxMagazines.sqf index b9655f1c69..4f67d2ab70 100644 --- a/addons/rearm/functions/fnc_getMaxMagazines.sqf +++ b/addons/rearm/functions/fnc_getMaxMagazines.sqf @@ -22,35 +22,5 @@ params ["_target", "_turretPath", "_magazine"]; if (isNull _target) exitWith {0}; -_cfg = configFile >> "CfgVehicles" >> (typeOf _target) >> "Turrets"; - -if (count _turretPath == 1) then { - _turretPath params ["_subPath"]; - - if (_subPath == -1) exitWith { - _cfg = configFile >> "CfgVehicles" >> (typeOf _target); - }; - - if (count _cfg > _subPath) then { - _cfg = _cfg select _subPath; - } else { - _cfg = nil; - }; -} else { - _turretPath params ["", "_subPath"]; - if (count _cfg > 0) then { - _cfg = (_cfg select 0) >> "Turrets"; - if (count _cfg > _subPath) then { - _cfg = _cfg select _subPath; - } else { - _cfg = nil; - }; - } else { - _cfg = nil; - }; -}; - -if !(isClass _cfg) exitWith {0}; - -_count = {_x == _magazine} count getArray (_cfg >> "magazines"); +_count = {_x == _magazine} count ([_target, _turretPath] call FUNC(getConfigMagazines)); _count diff --git a/addons/rearm/functions/fnc_getNeedRearmMagazines.sqf b/addons/rearm/functions/fnc_getNeedRearmMagazines.sqf index 62beddcd46..7a591c6c32 100644 --- a/addons/rearm/functions/fnc_getNeedRearmMagazines.sqf +++ b/addons/rearm/functions/fnc_getNeedRearmMagazines.sqf @@ -24,10 +24,15 @@ params ["_target", "_magazineClass"]; _return = [false, [], 0]; { - _magazines = _target magazinesTurret _x; + _magazines = []; + if (_x isEqualTo [-1]) then { + _magazines = [_target, _x] call FUNC(getConfigMagazines); + } else { + _magazines = _target magazinesTurret _x; + }; if (_magazineClass in _magazines) then { - _cnt = {_x == _magazineClass} count _magazines; + _cnt = {_x == _magazineClass} count (_target magazinesTurret _x); if ((_target magazineTurretAmmo [_magazineClass, _x]) < getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "count")) exitWith { _return = [true, _x, _cnt]; diff --git a/addons/rearm/functions/fnc_rearmEntireVehicleSuccess.sqf b/addons/rearm/functions/fnc_rearmEntireVehicleSuccess.sqf index 91c4e17efc..cddce3ac3a 100644 --- a/addons/rearm/functions/fnc_rearmEntireVehicleSuccess.sqf +++ b/addons/rearm/functions/fnc_rearmEntireVehicleSuccess.sqf @@ -18,16 +18,16 @@ private ["_turretPath", "_magazines", "_magazine", "_currentMagazines", "_maxMagazines", "_maxRounds", "_currentRounds"]; params ["_vehicle"]; -if !(local _vehicle) exitWith { // TODO if there are players inside the turrets they will not be rearmed due to locality issues - [_this, QFUNC(rearmEntireVehicleSuccess), _vehicle] call EFUNC(common,execRemoteFnc); -}; - if (isServer) then { { - _turretOwnerID = _target turretOwner _x; - EGVAR(common,remoteFnc) = [[_vehicle, _x], QFUNC(rearmEntireVehicleSuccesssLocal), 0]; - _turretOwnerID publicVariableClient QEGVAR(common,remoteFnc); + _turretOwnerID = _vehicle turretOwner _x; + if (_turretOwnerID == 0) then { + [[_vehicle, _x], QFUNC(rearmEntireVehicleSuccessLocal), _target] call EFUNC(common,execRemoteFnc); + } else { + EGVAR(common,remoteFnc) = [[_vehicle, _x], QFUNC(rearmEntireVehicleSuccessLocal), 0]; + _turretOwnerID publicVariableClient QEGVAR(common,remoteFnc); + }; } count REARM_TURRET_PATHS; } else { - [_this, QUOTE(DFUNC(rearmEntireVehicleSuccess)), 1] call EFUNC(common,execRemoteFnc); + [_this, QFUNC(rearmEntireVehicleSuccess), 1] call EFUNC(common,execRemoteFnc); }; diff --git a/addons/rearm/functions/fnc_rearmEntireVehicleSuccessLocal.sqf b/addons/rearm/functions/fnc_rearmEntireVehicleSuccessLocal.sqf index 4d2f5a1423..c9a2630644 100644 --- a/addons/rearm/functions/fnc_rearmEntireVehicleSuccessLocal.sqf +++ b/addons/rearm/functions/fnc_rearmEntireVehicleSuccessLocal.sqf @@ -16,10 +16,14 @@ #include "script_component.hpp" private ["_magazines", "_magazine", "_currentMagazines", "_maxMagazines", "_maxRounds", "_currentRounds"]; -params ["_args"]; -_args params ["_vehicle", "_turretPath"]; +params ["_vehicle", "_turretPath"]; -_magazines = _vehicle magazinesTurret _turretPath; +_magazines = []; +if (_turretPath isEqualTo [-1]) then { + _magazines = [_vehicle, _turretPath] call FUNC(getConfigMagazines); +} else { + _magazines = _vehicle magazinesTurret _turretPath; +}; { _magazine = _x; _currentMagazines = { _x == _magazine } count (_vehicle magazinesTurret _turretPath); @@ -29,16 +33,16 @@ _magazines = _vehicle magazinesTurret _turretPath; TRACE_7("Rearmed Turret",_vehicle,_turretPath,_currentMagazines,_maxMagazines,_currentRounds,_maxRounds,_magazine); + if (_turretPath isEqualTo [-1] && _currentMagazines == 0) then { + // On driver, the an empty magazine is still there, but is not returned by magazinesTurret + _currentMagazines = _currentMagazines + 1; + }; if (_currentMagazines < _maxMagazines) then { _vehicle setMagazineTurretAmmo [_magazine, _maxRounds, _turretPath]; for "_idx" from 1 to (_maxMagazines - _currentMagazines) do { _vehicle addMagazineTurret [_magazine, _turretPath]; }; } else { - if (_currentRounds > 0 || {_magazine == "SmokeLauncherMag"}) then { // When SmokeLauncherMag is empty removeMagazineTurret has no effect - _vehicle setMagazineTurretAmmo [_magazine, _maxRounds, _turretPath]; - } else { - _vehicle removeMagazineTurret [_magazine, _turretPath]; - }; + _vehicle setMagazineTurretAmmo [_magazine, _maxRounds, _turretPath]; }; } foreach _magazines; diff --git a/addons/rearm/functions/fnc_rearmSuccess.sqf b/addons/rearm/functions/fnc_rearmSuccess.sqf index 6ecb20f8c2..19987551bd 100644 --- a/addons/rearm/functions/fnc_rearmSuccess.sqf +++ b/addons/rearm/functions/fnc_rearmSuccess.sqf @@ -42,8 +42,12 @@ if (local _unit) then { if (isServer) then { _turretOwnerID = _target turretOwner _turretPath; - EGVAR(common,remoteFnc) = [_this, QFUNC(rearmSuccessLocal), 0]; - _turretOwnerID publicVariableClient QEGVAR(common,remoteFnc); + if (_turretOwnerID == 0) then { + [_this, QUOTE(DFUNC(rearmSuccessLocal)), _target] call EFUNC(common,execRemoteFnc); + } else { + EGVAR(common,remoteFnc) = [_this, QFUNC(rearmSuccessLocal), 0]; + _turretOwnerID publicVariableClient QEGVAR(common,remoteFnc); + }; } else { [_this, QUOTE(DFUNC(rearmSuccess)), 1] call EFUNC(common,execRemoteFnc); };