Skip to content

Commit

Permalink
Relocate arty asset when not in range
Browse files Browse the repository at this point in the history
  • Loading branch information
marceldev89 committed Oct 19, 2017
1 parent cc98238 commit ed7dc3b
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
5 changes: 5 additions & 0 deletions addons/sup_artillery/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
};
};
13 changes: 12 additions & 1 deletion addons/sup_artillery/fnc_artillery.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
43 changes: 43 additions & 0 deletions addons/sup_artillery/fnc_artilleryGetRange.sqf
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit ed7dc3b

Please sign in to comment.