/*
	FILE: fnc_unload.sqf

	Name: tbd_m119_m119_fnc_unload

	Author(s):
		ilbinek

	Description:
		Fired EH for the M119. This script is called when the M119 is fired. It animates the recoil of the M119.

	Parameters:
		_arty	- object	- M119 that fired

	Returns:
		Nothing
	
	Examples:
		> [_arty] call tbd_m119_m119_fnc_unload;

	Public:
		No
*/

#include "..\script_component.hpp"

params ["_arty", "_turret"];

if !([_arty] call FUNC(canUnload)) exitWith {};

private _mags = _arty magazinesTurret [_turret];
{
	_arty removeMagazinesTurret [_x, [_turret]];
} forEach _mags;

private _veh = "";

switch (_mags#0) do {
	case QUOTE(TBD_MORTARS_105mm_ROUND_HE_CHARGE_MAG_1): {_veh = QUOTE(TBD_MORTARS_105mm_ROUND_HE_CHARGE_1)};
	case QUOTE(TBD_MORTARS_105mm_ROUND_HE_CHARGE_MAG_2): {_veh = QUOTE(TBD_MORTARS_105mm_ROUND_HE_CHARGE_2)};
	case QUOTE(TBD_MORTARS_105mm_ROUND_HE_CHARGE_MAG_3): {_veh = QUOTE(TBD_MORTARS_105mm_ROUND_HE_CHARGE_3)};
	case QUOTE(TBD_MORTARS_105mm_ROUND_HE_CHARGE_MAG_4): {_veh = QUOTE(TBD_MORTARS_105mm_ROUND_HE_CHARGE_4)};
	case QUOTE(TBD_MORTARS_105mm_ROUND_HE_CHARGE_MAG_5): {_veh = QUOTE(TBD_MORTARS_105mm_ROUND_HE_CHARGE_5)};
	case QUOTE(TBD_MORTARS_105mm_ROUND_HE_CHARGE_MAG_6): {_veh = QUOTE(TBD_MORTARS_105mm_ROUND_HE_CHARGE_6)};
	case QUOTE(TBD_MORTARS_105mm_ROUND_HE_CHARGE_MAG_7): {_veh = QUOTE(TBD_MORTARS_105mm_ROUND_HE_CHARGE_7)};
};

_arty animateSource ["magazine_hide_source", 1];
_arty animateSource ["magazine_load_source", 0];

private _s = _veh createVehicle (getPos player);
[player, _s] call ace_dragging_fnc_startCarry;
