2021-05-18 06:32:55 +00:00
#include "script_component.hpp"
ADDON = false;
PREP_RECOMPILE_START;
#include "XEH_PREP.hpp"
PREP_RECOMPILE_END;
2021-05-19 03:32:04 +00:00
#include "initSettings.sqf"
2021-05-18 06:32:55 +00:00
// Server handles the tracking of all projectiles. It dispatches events to launchers to fire at specific targets
2021-05-18 09:18:42 +00:00
// The tracker and launcher array are global to allow for early-out if it is impossible to kill any projectiles to avoid wasting bandwidth
GVAR(trackers) = [];
GVAR(launchers) = [];
2021-05-18 06:32:55 +00:00
if (isServer) then {
GVAR(nonTrackingProjectiles) = [];
GVAR(trackingProjectiles) = [];
GVAR(interceptors) = [];
2021-05-18 08:23:52 +00:00
// Put these into hash table to avoid massive amounts of loops
GVAR(toBeShot) = call CBA_fnc_hashCreate;
2021-05-18 06:32:55 +00:00
[QGVAR(track), {
params ["_projectile"];
GVAR(nonTrackingProjectiles) pushBack _projectile;
}] call CBA_fnc_addEventHandler;
[QGVAR(registerInterceptor), {
params ["_interceptor", "_target"];
2021-05-18 10:12:44 +00:00
GVAR(interceptors) pushBack [_interceptor, _target, getPosASLVisual _interceptor, _interceptor distance _target];
2021-05-18 08:23:52 +00:00
[GVAR(toBeShot), _target] call CBA_fnc_hashRem;
2021-05-18 06:32:55 +00:00
}] call CBA_fnc_addEventHandler;
[LINKFUNC(projectileTrackerPFH)] call CBA_fnc_addPerFrameHandler;
[LINKFUNC(proximityFusePFH)] call CBA_fnc_addPerFrameHandler;
};
2021-05-18 09:18:42 +00:00
[QGVAR(registerLaunchers), {
2021-05-18 08:46:30 +00:00
{
2021-05-18 09:18:42 +00:00
GVAR(launchers) pushBackUnique _x;
_x setVariable [QGVAR(targetList), []];
_x setVariable [QGVAR(launchState), LAUNCH_STATE_IDLE];
_x setVariable [QGVAR(lastLaunchTime), 0];
_x setVariable [QGVAR(engagedTargets), [[], objNull] call CBA_fnc_hashCreate];
_x setVariable [QEGVAR(missileguidance,target), objNull];
2021-05-18 08:46:30 +00:00
if (local _x) then {
_x addEventHandler ["Fired", {
params ["_launcher", "", "", "", "", "", "_projectile"];
private _target = _launcher getVariable [QEGVAR(missileguidance,target), objNull];
if !(isNull _target) then {
[QGVAR(registerInterceptor), [_projectile, _target]] call CBA_fnc_serverEvent;
};
}];
2021-05-18 06:32:55 +00:00
};
2021-05-18 08:46:30 +00:00
} forEach _this;
2021-05-18 06:32:55 +00:00
}] call CBA_fnc_addEventHandler;
2021-05-18 09:18:42 +00:00
[QGVAR(registerTrackers), {
{
_x params ["_tracker", "_range"];
GVAR(trackers) pushBack [_tracker, _range];
} forEach _this;
}] call CBA_fnc_addEventHandler;
2021-05-18 06:32:55 +00:00
// When something is fired, determine if we want to track it. If so, send it to the server for processing
GVAR(projectilesToIntercept) = [];
2021-05-18 08:46:30 +00:00
[QGVAR(addProjectilesToIntercept), {
{
GVAR(projectilesToIntercept) pushBackUnique _x;
} forEach _this;
2021-05-18 06:32:55 +00:00
}] call CBA_fnc_addEventHandler;
["All", "fired", {
params ["", "", "", "", "", "", "_projectile"];
if (local _projectile && { (typeOf _projectile) in GVAR(projectilesToIntercept) }) then {
2021-05-18 09:18:42 +00:00
// avoid extra bandwidth: don't make a call to the server if we don't have any systems up
GVAR(launchers) = GVAR(launchers) select {
alive _x
};
GVAR(trackers) = GVAR(trackers) select {
_x params ["_tracker"];
alive _tracker
};
if !(GVAR(launchers) isEqualTo [] || { GVAR(trackers) isEqualTo [] }) then {
[QGVAR(track), [_projectile]] call CBA_fnc_serverEvent;
};
2021-05-18 06:32:55 +00:00
};
}] call CBA_fnc_addClassEventHandler;
2021-07-02 23:47:15 +00:00
// Needed on all clients to properly destroy it. Despite the fact that deleteVehicle is AG EG, unless if you delete it on all clients there will still be missiles seen
[QGVAR(destroyProjectile), {
params ["_projectile"];
deleteVehicle _projectile;
}] call CBA_fnc_addEventHandler;
2021-05-19 03:32:04 +00:00
ADDON = true;