Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cargo logic, adjust function for captives #8000

Merged
merged 1 commit into from Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
5 changes: 4 additions & 1 deletion addons/common/functions/fnc_loadPersonLocal.sqf
Expand Up @@ -21,8 +21,9 @@ 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 {
// Check if an empty turret is available
Expand All @@ -31,12 +32,14 @@ if ((_vehicle emptyPositions "cargo" > 0) && {!(_unit getVariable ['ACE_isUncons
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;
};

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})
|| {{isNull (_x#0)} count fullCrew [_x, "", true] > _x emptyPositions "driver"}
private _canSitInCargo = (!(_unit getVariable ['ACE_isUnconscious', false])) || {(getNumber (configFile >> "CfgVehicles" >> (typeOf _x) >> "ejectDeadCargo")) == 0};
((fullCrew [_x, "", true]) findIf {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How aboutfullCrew [_x, ["", "cargo"] select _cargoOnly, true]? Would reduce the entries you have to iterate over.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, that would not find any seats in the Polaris DAGOR for example.

_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
}
2 changes: 1 addition & 1 deletion addons/common/functions/fnc_unloadPersonLocal.sqf
Expand Up @@ -54,7 +54,7 @@ _unit action ["Eject", vehicle _unit];
params ["_unit"];

if (vehicle _unit != _unit) then {
TRACE_1("failsafe",_unit);
WARNING_1("UnloadPersonLocal [%1] did not eject normally",_unit);
moveOut _unit;
};
}, [_unit], 1] call CBA_fnc_waitAndExecute;
Expand Down