2015-08-10 21:07:47 +00:00
|
|
|
/*
|
|
|
|
* Author: Glowbal, ViperMaul
|
2015-08-16 20:41:35 +00:00
|
|
|
* Unload object from vehicle.
|
2015-08-10 21:07:47 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Object <OBJECT>
|
|
|
|
* 1: Vehicle <OBJECT>
|
|
|
|
*
|
|
|
|
* Return value:
|
2015-08-16 20:48:52 +00:00
|
|
|
* Object unloaded <BOOL>
|
2015-08-10 21:07:47 +00:00
|
|
|
*
|
2015-08-16 20:41:35 +00:00
|
|
|
* Example:
|
|
|
|
* [object, vehicle] call ace_cargo_fnc_unloadItem
|
|
|
|
*
|
2015-08-10 21:07:47 +00:00
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
|
|
|
private ["_loaded", "_space", "_itemSize", "_emptyPos", "_validVehiclestate"];
|
2015-08-16 20:41:35 +00:00
|
|
|
|
2015-08-10 21:07:47 +00:00
|
|
|
params ["_item", "_vehicle"];
|
|
|
|
|
2015-08-16 20:41:35 +00:00
|
|
|
if !([_item, _vehicle] call FUNC(canUnloadItem)) exitWith {
|
2015-08-10 21:07:47 +00:00
|
|
|
false
|
|
|
|
};
|
|
|
|
|
|
|
|
_validVehiclestate = true;
|
|
|
|
_emptyPos = [];
|
|
|
|
if (_vehicle isKindOf "Ship" ) then {
|
|
|
|
if !(speed _vehicle <1 && {(((getPosATL _vehicle) select 2) < 2)}) then {_validVehiclestate = false};
|
|
|
|
TRACE_1("SHIP Ground Check", getPosATL _vehicle );
|
|
|
|
_emptyPos = ((getPosASL _vehicle) call EFUNC(common,ASLtoPosition) findEmptyPosition [0, 15, typeOf _item]); // TODO: if spot is underwater pick another spot.
|
|
|
|
} else {
|
|
|
|
if (_vehicle isKindOf "Air" ) then {
|
|
|
|
if !(speed _vehicle <1 && {isTouchingGround _vehicle}) then {_validVehiclestate = false};
|
|
|
|
TRACE_1("Vehicle Ground Check", isTouchingGround _vehicle);
|
|
|
|
_emptyPos = (getPosASL _vehicle) call EFUNC(common,ASLtoPosition);
|
|
|
|
_emptyPos = [(_emptyPos select 0) + random(5), (_emptyPos select 1) + random(5), _emptyPos select 2 ];
|
|
|
|
} else {
|
|
|
|
if !(speed _vehicle <1 && {(((getPosATL _vehicle) select 2) < 2)}) then {_validVehiclestate = false};
|
|
|
|
TRACE_1("Vehicle Ground Check", isTouchingGround _vehicle);
|
|
|
|
_emptyPos = ((getPosASL _vehicle) call EFUNC(common,ASLtoPosition) findEmptyPosition [0, 13, typeOf _item]);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
TRACE_1("getPosASL Vehicle Check", getPosASL _vehicle);
|
2015-08-16 20:48:52 +00:00
|
|
|
if (!_validVehiclestate) exitWith {false};
|
2015-08-10 21:07:47 +00:00
|
|
|
|
2015-08-16 20:48:52 +00:00
|
|
|
if (count _emptyPos == 0) exitWith {false}; //consider displaying text saying there are no safe places to exit the vehicle
|
2015-08-10 21:07:47 +00:00
|
|
|
|
2015-08-16 20:41:35 +00:00
|
|
|
_loaded = _vehicle getVariable [QGVAR(loaded), []];
|
2015-08-10 21:07:47 +00:00
|
|
|
_loaded = _loaded - [_item];
|
2015-08-16 20:41:35 +00:00
|
|
|
_vehicle setVariable [QGVAR(loaded), _loaded, true];
|
2015-08-10 21:07:47 +00:00
|
|
|
|
|
|
|
_space = [_vehicle] call FUNC(getCargoSpaceLeft);
|
|
|
|
_itemSize = [_item] call FUNC(getSizeItem);
|
2015-08-16 20:41:35 +00:00
|
|
|
_vehicle setVariable [QGVAR(space), (_space + _itemSize), true];
|
2015-08-10 21:07:47 +00:00
|
|
|
|
|
|
|
detach _item;
|
|
|
|
_item setPosASL (_emptyPos call EFUNC(common,PositiontoASL));
|
2015-08-18 16:19:18 +00:00
|
|
|
["hideObjectGlobal", [_item, false]] call EFUNC(common,serverEvent);
|
2015-08-10 21:07:47 +00:00
|
|
|
|
2015-09-17 11:43:55 +00:00
|
|
|
// show hint
|
|
|
|
private ["_itemName", "_vehicleName"];
|
|
|
|
|
|
|
|
_itemName = getText (configFile >> "CfgVehicles" >> typeOf _item >> "displayName");
|
|
|
|
_vehicleName = getText (configFile >> "CfgVehicles" >> typeOf _vehicle >> "displayName");
|
|
|
|
|
|
|
|
["displayTextStructured", [[localize LSTRING(UnloadedItem), _itemName, _vehicleName], 3.0]] call EFUNC(common,localEvent);
|
|
|
|
|
2015-08-10 21:07:47 +00:00
|
|
|
// TOOO maybe drag/carry the unloaded item?
|
|
|
|
|
2015-08-18 16:48:21 +00:00
|
|
|
// Invoke listenable event
|
2015-08-22 14:45:50 +00:00
|
|
|
["cargoUnloaded", [_item, _vehicle]] call EFUNC(common,globalEvent);
|
2015-08-18 16:48:21 +00:00
|
|
|
|
2015-08-16 20:48:52 +00:00
|
|
|
true
|