diff --git a/addons/radar/$PBOPREFIX$ b/addons/radar/$PBOPREFIX$ new file mode 100644 index 0000000000..93eb6aa699 --- /dev/null +++ b/addons/radar/$PBOPREFIX$ @@ -0,0 +1 @@ +z\ace\addons\radar diff --git a/addons/radar/CfgEventHandlers.hpp b/addons/radar/CfgEventHandlers.hpp new file mode 100644 index 0000000000..319bdaf0ff --- /dev/null +++ b/addons/radar/CfgEventHandlers.hpp @@ -0,0 +1,25 @@ +class Extended_PreStart_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preStart)); + }; +}; + +class Extended_PreInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preInit)); + }; +}; + +class Extended_PostInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_postInit)); + }; +}; + +class Extended_Init_EventHandlers { + class Air { + class ADDON { + init = QUOTE(call FUNC(registerAircraft)); + }; + }; +}; diff --git a/addons/radar/XEH_PREP.hpp b/addons/radar/XEH_PREP.hpp new file mode 100644 index 0000000000..29d1ce9d34 --- /dev/null +++ b/addons/radar/XEH_PREP.hpp @@ -0,0 +1,4 @@ +PREP(changeCone); +PREP(registerAircraft); +PREP(scan); +PREP(switchRadar); diff --git a/addons/radar/XEH_postInit.sqf b/addons/radar/XEH_postInit.sqf new file mode 100644 index 0000000000..beacce145a --- /dev/null +++ b/addons/radar/XEH_postInit.sqf @@ -0,0 +1,50 @@ +#include "script_component.hpp" + +[ + "ACE3 Radar", + QGVAR(switchRadar), + [localize LSTRING(switchRadar), localize LSTRING(switchRadar_description)], + { call FUNC(switchRadar) }, + { false }, + [0x24, [false, false, false]] +] call CBA_fnc_addKeybind; + +// - Width -------------------------------------------------------------------- +[ + "ACE3 Radar", + QGVAR(increaseWidth), + [localize LSTRING(increaseWidth), localize LSTRING(increaseWidth_description)], + { [true, true] call FUNC(changeCone) }, + { false }, + [0x25, [false, false, false]], + true +] call CBA_fnc_addKeybind; +[ + "ACE3 Radar", + QGVAR(decreaseWidth), + [localize LSTRING(decreaseWidth), localize LSTRING(decreaseWidth_description)], + { [false, true] call FUNC(changeCone) }, + { false }, + [0x25, [true, false, false]], + true +] call CBA_fnc_addKeybind; + +// - Height ------------------------------------------------------------------- +[ + "ACE3 Radar", + QGVAR(increaseHeight), + [localize LSTRING(increaseHeight), localize LSTRING(increaseHeight_description)], + { [true, false] call FUNC(changeCone) }, + { false }, + [0x26, [false, false, false]], + true +] call CBA_fnc_addKeybind; +[ + "ACE3 Radar", + QGVAR(decreaseHeight), + [localize LSTRING(decreaseHeight), localize LSTRING(decreaseHeight_description)], + { [false, false] call FUNC(changeCone) }, + { false }, + [0x26, [true, false, false]], + true +] call CBA_fnc_addKeybind; diff --git a/addons/radar/XEH_preInit.sqf b/addons/radar/XEH_preInit.sqf new file mode 100644 index 0000000000..22b1a7fd1e --- /dev/null +++ b/addons/radar/XEH_preInit.sqf @@ -0,0 +1,9 @@ +#include "script_component.hpp" + +ADDON = false; + +#include "XEH_PREP.hpp" + +GVAR(aircraft) = []; + +ADDON = true; diff --git a/addons/radar/XEH_preStart.sqf b/addons/radar/XEH_preStart.sqf new file mode 100644 index 0000000000..022888575e --- /dev/null +++ b/addons/radar/XEH_preStart.sqf @@ -0,0 +1,3 @@ +#include "script_component.hpp" + +#include "XEH_PREP.hpp" diff --git a/addons/radar/config.cpp b/addons/radar/config.cpp new file mode 100644 index 0000000000..6cf0adc36d --- /dev/null +++ b/addons/radar/config.cpp @@ -0,0 +1,16 @@ +#include "script_component.hpp" + +class CfgPatches { + class ADDON { + units[] = {}; + weapons[] = {}; + requiredVersion = REQUIRED_VERSION; + requiredAddons[] = {"ace_common"}; + author = ECSTRING(common,ACETeam); + authors[] = {"BaerMitUmlaut"}; + url = ECSTRING(main,URL); + VERSION_CONFIG; + }; +}; + +#include "CfgEventHandlers.hpp" diff --git a/addons/radar/functions/fnc_changeCone.sqf b/addons/radar/functions/fnc_changeCone.sqf new file mode 100644 index 0000000000..5b279fcc62 --- /dev/null +++ b/addons/radar/functions/fnc_changeCone.sqf @@ -0,0 +1,49 @@ +/* + * Author: BaerMitUmlaut + * Changes the radar scanning cone. + * + * Arguments: + * 0: Increase value + * 1: Change width (false changes height) + * + * Return Value: + * Key handled + * + * Public: No + */ +#include "script_component.hpp" +params ["_increase", "_changeWidth"]; + +private _vehicle = vehicle ACE_player; +if !(_vehicle getVariable [QGVAR(radarEnabled), false]) exitWith {false}; + +private _angle = if (_changeWidth) then { + _vehicle getVariable QGVAR(coneAngleH) +} else { + _vehicle getVariable QGVAR(coneAngleV) +}; + +private _newAngle = 0; +if (_increase) then { + private _maxAngle = if (isNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> QVAR(coneAngleMax))) then { + getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> QVAR(coneAngleMax)) + } else { + 60 + }; + _newAngle = (_angle + 5) min _maxAngle; +} else { + private _minAngle = if (isNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> QVAR(coneAngleMin))) then { + getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> QVAR(coneAngleMin)) + } else { + 15 + }; + _newAngle = (_angle - 5) max _minAngle; +}; + +if (_changeWidth) then { + _vehicle setVariable [QGVAR(coneAngleH), _newAngle]; +} else { + _vehicle setVariable [QGVAR(coneAngleV), _newAngle]; +}; + +true diff --git a/addons/radar/functions/fnc_registerAircraft.sqf b/addons/radar/functions/fnc_registerAircraft.sqf new file mode 100644 index 0000000000..640857441f --- /dev/null +++ b/addons/radar/functions/fnc_registerAircraft.sqf @@ -0,0 +1,52 @@ +/* + * Author: BaerMitUmlaut + * Registers an aircraft to the radar system. + * + * Arguments: + * 0: Aircraft + * + * Return Value: + * None + * + * Public: No + */ +#include "script_component.hpp" +params ["_aircraft"]; + +private _config = configFile >> "CfgVehicles" >> typeOf _aircraft; + +private _rcs = if (isNumber (_config >> QGVAR(rcs))) then { + getNumber (_config >> QGVAR(rcs)) +} else { + // Arbitrary value, middle between F-15 and F/A-18 + // Source: http://www.globalsecurity.org/military/world/stealth-aircraft-rcs.htm + 12 +}; +_aircraft setVariable [QGVAR(rcs), _rcs]; + +/*private _range = if (isNumber (_config >> QGVAR(range))) then { + getNumber (_config >> QGVAR(range)) +} else { + // Arbitrary value + 25 +}; +_aircraft setVariable [QGVAR(range), _range];*/ + +private _coneAngleMin = if (isNumber (_config >> QGVAR(coneAngleMin))) then { + getNumber (_config >> QGVAR(coneAngleMin)) +} else { + // Arbitrary value + 60 +}; + +private _coneAngleMax = if (isNumber (_config >> QGVAR(coneAngleMax))) then { + getNumber (_config >> QGVAR(coneAngleMax)) +} else { + // Arbitrary value + 15 +}; + +_aircraft setVariable [QGVAR(coneAngleV), (_coneAngleMax - _coneAngleMin) / 2]; +_aircraft setVariable [QGVAR(coneAngleH), (_coneAngleMax - _coneAngleMin) / 2]; + +GVAR(aircraft) pushBack _aircraft; diff --git a/addons/radar/functions/fnc_scan.sqf b/addons/radar/functions/fnc_scan.sqf new file mode 100644 index 0000000000..3f80d90cfe --- /dev/null +++ b/addons/radar/functions/fnc_scan.sqf @@ -0,0 +1,40 @@ +/* + * Author: BaerMitUmlaut + * Scans the area in front of the aircraft by radar. + * + * Arguments: + * 0: Aircraft + * 1: The direction of the scanning cone + * 2: The horizontal angle (in deg) of the scanning cone + * 3: The vertical angle (in deg) of the scanning cone + * + * Return Value: + * Detected vehicles + * + * Public: No + */ +#include "script_component.hpp" +params ["_aircraft", "_scanVector", "_scanConeH", "_scanConeV"]; + +private _scanVectorH = _scanVector select [0, 2]; //[x, y] +private _scanVectorV = _scanVector select [1, 2]; //[y, z] +private _detectedAircraft = []; + +{ + if ((getPosATL _x) select 2 > 10) then { + private _dirToTarget = (getPosASL _x) vectorDiff (getPosASL _aircraft); + + private _diffRadH = (_dirToTarget select [0, 2]) vectorDotProduct _scanVectorH; + private _diffDegH = RAD_TO_DEG(_diffRadH); + private _diffRadV = (_dirToTarget select [1, 2]) vectorDotProduct _scanVectorV; + private _diffDegV = RAD_TO_DEG(_diffRadV); + + if (_diffDegH <= _scanConeH && {_diffDegV <= _scanConeV}) then { + _detectedAircraft pushBack _x; + }; + }; + + false +} count GVAR(aircraft); + +_detectedAircraft diff --git a/addons/radar/functions/fnc_switchRadar.sqf b/addons/radar/functions/fnc_switchRadar.sqf new file mode 100644 index 0000000000..1331ba95a1 --- /dev/null +++ b/addons/radar/functions/fnc_switchRadar.sqf @@ -0,0 +1,24 @@ +/* + * Author: BaerMitUmlaut + * Switches the radar on or off. + * + * Arguments: + * None + * + * Return Value: + * Key handled + * + * Public: No + */ +#include "script_component.hpp" + +private _vehicle = vehicle ACE_player; +if !(_vehicle isKindOf "Air") exitWith {false}; + +if (_vehicle getVariable [QGVAR(radarEnabled), false]) then { + _vehicle setVariable [QGVAR(radarEnabled), true]; +} else { + _vehicle setVariable [QGVAR(radarEnabled), false]; +}; + +true diff --git a/addons/radar/functions/script_component.hpp b/addons/radar/functions/script_component.hpp new file mode 100644 index 0000000000..7e415e9e1d --- /dev/null +++ b/addons/radar/functions/script_component.hpp @@ -0,0 +1 @@ +#include "\z\ace\addons\radar\script_component.hpp" diff --git a/addons/radar/script_component.hpp b/addons/radar/script_component.hpp new file mode 100644 index 0000000000..f31baf2028 --- /dev/null +++ b/addons/radar/script_component.hpp @@ -0,0 +1,19 @@ +#define COMPONENT radar +#include "\z\ace\addons\main\script_mod.hpp" + +// #define DEBUG_MODE_FULL +// #define DISABLE_COMPILE_CACHE +// #define CBA_DEBUG_SYNCHRONOUS +// #define ENABLE_PERFORMANCE_COUNTERS + +#ifdef DEBUG_ENABLED_RADAR + #define DEBUG_MODE_FULL +#endif + +#ifdef DEBUG_SETTINGS_RADAR + #define DEBUG_SETTINGS DEBUG_SETTINGS_RADAR +#endif + +#include "\z\ace\addons\main\script_macros.hpp" + +#define RAD_TO_DEG(var) (var * 180 / pi)