Code cleanup of Kestrel 4500 module.

This commit is contained in:
jokoho48 2015-08-14 01:55:54 +02:00
parent 7c60375105
commit 183aac1911
14 changed files with 150 additions and 112 deletions

View File

@ -17,3 +17,21 @@ PREP(updateDisplay);
PREP(updateImpellerState);
ADDON = true;
FUNC(updateMemory) = {
params ["_slot", "_value"];
GVAR(MIN) set [_slot, (GVAR(MIN) select _slot) min _value];
GVAR(MAX) set [_slot, _value max (GVAR(MAX) select _slot)];
GVAR(TOTAL) set [_slot, (GVAR(TOTAL) select _slot) + _value];
};
FUNC(dayOfWeek) = {
private "_table";
params ["_year", "_month", "_day"];
_table = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4];
if (_month < 3) then {
_year = _year - 1;
};
(_year + floor(_year/4) - floor(_year/100) + floor(_year/400) + (_table select (_month - 1)) + _day) % 7
};

View File

@ -3,10 +3,10 @@
* Handles the Kestrel 4500 dialog button actions
*
* Arguments:
* buttonID <integer>
* button ID <NUMBER>
*
* Return Value:
* Nothing
* None
*
* Example:
* 2 call ace_kestrel4500_fnc_buttonPressed

View File

@ -3,13 +3,13 @@
* Tests if the Kestrel 4500 can be shown
*
* Arguments:
* Nothing
* None
*
* Return Value:
* canShow (bool)
* canShow <BOOL>
*
* Example:
* [mode] call ace_kestrel4500_fnc_canShow
* call ace_kestrel4500_fnc_canShow
*
* Public: No
*/

View File

@ -3,18 +3,19 @@
* Gathers the weather data for the Kestrel 4500
*
* Arguments:
* Nothing
* None
*
* Return Value:
* Nothing
* None
*
* Example:
* call ace_kestrel4500_fnc_collectData
*
* Public: No
*/
#include "script_component.hpp"
private ["_playerDir", "_playerAltitude", "_temperature", "_humidity", "_barometricPressure", "_altitude", "_airDensity", "_densityAltitude", "_chill", "_heatIndex", "_dewPoint", "_wetBulb", "_fnc_updateMemory", "_windSpeed", "_crosswind", "_headwind"];
private ["_playerDir", "_playerAltitude", "_temperature", "_humidity", "_barometricPressure", "_altitude", "_airDensity", "_densityAltitude", "_chill", "_heatIndex", "_dewPoint", "_wetBulb", "_windSpeed", "_crosswind", "_headwind"];
_playerDir = getDir ACE_player;
_playerAltitude = (getPosASL ACE_player) select 2;
_temperature = _playerAltitude call EFUNC(weather,calculateTemperatureAtHeight);
@ -35,25 +36,19 @@ if (isNil QGVAR(MIN) || isNil QGVAR(MAX)) then {
{
GVAR(ENTRIES) set [_x, (GVAR(ENTRIES) select _x) + 1];
} forEach [1, 5, 6, 7, 8, 9, 10, 11, 12, 13];
} count [1, 5, 6, 7, 8, 9, 10, 11, 12, 13];
_fnc_updateMemory = {
PARAMS_2(_slot,_value);
GVAR(MIN) set [_slot, (GVAR(MIN) select _slot) min _value];
GVAR(MAX) set [_slot, _value max (GVAR(MAX) select _slot)];
GVAR(TOTAL) set [_slot, (GVAR(TOTAL) select _slot) + _value];
};
[0, _playerDir] call _fnc_updateMemory;
[0, _playerDir] call FUNC(updateMemory);
if (GVAR(MinAvgMaxMode) == 1) then {
{
GVAR(ENTRIES) set [_x, (GVAR(ENTRIES) select _x) + 1];
} forEach [2, 3, 4];
} count [2, 3, 4];
// Wind SPD
_windSpeed = call FUNC(measureWindSpeed);
[2, _windSpeed] call _fnc_updateMemory;
[2, _windSpeed] call FUNC(updateMemory);
// CROSSWIND
_crosswind = 0;
@ -62,7 +57,7 @@ if (GVAR(MinAvgMaxMode) == 1) then {
} else {
_crosswind = abs(sin(GVAR(RefHeading)) * _windSpeed);
};
[3, _crosswind] call _fnc_updateMemory;
[3, _crosswind] call FUNC(updateMemory);
// HEADWIND
_headwind = 0;
@ -80,12 +75,4 @@ if (GVAR(MinAvgMaxMode) == 1) then {
GVAR(TOTAL) set [4, (GVAR(TOTAL) select 4) + _headwind];
};
[5, _temperature] call _fnc_updateMemory;
[6, _chill] call _fnc_updateMemory;
[7, _humidity] call _fnc_updateMemory;
[8, _heatIndex] call _fnc_updateMemory;
[9, _dewPoint] call _fnc_updateMemory;
[10, _wetBulb] call _fnc_updateMemory;
[11, _barometricPressure] call _fnc_updateMemory;
[12, _altitude] call _fnc_updateMemory;
[13, _densityAltitude] call _fnc_updateMemory;
{ _x call FUNC(updateMemory); true } count [[5, _temperature],[6, _chill],[7, _humidity],[8, _heatIndex],[9, _dewPoint],[10, _wetBulb],[11, _barometricPressure],[12, _altitude],[13, _densityAltitude]];

View File

@ -3,7 +3,7 @@
* Opens the Kestrel 4500 dialog
*
* Arguments:
* Nothing
* None
*
* Return Value:
* Nothing

View File

@ -3,12 +3,13 @@
* Shows the Kestrel 4500 as rsc title
*
* Arguments:
* Nothing
* None
*
* Return Value:
* Nothing
*
* Example:
* call ace_kestrel4500_fnc_displayKestrell
*
* Public: No
*/
@ -65,33 +66,50 @@ GVAR(Overlay) = true;
_outputData = [] call FUNC(generateOutputData);
3 cutRsc ["RscKestrel4500", "PLAIN", 1, false];
_outputData params [
"_ctrlTop",
"_ctrlCenterBig",
"_ctrlCenter",
"_ctrlCenterLine1Left",
"_ctrlCenterLine2Left",
"_ctrlCenterLine3Left",
"_ctrlCenterLine1Right",
"_ctrlCenterLine2Right",
"_ctrlCenterLine3Right",
"_ctrlInfoLine1",
"_ctrlInfoLine2",
"_ctrlBottomBig",
"_ctrlCenterLine1",
"_ctrlCenterLine2",
"_ctrlCenterLine3",
"_ctrlCenterLine4",
"_ctrlCenterLine5",
"_ctrlCenterLine6"
];
__ctrlTop ctrlSetText (_outputData select 0);
__ctrlCenterBig ctrlSetText (_outputData select 1);
__ctrlTop ctrlSetText _ctrlTop;
__ctrlCenterBig ctrlSetText _ctrlCenterBig;
__ctrlCenter ctrlSetText _ctrlCenter;
__ctrlTop ctrlSetText (_outputData select 0);
__ctrlCenterBig ctrlSetText (_outputData select 1);
__ctrlCenter ctrlSetText (_outputData select 2);
__ctrlCenterLine1Left ctrlSetText _ctrlCenterLine1Left;
__ctrlCenterLine2Left ctrlSetText _ctrlCenterLine2Left;
__ctrlCenterLine3Left ctrlSetText _ctrlCenterLine3Left;
__ctrlCenterLine1Left ctrlSetText (_outputData select 3);
__ctrlCenterLine2Left ctrlSetText (_outputData select 4);
__ctrlCenterLine3Left ctrlSetText (_outputData select 5);
__ctrlCenterLine1Right ctrlSetText _ctrlCenterLine1Right;
__ctrlCenterLine2Right ctrlSetText _ctrlCenterLine2Right;
__ctrlCenterLine3Right ctrlSetText _ctrlCenterLine3Right;
__ctrlCenterLine1Right ctrlSetText (_outputData select 6);
__ctrlCenterLine2Right ctrlSetText (_outputData select 7);
__ctrlCenterLine3Right ctrlSetText (_outputData select 8);
__ctrlInfoLine1 ctrlSetText _ctrlInfoLine1;
__ctrlInfoLine2 ctrlSetText _ctrlInfoLine2;
__ctrlInfoLine1 ctrlSetText (_outputData select 9);
__ctrlInfoLine2 ctrlSetText (_outputData select 10);
__ctrlBottomBig ctrlSetText _ctrlBottomBig ;
__ctrlBottomBig ctrlSetText (_outputData select 11);
__ctrlCenterLine1 ctrlSetText (_outputData select 12);
__ctrlCenterLine2 ctrlSetText (_outputData select 13);
__ctrlCenterLine3 ctrlSetText (_outputData select 14);
__ctrlCenterLine4 ctrlSetText (_outputData select 15);
__ctrlCenterLine5 ctrlSetText (_outputData select 16);
__ctrlCenterLine6 ctrlSetText (_outputData select 17);
__ctrlCenterLine1 ctrlSetText _ctrlCenterLine1;
__ctrlCenterLine2 ctrlSetText _ctrlCenterLine2;
__ctrlCenterLine3 ctrlSetText _ctrlCenterLine3;
__ctrlCenterLine4 ctrlSetText _ctrlCenterLine4;
__ctrlCenterLine5 ctrlSetText _ctrlCenterLine5;
__ctrlCenterLine6 ctrlSetText _ctrlCenterLine6;
if (GVAR(referenceHeadingMenu) == 1) then {
if (GVAR(referenceHeadingAutoSet)) then {

View File

@ -3,12 +3,29 @@
* Generates the Kestrel 4500 output text.
*
* Arguments:
* Nothing
* None
*
* Return Value:
* [top <STRING>, centerBig <STRING>, CenterLine1Left <STRING>, CenterLine2Left <STRING>, CenterLine3Left <STRING>, CenterLine1Right <STRING>, CenterLine2Right <STRING>, CenterLine3Right <STRING>, InfoLine1 <STRING>, InfoLine2 <STRING>]
* 0: top <STRING>
* 1: centerBig <STRING>
* 2: CenterLine1Left <STRING>
* 3: CenterLine2Left <STRING>
* 4: CenterLine3Left <STRING>
* 5: CenterLine1Right <STRING>
* 6: CenterLine2Right <STRING>
* 7: CenterLine3Right <STRING>
* 8: InfoLine1 <STRING>
* 9: InfoLine2 <STRING>
* 10: Bottom Big <STRING>
* 11: Center Line 1 <STRING>
* 11: Center Line 2 <STRING>
* 12: Center Line 3 <STRING>
* 13: Center Line 4 <STRING>
* 14: Center Line 5 <STRING>
* 15: Center Line 6 <STRING>
*
* Example:
* _var = call ace_kestrell4500_fnc_generateOutputData
*
* Public: No
*/
@ -16,7 +33,7 @@
if (ACE_diagTime - GVAR(headingSetDisplayTimer) < 0.8) exitWith {["", "", " Heading Set", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]};
private ["_playerDir", "_playerAltitude", "_temperature", "_humidity", "_barometricPressure", "_airDensity", "_densityAltitude", "_chill", "_heatIndex", "_dewPoint", "_wetBulb", "_fnc_dayOfWeek", "_dayString", "_monthString", "_windSpeed", "_windDir", "_textTop", "_textCenterBig", "_textCenter", "_textCenterLine1Left", "_textCenterLine2Left", "_textCenterLine3Left", "_textCenterLine1Right", "_textCenterLine2Right", "_textCenterLine3Right", "_textInfoLine1", "_textInfoLine2", "_textBottomBig", "_textCenterLine1", "_textCenterLine2", "_textCenterLine3", "_textCenterLine4", "_textCenterLine5", "_textCenterLine6"];
private ["_playerDir", "_playerAltitude", "_temperature", "_humidity", "_barometricPressure", "_airDensity", "_densityAltitude", "_chill", "_heatIndex", "_dewPoint", "_wetBulb", "_dayString", "_monthString", "_windSpeed", "_windDir", "_textTop", "_textCenterBig", "_textCenter", "_textCenterLine1Left", "_textCenterLine2Left", "_textCenterLine3Left", "_textCenterLine1Right", "_textCenterLine2Right", "_textCenterLine3Right", "_textInfoLine1", "_textInfoLine2", "_textBottomBig", "_textCenterLine1", "_textCenterLine2", "_textCenterLine3", "_textCenterLine4", "_textCenterLine5", "_textCenterLine6"];
[] call FUNC(collectData);
@ -59,19 +76,6 @@ _heatIndex = [_temperature, _humidity] call EFUNC(weather,calculateHeatIndex);
_dewPoint = [_temperature, _humidity] call EFUNC(weather,calculateDewPoint);
_wetBulb = [_temperature, _barometricPressure, _humidity] call EFUNC(weather,calculateWetBulb);
_fnc_dayOfWeek = {
private ["_year", "_month", "_day", "_table"];
_year = _this select 0;
_month = _this select 1;
_day = _this select 2;
_table = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4];
if (_month < 3) then {
_year = _year - 1;
};
(_year + floor(_year/4) - floor(_year/100) + floor(_year/400) + (_table select (_month - 1)) + _day) % 7
};
GVAR(Direction) = 4 * floor(_playerDir / 90);
if (_playerDir % 90 > 10) then { GVAR(Direction) = GVAR(Direction) + 1};
if (_playerDir % 90 > 35) then { GVAR(Direction) = GVAR(Direction) + 1};
@ -82,8 +86,8 @@ GVAR(Direction) = GVAR(Direction) % 16;
if (GVAR(referenceHeadingMenu) == 0) then {
switch (GVAR(Menu)) do {
case 0: { // Date
EXPLODE_3_PVT(date,_year,_month,_day);
_dayString = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] select (date call _fnc_dayOfWeek);
date params ["_year", "_month", "_day"];
_dayString = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] select (date call FUNC(dayOfWeek));
_monthString = localize (["str_january","str_february","str_march","str_april","str_may","str_june","str_july","str_august","str_september","str_october","str_november","str_december"] select (_month - 1));
_textTop = _dayString;
_textCenter = format["%1 %2 %3", _day, _monthString, _year];

View File

@ -3,12 +3,13 @@
* Measures the wind speed, stores the information in GVAR(MeasuredWindSpeed) and updates GVAR(ImpellerState)
*
* Arguments:
* Nothing
* None
*
* Return Value:
* wind speed <NUMBER>
*
* Example:
* call ace_kestrel4500_fnc_canShow
*
* Public: No
*/

View File

@ -1,3 +1,18 @@
/*
* Author: Ruthberg
* Called if Kestrell Dialog is closed
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* call ace_kestrel4500_fnc_onCloseDialog
*
* Public: No
*/
#include "script_component.hpp"
uiNamespace setVariable ['Kestrel4500_Display', nil];

View File

@ -1,3 +1,18 @@
/*
* Author: Ruthberg
* Called if Kestrell Display is closed
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* call ace_kestrel4500_fnc_onCloseDisplay
*
* Public: No
*/
#include "script_component.hpp"
uiNamespace setVariable ['RscKestrel4500', nil];

View File

@ -6,7 +6,7 @@
* Nothing
*
* Return Value:
* Nothing
* None
*
* Example:
* call ace_kestrel4500_fnc_restore_user_data

View File

@ -3,10 +3,10 @@
* Saves user data into profileNamespace
*
* Arguments:
* Nothing
* None
*
* Return Value:
* Nothing
* None
*
* Example:
* call ace_kestrel4500_fnc_store_user_data

View File

@ -3,10 +3,10 @@
* Updates the Kestrel 4500 dialog text boxes.
*
* Arguments:
* Nothing
* None
*
* Return Value:
* Nothing
* None
*
* Example:
*
@ -22,29 +22,9 @@ private ["_outputData"];
_outputData = [] call FUNC(generateOutputData);
ctrlSetText [74100, _outputData select 0];
ctrlSetText [74200, _outputData select 1];
ctrlSetText [74201, _outputData select 2];
ctrlSetText [74300, _outputData select 3];
ctrlSetText [74301, _outputData select 4];
ctrlSetText [74302, _outputData select 5];
ctrlSetText [74303, _outputData select 6];
ctrlSetText [74304, _outputData select 7];
ctrlSetText [74305, _outputData select 8];
ctrlSetText [74400, _outputData select 9];
ctrlSetText [74401, _outputData select 10];
ctrlSetText [74500, _outputData select 11];
ctrlSetText [74600, _outputData select 12];
ctrlSetText [74601, _outputData select 13];
ctrlSetText [74602, _outputData select 14];
ctrlSetText [74603, _outputData select 15];
ctrlSetText [74604, _outputData select 16];
ctrlSetText [74605, _outputData select 17];
{
ctrlSetText [_x , _outputData select _foreachindex];
} forEach [74100, 74200, 74201, 74300, 74301, 74302, 74303, 74304, 74305, 74400, 74401, 74500, 74600, 74601, 74602, 74603, 74604, 74605];
if (GVAR(referenceHeadingMenu) == 1) then {
if (GVAR(referenceHeadingAutoSet)) then {

View File

@ -3,10 +3,10 @@
* Updates the Kestrel 4500 Impeller state
*
* Arguments:
* Nothing
* None
*
* Return Value:
* Nothing
* None
*
* Example:
*