Skip to content

Commit

Permalink
Common / Medical - Fix loading patients into turret only seats (#7980)
Browse files Browse the repository at this point in the history
* Fix loading patients into turret only seats

* Fix cargo logic, adjust function for captives (#8000)

Co-authored-by: PabstMirror <pabstmirror@gmail.com>
  • Loading branch information
BaerMitUmlaut and PabstMirror committed Nov 15, 2020
1 parent 6299428 commit ad75c7c
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 10 deletions.
2 changes: 1 addition & 1 deletion addons/captives/functions/fnc_addLoadCaptiveActions.sqf
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion addons/captives/functions/fnc_canLoadCaptive.sqf
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion addons/captives/functions/fnc_doLoadCaptive.sqf
Expand Up @@ -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 {
Expand Down
23 changes: 21 additions & 2 deletions addons/common/functions/fnc_loadPersonLocal.sqf
Expand Up @@ -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;
};
Expand Down
17 changes: 12 additions & 5 deletions addons/common/functions/fnc_nearestVehiclesFreeSeat.sqf
Expand Up @@ -5,22 +5,29 @@
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Distance <NUMBER>
* 1: Distance <NUMBER><OPTIONAL>
* 2: Restriceted to cargo only <BOOL><OPTIONAL>
*
* Return Value:
* Nearest vehicles with a free seat <ARRAY>
*
* 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
}
10 changes: 10 additions & 0 deletions addons/common/functions/fnc_unloadPersonLocal.sqf
Expand Up @@ -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}
Expand Down

0 comments on commit ad75c7c

Please sign in to comment.