diff --git a/addons/captives/functions/fnc_addLoadCaptiveActions.sqf b/addons/captives/functions/fnc_addLoadCaptiveActions.sqf index d1ad8f603db..279ca0924ef 100644 --- a/addons/captives/functions/fnc_addLoadCaptiveActions.sqf +++ b/addons/captives/functions/fnc_addLoadCaptiveActions.sqf @@ -22,4 +22,4 @@ private _statement = { [_player, _target, _vehicle] call FUNC(doLoadCaptive); }; -[_target call EFUNC(common,nearestVehiclesFreeSeat), _statement, _target] call EFUNC(interact_menu,createVehiclesActions) +[[_target, nil, true] call EFUNC(common,nearestVehiclesFreeSeat), _statement, _target] call EFUNC(interact_menu,createVehiclesActions) diff --git a/addons/captives/functions/fnc_canLoadCaptive.sqf b/addons/captives/functions/fnc_canLoadCaptive.sqf index 2129b36f5aa..b1757884b7e 100644 --- a/addons/captives/functions/fnc_canLoadCaptive.sqf +++ b/addons/captives/functions/fnc_canLoadCaptive.sqf @@ -34,7 +34,7 @@ if (isNull _target || {(vehicle _target) != _target} || {!(_target getVariable [ if (isNull _vehicle) then { // Looking at a captive unit, get nearest vehicle with valid seat: - _vehicle = (_target call EFUNC(common,nearestVehiclesFreeSeat)) param [0, objNull]; + _vehicle = ([_target, nil, true] call EFUNC(common,nearestVehiclesFreeSeat)) param [0, objNull]; } else { // We have a vehicle picked, make sure it has empty seats: if (_vehicle emptyPositions "cargo" == 0 && {_vehicle emptyPositions "gunner" == 0}) then { diff --git a/addons/captives/functions/fnc_doLoadCaptive.sqf b/addons/captives/functions/fnc_doLoadCaptive.sqf index e4e3b5f45be..7740610b6ab 100644 --- a/addons/captives/functions/fnc_doLoadCaptive.sqf +++ b/addons/captives/functions/fnc_doLoadCaptive.sqf @@ -31,7 +31,7 @@ if (isNull _target || {(vehicle _target) != _target} || {!(_target getVariable [ if (isNull _vehicle) then { // Looking at a captive unit, get nearest vehicle with valid seat: - _vehicle = (_target call EFUNC(common,nearestVehiclesFreeSeat)) param [0, objNull]; + _vehicle = ([_target, nil, true] call EFUNC(common,nearestVehiclesFreeSeat)) param [0, objNull]; } else { // We have a vehicle picked, make sure it has empty seats: if (_vehicle emptyPositions "cargo" == 0 && {_vehicle emptyPositions "gunner" == 0}) then { diff --git a/addons/common/functions/fnc_loadPersonLocal.sqf b/addons/common/functions/fnc_loadPersonLocal.sqf index 0426a945829..7135e9e302c 100644 --- a/addons/common/functions/fnc_loadPersonLocal.sqf +++ b/addons/common/functions/fnc_loadPersonLocal.sqf @@ -21,11 +21,30 @@ params ["_unit", "_vehicle", ["_caller", objNull]]; TRACE_3("loadPersonLocal",_unit,_vehicle,_caller); private _slotsOpen = false; -if ((_vehicle emptyPositions "cargo" > 0) && {!(_unit getVariable ['ACE_isUnconscious', false])} || {(getNumber (configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "ejectDeadCargo")) == 0}) then { +if ((_vehicle emptyPositions "cargo" > 0) && {!(_unit getVariable ['ACE_isUnconscious', false]) || {(getNumber (configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "ejectDeadCargo")) == 0}}) then { _unit moveInCargo _vehicle; + TRACE_1("moveInCargo",_vehicle); _slotsOpen = true; } else { - if (_vehicle emptyPositions "gunner" > 0) then { + // Check if an empty turret is available + // This already excludes FFV seats, which count as cargo positions + private _turrets = fullCrew [_vehicle, "turret", true]; + private _index = _turrets findIf {isNull (_x#0)}; + if (_index >= 0) exitWith { + _unit moveInTurret [_vehicle, _turrets#_index#3]; + TRACE_2("moveInTurret",_vehicle,_turrets#_index#3); + _slotsOpen = true; + }; + + // Check if the commander seat is available + if (_vehicle emptyPositions "commander" > 0) exitWith { + _unit moveInCommander _vehicle; + TRACE_1("moveInCommander",_vehicle); + _slotsOpen = true; + }; + + // Lastly, check if the gunner seat is available + if (_vehicle emptyPositions "gunner" > 0) exitWith { _unit moveInGunner _vehicle; _slotsOpen = true; }; diff --git a/addons/common/functions/fnc_nearestVehiclesFreeSeat.sqf b/addons/common/functions/fnc_nearestVehiclesFreeSeat.sqf index aba75ff60f8..83ed8ceb209 100644 --- a/addons/common/functions/fnc_nearestVehiclesFreeSeat.sqf +++ b/addons/common/functions/fnc_nearestVehiclesFreeSeat.sqf @@ -5,22 +5,29 @@ * * Arguments: * 0: Unit - * 1: Distance + * 1: Distance + * 2: Restriceted to cargo only * * Return Value: * Nearest vehicles with a free seat * * Example: - * [bob] call ace_common_fnc_nearestVehiclesFreeSeat + * [cursorObject] call ace_common_fnc_nearestVehiclesFreeSeat * * Public: Yes */ -params ["_unit", ["_distance", 10]]; +params ["_unit", ["_distance", 10], ["_cargoOnly", false]]; private _nearVehicles = nearestObjects [_unit, ["Car", "Air", "Tank", "Ship_F", "Pod_Heli_Transport_04_crewed_base_F"], _distance]; _nearVehicles select { // Filter cargo seats that will eject unconscious units (e.g. quad bike) - ((_x emptyPositions "cargo" > 0) && {!(_unit getVariable ['ACE_isUnconscious', false])} || {(getNumber (configFile >> "CfgVehicles" >> (typeOf _x) >> "ejectDeadCargo")) == 0}) - || {_x emptyPositions "gunner" > 0} + private _canSitInCargo = (!(_unit getVariable ['ACE_isUnconscious', false])) || {(getNumber (configFile >> "CfgVehicles" >> (typeOf _x) >> "ejectDeadCargo")) == 0}; + ((fullCrew [_x, "", true]) findIf { + _x params ["_body", "_role", "_cargoIndex"]; + (isNull _body) // seat empty + && {_role != "DRIVER"} // not driver seat + && {_canSitInCargo || {_cargoIndex == -1}} // won't be ejected (uncon) + && {(!_cargoOnly) || {_cargoIndex != -1}} // not restricted (captive) + }) > -1 } diff --git a/addons/common/functions/fnc_unloadPersonLocal.sqf b/addons/common/functions/fnc_unloadPersonLocal.sqf index d51f911eaf0..dd4480c1f95 100644 --- a/addons/common/functions/fnc_unloadPersonLocal.sqf +++ b/addons/common/functions/fnc_unloadPersonLocal.sqf @@ -49,6 +49,16 @@ unassignVehicle _unit; TRACE_1("Ejecting", alive _unit); _unit action ["Eject", vehicle _unit]; +// Failsafe - sometimes eject alone doesn't work, but moveOut does +[{ + params ["_unit"]; + + if (vehicle _unit != _unit) then { + WARNING_1("UnloadPersonLocal [%1] did not eject normally",_unit); + moveOut _unit; + }; +}, [_unit], 1] call CBA_fnc_waitAndExecute; + [{ params ["_unit", "_emptyPos"]; (alive _unit) && {(vehicle _unit) != _unit}