Fixed turret locality and driver empty magazine issues

This commit is contained in:
IngoKauffmann 2015-08-19 17:33:32 +02:00
parent 8b9be1923c
commit bdc5e54f55
9 changed files with 99 additions and 55 deletions

View File

@ -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 {

View File

@ -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;

View File

@ -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);

View File

@ -0,0 +1,53 @@
/*
* Author: GitHawk, Jonpas
* Returns all magazines a turret can hold according to config.
*
* Arguments:
* 0: Target <OBJECT>
* 1: Turret Path <ARRAY>
*
* Return Value:
* Magazine classes in TurretPath <ARRAY>
*
* 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")

View File

@ -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

View File

@ -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];

View File

@ -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);
};

View File

@ -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;

View File

@ -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);
};