/*
	FILE: fnc_canBeTowed.sqf

	Name: tbd_m119_m119_fnc_canBeTowed

	Author(s):
		ilbinek

	Description:
		Check if the M119 can be towed

	Parameters:
		_arty	- object	- M119 to be checked

	Returns:
		bool - true if the M119 can be towed
	
	Examples:
		> [_arty] call tbd_m119_m119_fnc_canBeTowed;

	Public:
		No
*/

#include "..\script_component.hpp"

params ["_arty"];

// check if being towed
if (_arty getVariable [QGVAR(towed), false]) exitWith {false};

// Check if folded
if !(_arty getVariable [QGVAR(folded), false]) exitWith {false};

// Get pos of the towing point
private _pos = _arty modelToWorld (_arty selectionPosition ["towing_point", "Memory"]);
private _radius = TOW_RADIUS;
private _vehicles = _pos nearEntities _radius;


private _canBeTowed = false;
{
	private _veh = _x;
	private _class = typeOf _veh;
	{
		if (_class regexMatch _x#0) then {
			private _p = _veh modelToWorldVisual [_x#1#0, _x#1#1, _x#1#2];
			if (_p distance _pos < ATTACH_RADIUS) exitWith { _canBeTowed = true;};
		};
	} forEach GVAR(towingList);
	if (_canBeTowed) exitWith {};
} forEach _vehicles;

_canBeTowed
