Initial commit ACE_Radar

This commit is contained in:
BaerMitUmlaut 2016-06-13 11:44:16 +02:00
parent a4bd6ea80f
commit 615d2ed0cf
13 changed files with 293 additions and 0 deletions

1
addons/radar/$PBOPREFIX$ Normal file
View File

@ -0,0 +1 @@
z\ace\addons\radar

View File

@ -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));
};
};
};

View File

@ -0,0 +1,4 @@
PREP(changeCone);
PREP(registerAircraft);
PREP(scan);
PREP(switchRadar);

View File

@ -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;

View File

@ -0,0 +1,9 @@
#include "script_component.hpp"
ADDON = false;
#include "XEH_PREP.hpp"
GVAR(aircraft) = [];
ADDON = true;

View File

@ -0,0 +1,3 @@
#include "script_component.hpp"
#include "XEH_PREP.hpp"

16
addons/radar/config.cpp Normal file
View File

@ -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"

View File

@ -0,0 +1,49 @@
/*
* Author: BaerMitUmlaut
* Changes the radar scanning cone.
*
* Arguments:
* 0: Increase value <BOOL>
* 1: Change width (false changes height) <BOOL>
*
* Return Value:
* Key handled <BOOL>
*
* 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

View File

@ -0,0 +1,52 @@
/*
* Author: BaerMitUmlaut
* Registers an aircraft to the radar system.
*
* Arguments:
* 0: Aircraft <OBJECT>
*
* 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;

View File

@ -0,0 +1,40 @@
/*
* Author: BaerMitUmlaut
* Scans the area in front of the aircraft by radar.
*
* Arguments:
* 0: Aircraft <OBJECT>
* 1: The direction of the scanning cone <ARRAY>
* 2: The horizontal angle (in deg) of the scanning cone
* 3: The vertical angle (in deg) of the scanning cone
*
* Return Value:
* Detected vehicles <ARRAY>
*
* 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

View File

@ -0,0 +1,24 @@
/*
* Author: BaerMitUmlaut
* Switches the radar on or off.
*
* Arguments:
* None
*
* Return Value:
* Key handled <BOOL>
*
* 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

View File

@ -0,0 +1 @@
#include "\z\ace\addons\radar\script_component.hpp"

View File

@ -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)