Captives - rewrite findEmptyNonFFVCargoSeat (#4348)

Simplify func using `fullCrew`
Fix #4339
also switch hard `ERROR(` macro to `WARNING(`
This commit is contained in:
PabstMirror 2016-09-13 16:52:51 -05:00 committed by GitHub
parent 39ffdff920
commit b81ccca3f7
5 changed files with 21 additions and 49 deletions

View File

@ -27,7 +27,7 @@ if ((isNull _target) && {_unit getVariable [QGVAR(isEscorting), false]}) then {
};
} forEach (attachedObjects _unit);
};
if ((isNull _target) || {(vehicle _target) != _target} || {!(_target getVariable [QGVAR(isHandcuffed), false])}) exitWith {ERROR("");};
if ((isNull _target) || {(vehicle _target) != _target} || {!(_target getVariable [QGVAR(isHandcuffed), false])}) exitWith {WARNING("");};
if (isNull _vehicle) then {
//Looking at a captive unit, search for nearby vehicles with valid seats:
@ -44,7 +44,7 @@ if (isNull _vehicle) then {
};
};
if (isNull _vehicle) exitWith {ERROR("");};
if (isNull _vehicle) exitWith {WARNING("Could not find vehicle to load captive");};
_unit setVariable [QGVAR(isEscorting), false, true];
[QGVAR(moveInCaptive), [_target, _vehicle], [_target]] call CBA_fnc_targetEvent;

View File

@ -18,50 +18,22 @@
params ["_vehicle"];
TRACE_1("params", _vehicle);
_vehicleConfig = configFile >> "CfgVehicles" >> (typeOf _vehicle);
private _vehicleConfig = configFile >> "CfgVehicles" >> (typeOf _vehicle);
_proxyOrder = getArray (_vehicleConfig >> "getInProxyOrder");
_transportSoldier = getNumber (_vehicleConfig >> "transportSoldier");
_realCargoCount = if (isArray (_vehicleConfig >> "getInProxyOrder")) then {count _proxyOrder} else {_transportSoldier};
scopeName "main";
//Find FFV turrets:
_ffvCargoIndexes = [];
{
_turretConfig = [_vehicleConfig, _x] call EFUNC(common,getTurretConfigPath);
_isCargoProxy = ((getText (_turretConfig >> "proxyType")) == "CPCargo") && {isNumber (_turretConfig >> "proxyIndex")};
if (_isCargoProxy) then {
_proxyCargoIndex = getNumber (_turretConfig >> "proxyIndex");
_cargoIndex = _proxyOrder find _proxyCargoIndex;
_ffvCargoIndexes pushBack _cargoIndex;
_x params ["_unit", "_role", "_cargoIndex", "_turretPath", "_isPersonTurret"];
if ((isNull _unit) && {_role == "cargo"} && {_cargoIndex > -1} && {!_isPersonTurret}) then {
[_cargoIndex, false] breakOut "main";
};
} forEach (allTurrets [_vehicle, true]);
} forEach (fullCrew [_vehicle, "", true]);
//Find Empty Seats:
_occupiedSeats = [];
{
_x params ["", "", "_xIndex"];
if (_xIndex > -1) then {_occupiedSeats pushBack _xIndex;};
} forEach (fullCrew _vehicle);
TRACE_3("Searching for empty seat",_realCargoCount,_ffvCargoIndexes,_occupiedSeats);
_emptyCargoSeatReturn = [-1, false];
//First seach for non-ffv seats:
for "_index" from 0 to (_realCargoCount - 1) do {
if ((!(_index in _ffvCargoIndexes)) && {!(_index in _occupiedSeats)}) exitWith {
_emptyCargoSeatReturn = [_index, false];
_x params ["_unit", "_role", "_cargoIndex", "_turretPath", "_isPersonTurret"];
if ((isNull _unit) && {_cargoIndex > -1}) then {
[_cargoIndex, true] breakOut "main";
};
};
} forEach (fullCrew [_vehicle, "", true]);
//Only use FFV if none found:
if (_emptyCargoSeatReturn isEqualTo [-1, false]) then {
for "_index" from 0 to (_realCargoCount - 1) do {
if (!(_index in _occupiedSeats)) exitWith {
_emptyCargoSeatReturn = [_index, true];
};
};
};
_emptyCargoSeatReturn
[-1, false]

View File

@ -20,7 +20,7 @@ params ["_unit","_state"];
TRACE_2("params",_unit,_state);
if (!local _unit) exitWith {
ERROR("running setHandcuffed on remote unit");
WARNING("running setHandcuffed on remote unit");
};
if !(missionNamespace getVariable [QGVAR(captivityEnabled), false]) exitWith {
@ -35,7 +35,7 @@ if !(missionNamespace getVariable [QGVAR(captivityEnabled), false]) exitWith {
};
if ((_unit getVariable [QGVAR(isHandcuffed), false]) isEqualTo _state) exitWith {
ERROR("setHandcuffed: current state same as new");
WARNING("setHandcuffed: current state same as new");
};
if (_state) then {

View File

@ -20,7 +20,7 @@ params ["_unit","_state"];
TRACE_2("params",_unit,_state);
if (!local _unit) exitWith {
ERROR("running surrender on remote unit");
WARNING("running surrender on remote unit");
};
if !(missionNamespace getVariable [QGVAR(captivityEnabled), false]) exitWith {
@ -35,12 +35,12 @@ if !(missionNamespace getVariable [QGVAR(captivityEnabled), false]) exitWith {
};
if ((_unit getVariable [QGVAR(isSurrendering), false]) isEqualTo _state) exitWith {
ERROR("Surrender: current state same as new");
WARNING("Surrender: current state same as new");
};
if (_state) then {
if ((vehicle _unit) != _unit) exitWith {ERROR("Cannot surrender while mounted");};
if (_unit getVariable [QGVAR(isHandcuffed), false]) exitWith {ERROR("Cannot surrender while handcuffed");};
if ((vehicle _unit) != _unit) exitWith {WARNING("Cannot surrender while mounted");};
if (_unit getVariable [QGVAR(isHandcuffed), false]) exitWith {WARNING("Cannot surrender while handcuffed");};
_unit setVariable [QGVAR(isSurrendering), true, true];

View File

@ -19,10 +19,10 @@
params ["_target","_vehicle"];
TRACE_2("params",_target,_vehicle);
_getSeat = [_vehicle] call FUNC(findEmptyNonFFVCargoSeat);
private _getSeat = [_vehicle] call FUNC(findEmptyNonFFVCargoSeat);
TRACE_1("free cargo seat",_getSeat);
_getSeat params ["_cargoIndex"];
if (_cargoIndex == -1) exitWith {ERROR("cargo index -1");};
if (_cargoIndex == -1) exitWith {WARNING("cargo index -1");};
_target moveInCargo [_vehicle, _cargoIndex];
_target assignAsCargoIndex [_vehicle, _cargoIndex];