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

Cargo - Add unloading of cargo to killed vehicles #10017

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from
Draft
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
16 changes: 16 additions & 0 deletions addons/cargo/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@
};
}] call CBA_fnc_addEventHandler;

[QGVAR(unloadedCargoOnKilled), {
johnb432 marked this conversation as resolved.
Show resolved Hide resolved
params ["_item", "_vehicle"];

// Get direction from vehicle to item, so that item is thrown away from vehicle
private _vectorDir = (getPosWorld _vehicle) vectorFromTo (getPosWorld _item);

// Give some z
_vectorDir set [2, random [0.5, 0.75, 1]];

// Add some randomness to resulting velocity
_vectorDir = (_vectorDir vectorMultiply random CARGO_TUMBLE_RANDOM_MUL) vectorAdd (velocity _vehicle);

_item setVelocity _vectorDir;
_item addTorque [random CARGO_TUMBLE_TORQUE, random CARGO_TUMBLE_TORQUE, random CARGO_TUMBLE_TORQUE];
}] call CBA_fnc_addEventHandler;

// Direction must be set before setting position according to wiki
[QGVAR(setDirAndUnload), {
params ["_item", "_emptyPosAGL", "_direction"];
Expand Down
20 changes: 16 additions & 4 deletions addons/cargo/functions/fnc_handleDestroyed.sqf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "..\script_component.hpp"
/*
* Author: mharis001, Glowbal
* Author: mharis001, Glowbal, drofseh
* Handles an object being destroyed/deleted.
* If object contained loaded cargo, the cargo is deleted.
* If object was loaded cargo, it's removed from loaded cargo list.
Expand All @@ -19,16 +19,28 @@

params ["_object"];

private _killed = count _this > 1; // The Killed event has 4 params. The Deleted event only has 1 param.

private _loaded = _object getVariable [QGVAR(loaded), []];

if (_loaded isNotEqualTo []) then {
// Delete all cargo
{
if (_x isEqualType objNull) then {
detach _x;
deleteVehicle _x;
private _delete = true;

if (_killed && {random 1 < GVAR(unloadOnKilled)}) then {
_delete = !([_x, _object, objNull, [], false] call FUNC(unloadItem)); // If a safe position to unload cannot be found FUNC(unloadItem) returns false, delete cargo instead
};

if (_delete) then {
detach _x;
deleteVehicle _x;
} else {
[QGVAR(unloadedCargoOnKilled), [_x, _object], _x] call CBA_fnc_targetEvent;
};
};
} forEach _loaded;
} forEachReversed _loaded;

// In case vehicle is killed, but not deleted, reset loaded list
_object setVariable [QGVAR(loaded), [], true];
Expand Down
13 changes: 10 additions & 3 deletions addons/cargo/functions/fnc_unloadItem.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* 3: Deploy parameters <ARRAY> (default: [])
* - 0: Position AGL <ARRAY>
* - 1: Direction <NUMBER>
* 4: Unload only if stable <BOOL> (default: true) (Applies only if argument 3 is [])
*
* Return Value:
* Object unloaded <BOOL>
Expand All @@ -20,10 +21,16 @@
* Public: Yes
*/

params [["_item", "", [objNull, ""]], ["_vehicle", objNull, [objNull]], ["_unloader", objNull, [objNull]], ["_deploy", []]];
params [
["_item", "", [objNull, ""]],
["_vehicle", objNull, [objNull]],
["_unloader", objNull, [objNull]],
["_deploy", []],
["_checkVehicleIsStable", true, [true]]
];
_deploy params ["_emptyPosAGL", "_direction"];

TRACE_4("params",_item,_vehicle,_unloader,_deploy);
TRACE_5("params",_item,_vehicle,_unloader,_deploy,_checkVehicleIsStable);

// Get config sensitive case name
if (_item isEqualType "") then {
Expand Down Expand Up @@ -51,7 +58,7 @@ private _deployed = _deploy isNotEqualTo [];
if (!_deployed) then {
// This covers testing vehicle stability and finding a safe position
for "_i" from 1 to 3 do {
_emptyPosAGL = [_vehicle, _item, _unloader] call EFUNC(common,findUnloadPosition);
_emptyPosAGL = [_vehicle, _item, _unloader, nil, _checkVehicleIsStable] call EFUNC(common,findUnloadPosition);

if (_emptyPosAGL isNotEqualTo []) exitWith {};
};
Expand Down
9 changes: 9 additions & 0 deletions addons/cargo/initSettings.inc.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ private _category = [ELSTRING(main,Category_Logistics), LSTRING(openMenu)];
1
] call CBA_fnc_addSetting;

[
QGVAR(unloadOnKilled),
"SLIDER",
[LSTRING(unloadOnKilled), LSTRING(unloadOnKilled_description)],
_category,
[0, 1, 0, 1, true], // [_min, _max, _default, _trailingDecimals, _isPercentage]
1
] call CBA_fnc_addSetting;

[
QGVAR(openAfterUnload),
"LIST",
Expand Down
3 changes: 3 additions & 0 deletions addons/cargo/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
#define MAX_LOAD_DISTANCE 5

#define GET_NUMBER(config,default) (if (isNumber (config)) then {getNumber (config)} else {default})

#define CARGO_TUMBLE_RANDOM_MUL 8
#define CARGO_TUMBLE_TORQUE 500
6 changes: 6 additions & 0 deletions addons/cargo/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,12 @@
<Czech>Upravuje jak dlouho výsadek trvá pro náklad.</Czech>
<Spanish>Modificador de tiempo de lanzamiento en paracaídas de un objeto cargado</Spanish>
</Key>
<Key ID="STR_ACE_Cargo_unloadOnKilled">
<English>Unload Cargo On Killed</English>
</Key>
<Key ID="STR_ACE_Cargo_unloadOnKilled_description">
<English>The chance for each cargo loaded into a vehicle to be unloaded if the vehicle is killed.\nApplies to objects only.</English>
</Key>
<Key ID="STR_ACE_Cargo_loadTimeCoefficient">
<English>Load Time Coefficient</English>
<German>Ladezeitmultiplikator</German>
Expand Down