/*
	FILE: fnc_load.sqf

	Name: tbd_m119_m119_fnc_load

	Author(s):
		ilbinek

	Description:
		Load the round into the M119

	Parameters:
		_arty	- object	- M119 to be loaded
		_shell  - string	- type of round to be loaded
		_turret - number	- path to turret

	Returns:
		Nothing
	
	Examples:
		> [_arty, tbd_mortars_105mm_he_round_1, 0] call tbd_m119_m119_fnc_load;

	Public:
		No
*/

#include "..\script_component.hpp"

params ["_arty", "_shell", "_turret"];

if !([_arty, _shell] call FUNC(canLoad)) exitWith {};

private _mag = "";

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

	case QUOTE(TBD_MORTARS_105mm_ROUND_LASER_CHARGE_1): {_mag = QUOTE(TBD_MORTARS_105mm_ROUND_LASER_CHARGE_MAG_1)};
	case QUOTE(TBD_MORTARS_105mm_ROUND_LASER_CHARGE_2): {_mag = QUOTE(TBD_MORTARS_105mm_ROUND_LASER_CHARGE_MAG_2)};
	case QUOTE(TBD_MORTARS_105mm_ROUND_LASER_CHARGE_3): {_mag = QUOTE(TBD_MORTARS_105mm_ROUND_LASER_CHARGE_MAG_3)};
	case QUOTE(TBD_MORTARS_105mm_ROUND_LASER_CHARGE_4): {_mag = QUOTE(TBD_MORTARS_105mm_ROUND_LASER_CHARGE_MAG_4)};
	case QUOTE(TBD_MORTARS_105mm_ROUND_LASER_CHARGE_5): {_mag = QUOTE(TBD_MORTARS_105mm_ROUND_LASER_CHARGE_MAG_5)};
	case QUOTE(TBD_MORTARS_105mm_ROUND_LASER_CHARGE_6): {_mag = QUOTE(TBD_MORTARS_105mm_ROUND_LASER_CHARGE_MAG_6)};
	case QUOTE(TBD_MORTARS_105mm_ROUND_LASER_CHARGE_7): {_mag = QUOTE(TBD_MORTARS_105mm_ROUND_LASER_CHARGE_MAG_7)};

	case QUOTE(TBD_MORTARS_105mm_ROUND_SMOKE_CHARGE_1): {_mag = QUOTE(TBD_MORTARS_105mm_ROUND_SMOKE_CHARGE_MAG_1)};
	case QUOTE(TBD_MORTARS_105mm_ROUND_SMOKE_CHARGE_2): {_mag = QUOTE(TBD_MORTARS_105mm_ROUND_SMOKE_CHARGE_MAG_2)};
	case QUOTE(TBD_MORTARS_105mm_ROUND_SMOKE_CHARGE_3): {_mag = QUOTE(TBD_MORTARS_105mm_ROUND_SMOKE_CHARGE_MAG_3)};
	case QUOTE(TBD_MORTARS_105mm_ROUND_SMOKE_CHARGE_4): {_mag = QUOTE(TBD_MORTARS_105mm_ROUND_SMOKE_CHARGE_MAG_4)};
	case QUOTE(TBD_MORTARS_105mm_ROUND_SMOKE_CHARGE_5): {_mag = QUOTE(TBD_MORTARS_105mm_ROUND_SMOKE_CHARGE_MAG_5)};
	case QUOTE(TBD_MORTARS_105mm_ROUND_SMOKE_CHARGE_6): {_mag = QUOTE(TBD_MORTARS_105mm_ROUND_SMOKE_CHARGE_MAG_6)};
	case QUOTE(TBD_MORTARS_105mm_ROUND_SMOKE_CHARGE_7): {_mag = QUOTE(TBD_MORTARS_105mm_ROUND_SMOKE_CHARGE_MAG_7)};

	case QUOTE(TBD_MORTARS_105mm_ROUND_DPICM_CHARGE_1): {_mag = QUOTE(TBD_MORTARS_105mm_ROUND_DPICM_CHARGE_MAG_1)};
	case QUOTE(TBD_MORTARS_105mm_ROUND_DPICM_CHARGE_2): {_mag = QUOTE(TBD_MORTARS_105mm_ROUND_DPICM_CHARGE_MAG_2)};
	case QUOTE(TBD_MORTARS_105mm_ROUND_DPICM_CHARGE_3): {_mag = QUOTE(TBD_MORTARS_105mm_ROUND_DPICM_CHARGE_MAG_3)};
	case QUOTE(TBD_MORTARS_105mm_ROUND_DPICM_CHARGE_4): {_mag = QUOTE(TBD_MORTARS_105mm_ROUND_DPICM_CHARGE_MAG_4)};
	case QUOTE(TBD_MORTARS_105mm_ROUND_DPICM_CHARGE_5): {_mag = QUOTE(TBD_MORTARS_105mm_ROUND_DPICM_CHARGE_MAG_5)};
	case QUOTE(TBD_MORTARS_105mm_ROUND_DPICM_CHARGE_6): {_mag = QUOTE(TBD_MORTARS_105mm_ROUND_DPICM_CHARGE_MAG_6)};
	case QUOTE(TBD_MORTARS_105mm_ROUND_DPICM_CHARGE_7): {_mag = QUOTE(TBD_MORTARS_105mm_ROUND_DPICM_CHARGE_MAG_7)};
};

[QGVAR(loadShell), [_arty, _mag, _turret], _arty, [-1]] call CBA_fnc_turretEvent;

// Delete closest
private _veh = nearestObjects [player, [_shell], 3];
{
	if (typeOf _x == _shell) exitWith {deleteVehicle _x};
} forEach _veh;

if ("laser" in _shell) exitWith {
	_arty animateSource ["magazine_laser_load_source", 0, true];
	_arty animateSource ["magazine_laser_hide_source", 0, true];
	_arty animateSource ["magazine_laser_load_source", 0.36, 0.2];
};

if ("smoke" in _shell) exitWith {
	_arty animateSource ["magazine_smoke_load_source", 0, true];
	_arty animateSource ["magazine_smoke_hide_source", 0, true];
	_arty animateSource ["magazine_smoke_load_source", 0.36, 0.2];
};
if ("dpicm" in _shell) exitWith {
	_arty animateSource ["magazine_dpicm_load_source", 0, true];
	_arty animateSource ["magazine_dpicm_hide_source", 0, true];
	_arty animateSource ["magazine_dpicm_load_source", 0.36, 0.2];
};

_arty animateSource ["magazine_load_source", 0, true];
_arty animateSource ["magazine_hide_source", 0, true];
_arty animateSource ["magazine_load_source", 0.36, 0.2];
