Common / Medical - Fix loading patients into turret only seats (#7980)

* Fix loading patients into turret only seats

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

Co-authored-by: PabstMirror <pabstmirror@gmail.com>
This commit is contained in:
BaerMitUmlaut 2020-11-15 19:57:27 +01:00 committed by GitHub
parent 629942885e
commit ad75c7c9b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 46 additions and 10 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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