diff --git a/addons/sup_artillery/CfgFunctions.hpp b/addons/sup_artillery/CfgFunctions.hpp index 9fdeef2ad..0b59b73a8 100644 --- a/addons/sup_artillery/CfgFunctions.hpp +++ b/addons/sup_artillery/CfgFunctions.hpp @@ -21,6 +21,11 @@ class cfgFunctions { file = "\x\alive\addons\sup_artillery\fnc_artilleryFiredEH.sqf"; RECOMPILE; }; + class artilleryGetRange { + description = "Gets range of artillery asset"; + file = "\x\alive\addons\sup_artillery\fnc_artilleryGetRange.sqf"; + RECOMPILE; + }; }; }; }; diff --git a/addons/sup_artillery/fnc_artillery.sqf b/addons/sup_artillery/fnc_artillery.sqf index 6d3a56972..883ecef54 100644 --- a/addons/sup_artillery/fnc_artillery.sqf +++ b/addons/sup_artillery/fnc_artillery.sqf @@ -123,7 +123,18 @@ switch (_operation) do { }; case "activate": { if (!([_logic, "inRange"] call MAINCLASS)) then { - _logic setVariable ["moveToPos", [3744.56,4757.54,0]]; // TODO: Figure out best firing position + private _fireMission = _logic getVariable ["fireMission", []]; + private _position = [_fireMission, "position"] call ALIVE_fnc_hashGet; + private _roundType = [_fireMission, "roundType"] call ALIVE_fnc_hashGet; + private _group = _logic getVariable ["group", grpNull]; + private _units = (units _group) select {vehicle _x != _x && {gunner (vehicle _x) == _x}}; + + private _vehicle = vehicle (_units select 0); + private _range = [_vehicle, _roundType] call ALIVE_fnc_artilleryGetRange; + private _radius = 500; + private _newPosition = [_position, _range - _radius, _position getDir _vehicle] call BIS_fnc_relPos; + _newPosition = [_newPosition, 10, _radius, 5, 0, 0.15, 0] call BIS_fnc_findSafePos; + _logic setVariable ["moveToPos", _newPosition]; }; }; case "inRange": { diff --git a/addons/sup_artillery/fnc_artilleryGetRange.sqf b/addons/sup_artillery/fnc_artilleryGetRange.sqf new file mode 100644 index 000000000..c303ca69a --- /dev/null +++ b/addons/sup_artillery/fnc_artilleryGetRange.sqf @@ -0,0 +1,43 @@ +#include <\x\alive\addons\sup_artillery\script_component.hpp> +SCRIPT(ArtilleryGetRange); + +/* ---------------------------------------------------------------------------- +Function: ALIVE_fnc_artilleryGetRange +Description: +Gets the range for artillery assets + +Parameters: +Object - The artillery asset +String - The round type + +Returns: +Number - The range + +Examples: + +See Also: + +Author: +marceldev89 +---------------------------------------------------------------------------- */ +private _vehicle = param [0, objNull, [objNull]]; +private _roundType = param [1, "", [""]]; + +private _range = 0; +private _inRange = true; +private _eta = 0; +private _target = position _vehicle; + +// Figure out range by incrementing distance from asset. Configs seem unreliable. +while {_range == 0 || (_inRange && _eta != -1)} do { + _inRange = _target inRangeOfArtillery [[_vehicle], _roundType]; + _eta = _vehicle getArtilleryETA [_target, _roundType]; + + if (_inRange && _eta != -1) then { + _range = (position _vehicle) distance2D _target; + }; + + _target = [_target, 1, 0] call BIS_fnc_relPos; +}; + +_range;