Make the item load throught ACE ViV working with vehicle already loaded with BI system

This commit is contained in:
Vdauphin 2020-11-07 16:39:12 +01:00
parent d8118ac3aa
commit ba3726c697
5 changed files with 86 additions and 30 deletions

View File

@ -1,10 +1,12 @@
PREP(addCargoItem); PREP(addCargoItem);
PREP(addCargoVehiclesActions); PREP(addCargoVehiclesActions);
PREP(canItemCargo);
PREP(canLoadItemIn); PREP(canLoadItemIn);
PREP(canShowUnloadAllVehicles); PREP(canShowUnloadAllVehicles);
PREP(canUnloadItem); PREP(canUnloadItem);
PREP(getCargoSpaceLeft); PREP(getCargoSpaceLeft);
PREP(getSizeItem); PREP(getSizeItem);
PREP(getSurfaceItem);
PREP(getVehicleCargo); PREP(getVehicleCargo);
PREP(handleDeleted); PREP(handleDeleted);
PREP(handleDestroyed); PREP(handleDestroyed);

View File

@ -0,0 +1,37 @@
#include "script_component.hpp"
/*
* Author: Vdauphin
* Check if an item will fit in the empty space already used by loaded items.
*
* Arguments:
* 0: Vehicle <OBJECT>
* 1: Item <OBJECT>
* 2: Items from vehicle cargo <OBJECT>
*
* Return Value:
* Will fit or not the space occupied by items <BOOL>
*
* Example:
* [] call ace_cargo_fnc_canItemCargo
*
* Public: No
*/
params [
"_vehicle",
"_item",
["_items", [], [[]]]
];
if (
_items isEqualTo [] ||
{!((_vehicle canVehicleCargo _item) select 1)}
) exitWith {false};
private _itemSurface = [_item] call FUNC(getSurfaceItem);
private _itemsSurface = 0;
{
_itemsSurface = _itemsSurface + ([_item] call FUNC(getSurfaceItem));
} forEach _items;
_itemSurface <= _itemsSurface

View File

@ -0,0 +1,26 @@
#include "script_component.hpp"
/*
* Author: Vdauphin
* Get surface of an item.
*
* Arguments:
* 0: Object <OBJECT>
*
* Return Value:
* Surface in m² <NUMBER>
*
* Example:
* [player] call ace_cargo_fnc_getSurfaceItem
*
* Public: No
*/
params ["_object"];
private _bbr = 0 boundingBoxReal _object;
private _p1 = _bbr select 0;
private _p2 = _bbr select 1;
private _width = abs ((_p2 select 0) - (_p1 select 0));
private _length = abs ((_p2 select 1) - (_p1 select 1));
_width * _length

View File

@ -36,22 +36,13 @@ _vehicle setVariable [QGVAR(space), _space - _itemSize, true];
if (_item isEqualType objNull) then { if (_item isEqualType objNull) then {
detach _item; detach _item;
if !(_vehicle setVehicleCargo _item) then { if !(_vehicle setVehicleCargo _item) then {
private _vehicleCargo = getVehicleCargo _vehicle; private _itemsCargo = _loaded arrayIntersect getVehicleCargo _vehicle;
if (
(_vehicle canVehicleCargo _item) isEqualTo [false, true] && // Could be loaded if _vehicle was empty
{_vehicleCargo findIf {
!(_x in _loaded) && // Don't use ViV if ViV was used outside of ACE Cargo
!(_x getVariable [QGVAR(isCargoNet), false])
} isEqualTo -1}
) then {
private _cargoNet = createVehicle ["CargoNet_01_box_F", [0, 0, 0], [], 0, "CAN_COLLIDE"]; private _cargoNet = createVehicle ["CargoNet_01_box_F", [0, 0, 0], [], 0, "CAN_COLLIDE"];
if ((_vehicle canVehicleCargo _cargoNet) select 1) then { if ([_vehicle, _cargoNet, _itemsCargo] call FUNC(canItemCargo)) then {
while {!(_vehicle setVehicleCargo _cargoNet)} do { // Move ViV cargo to ACE Cargo while {!(_vehicle setVehicleCargo _cargoNet)} do { // Move ViV cargo to ACE Cargo
private _itemViV = _vehicleCargo deleteAt 0; if (_itemsCargo isEqualTo []) exitWith {deleteVehicle _cargoNet; /*Should not happen*/};
if (_itemViV getVariable [QGVAR(isCargoNet), false]) exitWith { // The vehicle is already full of cargo net private _itemViV = _itemsCargo deleteAt 0;
deleteVehicle _cargoNet;
_item setVariable [QGVAR(cargoNet), _itemViV, true];
};
if !(objNull setVehicleCargo _itemViV) exitWith {deleteVehicle _cargoNet;}; if !(objNull setVehicleCargo _itemViV) exitWith {deleteVehicle _cargoNet;};
_itemViV setVariable [QGVAR(cargoNet), _cargoNet, true]; _itemViV setVariable [QGVAR(cargoNet), _cargoNet, true];
@ -61,14 +52,14 @@ if (_item isEqualType objNull) then {
// Some objects below water will take damage over time and eventualy become "water logged" and unfixable (because of negative z attach) // Some objects below water will take damage over time and eventualy become "water logged" and unfixable (because of negative z attach)
[_itemViV, "blockDamage", "ACE_cargo", true] call EFUNC(common,statusEffect_set); [_itemViV, "blockDamage", "ACE_cargo", true] call EFUNC(common,statusEffect_set);
}; };
} else {
deleteVehicle _cargoNet;
};
if !(isNull _cargoNet) then { if !(isNull _cargoNet) then {
_cargoNet setVariable [QGVAR(isCargoNet), true, true]; _cargoNet setVariable [QGVAR(isCargoNet), true, true];
_item setVariable [QGVAR(cargoNet), _cargoNet, true]; _item setVariable [QGVAR(cargoNet), _cargoNet, true];
}; };
} else {
deleteVehicle _cargoNet;
};
};
_item attachTo [_vehicle, [0,0,-100]]; _item attachTo [_vehicle, [0,0,-100]];
[QEGVAR(common,hideObjectGlobal), [_item, true]] call CBA_fnc_serverEvent; [QEGVAR(common,hideObjectGlobal), [_item, true]] call CBA_fnc_serverEvent;