Skip to content

Commit

Permalink
Handle timeouts in fnc_unpackMortar
Browse files Browse the repository at this point in the history
  • Loading branch information
marceldev89 committed Jul 14, 2016
1 parent ded2c78 commit 4661c80
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions addons/sup_combatsupport/fnc_unpackMortar.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ private _assembleTo = "";
private _disassembleTo = [];
private _backpacks = [];

// TODO: Extract to seperate script?
{
private _backpack = unitBackpack _x;

Expand Down Expand Up @@ -103,31 +104,50 @@ _assistant action ["PutBag"];
_timeout = time + 5;
while {!isNull (unitBackpack _assistant)} do {
if (time >= _timeout) exitWith {
// TODO: handle timeout
_assistantBackpack = createVehicle [typeOf _assistantBackpack, position _assistant, [], 0, "NONE"];
removeBackpackGlobal _assistant;
};
sleep 0.1;
};

_gunner action ["Assemble", _assistantBackpack];

private _assembledEH = _gunner addEventHandler ["WeaponAssembled", {
private _unit = _this param [0, objNull];
private _weapon = _this param [1, objNull];

_unit setVariable ["assembledWeapon", _weapon];
}];

_gunner action ["Assemble", _assistantBackpack];

_timeout = time + 5;
while {isNull _weapon} do {
if (time >= _timeout) exitWith {
// TODO: handle timeout
_weapon = createVehicle [_assembleTo, position _gunner, [], 0, "NONE"];
removeBackpackGlobal _gunner;
};

_weapon = _gunner getVariable ["assembledWeapon", objNull];
sleep 0.1;
};

_gunner removeEventHandler ["WeaponAssembled", _assembledEH];

// Cleanup possible remaining backpacks
private _weaponHolders = nearestObjects [position _gunner, ["GroundWeaponHolder"], 25];

{
private _weaponHolder = _x param [0, objNull];
private _weaponHolderBackpacks = backpackCargo _weaponHolder;

{
private _backpack = _x param [0, objNull];

if (_backpack in _weaponHolderBackpacks) exitWith {
deleteVehicle _weaponHolder;
};
} forEach _disassembleTo;
} forEach _weaponHolders;

private _dirTo = [position _weapon, _targetPos] call BIS_fnc_dirTo;
_weapon setDir _dirTo;

Expand Down

0 comments on commit 4661c80

Please sign in to comment.