2015-05-25 16:41:24 +00:00
/*
* Author: ViperMaul
* Unload a person from a vehicle, local
*
* Arguments:
* 0: unit <OBJECT>
*
* Return Value:
* Returns true if succesfully unloaded person <BOOL>
*
* Public: No
*/
#include "script_component.hpp"
#define GROUP_SWITCH_ID QUOTE(FUNC(loadPerson))
2015-09-18 17:12:38 +00:00
params ["_unit", "_vehicle"];
private ["_validVehiclestate", "_emptyPos", "_loaded"];
2015-06-23 02:48:28 +00:00
_validVehiclestate = true;
2015-05-25 16:41:24 +00:00
2015-09-18 17:40:48 +00:00
if (_vehicle isKindOf "Ship") then {
2015-09-18 17:12:38 +00:00
if (speed _vehicle > 1 || {getPos _vehicle select 2 > 2}) then {
_validVehiclestate = false;
};
TRACE_1("SHIP Ground Check",getPos _vehicle);
_emptyPos = (ASLToAGL getPosASL _vehicle) findEmptyPosition [0, 13, typeof _unit]; // TODO: if spot is underwater pick another spot.
2015-06-23 02:48:28 +00:00
} else {
2015-09-18 17:12:38 +00:00
if (_vehicle isKindOf "Air") then {
if (speed _vehicle > 1 || {isTouchingGround _vehicle}) then {
_validVehiclestate = false;
};
TRACE_1("Vehicle Ground Check",isTouchingGround _vehicle);
_emptyPos = ASLToAGL getPosASL _vehicle;
_emptyPos = _emptyPos vectorAdd [random 10 - 5, random 10 - 5, 0];
2015-06-23 23:11:00 +00:00
} else {
2015-09-18 17:12:38 +00:00
if (speed _vehicle > 1 || {getPos _vehicle select 2 > 2}) then {
_validVehiclestate = false;
};
2015-06-23 23:11:00 +00:00
TRACE_1("Vehicle Ground Check", isTouchingGround _vehicle);
2015-09-18 17:12:38 +00:00
2015-09-18 17:40:48 +00:00
_emptyPos = (ASLToAGL getPosASL _vehicle) findEmptyPosition [0, 13, typeof _unit];
2015-06-23 23:11:00 +00:00
};
2015-06-23 02:48:28 +00:00
};
TRACE_1("getPosASL Vehicle Check", getPosASL _vehicle);
2015-09-18 17:12:38 +00:00
if !(_validVehiclestate) exitwith {
2015-08-26 15:39:44 +00:00
ACE_LOGWARNING_4("Unable to unload patient because invalid (%1) vehicle state. Either moving or Not close enough on the ground. position: %2 isTouchingGround: %3 Speed: %4",_vehicle,getPos _vehicle,isTouchingGround _vehicle,speed _vehicle);
2015-08-26 13:20:11 +00:00
false
};
2015-06-23 23:11:00 +00:00
2015-08-26 13:20:11 +00:00
if (count _emptyPos == 0) exitwith {
2015-08-26 15:39:44 +00:00
ACE_LOGWARNING_1("No safe empty spots to unload patient. %1",_emptyPos);
2015-08-26 13:20:11 +00:00
false
}; //consider displaying text saying there are no safe places to exit the vehicle
2015-05-25 16:41:24 +00:00
unassignVehicle _unit;
2015-06-11 22:56:11 +00:00
[_unit] orderGetIn false;
2015-09-18 17:12:38 +00:00
2015-06-11 22:56:11 +00:00
TRACE_1("Ejecting", alive _unit);
2015-09-18 17:12:38 +00:00
2015-06-11 22:56:11 +00:00
_unit action ["Eject", vehicle _unit];
2015-09-18 17:12:38 +00:00
[{
params ["_unit", "_emptyPos"];
_unit setPosASL AGLToASL _emptyPos;
// @todo never used. Remove?
/*if !([_unit] call FUNC(isAwake)) then {
2015-06-12 23:56:13 +00:00
TRACE_1("Check if isAwake", [_unit] call FUNC(isAwake));
2015-09-18 17:12:38 +00:00
2015-06-12 23:56:13 +00:00
if (driver _unit == _unit) then {
2015-09-18 17:12:38 +00:00
private "_anim";
_anim = [_unit] call FUNC(getDeathAnim);
[_unit, _anim, 1, true] call FUNC(doAnimation);
2015-06-12 23:56:13 +00:00
[{
_unit = _this select 0;
_anim = _this select 1;
if ((_unit getVariable "ACE_isUnconscious") and (animationState _unit != _anim)) then {
2015-09-18 17:12:38 +00:00
[_unit, _anim, 2, true] call FUNC(doAnimation);
2015-06-12 23:56:13 +00:00
};
2015-09-18 17:12:38 +00:00
}, [_unit, _anim], 0.5, 0] call FUNC(waitAndExecute);
2015-06-12 23:56:13 +00:00
};
2015-09-18 17:12:38 +00:00
};*/
}, [_unit, _emptyPos], 0.5, 0] call FUNC(waitAndExecute);
2015-05-25 16:41:24 +00:00
[_unit, false, GROUP_SWITCH_ID, side group _unit] call FUNC(switchToGroupSide);
_loaded = _vehicle getvariable [QGVAR(loaded_persons),[]];
2015-09-18 17:12:38 +00:00
_loaded deleteAt (_loaded find _unit);
_vehicle setvariable [QGVAR(loaded_persons), _loaded, true];
2015-05-25 16:41:24 +00:00
2015-08-26 13:20:11 +00:00
true