From c8fd07a5abac38d3596215e453a1469d11c085cc Mon Sep 17 00:00:00 2001 From: KoffeinFlummi Date: Tue, 13 Jan 2015 22:51:02 +0100 Subject: [PATCH] Finalize FCS port --- addons/fcs/CfgEventHandlers.hpp | 4 +-- addons/fcs/XEH_preInit.sqf | 21 ++++++++-------- addons/fcs/config.cpp | 30 +++++++++++------------ addons/fcs/functions/fnc_canResetFCS.sqf | 16 ++++++++++++ addons/fcs/functions/fnc_firedEH.sqf | 2 +- addons/fcs/functions/fnc_keyDown.sqf | 8 +++--- addons/fcs/functions/fnc_keyUp.sqf | 9 ++++--- addons/fcs/functions/fnc_reset.sqf | 2 +- addons/fcs/functions/fnc_vehicleInit.sqf | 2 ++ addons/fcs/functions/script_component.hpp | 12 +++++++++ 10 files changed, 70 insertions(+), 36 deletions(-) create mode 100644 addons/fcs/functions/fnc_canResetFCS.sqf create mode 100644 addons/fcs/functions/script_component.hpp diff --git a/addons/fcs/CfgEventHandlers.hpp b/addons/fcs/CfgEventHandlers.hpp index c1e0bb73f1..69ef4a3057 100644 --- a/addons/fcs/CfgEventHandlers.hpp +++ b/addons/fcs/CfgEventHandlers.hpp @@ -1,12 +1,12 @@ class Extended_PreInit_EventHandlers { class ADDON { - init = QUOTE( call compile preprocessFileLineNumbers PATHTOF(XEH_preInit.sqf) ); + init = QUOTE(call COMPILE_FILE(XEH_preInit) ); }; }; class Extended_PostInit_EventHandlers { class ADDON { - clientInit = QUOTE( call compile preprocessFileLineNumbers PATHTOF(XEH_clientInit.sqf) ); + clientInit = QUOTE(call COMPILE_FILE(XEH_clientInit) ); }; }; diff --git a/addons/fcs/XEH_preInit.sqf b/addons/fcs/XEH_preInit.sqf index c9726ac36b..ce6f5c99dd 100644 --- a/addons/fcs/XEH_preInit.sqf +++ b/addons/fcs/XEH_preInit.sqf @@ -1,12 +1,13 @@ #include "script_component.hpp" -PREPF(adjustRange) -PREPF(canUseFCS) -PREPF(canUseRangefinder) -PREPF(firedEH) -PREPF(getAngle) -PREPF(getRange) -PREPF(keyDown) -PREPF(keyUp) -PREPF(reset) -PREPF(vehicleInit) +PREP(adjustRange); +PREP(canResetFCS); +PREP(canUseFCS); +PREP(canUseRangefinder); +PREP(firedEH); +PREP(getAngle); +PREP(getRange); +PREP(keyDown); +PREP(keyUp); +PREP(reset); +PREP(vehicleInit); diff --git a/addons/fcs/config.cpp b/addons/fcs/config.cpp index 737f1d06e9..ddd490e674 100644 --- a/addons/fcs/config.cpp +++ b/addons/fcs/config.cpp @@ -5,7 +5,7 @@ class CfgPatches { units[] = {}; weapons[] = {}; requiredVersion = 0.60; - requiredAddons[] = {ace_core, ace_interaction}; + requiredAddons[] = {ace_common, ace_interaction}; version = QUOTE(VERSION); versionStr = QUOTE(VERSION); versionAr[] = {VERSION_AR}; @@ -16,22 +16,22 @@ class CfgPatches { #include "CfgEventHandlers.hpp" -class EGVAR(Core, Default_Keys) { +class ACE_Default_Keys { class laseTarget { - displayName = $STR_ACE_FireControlSystem_LaseTarget; + displayName = $STR_ACE_FCS_LaseTarget; condition = QUOTE(call FUNC(canUseRangefinder) || FUNC(canUseFCS)); - statement = QUOTE(_range = call FUNC(getRange); if (call FUNC(canUseFCS)) then {[_vehicle, _range] call FUNC(keyDown)};); + statement = QUOTE([_vehicle] call FUNC(keyDown)); conditionUp = QUOTE(GVAR(enabled) && FUNC(canUseFCS)); - statementUp = QUOTE(_range = call FUNC(getRange); if (GVAR(enabled) && FUNC(canUseFCS)) then {[_vehicle, _range] call FUNC(keyUp)};); + statementUp = QUOTE([_vehicle] call FUNC(keyUp)); key = 15; shift = 0; control = 0; alt = 0; }; class adjustRangeUp { - displayName = $STR_ACE_FireControlSystem_AdjustRangeUp; - condition = QUOTE(ACE_player == gunner _vehicle && {getNumber (configFile >> 'CfgVehicles' >> (typeOf _vehicle) >> QGVAR(Enabled)) == 1}); - statement = QUOTE([_vehicle, 50] call FUNC(adjustRange)); + displayName = $STR_ACE_FCS_AdjustRangeUp; + condition = QUOTE(call FUNC(canUseRangefinder) || FUNC(canUseFCS)); + statement = QUOTE([_vehicle, 50] call FUNC(adjustRange)); key = 201; shift = 0; control = 0; @@ -39,7 +39,7 @@ class EGVAR(Core, Default_Keys) { allowHolding = 1; }; class adjustRangeDown: adjustRangeUp { - displayName = $STR_ACE_FireControlSystem_AdjustRangeDown; + displayName = $STR_ACE_FCS_AdjustRangeDown; statement = QUOTE([_vehicle, -50] call FUNC(adjustRange)); key = 209; }; @@ -71,9 +71,9 @@ class CfgVehicles { class Car: LandVehicle { class ACE_SelfActions { class ResetFCS { - displayName = $STR_ACE_FireControlSystem_ResetFCS; + displayName = $STR_ACE_FCS_ResetFCS; enableInside = 1; - condition = QUOTE((count (_vehicle getVariable [QGVAR(Magazines), []]) > 1) and (_player == gunner _vehicle)); + condition = QUOTE(call FUNC(canResetFCS)); statement = QUOTE([vehicle _player] call FUNC(reset);); showDisabled = 0; priority = 1; @@ -125,9 +125,9 @@ class CfgVehicles { GVAR(Enabled) = 1; // all tracked vehicles get one by default class ACE_SelfActions { class ResetFCS { - displayName = $STR_ACE_FireControlSystem_ResetFCS; + displayName = $STR_ACE_FCS_ResetFCS; enableInside = 1; - condition = QUOTE((count (_vehicle getVariable [QGVAR(Magazines), []]) > 1) and (_player == gunner _vehicle)); + condition = QUOTE(call FUNC(canResetFCS)); statement = QUOTE([vehicle _player] call FUNC(reset);); showDisabled = 0; priority = 1; @@ -243,9 +243,9 @@ class CfgVehicles { class Helicopter: Air { class ACE_SelfActions { class ResetFCS { - displayName = $STR_ACE_FireControlSystem_ResetFCS; + displayName = $STR_ACE_FCS_ResetFCS; enableInside = 1; - condition = QUOTE((count (_vehicle getVariable [QGVAR(Magazines), []]) > 1) and (_player == gunner _vehicle)); + condition = QUOTE(call FUNC(canResetFCS)); statement = QUOTE([vehicle _player] call FUNC(reset);); showDisabled = 0; priority = 1; diff --git a/addons/fcs/functions/fnc_canResetFCS.sqf b/addons/fcs/functions/fnc_canResetFCS.sqf new file mode 100644 index 0000000000..0aa281bd85 --- /dev/null +++ b/addons/fcs/functions/fnc_canResetFCS.sqf @@ -0,0 +1,16 @@ +/* + * Author: KoffeinFlummi + * + * Called from config. Can player reset FCS? + * + * Argument: + * Nothing + * + * Return value: + * Boolean (Bool) + */ + +#include "script_component.hpp" + +_player == gunner _vehicle +&& (count (_vehicle getVariable [QGVAR(Magazines), []]) > 1) diff --git a/addons/fcs/functions/fnc_firedEH.sqf b/addons/fcs/functions/fnc_firedEH.sqf index c8b5649f6a..235e4531b8 100644 --- a/addons/fcs/functions/fnc_firedEH.sqf +++ b/addons/fcs/functions/fnc_firedEH.sqf @@ -34,7 +34,7 @@ _offset = 0; }; } forEach _FCSMagazines; -[_round, (_unit getVariable QGVAR(Azimuth)), _offset, 0] call EFUNC(core, changeProjectileDirection); +[_round, (_unit getVariable QGVAR(Azimuth)), _offset, 0] call EFUNC(common,changeProjectileDirection); // Air burst missile // may need to get rewritten diff --git a/addons/fcs/functions/fnc_keyDown.sqf b/addons/fcs/functions/fnc_keyDown.sqf index 41f9d793dc..e0c6cd35f9 100644 --- a/addons/fcs/functions/fnc_keyDown.sqf +++ b/addons/fcs/functions/fnc_keyDown.sqf @@ -4,7 +4,7 @@ * Starts watching the target for sideways correction. * * Arguments: - * none + * 0: Vehicle * * Return Value: * none @@ -15,13 +15,15 @@ private ["_vehicle", "_distance", "_weaponDirection"]; _vehicle = _this select 0; -_distance = _this select 1; +_distance = call FUNC(getRange); + +if !(call FUNC(canUseFCS)) exitWith {}; GVAR(Enabled) = true; GVAR(Time) = time; if (_distance == 0) then { - _distance = [5, 5000, 0] call EFUNC(core, getTargetDistance); // maximum distance: 5000m, 5m precision + _distance = [5, 5000, 0] call EFUNC(common,getTargetDistance); // maximum distance: 5000m, 5m precision }; _weaponDirection = _vehicle weaponDirection currentWeapon _vehicle; diff --git a/addons/fcs/functions/fnc_keyUp.sqf b/addons/fcs/functions/fnc_keyUp.sqf index 7ad410a241..69c11137cf 100644 --- a/addons/fcs/functions/fnc_keyUp.sqf +++ b/addons/fcs/functions/fnc_keyUp.sqf @@ -5,7 +5,6 @@ * * Arguments: * 0: The vehicle - * 1: Range Override (Optional) * * Return Value: * none @@ -16,7 +15,9 @@ private ["_ammoType", "_viewDiff", "_posArrival", "_airFriction", "_timeToLive", "_maxElev", "_vehicle", "_posTarget", "_distance", "_simulationStep", "_posX", "_velocityMagnitude", "_magazines", "_movingAzimuth", "_FCSElevation", "_velocityX", "_velocityY", "_weaponDirection", "_velocityTarget", "_FCSAzimuth", "_FCSMagazines", "_dirArrival", "_i", "_magazineType", "_angleTarget", "_offset", "_timeToTarget", "_initSpeed"]; _vehicle = _this select 0; -_distance = _this select 1; +_distance = call FUNC(getRange); + +if !(GVAR(enabled) && FUNC(canUseFCS)) exitWith {}; _magazines = magazines _vehicle; @@ -25,7 +26,7 @@ if (_distance == 0) then { getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> QGVAR(DistanceInterval)), getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> QGVAR(MaxDistance)), getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> QGVAR(MinDistance)) - ] call EFUNC(core, getTargetDistance); // maximum distance: 5000m, 5m precision + ] call EFUNC(common,getTargetDistance); // maximum distance: 5000m, 5m precision }; _weaponDirection = _vehicle weaponDirection currentWeapon _vehicle; @@ -159,4 +160,4 @@ GVAR(backgroundCalculation) = [_vehicle, _magazines, _distance, _angleTarget, _F _vehicle setVariable [QGVAR(Elevation), _FCSElevation, true]; }; -[format ["%1: %2", localize "STR_ACE_FireControlSystem_ZeroedTo", _distance]] call EFUNC(core, displayTextStructured); +[format ["%1: %2", localize "STR_ACE_FCS_ZeroedTo", _distance]] call EFUNC(common,displayTextStructured); diff --git a/addons/fcs/functions/fnc_reset.sqf b/addons/fcs/functions/fnc_reset.sqf index 326b5c3212..f49c4c9589 100644 --- a/addons/fcs/functions/fnc_reset.sqf +++ b/addons/fcs/functions/fnc_reset.sqf @@ -21,4 +21,4 @@ _vehicle setVariable [QGVAR(Magazines), [], true]; _vehicle setVariable [QGVAR(Elevation), 0, true]; _vehicle setVariable [QGVAR(Azimuth), 0, true]; -[localize "STR_ACE_FireControlSystem_HasBeenReset"] call EFUNC(core, displayTextStructured); +[localize "STR_ACE_FCS_HasBeenReset"] call EFUNC(common,displayTextStructured); diff --git a/addons/fcs/functions/fnc_vehicleInit.sqf b/addons/fcs/functions/fnc_vehicleInit.sqf index 87d27e1d84..f65ce6dc7d 100644 --- a/addons/fcs/functions/fnc_vehicleInit.sqf +++ b/addons/fcs/functions/fnc_vehicleInit.sqf @@ -10,6 +10,8 @@ * none */ +#include "script_component.hpp" + private ["_gunBeg", "_gunnerView", "_gunBegPos", "_gunnerViewPos", "_viewDiff"]; if (getNumber (configFile >> "CfgVehicles" >> (typeOf (_this select 0)) >> QGVAR(Enabled)) == 1) then { diff --git a/addons/fcs/functions/script_component.hpp b/addons/fcs/functions/script_component.hpp new file mode 100644 index 0000000000..153cad41b2 --- /dev/null +++ b/addons/fcs/functions/script_component.hpp @@ -0,0 +1,12 @@ +#define COMPONENT fcs +#include "\z\ace\Addons\main\script_mod.hpp" + +#ifdef DEBUG_ENABLED_FCS + #define DEBUG_MODE_FULL +#endif + +#ifdef DEBUG_SETTINGS_FCS + #define DEBUG_SETTINGS DEBUG_SETTINGS_FCS +#endif + +#include "\z\ace\Addons\main\script_macros.hpp"