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

Medical Engine - Fix unloading dead units in vehicles and handle deleted units vehicles #9283

Merged
merged 8 commits into from
Aug 2, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions addons/common/functions/fnc_unloadPersonLocal.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#define GROUP_SWITCH_ID QFUNC(loadPerson)

params ["_unit", "_vehicle", ["_unloader", objNull]];
params ["_unit", ["_vehicle", objNull], ["_unloader", objNull]];
TRACE_3("unloadpersonLocal",_unit,_vehicle,_unloader);

//This covers testing vehicle stability and finding a safe position
Expand All @@ -46,16 +46,20 @@ if (count _emptyPos != 3) exitwith {
unassignVehicle _unit;
[_unit] orderGetIn false;

TRACE_1("Ejecting", alive _unit);
private _vehicle = vehicle _unit;
TRACE_2("Ejecting",alive _unit,local _vehicle);

if (local _vehicle) then {
_unit action ["Eject", _vehicle];
// 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);
if (!isNull objectParent _unit) then {
if ([_unit] call FUNC(isAwake)) then {
WARNING_1("UnloadPersonLocal [%1] did not eject normally",_unit);
} else {
TRACE_1("UnloadPersonLocal dead/uncon did not eject normally",_unit);
};
moveOut _unit;
};
}, [_unit], 1] call CBA_fnc_waitAndExecute;
Expand All @@ -64,18 +68,21 @@ if (local _vehicle) then {
moveOut _unit;
};

[{
params ["_unit", "_emptyPos"];
(alive _unit) && {(vehicle _unit) != _unit}
}, {
params ["_unit", "_emptyPos"];
TRACE_2("success",_unit,_emptyPos);
_unit setPosASL AGLToASL _emptyPos;
}, [_unit, _emptyPos], 2, {
params ["_unit", "_emptyPos"];
if (!alive _unit) exitWith {};
WARNING_2("timeout %1->%2",_unit,vehicle _unit);
}] call CBA_fnc_waitUntilAndExecute;
// Wait until unit has actually exited vehicle and then move them to the unload position
if (alive _unit) then {
[{
params ["_unit", "_emptyPos"];
(alive _unit) && {isNull objectParent _unit}
}, {
params ["_unit", "_emptyPos"];
TRACE_2("unload success",_unit,_emptyPos);
_unit setPosASL AGLToASL _emptyPos;
}, [_unit, _emptyPos], 2, {
params ["_unit", "_emptyPos"];
if (!alive _unit) exitWith {};
WARNING_2("timeout %1->%2",_unit,objectParent _unit);
}] call CBA_fnc_waitUntilAndExecute;
};

[_unit, false, GROUP_SWITCH_ID, side group _unit] call FUNC(switchToGroupSide);

Expand Down
20 changes: 18 additions & 2 deletions addons/medical_engine/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,28 @@

["ace_unconscious", {
params ["_unit", "_unconscious"];

if (vehicle _unit != _unit && {local vehicle _unit}) then {
TRACE_3("unit uncon",_unit,objectParent _unit,local _unit);
if (!isNull objectParent _unit && {local objectParent _unit}) then {
if (_unconscious) then {
[_unit] call FUNC(lockUnconsciousSeat);
} else {
[_unit] call FUNC(unlockUnconsciousSeat);
};
};
}] call CBA_fnc_addEventHandler;

["ace_killed", { // global event
params ["_unit"];
TRACE_3("unit Killed",_unit,objectParent _unit,local _unit);
if (!isNull objectParent _unit && {local objectParent _unit}) exitWith {
Copy link
Contributor

Choose a reason for hiding this comment

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

We might be able to switch this to just

Suggested change
if (!isNull objectParent _unit && {local objectParent _unit}) exitWith {
if (local objectParent _unit) exitWith {

as local objNull seems to always be false, but it's a minuscule gain and less readable IMO.

[_unit] call FUNC(lockUnconsciousSeat);
};
}] call CBA_fnc_addEventHandler;

["CAManBase", "deleted", {
params ["_unit"];
TRACE_3("unit deleted",_unit,objectParent _unit,local _unit);
if ((!isNull objectParent _unit) && {local objectParent _unit}) then {
[_unit] call FUNC(unlockUnconsciousSeat);
};
}, true, []] call CBA_fnc_addClassEventHandler;
4 changes: 4 additions & 0 deletions addons/medical_engine/functions/fnc_lockUnconsciousSeat.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
*
* Public: No
*/
if (missionNamespace getVariable [QGVAR(disableSeatLocking), false]) exitWith {};
params ["_unit"];

private _vehicle = objectParent _unit;
TRACE_3("lockUnconsciousSeat",_unit,_vehicle,lifeState _unit);

if (isNull _vehicle) exitWith {};
if (alive _unit && {lifeState _unit != "INCAPACITATED"}) exitWith {};

switch (true) do {
Expand All @@ -35,3 +38,4 @@ switch (true) do {
_unit setVariable [QGVAR(lockedSeat), [_vehicle, "turret", _turretPath], true];
};
};
TRACE_1("locked",_unit getVariable QGVAR(lockedSeat));
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ params ["_unit"];
private _seat = _unit getVariable [QGVAR(lockedSeat), []];
_seat params ["_vehicle", "_type", "_position"];

TRACE_2("unlockUnconsciousSeat",_unit,_seat);
if (_seat isEqualTo []) exitWith {};

switch (_type) do {
Expand Down