From 989ce332f7379cb4b308f5e6045044d950d32c04 Mon Sep 17 00:00:00 2001 From: zhongjin Date: Thu, 24 Nov 2022 08:41:35 +0800 Subject: [PATCH] first commit --- Changelog.txt | 227 + LICENSE.md | 675 ++ README.md | 809 +++ addon-config.xml | 28 + addon-main.nas | 40 + addon-menubar-items.xml | 84 + addon-metadata.xml | 111 + festival.xml | 111 + globals.nas | 756 +++ gui/dialogs/about-dialog.xml | 69 + gui/dialogs/help-dialog.xml | 121 + gui/dialogs/set-aircraft-type-dialog.xml | 53 + gui/dialogs/settings-dialog.xml | 563 ++ rgatc.nas | 7157 ++++++++++++++++++++++ settings.nas | 485 ++ 15 files changed, 11289 insertions(+) create mode 100644 Changelog.txt create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 addon-config.xml create mode 100644 addon-main.nas create mode 100644 addon-menubar-items.xml create mode 100644 addon-metadata.xml create mode 100644 festival.xml create mode 100644 globals.nas create mode 100644 gui/dialogs/about-dialog.xml create mode 100644 gui/dialogs/help-dialog.xml create mode 100644 gui/dialogs/set-aircraft-type-dialog.xml create mode 100644 gui/dialogs/settings-dialog.xml create mode 100644 rgatc.nas create mode 100644 settings.nas diff --git a/Changelog.txt b/Changelog.txt new file mode 100644 index 0000000..2920458 --- /dev/null +++ b/Changelog.txt @@ -0,0 +1,227 @@ +Changelog 2.3.0 - 7 May 2021 + +- [RedGriffin] Added option "Open dialog at startup" in settings +- [RedGriffin] Added option "ATC text position" in settings +- [RedGriffin] Added option "ATC text transparency" in settings +- [RedGriffin] Added support for multiple transponders +- [RedGriffin] Radio frequencies now uses a three decimal digits resolution +- [RedGriffin] Add airport city name to radio station name in case it is missing +- [RedGriffin] Added ATC log window +- [RedGriffin] Altitude check warning now uses a variable time according to aircraft + type, current and target altitude + + +*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* + + +Changelog 2.2.0 - 6 March 2021 + +- [RedGriffin] Voices are now assigned at random from the whole pool of voices available in the property tree. + This will give the sensation of speaking to different operators, especially when used with + festival server and providing a fairly good number of different voices with custom properties + in /sim/sound/voices/voice[x]. + Pilot voice is always assigned to the voice having in the description the tag "pilot". This voice + is exclusively assigned to the pilot and excluded from the pool of random voices. +- [RedGriffin] Added support for festival server. In case /sim/sound/voices/voice[x]/festival is true and + festival is initialized with audio async mode (audio_mode 'async) in + sound/sim/sound/voices/voice[x]/preamble, Red Griffin ATC will split text in multiple parts and + send them all in sequence to festival in order to provide a quicker response (actually, creating + utterances while speaking), otherwise text is sent to the speech synthetizer (internal flite-hts + or festival) in just one string. +- [RedGriffin} Improved algorithm in getApproachingRunway() to determine the right runway in case of + parallel runways +- [RedGriffin] Changed most of getprop and setprop to Nasal global.props functions +- [RedGriffin] Improved COM radio detection and usability + + +*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* + + +Changelog 2.1.0 - 2 January 2021 + +- [RedGriffin] Added menubar item "on/off" +- [RedGriffin] Improved "too low" and "towards terrain" warnings +- [RedGriffin] Added squawking +- [RedGriffin] Weather information is now completely based on user settings (live-data or scenario preset) +- [RedGriffin] Added information identification to departure information +- [RedGriffin] Added approach slope angle to settings +- [RedGriffin] Added aircraft type auto detection to settings according to /sim/tags +- [RedGriffin] Altitude of approach point is now determined according to the slope angle + + +*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* + + +Changelog 2.0.0 - 7 November 2020 + +- [RedGriffin] Production release + + +*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* + + +Changelog 2.0.0 beta 1 - 4 October 2020 + +- [RedGriffin] Added "Wind calm" message in case wind speed is zero +- [RedGriffin] Moved "Departure Information" button to position 2 when Aircraft is not near runway +- [RedGriffin] Main dialog window now shows version +- [RedGriffin] Changed some Pilot/ATC messages for a more complete and clear take off/approach/landing procedure +- [RedGriffin] "Ready for Departure" button changes to "Abort Departure" when cleared for take off +- [RedGriffin] Warnings "too low" and "towards terrain" are now issued only in case radio is tuned to the CTR radio +- [RedGriffin] In case aircraft enters a CTR without approval, ATC issues a warning if radio is tuned to the CTR radio +- [RedGriffin] Added "ATC Radio" mode Auto/COM1/COM2/COM3 to settings +- [RedGriffin] Added "too low" and "terrain" warnings On/Off to settings +- [RedGriffin] Added assistedAtcApproach() to let the Atc assist and provide instructions to the aircraft when approaching an airport +- [RedGriffin] Added "Aircraft type" setting in order to "fine tune" specific operational values +- [RedGriffin] Added "Multiplay chat" setting support to send ATC messages to chat + + +*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* + + +Changelog 1.4.0 - 16 May 2020 + +- [RedGriffin] Added "Include Manufacturer" in settings +- [RedGriffin] Pilot messages are now spoken via /sim/sound/voice/pilot property +- [RedGriffin] Added "Pilot message mode" in settings +- [RedGriffin] Added "Pilot response mode" in settings +- [RedGriffin] Added "ATC message mode" in settings +- [RedGriffin] Added "R" button and corresponding key binding to repeat the last ATC message +- [RedGriffin] Callsign in settings is now written to both /sim/multiplay/callsign and + /sim/user/callsign properties + + +*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* + + +Changelog 1.3.0 - 3 May 2020 + +- [RedGriffin] getRadioType(): "radio" pattern is associated to tower if nothing else applies +- [RedGriffin] Dialog can now be opened to any corner of the screen. Defaults to bottom-left position. +- [RedGriffin] Added del() overload to dlgWindow to properly manage dialog status +- [RedGriffin] Added settings dialog + + +*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* + + +Changelog 1.2.2 - 22 April 2020 + +- [RedGriffin] Fixed missing getprop() in updateATC() due to unknown editing + procedure which unintentionally removed it, who knows why, maybe it + was kate editor's pedantic highlighting when searching? + I like kate editor (a very nice programmer editor also having Nasal + syntax support) but sometimes it is quite annoying when it keeps + the text highlighted and you can easily overwrite/replace it. I + guess this was the case because it happens quite often. + + +*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* + + +Changelog 1.2.1 - 18 April 2020 + +- [RedGriffin] Added degreesDifference() function to compute the difference between two headings and turn + direction +- [RedGriffin] When approaching a runway during landing, dialog now shows the correction to runway alignment +- [RedGriffin] Improved check for radio usability. Some aircrafts have incomplete and/or unusable radio + implementations +- [RedGriffin] Dialog now shows course to current CTR + + +*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* + + +Changelog 1.2.0 - 4 April 2020 + +- [RedGriffin] Improved key bindings management. It now checks whether the "ctrl" and "shift" are pressed + besides checking the actual key binding. This avoids keyboard conflicts in some cases, in + particular with "Num Lock" and numerical keypad +- [RedGriffin] Added "You are already approved in CTR airspace" message +- [RedGriffin] Added COM3 to comply to the radio configuration of some aircrafts, mainly some airliners + + +*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* + + +Changelog 1.1.0 - 29 March 2020 + +- [RedGriffin] Better post initialization of dialog buttons +- [RedGriffin] availableRadioDialog(): Show popup message in case no radio is available +- [RedGriffin] split FlightGear's native "approach-departure" radio type into separate types +- [RedGriffin] added getCtrRadio(): it returns the appropriate "departure" or "approach" radio + according to flight status and aircraftIsDeparting variable +- [RedGriffin] increased max_radios to 30 +- [RedGriffin] getNearestRunway() renamed to getApproachingRunway() +- [RedGriffin] getApproachingRunway(): improved determination of approaching runway, in particular + in case airport has "parallel runways" with the same heading + + +*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* + + +Changelog 1.0.0 - 21 March 2020 + +- [RedGriffin] Production/stable release +- [RedGriffin] When the aircraft is in approach or ILS mode, dialog shows course and distance to pattern + and final points +- [RedGriffin] Added button for aborting/cancelling approach, ILS and landing requests +- [RedGriffin] Flight Level buttons and Cancel approach/landing button are shown according to aircraft status + + +*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* + + +Changelog 1.0.0 RC 2 - 8 March 2020 + +- [RedGriffin] Added Usage / Keys menu item +- [RedGriffin] Added getRadioVolume function in order to properly determine comm radio volume. Some + aircrafts use "volume-selected" property (such as Cessna 172p) whereas others use "volume". + The function evaluate both properties and determine volume accordingly +- [RedGriffin] Disable all ATC operations in case instant replay is active +- [RedGriffin] Added current flight level request button +- [RedGriffin] Remapped flight level request keys to ctrl+shift+[4|5|6] and CTR request to ctrl+0 +- [RedGriffin] When the aircraft is not flying over an airport area, dialog shows Altitude, AGL, Heading and Speed + + +*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* + + +Changelog 1.0.0 RC 1 - 1 March 2020 + +- [RedGriffin] Improved altitude check and determination +- [RedGriffin] Departure Information: QNH is now correctly spoken +- [RedGriffin] Improved radio station name normalization in order to avoid pattern confusion +- [RedGriffin] Altitude determination now properly consider Route Manager's Flight Plan +- [RedGriffin] Improved flight level requests + + +*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* + + +Changelog 1.0.0 beta 3 - 8 February 2020 + +- [RedGriffin] runwayInUse() now consider wind direction properly in determining runway +- [RedGriffin] Implemented CTR airspaces +- [RedGriffin] Pilot's request messages are now shown on the screen before ATC reply +- [RedGriffin] ATC now automatically warns the pilot in case the airplane is flying + too low or the aircraft is heading towards terrain (such as hills or + mountains) +- [RedGriffin] Implemented flight levels request +- [RedGriffin] Bug fixes and many improvements + + +*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* + + +Changelog 1.0.0 beta 2 - 8 January 2020 + +- [RedGriffin] Improved operations with "keyboard mode" + + +*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* + + +Changelog 1.0.0 beta 1 - 5 January 2020 + +- [RedGriffin] Initial public release diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..01a7a80 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,675 @@ +### GNU GENERAL PUBLIC LICENSE + +Version 3, 29 June 2007 + +Copyright (C) 2007 Free Software Foundation, Inc. + + +Everyone is permitted to copy and distribute verbatim copies of this +license document, but changing it is not allowed. + +### Preamble + +The GNU General Public License is a free, copyleft license for +software and other kinds of works. + +The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom +to share and change all versions of a program--to make sure it remains +free software for all its users. We, the Free Software Foundation, use +the GNU General Public License for most of our software; it applies +also to any other work released this way by its authors. You can apply +it to your programs, too. + +When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + +To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you +have certain responsibilities if you distribute copies of the +software, or if you modify it: responsibilities to respect the freedom +of others. + +For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + +Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + +For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + +Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the +manufacturer can do so. This is fundamentally incompatible with the +aim of protecting users' freedom to change the software. The +systematic pattern of such abuse occurs in the area of products for +individuals to use, which is precisely where it is most unacceptable. +Therefore, we have designed this version of the GPL to prohibit the +practice for those products. If such problems arise substantially in +other domains, we stand ready to extend this provision to those +domains in future versions of the GPL, as needed to protect the +freedom of users. + +Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish +to avoid the special danger that patents applied to a free program +could make it effectively proprietary. To prevent this, the GPL +assures that patents cannot be used to render the program non-free. + +The precise terms and conditions for copying, distribution and +modification follow. + +### TERMS AND CONDITIONS + +#### 0. Definitions. + +"This License" refers to version 3 of the GNU General Public License. + +"Copyright" also means copyright-like laws that apply to other kinds +of works, such as semiconductor masks. + +"The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + +To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of +an exact copy. The resulting work is called a "modified version" of +the earlier work or a work "based on" the earlier work. + +A "covered work" means either the unmodified Program or a work based +on the Program. + +To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + +To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user +through a computer network, with no transfer of a copy, is not +conveying. + +An interactive user interface displays "Appropriate Legal Notices" to +the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + +#### 1. Source Code. + +The "source code" for a work means the preferred form of the work for +making modifications to it. "Object code" means any non-source form of +a work. + +A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + +The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + +The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + +The Corresponding Source need not include anything that users can +regenerate automatically from other parts of the Corresponding Source. + +The Corresponding Source for a work in source code form is that same +work. + +#### 2. Basic Permissions. + +All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + +You may make, run and propagate covered works that you do not convey, +without conditions so long as your license otherwise remains in force. +You may convey covered works to others for the sole purpose of having +them make modifications exclusively for you, or provide you with +facilities for running those works, provided that you comply with the +terms of this License in conveying all material for which you do not +control copyright. Those thus making or running the covered works for +you must do so exclusively on your behalf, under your direction and +control, on terms that prohibit them from making any copies of your +copyrighted material outside their relationship with you. + +Conveying under any other circumstances is permitted solely under the +conditions stated below. Sublicensing is not allowed; section 10 makes +it unnecessary. + +#### 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + +No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + +When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such +circumvention is effected by exercising rights under this License with +respect to the covered work, and you disclaim any intention to limit +operation or modification of the work as a means of enforcing, against +the work's users, your or third parties' legal rights to forbid +circumvention of technological measures. + +#### 4. Conveying Verbatim Copies. + +You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + +You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + +#### 5. Conveying Modified Source Versions. + +You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these +conditions: + +- a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. +- b) The work must carry prominent notices stating that it is + released under this License and any conditions added under + section 7. This requirement modifies the requirement in section 4 + to "keep intact all notices". +- c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. +- d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + +A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + +#### 6. Conveying Non-Source Forms. + +You may convey a covered work in object code form under the terms of +sections 4 and 5, provided that you also convey the machine-readable +Corresponding Source under the terms of this License, in one of these +ways: + +- a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. +- b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the Corresponding + Source from a network server at no charge. +- c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. +- d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. +- e) Convey the object code using peer-to-peer transmission, + provided you inform other peers where the object code and + Corresponding Source of the work are being offered to the general + public at no charge under subsection 6d. + +A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + +A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, +family, or household purposes, or (2) anything designed or sold for +incorporation into a dwelling. In determining whether a product is a +consumer product, doubtful cases shall be resolved in favor of +coverage. For a particular product received by a particular user, +"normally used" refers to a typical or common use of that class of +product, regardless of the status of the particular user or of the way +in which the particular user actually uses, or expects or is expected +to use, the product. A product is a consumer product regardless of +whether the product has substantial commercial, industrial or +non-consumer uses, unless such uses represent the only significant +mode of use of the product. + +"Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to +install and execute modified versions of a covered work in that User +Product from a modified version of its Corresponding Source. The +information must suffice to ensure that the continued functioning of +the modified object code is in no case prevented or interfered with +solely because modification has been made. + +If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + +The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or +updates for a work that has been modified or installed by the +recipient, or for the User Product in which it has been modified or +installed. Access to a network may be denied when the modification +itself materially and adversely affects the operation of the network +or violates the rules and protocols for communication across the +network. + +Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + +#### 7. Additional Terms. + +"Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + +When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + +Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders +of that material) supplement the terms of this License with terms: + +- a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or +- b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or +- c) Prohibiting misrepresentation of the origin of that material, + or requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or +- d) Limiting the use for publicity purposes of names of licensors + or authors of the material; or +- e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or +- f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions + of it) with contractual assumptions of liability to the recipient, + for any liability that these contractual assumptions directly + impose on those licensors and authors. + +All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + +If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + +Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; the +above requirements apply either way. + +#### 8. Termination. + +You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + +However, if you cease all violation of this License, then your license +from a particular copyright holder is reinstated (a) provisionally, +unless and until the copyright holder explicitly and finally +terminates your license, and (b) permanently, if the copyright holder +fails to notify you of the violation by some reasonable means prior to +60 days after the cessation. + +Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + +Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + +#### 9. Acceptance Not Required for Having Copies. + +You are not required to accept this License in order to receive or run +a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + +#### 10. Automatic Licensing of Downstream Recipients. + +Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + +An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + +You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + +#### 11. Patents. + +A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + +A contributor's "essential patent claims" are all patent claims owned +or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + +Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + +In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + +If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + +If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + +A patent license is "discriminatory" if it does not include within the +scope of its coverage, prohibits the exercise of, or is conditioned on +the non-exercise of one or more of the rights that are specifically +granted under this License. You may not convey a covered work if you +are a party to an arrangement with a third party that is in the +business of distributing software, under which you make payment to the +third party based on the extent of your activity of conveying the +work, and under which the third party grants, to any of the parties +who would receive the covered work from you, a discriminatory patent +license (a) in connection with copies of the covered work conveyed by +you (or copies made from those copies), or (b) primarily for and in +connection with specific products or compilations that contain the +covered work, unless you entered into that arrangement, or that patent +license was granted, prior to 28 March 2007. + +Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + +#### 12. No Surrender of Others' Freedom. + +If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under +this License and any other pertinent obligations, then as a +consequence you may not convey it at all. For example, if you agree to +terms that obligate you to collect a royalty for further conveying +from those to whom you convey the Program, the only way you could +satisfy both those terms and this License would be to refrain entirely +from conveying the Program. + +#### 13. Use with the GNU Affero General Public License. + +Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + +#### 14. Revised Versions of this License. + +The Free Software Foundation may publish revised and/or new versions +of the GNU General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in +detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies that a certain numbered version of the GNU General Public +License "or any later version" applies to it, you have the option of +following the terms and conditions either of that numbered version or +of any later version published by the Free Software Foundation. If the +Program does not specify a version number of the GNU General Public +License, you may choose any version ever published by the Free +Software Foundation. + +If the Program specifies that a proxy can decide which future versions +of the GNU General Public License can be used, that proxy's public +statement of acceptance of a version permanently authorizes you to +choose that version for the Program. + +Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + +#### 15. Disclaimer of Warranty. + +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT +WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND +PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE +DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR +CORRECTION. + +#### 16. Limitation of Liability. + +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR +CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES +ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT +NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR +LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM +TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER +PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +#### 17. Interpretation of Sections 15 and 16. + +If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + +END OF TERMS AND CONDITIONS + +### How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these +terms. + +To do so, attach the following notices to the program. It is safest to +attach them to the start of each source file to most effectively state +the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper +mail. + +If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands \`show w' and \`show c' should show the +appropriate parts of the General Public License. Of course, your +program's commands might be different; for a GUI interface, you would +use an "about box". + +You should also get your employer (if you work as a programmer) or +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. For more information on this, and how to apply and follow +the GNU GPL, see . + +The GNU General Public License does not permit incorporating your +program into proprietary programs. If your program is a subroutine +library, you may consider it more useful to permit linking proprietary +applications with the library. If this is what you want to do, use the +GNU Lesser General Public License instead of this License. But first, +please read . \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..015cc84 --- /dev/null +++ b/README.md @@ -0,0 +1,809 @@ +# Red Griffin ATC + +### A speaking Air Traffic Controller addon for FlightGear + +#### Version 2.3.0 - Release date 7 May 2021 + +### Main features: + +* Support for ground, take off, visual approach, ILS and landing operations +* ATC assisted approach, guiding the pilot to the proper route, altitude and + speed up to the final approach point to runway and according to aircraft type +* Festival Speech Synthesis System support +* Squawking +* Approach and slope monitor +* Speech synthesis of messages through native FlightGear speech synthesizer +* ATC can be operated both with mouse and keyboard +* Independent dialog window or pop-up window operation modes +* Determination of proper take-off and landing runways according to wind direction + and airport settings +* Status monitor for both ground and flying modes (ground speed, current position, + runway alignment, runway approaching) +* Determination of approaching routes and patterns according to position and route + manager +* Automatic control and warning in case of incorrect procedure +* Radio station type check according to ATC request +* Automated ATC callback messages according to procedure +* Dedicated window with available radios +* Automatic selection of ATC requests according to aircraft status and position +* Information about the current airport +* Information about the tuned communication radio +* Support for CTR (Controlled Traffic Region) +* When flying in an approved CTR, ATC will check your correct altitude and warns in + case the aircraft is flying too low or towards terrain, such as hills or mountains. + ATC may also require the pilot to change altitude according to heading and area. +* When flying in an approved CTR, the pilot can request to the ATC to change its current + flight level with dedicated buttons +* When flying in an approved CTR, in case the aircraft is about to leave the CTR range, + ATC will inform the pilot about the neighboring CTR and gives information about the + corresponding radio in order to request transition approval to the new zone. +* Displayed information according to flight/approach/lading modes +* Buttons for aborting approach, ILS and landing procedures +* And a lot more + +You can download the latest "ready to install" package from the [sourceforge repository](https://sourceforge.net/projects/red-griffin-atc/files/latest/download). + + +## How to install Red Griffin ATC + +* Download Red Griffin ATC package from the this [sourceforge repository](https://sourceforge.net/projects/red-griffin-atc/files/latest/download). +* You will automatically get either a .zip or .tar.gz depending + on your system +* Unpack the archive with a proper command (zip or tar) or utility in a convenient place + of your disk +* It will be created a directory named RedGriffinATC containing the addon + + +### Running Red Griffin ATC addon from command line + +* Start fgfs including --addon=<your_local_path>/RedGriffinATC option in the command line + + +### Running Red Griffin ATC addon from the Launcher + +* Start FlightGear launcher +* Click "Add-ons" button +* Scroll down to "Add-on Module folders" section +* Click "Add +" button +* Select "RedGriffinATC" directory from the path where you unpacked the distribution file +* The add-on will be added to the list of installed addons. Make sure it is enabled + and the corresponding "check-box" is checked. +* Start FlightGear by clicking the "Fly!" button + + +### How to use Red Griffin ATC + +Red Griffin ATC can be operated both with the mouse and the keyboard. You will +find a new item "Red Griffin ATC" in FlightGear's menu from which you can open +and close the main dialog window as well as get help about keyboard commands and +information about the addon. You can open or close the main dialog window by +pressing the <\> key (backslash). You can also show the "pop-up dialog" by +pressing key sequence (control + backslash). + + +### The Main Dialog + +Red Griffin ATC can be operated with the mouse through its main dialog window in +which are shown information about the current flight, radios, approaching and +landing instructions. + +The dialog is divided in three main areas: + +* **Top area**: information about the current airport, altitude, speed, + approaching and landing instruction, current CTR, radio station in use + +* **Middle area**: Requests to the ATC, Radio list + +* **Bottom area**: CTR requests, Flight level requests, Abort requests, Radio + list, Dialog close + + +#### Top Area + +The top area of the dialog is divided in three sub areas: white (top), blue +(middle), yellow (bottom). + +The **white area** changes according the flight status. During ground operations +and when the aircraft is flying over an airport area, in this part are shown +airport information, aircraft speed and altitude according to the status of the +flight. + +During the flight and in case the aircraft is not flying over an airport, in +this part are shown flight information such as altitude, AGL, heading and speed. +When the aircraft is approaching an airport for landing (both visual and ILS) in +this area are shown the course and distance to both the pattern point and final +point (see picture above) as well as the landing runway. + +When the aircraft is on the final course to landing, here are shown the +approaching runway, distance to the runway, AGL and a "correction bar". This bar +shows the correction in relation to the center of the runway: the shorter the +more the aircraft is near the runway horizontal path. For example, a bar like +this one [===>] means the aircraft should heavily correct the course to the +right, while a bar like [=>] means the aircraft need to slightly turn to right +in order to be in the correct path, [ok] means the aircraft is aligned to the +center of the runway. In case the correction needs a left turn, the bar is shown +as [<===] or [<=]. + +The **blue area** is reserved to CTR information (Controlled Traffic Region) +such as name of the airport controlling the CTR, controlled area range in +nautical miles, distance and course to the center of CTR, frequency of the +corresponding radio. In this area is also reported the aircraft status in +relation to the CTR: "inside", "approved" or "flying to". "Inside" means the +aircraft is flying inside the CTR but has not been approved by the ATC; +"approved" means the aircraft is flying inside the CTR and has been granted +transition permission by the ATC; "flying to" means the aircraft is outside the +CTR but it is flying towards the controlled area. + +The **yellow area** is reserved to the radio information and status, such as COM +radio in use, radio station name and type, frequency, distance and course to the +station, readability quality from 1 to 5. + + +#### Middle Area + +The middle area is divided in two parts. In the left side are found the +operational buttons with the requests to be transmitted to the ATC, in the right +side is found the list of the available radios provided and operated by the +currently tuned airport. + +The left side provides a maximum of four buttons, each corresponding to a +specific request and depending on the aircraft position and status. In the top +part can also be found a "R" button (Repeat) to be used for requesting the ATC +to repeat the last message. + +The right side is used to tune and select a specific radio from the ones +currently available and operated by the tuned airport. Each entry is actually a +button to be used for tuning the COM in use to the corresponding radio station. + + +#### Bottom Area + +The bottom area of the dialog is reserved to CTR, flight level requests, abort +operation, radio list and dialog closing. The Leftmost button is used to request +the CTR transition to the ATC, while the three buttons in the center are used +for requesting a new flight level to the ATC. During the approach, ILS and +landing operations, these three buttons are replaced by the "abort" button used +to cancel the current operation. The "radio" button shows a list of the radio +stations available in the current airport, while the "close" button dismiss the +dialog. The dialog can be reopened by pressing the backslash key or by using the +menu. + + +### Red Griffin ATC Keys and Commands + +* **<\>** (backslash) - Open or close dialog +* **** (control + backslash) - Show popup dialog +* **** - Send message 1 to ATC +* **** - Send message 2 to ATC +* **** -Send message 3 to ATC +* **** - Send message 4 to ATC +* **** - Repeat last ATC message +* **** - Request CTR transition +* **** - Request Flight Level 1 +* **** - Request Flight Level 2 +* **** - Request Flight Level 3 +* **** - Abort Approach/ILS/Landing + + +### Settings + +Red Griffin ATC can be configured by using the settings dialog in which it is +possible to set how the ATC will provide information to the pilot as well as how +the pilot will interact with the ATC. + +To open the settings dialog select the corresponding function in "Red Griffin ATC" +menu. + +The changes done in the settings dialog are immediate and are effective as soon +as the dialog is closed. The settings dialog allows to change the following +options and therefore affecting the operational mode of the Red Griffin ATC +addon: + +* **Dialog Position** *(possible values: Top Left, Top Right, Bottom Left, + Bottom Right)* - Sets the initial position of the main dialog relative to the + screen or window. + +* **ATC text position** *(possible values: Top Left, Top Center, Top Right, + Middle Left, Middle Center, Middle Right, Bottom Left, Bottom Center, Bottom Right)* + - Sets the position of the ATC messages relative to the screen. + +* **ATC text transparency** *(possible values: Off, Very low, Low, Medium, High, + Very high)* - Sets the transparency of ATC messages in the screen. + +* **Call sign** - Pilot call sign or aircraft registration code. It defaults to + /sim/multiplay/callsign property. This value is copied both to + /sim/multiplay/callsign and /sim/user/callsign + properties. + +* **Call sign usage** *(possible values: Complete, Last three letters, First and + last two letters)* - Defines how the ATC will use the pilot's call sign in all + communications. Please note whenever a radio is tuned for the first time, the + pilot will always provide the call sign in complete form in the very first + contact to the radio station. + +* **Include manufacturer** *(possible values: Yes, No)* - Defines whether the + name of the aircraft manufacturer is to be used during the communication with + the ATC. + +* **QNH reported in** *(possible values: hPa, inHg, hPa and inHg)* - Sets the + unit of measure used by the ATC to report the QNH value (atmospheric pressure) + to the pilot for the proper altimeter setting: hectopascal (hPa), inches of + mercury (inHg) or both. + +* **Aircraft type** *(possible values: Auto, Small single engine, Small multi + engine, Executive turboprop/jet, Business jet, Airline jet, Large/military jet, + Special military)* - Defines the rules and settings used by the ATC and + according to the aircraft type. In particular, it changes the parameters used in + the assisted approach procedure - such as altitude, distance and speed - initial + altitude after take off and cruising altitude. When set to "Auto" Red Griffin + ATC will try to automatically detect the aircraft type according to the values + set in /sim/tags. In case it was not possible to detect the + aircraft types, including the case the aircraft in use has no tags defined, Red + Griffin ATC will warn the user to properly choose the aircraft type. In case the + user does not set an aircraft type, Red Griffin ATC will consider the aircraft + as a "Small single engine" and set operational parameters accordingly. The + currently selected aircraft type is always shown in the main dialog's title bar. + +* **Squawking** *(possible values: On, Off)* - Enable or disable ATC squawking. + When on, the ATC will require the pilot to properly set the aircraft's + transponder as well as operating it according to the ATC requests. + +* **Open dialog at startup** *(possible values: On, Off)* - Enable or disable the + opening of Red Griffin ATC dialog at FlightGear startup. + +* **Pilot request** *(possible values: Disabled, Voice only, Text only, Voice + and text)* - Defines how the pilot requests to the ATC are to be shown, spoken + or disabled. Text modes will show a pop-up message with the pilot request to be + transmitted to the ATC, Voice modes will activate the speech synthesis for the + requests by using /sim/sound/voices/pilot property and will + therefore use the voice assigned by FlightGear for that specific purpose. + +* **Pilot response** *(possible values: Disabled, Voice only, Text only, Voice + and text)* - Same as "Pilot request" but referring to the confirmation responses + and message used by the pilot to acknowledge the ATC operations and + instructions. + +* **ATC message** *(possible values: Voice only, Text only, Voice and text)* - + Defines how the ATC messages to the pilot are to be shown or spoken. Text modes + will show a pop-up message with the ATC message, Voice modes will activate the + speech synthesis for the messages by using /sim/sound/voices/atc, + /sim/sound/voices/approach and + /sim/sound/voices/ground properties according to the radio station + type and will therefore use the voice assigned by FlightGear for that specific + purpose. + +* **ATC radio** *(possible values: Auto, COM1, COM2, COM3)* - Select the COM + radio to be used for ATC communications. In case it is set to "Auto", the first + radio tuned to a valid ATC frequency will be used. + +* **Too low warning** *(possible values: On, Off)* - Enable or disable ATC + warning in case the aircraft is flying too low. + +* **Terrain warning** *(possible values: On, Off)* - Enable or disable ATC + warning in case the aircraft is flying towards terrain, such as a mountain or + hill. + +* **Multiplayer chat** *(possible values: Off, Important messages only, All + messages)* - Define how ATC messages should be broadcast to the multiplayer chat + in order to let other know about the traffic in your current airport. When set + to "Important messages only", only relevant traffic information will be sent to + the multiplayer chat, such as taxing, take off and landing. + +* **Approach slope angle** *(possible values: from 2 to 8)* - Approach slope + angle in degrees for the final leg to the destination runway. Default: 3 + degrees. + +* **Reset button** - Resets all the setting options to their default value. + +* **Close button** - Close the settings dialog and permanently save the options + to the file $FG_HOME/Export/RedGriffinATC-config.xml + + +### ATC Log + +Red Griffin ATC logs every message sent and received to or from any radio tuned +during the flight session. The ATC Log can be opened by selecting "ATC Log" from +the menu. The messages can be scrolled with the mouse wheel or by grabbing the +"scroll bar" to the right of the window. + +The log widows has two buttons and corresponding to the following actions: + +* **Clear** - Clears all the messages contained in the log + +* **Close** - Close the log window + + +### Supported Aircraft Types and Operational Values + +Red Griffin ATC provides support for the below aircraft types. Each of them uses +specific operational values and used by Red Griffin ATC in determining the +procedures of approach and landing, such as minimum cruise altitude, speed, +approach and pattern distance. For each aircraft type are used the below values: + +#### Small single engine + +* Minimum cruise altitude: 3500 feet +* Pattern speed: 100 knots +* Approach speed: 90 knots +* Final speed: 70 knots +* Approach point distance: 10 nautical miles +* Pattern point distance: 3 nautical miles + +#### Small multi engine + +* Minimum cruise altitude: 3500 feet +* Pattern speed: 120 knots +* Approach speed: 100 knots +* Final speed: 85 knots +* Approach point distance: 10 nautical miles +* Pattern point distance: 3 nautical miles + +#### Executive turboprop/jet + +* Minimum cruise altitude: 5500 feet +* Pattern speed: 160 knots +* Approach speed: 140 knots +* Final speed: 120 knots +* Approach point distance: 12 nautical miles +* Pattern point distance: 5 nautical miles + +#### Business jet + +* Minimum cruise altitude: 5500 feet +* Pattern speed: 170 knots +* Approach speed: 150 knots +* Final speed: 130 knots +* Approach point distance: 15 nautical miles +* Pattern point distance: 5 nautical miles + +#### Airline jet + +* Minimum cruise altitude: 7500 feet +* Pattern speed: 180 knots +* Approach speed: 160 knots +* Final speed: 140 knots +* Approach point distance: 15 nautical miles +* Pattern point distance: 6 nautical miles + +#### Large/military jet + +* Minimum cruise altitude: 8500 feet +* Pattern speed: 210 knots +* Approach speed: 190 knots +* Final speed: 150 knots +* Approach point distance: 15 nautical miles +* Pattern point distance: 7 nautical miles + +#### Special military + +* Minimum cruise altitude: 8500 feet +* Pattern speed: 210 knots +* Approach speed: 190 knots +* Final speed: 150 knots +* Approach point distance: 15 nautical miles +* Pattern point distance: 8 nautical miles + +### Aircraft compatibility + +Red Griffin ATC radio support and use rely on FlightGear properties and, for this +reason, it is essential for the aircraft to provide a functional implementation of +both the radio stack and transponder. Red Griffin ATC has been extensively tested +with tens of aircraft and, according to these tests, not all aircraft seem to +provide a complete implementation of COM radios and transponder. In this particular +case, those aircraft will not work because of lack of fundamental properties needed +by Red Griffin ATC. As of version 2.3.0, Red Griffin ATC uses and relies on the +following radio properties for each COM radio: + +* /instrumentation/comm[x]/serviceable +* /instrumentation/comm[x]/signal-quality-norm +* /instrumentation/comm[x]/volume +* /instrumentation/comm[x]/volume-selected +* /instrumentation/comm[x]/power-btn +* /instrumentation/comm[x]/airport-id +* /instrumentation/comm[x]/station-name +* /instrumentation/comm[x]/frequencies/selected-mhz +* /instrumentation/comm[x]/track-distance-m +* /instrumentation/comm[x]/true-bearing-to-deg + +Moreover, in order to be fully compatible with Red Griffin ATC, the aircraft must also +provide operative support for its transponders, in particular, the below properties need +to be properly defined and usable: + +* /instrumentation/transponder[x]/serviceable +* /instrumentation/transponder[x]/operable +* /instrumentation/transponder[x]/inputs/knob-mode +* /instrumentation/transponder[x]/id-code +* /instrumentation/transponder[x]/ident + +In case the aircraft does not provide some of the above properties, Red Griffin +ATC will show a warning message in the main dialog and any radio operation will +not be possible. In this specific case, you can contact the aircraft developer +and ask for a revision of the radio implementation in order to comply to the +above properties. + +Please note Red Griffin ATC reads and uses the above properties "as they are" +and relies on their data. If you notice some incongruence in data shown both in +the radio stack or Red Griffin ATC dialog window or popup, it is probably +because of improper data written by the aircraft in FlightGear properties. + +A list of the aircraft tested with Red Griffin ATC can be found +[here](https://wiki.flightgear.org/Red_Griffin_ATC_compatible_aircraft). The +list is continuously updated and tries to provide both a reliable and up-to-date +source of compatible and incompatible aircraft. You are invited to browse this +list and check aircraft compatibility in case you see or experience a wrong or +unexpected behavior in Red Griffin ATC. + + +### Controlled Traffic Region + +Red Griffin ATC provides a simple Controlled Traffic Region (CTR) management +however effective and enough for normal flight simulation. CTR range is +determined according to the the supposed size of the airport controlling it. +Airport size is arbitrarily determined by the number of radio stations operating +in the airport. The greater the number of radio stations, the bigger the +supposed airport size and according to this schema: + +* 1 radio station: small +* 2-4 radio stations: medium +* 5 or more radio stations: big + +CTR range is therefore determined according to this schema: + +* Small airport: 20 nm +* Medium airport: 30 nm +* Big airport: 50 nm + + +### Assisted Approach and Landing + +Red Griffin ATC can guide the pilot to the proper route up to the final leg to +the runway. In order to work properly, the assisted approach and landing +procedure requires the pilot to provide the right operational settings, in +particular aircraft type and approach slope angle. It is also very important to +set the altimeter according to the QNH provided by the ATC in order to follow a +reliable and consistent altitude. + +As for approach slope angle, Red Griffin ATC uses 3 degree as a default value, +however this can be changed in the settings dialog. The pilot is therefore +required to properly set the approach slope angle before initiating the assisted +approaching procedure and according to the destination airport and runway. The +correct approach slope angle is usually reported in airport charts and each +airport usually has its own angle setting. + +Before initiating the assisted approach procedure (or before taking off) it is +advised to follow this very minimal checklist: + +* Set aircraft type (settings dialog) +* Set approach slope angle according to the runway of destination airport (settings dialog) +* Set the altimeter according to the QNH provided by the ATC (aircraft cockpit panel) + + +### Approach and slope monitor + +When the aircraft is about to land, while it is flying the final leg to runway +and within 5 nautical miles from the runway landing area, Red Griffin ATC gives +the pilot both the distance to the touch down point as well as an "approach and +slope monitor" in order to assist the pilot in following the right course and +glide path to landing. + +Course correction is represented by a "bar" showing the direction in which the +aircraft should turn in order to align to the center of runway. Specifically, +when the monitor shows "<===" means the pilot should turn to the left, whereas +in case it shows "===>" it is needed a turn to the right. The longer the bar, +the farther the distance from the center of glide path. + +The monitor also provides information about the correction in altitude in order +to follow the proper glide path to the landing area of runway. In case the +monitor shows a "v" it means the aircraft is flying too high and the pilot must +descend, whereas in case it shows a "^", the aircraft is flying too low and the +pilot must climb. + +In case the aircraft is perfectly aligned and following the proper glide path, +the monitor will show "ok". + +## Festival Speech Synthesis System Support + +Red Griffin ATC can take advantage of the superior voice quality offered by the +[Festival Speech Synthesis System](https://www.cstr.ed.ac.uk/projects/festival) +through FlightGear direct support for Festival running in server mode. In order +to use the Festival Speech Synthesis System, you need to have a properly +installed and working Festival system in your machine as well as having at least +FlightGear version 2020.3.6. Prior to this version, FlightGear cannot properly +support and initialize the Festival Speech Synthesis System and will therefore +fall back to the internal default speech synthesizer. + +The Festival Speech Synthesis System running in server mode allows up to ten +simultaneous connections, therefore it can provide up to ten different voices. +Red Griffin ATC takes advantage of this feature and can provide a fuller and +deeper experience by using those ten different voices and by assigning them to +each specific radio. The available voices are assigned at random from the whole +pool of voices available and properly configured through FlightGear COMM +properties. This will give the sensation of speaking to different operators +during the whole flight session. Red Griffin ATC associates a specific voice to +any specific radio frequency and the association is kept for the whole duration +of the flight. This means you are going to hear the very same voice in case you +are tuning back to a radio frequency already used in the current flight session. +Please note pilot voice is associated to a specific voice and exclusively used +for that purpose. This means the pilot voice will never be used for radio +operators. + +### Configuring Red Griffin ATC with Festival Support + +Festival Speech Synthesis System support in Red Griffin ATC is implemented +through FlightGear internal properties, in particular those related to sound and +voice support, found in the /sim/sound/voices tree. + +Voices can be defined and set up by using a configuration XML file +describing each FlightGear voice according to the internal structure of the +property tree. Here it is how a voice should be configured in order to support +the Festival Speech Synthesis System: + + +<voice>
+ <desc>Pilot</desc>
+ <text type="string"/>
+ <volume type="double">1.0</volume>
+ <pitch type="double">100.0</pitch>
+ <speed type="double">0.8</speed>
+ <preamble type="string">(voice_cmu_us_rms_cg) (audio_mode 'async)</preamble>
+ <festival type="bool">true</festival>
+ <htsvoice type="string">cstr_uk_female-1.0.htsvoice</htsvoice>
+</voice>
+
+ +In order to be used in Festival, a voice needs the <festival> +and <preamble> properties to be properly initialized. +Specifically, <festival> property must be true +(that is, enabled) while <preamble> property must contain +valid Festival scheme commands to be sent to the server at +initialization time. The <preamble> property must at least +contain the scheme command selector for the specific Festival voice +to be associated to a FlightGear voice. + +In this regard, it is strongly advised to set Festival in asynchronous audio +mode by adding the scheme command (audio_mode 'async) +to the <preamble> property. In this case, Red Griffin ATC +will interact with Festival in a way that will provide a quicker response and by +actually creating utterances while speaking, therefore getting a better +synchronization with ATC texts shown in the screen. + +In case (audio_mode 'async) is not used, Red Griffin ATC +interaction with Festival server will result with an "out of sync" speaking in +relation to the text shown in the screen. + +Voices can also be "fine tuned" by properly setting <volume>, +<pitch> and <<speed> properties. + +The property <desc> can optionally describe the defined voice +and, in particular, the voice to be used for the pilot. In this specific case, +<desc> property must be assigned to "Pilot", like the sample +shown above. In case no voice is assigned to the pilot, Red Griffin ATC will use +the value found in /sim/sound/voices/pilot. + +Red Griffin ATC is distributed with a sample configuration file defining ten +different Festival voices and can be used "out of the box" or used as a template +in case it is wished a different voice scheme or configuration. The sample +configuration file is found at +<your_local_path>/RedGriffinATC/festival.xml. The +festival.xml is configured in order to use some Festival default +voices as well as some of those available at +[http://festvox.org/packed/festival/2.4/voices Festvox website]. In order to use +the configuration file provided with Red Griffin ATC, you need to properly +install the Festival voices defined in festival.xml and available +at the Festvox website. + +### Running Festival in Server Mode + +In order to run Festival, you need it to be properly installed and working in +your system. Festival can be compiled and installed from the source distribution +or by using the binary package available for your system. + +To start Festival in server mode, you need to open a shell or console window and +type: + +festival --server + +The Festival Speech Synthesis System will then listen to port 1314 waiting for +incoming requests and will accept up to ten simultaneous clients. + +### Running FlightGear with Festival Support + +In order to have FlightGear using the configuration file as described above, you +need to use the --config option. + +In case you are going to start FlightGear from the command line, you need to +append the --config option and the path of festival configuration +file: + +fgfs [your_options] --config=<your_local_path>/RedGriffinATC/festival.xml + +In case you are using FlightGear launcher, you need to add +--config=<your_local_path>/RedGriffinATC/festival.xml in the +"Additional Settings" box found in the "Settings" tab. + + +### Videos and tutorials + +For a quick preview and sample sessions of Red Griffin ATC, you can watch these videos: + + +### Demonstration Flight and Tutorial + +[[embed url=https://www.youtube.com/watch?v=DEuz9hTpvuI]] + +[[embed url=https://www.youtube.com/watch?v=ZOxDTGj9UnQ]] + +**Initial operations and setup** + +[[embed url=https://youtu.be/ZOxDTGj9UnQ?t=110]] + +**Take-off** + +[[embed url=https://youtu.be/ZOxDTGj9UnQ?t=313]] + +**Terrain alert** + +[[embed url=https://youtu.be/ZOxDTGj9UnQ?t=513]] + +**Flight information** + +[[embed url=https://youtu.be/ZOxDTGj9UnQ?t=660]] + +**Altitude check** + +[[embed url=https://youtu.be/ZOxDTGj9UnQ?t=708]] + +[[embed url=https://youtu.be/ZOxDTGj9UnQ?t=1470]] + +**Leaving and entering CTR** + +[[embed url=https://youtu.be/ZOxDTGj9UnQ?t=848]] + +[[embed url=https://youtu.be/ZOxDTGj9UnQ?t=1905]] + +[[embed url=https://youtu.be/ZOxDTGj9UnQ?t=2105]] + +**CTR assigning a new altitude** + +[[embed url=https://youtu.be/ZOxDTGj9UnQ?t=957]] + +[[embed url=https://youtu.be/ZOxDTGj9UnQ?t=1945]] + +**Flight level change** + +[[embed url=https://youtu.be/ZOxDTGj9UnQ?t=1023]] + +[[embed url=https://youtu.be/ZOxDTGj9UnQ?t=1190]] + +[[embed url=https://youtu.be/ZOxDTGj9UnQ?t=1505]] + +**Flying over an airport area** + +[[embed url=https://youtu.be/ZOxDTGj9UnQ?t=1278]] + +**Request ILS procedure** + +[[embed url=https://youtu.be/ZOxDTGj9UnQ?t=2380]] + +[[embed url=https://youtu.be/ZOxDTGj9UnQ?t=2460]] + +**Abort ILS procedure** + +[[embed url=https://youtu.be/ZOxDTGj9UnQ?t=2450]] + +**ILS established** + +[[embed url=https://youtu.be/ZOxDTGj9UnQ?t=2865]] + +**Request visual approach** + +[[embed url=https://youtu.be/ZOxDTGj9UnQ?t=2950]] + +**Reaching pattern point** + +[[embed url=https://youtu.be/ZOxDTGj9UnQ?t=3210]] + +**Reaching final approach point** + +[[embed url=https://youtu.be/ZOxDTGj9UnQ?t=3305]] + +**Landing** + +[[embed url=https://youtu.be/ZOxDTGj9UnQ?t=3413]] + +**Abort landing** + +[[embed url=https://youtu.be/ZOxDTGj9UnQ?t=2910]] + + +### Red Griffin ATC videos + +Assisted Visual Approach and Landing + +[[embed url=https://www.youtube.com/watch?v=U7XqA1iUBF4]] + +ILS Landing + +[[embed url=https://www.youtube.com/watch?v=7FEtAvhdx4U]] + +Operating the ATC with Keyboard Only + +[[embed url=https://www.youtube.com/watch?v=s9G_zkjUMnY]] + +Procedure Control, Warning and Approach Routes + +[[embed url=https://www.youtube.com/watch?v=BHfvSL_4XuA]] + +Altitude, Terrain Control, Flight Level Change + +[[embed url=https://www.youtube.com/watch?v=65KjUT3Avl4]] + +Red Griffin ATC Using Festival Speech Synthesis System + +[[embed url=https://www.youtube.com/watch?v=5IhPebn2TgI]] + +### Resources and links + +* [Red Griffin ATC Wiki Page](http://wiki.flightgear.org/Red_Griffin_ATC) +* [Red Griffin YouTube Channel](https://www.youtube.com/c/RedGriffin) +* [Red Griffin ATC Thread in FlightGear Forum](https://forum.flightgear.org/viewtopic.php?f=6&t=36755) +* [FlightGear Newsletter April 2020](https://wiki.flightgear.org/FlightGear_Newsletter_April_2020#Red_Griffin_ATC_release) +* [FlightGear Newsletter October 2020](https://wiki.flightgear.org/FlightGear_Newsletter_October_2020#Red_Griffin_ATC_2.0_released) +* [FlightGear Newsletter November 2020](https://wiki.flightgear.org/FlightGear_Newsletter_November_2020#Red_Griffin_ATC_2.0_released) +* [Festival Speech Synthesis System](https://www.cstr.ed.ac.uk/projects/festival) +* [Festvox Project](http://festvox.org/festival/index.html) +* [Voices and lexicons for Festival 2.4](http://festvox.org/packed/festival/2.4/voices) + + +### Special thanks + +Special thanks to the FlightGear community for the valuable help and for providing +very useful information about ATC phraseology, procedures and communication, in +particular to those participating to [Red Griffin ATC](https://forum.flightgear.org/viewtopic.php?f=6&t=36755) +thread in [FlightGear forum](https://forum.flightgear.org) + + +#### Note + +Red Griffin ATC has been developed and written by Antonello Biancalana (Red +Griffin, IK0TOJ) in Nasal language and it has been tested in FlightGear +2019.1.1, 2019.1.2, 2020.3.x and 2020.4.0 git, specifically in my Fedora Linux +FC33. I understand there can be bugs or the ATC procedures may be formally +incorrect. On this regard, any feedback, suggestion, criticism and hint on how +to improve this addon are warmly welcome. You are kindly invited to contribute +with your ideas and feedback by posting in the forum thread. + +I am not a pilot and I do not have a plane pilot license, I have never been in a +real aircraft's cabin and all the times I have been in a real airplane I did it +as a passenger. All of my "plane pilot" experience is only as a "virtual and +simulated pilot", a hobby I started in 1982 and the very first flight simulator +I used was subLOGIC's FS1 Flight Simulator by Bruce Artwick running on an Apple +II. + +It was not my computer though as at that time I owned a Commodore VIC20 and, +alas, the only "flight simulators" available for it were Ron Wanttaja's IFR +Flight Simulator and Anirog's Flight Path 737. The big step forward was Flight +Simulator II for Commodore 64 in 1984 and featuring a Piper PA-28-181 Archer II. +The giant step forward was in 1987 when it was released the Commodore Amiga +version (one of the most amazing and very best, revolutionary, exceptional +computer of all times) which featured three aircraft: Cessna 182RG, Gates +Learjet 25G and Sopwith Camel. + +I therefore have no real ATC procedures experience and what I know about this +subject is from what I read in specialized books about ATC procedures and +phraseology found in various website of flight schools, airports and aero clubs. +Most of the phraseology used in Red Griffin ATC is created according to the +procedures found in these books and manuals, as well as from the many valuable +contributions from Red Griffin ATC users, both in FlightGear forum and direct +exchange of messages from amateur and professional licensed pilots. I understand +the procedures used in this addon may however result incorrect to real pilots, +either because of my lack of experience in this subject or because of improper +implementation. I am more than glad to get any feedback about ATC procedures +from experienced pilots and anyone knowing this subject in order to improve this +addon. + + + +Red Griffin ATC is hosted in [https://sourceforge.net/projects/red-griffin-atc/](https://sourceforge.net/projects/red-griffin-atc/) + +Red Griffin ATC (C) 2019-2021 Antonello Biancalana, Red Griffin, IK0TOJ diff --git a/addon-config.xml b/addon-config.xml new file mode 100644 index 0000000..eaa4ca4 --- /dev/null +++ b/addon-config.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + diff --git a/addon-main.nas b/addon-main.nas new file mode 100644 index 0000000..5359844 --- /dev/null +++ b/addon-main.nas @@ -0,0 +1,40 @@ +# +# Red Griffin ATC - Speaking Air Traffic Controller for FlightGear +# +# Written and developer by Antonello Biancalana (Red Griffin, IK0TOJ) +# +# Copyright (C) 2019-2021 Antonello Biancalana +# +# addon-main.nas +# +# Launcher script +# +# Version 2.3.0 - 7 May 2021 +# +# Red Griffin ATC is an Open Source project and it is licensed +# under the Gnu Public License v3 (GPLv3) +# + +var main = func(addon) +{ + print("Installing Red Griffin ATC addon from ", addon.basePath); + + foreach(var script; ['globals.nas', 'settings.nas', 'rgatc.nas']) + { + var fname = addon.basePath ~ "/" ~ script; + + print("Loading ", fname, " module"); + + io.load_nasal(fname, "RgATC"); + } + + RgATC.loadSettings(); + + var openRgATCDialog = getprop("/rgatc/open-dialog-startup"); + + if(openRgATCDialog != nil) + { + if(openRgATCDialog == "On") + RgATC.openATCDialog(); + } +} diff --git a/addon-menubar-items.xml b/addon-menubar-items.xml new file mode 100644 index 0000000..2a39731 --- /dev/null +++ b/addon-menubar-items.xml @@ -0,0 +1,84 @@ + + + + + + + FlightGear add-on menu bar items + 1 + + + + + true + + + + + nasal + + + + + + + + nasal + + + + + + + + dialog-show + help-dialog + + + + + + + nasal + + + + dialog-show + settings-dialog + + + + + + + nasal + + + + + + + + dialog-show + about-dialog + + + + + + diff --git a/addon-metadata.xml b/addon-metadata.xml new file mode 100644 index 0000000..0c3a38d --- /dev/null +++ b/addon-metadata.xml @@ -0,0 +1,111 @@ + + + + + + FlightGear add-on metadata + 1 + + + + org.flightgear.addons.RGATC + Red Griffin ATC + 2.3.0 + + + + Antonello Biancalana (Red Griffin, IK0TOJ) + provinum@gmail.com + + + + + + + Antonello Biancalana (Red Griffin, IK0TOJ) + + https://sourceforge.net/projects/red-griffin-atc + + + + + + Speaking Air Traffic Controller for FlightGear + + + + Speaking Air Traffic Controller simulator for FlightGear. It manages ground operations, + take off, approach, ILS, landing procedures, squawking and CTR transitions. + + + + + GNU Public License v3 (GNU GPL version 3 or later) + + + + + + + + https://www.gnu.org/licenses/gpl-3.0.html + + + + 2018.2 + none + + + + https://sourceforge.net/projects/red-griffin-atc + + + + https://sourceforge.net/projects/red-griffin-atc/files/ + + + + https://sourceforge.net/projects/red-griffin-atc/support + + + + https://sourceforge.net/p/red-griffin-atc/code/ci/master/tree/ + + + + + Antonello Biancalana + Red Griffin + IK0TOJ + ATC + Air Traffic Controller + Voice + Speak + Talk + Ground + Take off + Approach + ILS + Landing + CTR + Controlled Traffic Region + Flight Level + + + diff --git a/festival.xml b/festival.xml new file mode 100644 index 0000000..5ef78a4 --- /dev/null +++ b/festival.xml @@ -0,0 +1,111 @@ + + + + + true + + true + + Pilot + + 1.0 + 100.0 + 0.8 + (voice_cmu_us_rms_cg) (audio_mode 'async) + true + cstr_uk_female-1.0.htsvoice + + + Ahw + + 1.0 + 100.0 + 0.9 + (voice_cmu_us_ahw_cg) (audio_mode 'async) + true + cmu_us_arctic_slt.htsvoice + + + Eey + + 1.0 + 100.0 + 1 + (voice_cmu_us_eey_cg) (audio_mode 'async) + true + cmu_us_arctic_slt.htsvoice + + + Bdl + + 1.0 + 100.0 + 1 + (voice_cmu_us_bdl_cg) (audio_mode 'async) + true + cmu_us_arctic_slt.htsvoice + + + Rxr + + 1.0 + 100.0 + 1 + (voice_cmu_us_rxr_cg) (audio_mode 'async) + true + cmu_us_arctic_slt.htsvoice + + + Clb + + 1.0 + 100.0 + 0.8 + (voice_cmu_us_clb_cg) (audio_mode 'async) + true + cmu_us_arctic_slt.htsvoice + + + Jmk + + 1.0 + 100.0 + 1.0 + (voice_cmu_us_jmk_cg) (audio_mode 'async) + true + cmu_us_arctic_slt.htsvoice + + + Lnh + + 1.0 + 100.0 + 0.9 + (voice_cmu_us_lnh_cg) (audio_mode 'async) + true + cmu_us_arctic_slt.htsvoice + + + Slt + + 1.0 + 100.0 + 1.0 + (voice_cmu_us_slt_cg) (audio_mode 'async) + true + cmu_us_arctic_slt.htsvoice + + + Ljm + + 1.0 + 100.0 + 1.0 + (voice_cmu_us_ljm_cg) (audio_mode 'async) + true + cmu_us_arctic_slt.htsvoice + + + + + diff --git a/globals.nas b/globals.nas new file mode 100644 index 0000000..c3686f2 --- /dev/null +++ b/globals.nas @@ -0,0 +1,756 @@ +# +# Red Griffin ATC - Speaking Air Traffic Controller for FlightGear +# +# Written and developer by Antonello Biancalana (Red Griffin, IK0TOJ) +# +# Copyright (C) 2019-2021 Antonello Biancalana +# +# global.nas +# +# Global variables for Red Griffin ATC (rgatc.nas) +# +# Version 2.3.0 - 7 May 2021 +# +# Red Griffin ATC is an Open Source project and it is licensed +# under the Gnu Public License v3 (GPLv3) +# + +var RGAtcAddonID = "org.flightgear.addons.RGATC"; +var RGAtcAddonProp = "/addons/by-id/" ~ RGAtcAddonID ~ "/"; +var RGAtcVersion = ""; +var RGAtcTitle = "Red Griffin ATC"; +var RGAtcName = RGAtcTitle; +var RGAtcEnabled = 1; + +var min_distance = 0.25; +var min_near_distance = 0.1; +var max_runway_alignment_degrees = 5; +var min_ground_altitude = 30; +var min_cruise_altitude = 3500; +var min_safe_altitude = 1500; +var flight_level_step = 2000; +var pattern_speed = 110; +var approach_speed = 100; +var final_speed = 80; +var flight_level_rate = 1000; +var min_airport_range = 3; +var atc_callback_seconds_counter = -1; +var atc_callback_wait_seconds = -1; +var timer_interval = 2; +var pilot_message_wait_seconds = -1; +var pilot_message_counter = 0; +var pilot_message_pause_atc_seconds = 2; +var pilot_response_wait_seconds = -1; +var pilot_response_counter = 0; +var pilot_response_pause_atc_seconds = 2; +var ctr_check_interval = 15; +var ctr_check_counter = 0; +var ctr_update_interval = 4; +var ctr_update_counter = 0; +var altitude_change_wait_seconds = 0; +var altitude_change_counter = 0; +var altitude_check_interval = 45; +var altitude_check_counter = 0; +var squawk_check_interval = 60; +var squawk_check_counter = 0; +var ctr_update_counter = 0; +var approach_check_interval = 60; +var approach_check_interval_initial = 45; +var approach_check_interval_near_point = 20; +var approach_check_interval_final = 10; +var approach_check_counter = 0; +var approach_slope_angle = 3; +var flight_plan_min_distance = 5; +var assigned_altitude_delta = 400; +var approach_speed_delta = 20; +var departure_extra_time = 0; +var flight_time_seconds = 0; +var take_off_max_seconds = 120; +var max_radios = 30; +var radioButton = []; +var radioButtonFrequency = []; +var KT2KMH = 1.852; +var NM2FT = 6076.12; + +var altitudeFromTerrain = -1; +var min_altitude_from_terrain = 350; +var min_altitude_too_low_warning = 50; +var min_safety_distance_from_terrain_miles = 4; +var terrainWarning = 0; +var terrain_warning_interval = 10; +var terrain_warning_counter = 0; + +var auto_reply_off = -1; +var min_altitude_change_secs = 30; +var max_altitude_change_secs = 60 - min_altitude_change_secs; +var min_cleared_takeoff_secs = 20; +var max_cleared_takeoff_secs = 45 - min_cleared_takeoff_secs; +var wait_after_take_off = 15; +var max_departure_secs = 120; +var extra_departure_secs = 120; +var max_take_off_secs = 60; +var land_check_secs = 15; +var welcome_airport_secs = 15; + +var aircraft_type_unknown = "Unknown"; +var aircraft_type_small_single_engine = "Small single engine"; +var aircraft_type_small_multi_engine = "Small multi engine"; +var aircraft_type_executive_turboprop_jet = "Executive turboprop/jet"; +var aircraft_type_business_jet = "Business jet"; +var aircraft_type_airline_jet = "Airline jet"; +var aircraft_type_large_military_jet = "Large/military jet"; +var aircraft_type_special_military = "Special military"; + +var com1quality = 0; +var com1volume = 0; +var com1serviceable = 0; +var com1PowerStatus = 0; +var com1Operable = 0; +var com2quality = 0; +var com2volume = 0; +var com2serviceable = 0; +var com2PowerStatus = 0; +var com2Operable = 0; +var com3quality = 0; +var com3volume = 0; +var com3serviceable = 0; +var com3PowerStatus = 0; +var com3Operable = 0; +var contactRadio = nil; +var squawkingMode = "On"; +var squawkCode = ""; +var squawkChange = 0; +var squawkIdent = 0; +var squawkIdentButtonPushed = 0; +var squawk_ident_off = 0; +var squawk_ident_only = 1; +var squawk_ident_code = 2; + +var reservedSquawkCodes = [ 21, 22, 25, 33, 100, 500, 600, 700, 1000, 1100, 1200, 1201, 1202, + 1203, 1255, 1273, 1274, 1275, 1276, 1277, 1300, 1400, 1500, 1600, + 1700, 2000, 2100, 220, 2300, 2400, 2500, 2600, 2700, 3000, 3100, + 3200, 3300, 3400, 3500, 3600, 3700, 4000, 4100, 4200, 4300, 4400, + 4454, 4466, 4500, 4600, 4700, 5000, 5061, 5062, 5100, 5200, 5300, + 5400, 5500, 5600, 5700, 6000, 6100, 6200, 6300, 6400, 6500, 6600, + 6700, 7000, 7001, 7100, 7200, 7300, 7400, 7500, 7600, 7610, 7615, + 7700, 7701, 7702, 7703, 7704, 7705, 7706, 7707, 7710, 7777 ]; + +var departureInformation = ""; +var departureInformationAirport = ""; + +var initialized = 0; +var dialogInitialized = 0; +var callsign = ""; +var atcCallsignText = ""; +var atcCallsignVoice = ""; +var callsignMode = ""; +var includeManufacturer = ""; +var aircraftManufacturer = ""; +var atcMessageMode = ""; +var synthVoice = []; +var usedSynthVoice = []; +var stationVoice = {}; +var stationVoicePool = []; +var pilotRequestMode = ""; +var pilotResponseMode = ""; +var pilotVoice = {}; +var availableRadio = {}; +var currentRadioStationId = ""; +var radioListHasChanged = 1; +var qnhUnitMeasure = ""; +var qualityThreshold = 0.01; +var atcRadioMode = "Auto"; +var aircraftType = aircraft_type_small_single_engine; +var tooLowWarningMode = "On"; +var terrainWarningMode = "On"; +var multiplayerChatEcho = "Off"; +var slopeAngle = 3.0; + +var airportRunwayInUse = ""; +var airportRunwayInUseILS = nil; +var airportLandingRunway = ""; +var landingRunway = ""; + +var approach_point_distance = -10; +var pattern_point_distance = -3; +var min_distance_for_altitude_change = 8; +var max_runway_align_angle = 30; +var miles_altitude_step = 10; +var feet_altitude_step = 1000; + +var last_key = 0; +var reset_key_interval = 10; +var key_press_counter = 0; +var binding_key_dialog = 92; +var binding_key_name = "\\"; +var binding_key_description = "backslash"; +var binding_key_msg1 = 28; +var binding_key_msg2 = 29; +var binding_key_msg3 = 30; +var binding_key_msg4 = 31; +var binding_key_request_ctr = 48; +var binding_key_flight_level_1 = 36; +var binding_key_flight_level_2 = 37; +var binding_key_flight_level_3 = 38; +var binding_key_repeat_last_atc_message = 57; +var binding_key_abort_approach = 61; + +var update_dialog = 0; +var update_popup = 1; +var update_data_only = 2; + +var position_unknown = -1; +var position_ground = 1; +var position_runway = 2; +var position_flying = 3; + +var status_going_around = 1; +var status_ready_for_departure = 2; +var status_cleared_for_takeoff = 3; +var status_took_off = 4; +var status_flying = 5; +var status_requested_approach = 6; +var status_requested_ils = 7; +var status_cleared_for_land_approach = 8; +var status_cleared_for_land_ils = 9; +var status_landed = 10; + +var aircraft_status = status_going_around; + +var radio_station_type_unknown = -1; +var radio_station_type_ground = 1; +var radio_station_type_tower = 2; +var radio_station_type_atis = 3; +var radio_station_type_departure = 4; +var radio_station_type_approach = 5; +var radio_station_type_clearance = 6; + +var selectedComRadio = ""; +var selectedComServiceable = 0; +var selectedComServiceableProperty = nil; +var selectedComPowerStatus = 0; +var selectedComOperable = 0; +var selectedComVolume = 0; +var selectedComStationType = radio_station_type_unknown; +var selectedComAirportId = ""; +var selectedComStationName = ""; +var selectedComFrequency = 0; +var selectedComStationDistance = 0; +var selectedComStationBearing = 0; +var selectedComSignalQuality = 0; +var selectedTransponder = 0; + +var radio_type_exact_match = 1; +var radio_type_any = 2; + +var currentCtr = nil; +var approvedCtr = nil; + +var aircraftIsDeparting = 0; + +var ctr_request_approved = 1; +var ctr_already_approved = 2; +var ctr_request_denied = 3; + +var ctr_status_inside = 1; +var ctr_status_in_range = 2; +var ctr_status_outside = 3; + +var ctr_range_short = 20; +var ctr_range_medium = 30; +var ctr_range_wide = 50; + +var ctr_search_range = ctr_range_wide + 20; +var ctr_leaving_range = 1; +var ctr_leaving_warning = 0; + +var ctr_maximum_range_distance = 10; +var ctr_maximum_range_angle = 90; + +var meteo_type_full = 1; +var meteo_type_wind = 2; +var meteo_type_qnh = 3; + +var runway_take_off = 1; +var runway_landing = 2; + +var approach_status_none = 1; +var approach_status_to_pattern = 2; +var approach_status_to_approach = 3; +var approach_status_to_final = 4; +var approach_status_landing = 5; + +var approachStatus = approach_status_none; +var approach_turn_distance = 0.5; +var approachRouteTextInstructions = ""; +var approachRouteVoiceInstructions = ""; +var approachAltitude = 0; + +var spell_text = 1; +var spell_number = 2; +var spell_number_to_literal = 3; +var spell_runway = 4; + +var altitude_zone_odd = 1; +var altitude_zone_even = 2; + +var ctr_request_button = -1; + +var message_none = -1; +var message_radio_check = 1; +var message_engine_start = 2; +var message_departure_information = 3; +var message_request_taxi = 4; +var message_ready_for_departure = 5; +var message_abort_departure = 6; +var message_request_approach = 7; +var message_request_ils = 8; +var message_request_ctr = 9; +var message_request_fl = 10; +var message_airfield_in_sight = 11; +var message_ils_established = 12; +var message_flying_too_low = 13; +var message_terrain_ahead = 14; +var message_leaving_ctr = 15; +var message_change_altitude = 16; +var message_check_altitude = 17; +var message_abort_approach = 18; +var message_roger = 19; +var message_wilco = 20; +var message_ctr_approved = 21; +var message_not_in_this_ctr = 22; +var message_cleared_take_off = 23; +var message_approved_approach = 24; +var message_approved_ils = 25; +var message_approach_route_instructions = 26; +var message_cleared_landing = 27; +var message_fl_approved = 28; +var message_wait_for_departure = 29; +var message_leaving_airport = 30; +var message_going_around = 31; +var message_contact_radio = 32; +var message_check_transponder = 33; +var message_say_again = 34; + +var message_type_local = 1; +var message_type_important = 2; + +var multiplayMessageType = message_type_local; + +var openDialogStartup = "Off"; +var dialogPosition = ""; +var atcTextPosition = ""; +var atcTextTransparency = "Medium"; +var menu_bar_height = 30; + +var dialogWidth = 480; +var dialogHeight = 160; +var maxDialogWidth = 462; +var maxDialogHeight = 314; +var dialogPosX = 0; +var dialogPosY = 0; +var popup_window_bg_color = [0.0, 0.0, 0.0, 0.40]; +var popup_window_fg_atc_color = [1.0, 1.0, 0.5, 1]; +var popup_window_fg_pilot_color = [0.7, 1.0, 0.5, 1]; +var atc_popup_y_position = nil; +var atc_popup_x_position = nil; +var atc_popup_align = "center"; +var dlgWindow = nil; +var dlgCanvas = nil; +var dlgRoot = nil; +var dlgLayout = nil; +var atcLogWindow = nil; +var atcLogScroll = nil; +var txtAtcLog = nil; +var radioBox = nil; +var radioList = nil; +var radioScroll = nil; +var radioScrollContent = nil; +var txtAirport = nil; +var txtAircraftPosition = nil; +var txtCurrentCtr = nil; +var txtCurrentCtrSpecs = nil; +var txtCurrentRadio = nil; +var txtCurrentRadioSpecs = nil; +var btnMessage = [nil, nil, nil, nil]; +var btnRepeatATCMessage = nil; +var btnRequestCtr = nil; +var btnRequestFlightLevel1 = nil; +var btnRequestFlightLevel2 = nil; +var btnRequestFlightLevel3 = nil; +var btnAvailableRadio = nil; +var btnAbortApproach = nil; +var repeatBtnWidth = 22; +var dialogOpened = 0; +var atcLogOpened = 0; +var currentAirport = nil; +var currentRunway = ""; +var alignedOnRunway = 0; +var nearRunway = 0; +var assignedAltitude = -1; +var requestedAltitude = -1; +var currentAltitudeZone = -1; +var flightLevel1 = 0; +var flightLevel2 = 0; +var flightLevel3 = 0; +var patternPoint = nil; +var approachPoint = nil; +var pilotMessageType = message_none; +var pilotResponseType = message_none; +var atcMessageType = [message_none, message_none, message_none, message_none]; + +var lastAtcText = ""; +var lastAtcVoice = ""; +var atcLogText = ""; + +var pilotMessageRequest = { + radio_check:"%s, %s, radio check %s", + engine_start:"%s, %s, Request start up", + departure_information:"%s, %s, Request departure information", + request_taxi:"%s, %s, Request taxi instructions%s", + ready_departure:"%s, %s, Ready for departure, runway %s", + abort_departure:"%s, %s, Abort departure, runway %s", + request_approach:"%s, %s, Request approach information", + abort_approach:"%s, %s, Abort approach request runway %s", + request_ils:"%s, %s, Request %s information", + abort_ils:"%s, %s, Abort %s request runway %s", + airfield_in_sight:"%s, %s, Airfield in sight", + ils_established:"%s, %s, %s established runway %s", + abort_landing:"%s, %s, Abort landing runway %s", + request_ctr:"%s, %s, Request clearance to transition through the %s airspace", + request_fl:"%s, %s, Request %s%s", + say_again:"%s, %s, Say again" + }; + +var pilotMessageResponse = { + roger:"%s, %s, Roger", + wilco:"%s, %s, Wilco", + engine_start:"%s, %s, Start up approved, departure runway %s.", + approved_ctr:"%s, %s, %s transition approved%s", + taxi:"%s, %s.\nTaxi to hold short of runway %s%s", + wait_departure:"%s, %s, %sReady for departure, runway %s", + cleared_take_off:"%s, %s, Cleared for take off, runway %s.", + leaving_airport:"%s, %s, Fly at runway heading, climb to %s feet.\n%s", + approved_approach:"%s, %s. Cleared to approach runway %s", + approved_ils:"%s, %s. Cleared %s approach to runway %s", + approach_route_instructions:"%s, %s, %s", + cleared_landing:"%s, %s. Cleared to land runway %s", + approved_fl:"%s, %s, Approved %s%s", + change_altitude:"%s, %s, %s and maintain %s feet", + going_around:"%s, %s, Going around", + contact_radio:"%s, %s. Contact %s at %s.", + check_transponder:"%s, %s. Squawk %sIDENT", + departure_information:"%s, %s. I have information %s." + }; + +var atcMessageRequest = { + radio_check:"Radio Check", + engine_start:"Request Engine Start", + departure_information:"Departure Information", + request_taxi:"Request Taxi", + ready_departure:"Ready for Departure", + abort_departure:"Abort Departure", + request_approach:"Request Approach", + request_ils:"Request ILS", + airfield_in_sight:"Airfield in Sight", + ils_established:"ILS Established" + }; + +var atcMessageReply = { + radio_check:"%s, %s, Reading you %s.%s", + engine_start:"%s, %s, Start up approved.\nDeparture runway %s, %s %s.\nReport when ready to taxi.", + departure_information:"%s, %s.\nDeparture runway %s, %s.\nCorrect time %s. End of information %s.", + request_taxi:"%s, %s.\nTaxi to hold short of runway %s.\n%s%s", + ready_departure:"%s, %s.\n%sGet ready for departure, runway %s.", + report_ready_departure:"Report when ready for departure", + cleared_for_takeoff:"%s, %s, Runway %s, %s, cleared for take off.", + leaving_airport:"%s, %s, %s. Fly at runway heading,\nclimb to %s feet and follow your flight plan.\n%s", + abort_departure:"%s, %s.\nAborted departure, runway %s.\nVacate runway and go around.", + request_pattern_approach:"%s, %s. Cleared to approach.\n%sHeading %s for %s miles to join %s pattern,\nthen turn %s and then turn %s to final %srunway %s with %s feet.\n%s.", + request_approach:"%s, %s. Cleared to approach.\n%sHeading %s for %s miles then turn to %s final %srunway %s with %s feet.\n%s.", + request_pattern_ils:"%s, %s.\n%sHeading %s for %s miles to join %s pattern,\nthen turn %s to intercept the %slocalizer.\nCleared %s runway %s, maintain %s feet until established.\n%s.", + request_ils:"%s, %s.\n%sHeading %s for %s miles to intercept the %slocalizer.\nCleared %s runway %s, maintain %s feet until established.\n%s.", + approach_route_instructions:"%s, %s, %s", + abort_approach:"%s, %s, Approach to runway %s aborted. Go around", + airfield_in_sight:"%s, %s. %s. Cleared to land runway %s.", + report_airfield_in_sight:"%seport on airfield in sight.", + report_established_ils:"%seport on established %s runway %s", + wrong_approach_runway:"%s, %s, You are approaching the wrong runway.\nLanding runway is %s. Leave this route immediately,\nrequest approach and follow instructions.", + welcome_to_airport:"%s, %s, welcome to %s.\nExit runway at first taxiway and taxi to platform.", + abort_landing:"%s, %s, Landing runway %s aborted.\nLeave route and go around", + ctr_approved:"%s, %s, Transition through %s airspace approved%s", + ctr_already_approved:"%s, %s, You are already approved in this %s airspace%s", + ctr_not_approved:"%s, %s, You are not approved in this %s.\nContact me when you are near this %s or request transition permission.", + not_in_this_ctr:"%s, %s, You are not approved in this %s.\nLeave this %s immediately.", + leaving_ctr:"%s, %s, You are about to leave this %s.%s", + change_altitude:"%s, %s, %s and maintain %s feet", + check_altitude:"%s, %s, %s to your assigned altitude %s feet", + fl_approved:"%s, %s, Approved %s%s.", + flying_too_low:"%s,\nYou are flying too low. Pull up! Pull up!", + terrain_ahead:"%s,\nYou are flying towards terrain.\nPull up and climb immediately\nor turn to a safe heading immediately", + wrong_runway:"%s, %s,\nYou are on the wrong runway.\nTaxi to hold short of runway %s via taxiway and report when ready for departure.", + not_in_this_airfield:"%s, This is %s.%s\nYou are not in this airfield.", + not_allowed_to_land:"%s, %s. You are not allowed to land. Request approach or landing.", + vacate_runway:"%s, %s, Take off immediately or vacate the runway.", + turn_to_heading:"Turn %s heading to %s", + turn_to_final:"Turn %s heading %s to final runway %s", + radio_available_at:"%s available at %s.", + contact_radio:"Contact %s at %s", + wrong_radio:"%s, This is %s.\nContact %s at %s.", + check_transponder:"%s, %s. Squawk %sIDENT" + }; + +var atcMessageAction = { + atc_message:"%s, This is %s.%s", + startup:"startup", + taxi_request:"taxi request", + departure_request:"departure request", + lineup_and_wait:"Line up and wait. ", + contact_when_ready:"Contact %s at %s when ready.", + unable_approve:"Unable to approve", + negative:"Negative", + tower_not_reachable:"tower radio is not reachable", + no_radio_available:"no radio available in this area", + left_tag:"left", + right_tag:"right", + climb:"Climb", + descend:"Descend", + reduce:"Reduce", + increase:"Increase", + altitude_change:"%s to %s feet with ", + turn_radio_on:"Turn radio on", + radio_volume_up:"Turn radio volume up", + no_radio_tuned:"Tuned radio is not readable or is out of range", + bad_radio_data:"** WARNING: This aircraft's radio is unusable **", + bad_airport_radio:"** WARNING: This airport radio is unusable **", + unknown_radio_type:"** WARNING: Cannot detect radio type **", + inconsistent_radio_data:"ERROR: Aircraft radio use inconsistent frequency settings", + contact_ctr:"\nFly current heading and request transition\nto %s %s at %s", + check_transponder:"Squawk %s and IDENT" + }; + +var meteoMessage = { + wind_report:"Wind %s degrees, %s knots", + wind_calm:"Wind calm", + full:"%s %s,\nTemperature %s, Dew point %s, Visibility %s kilometers", + cloud_report:"Clouds %s at %s feet", + rain_report:"%s rain", + snow_report:"%s snow", + sky_clear:"Sky clear", + light:"Light", + moderate:"Moderate", + heavy:"Heavy", + cover:"cover", + qnh_report:"%s %s" + }; + +var phoneticLetter = { + A:"Alpha", + B:"Bravo", + C:"Charlie", + D:"Delta", + E:"Echo", + F:"Fox trot", + G:"Golf", + H:"Hotel", + I:"India", + J:"Juliet", + K:"Kilo", + L:"Leema", + M:"Mike", + N:"November", + O:"Oscar", + P:"Papa", + Q:"Quebec", + R:"Romeo", + S:"Sierra", + T:"Tango", + U:"Uniform", + V:"Victor", + W:"Whiskey", + X:"X ray", + Y:"Yankee", + Z:"Zulu" + }; + +var phoneticDigit = { + 0:"Zero", + 1:"One", + 2:"Two", + 3:"Three", + 4:"Fower", + 5:"Five", + 6:"Six", + 7:"Seven", + 8:"Eight", + 9:"Niner" + }; + +var phoneticNumber = { + 0:"Zero", + 1:"One", + 2:"Two", + 3:"Three", + 4:"Fower", + 5:"Five", + 6:"Six", + 7:"Seven", + 8:"Eight", + 9:"Niner", + 10:"Ten", + 11:"Eleven", + 12:"Twelve", + 13:"Thirteen", + 14:"Fourteen", + 15:"Fifteen", + 16:"Sixteen", + 17:"Seventeen", + 18:"Eighteen", + 19:"Nineteen" + }; + +var phoneticTen = { + 0:"", + 1:"Ten", + 2:"Twenty", + 3:"Thirty", + 4:"Forty", + 5:"Fifty", + 6:"Sixty", + 7:"Seventy", + 8:"Eighty", + 9:"Ninety" + }; + +# FlightGear Properties + +var property_MultiplayCallsign = props.globals.getNode("/sim/multiplay/callsign"); +var property_UserCallsign = props.globals.getNode("/sim/user/callsign"); + +var property_Setting_OpenDialogStartup = props.globals.getNode("/rgatc/open-dialog-startup", 1); +var property_Setting_DialogPosition = props.globals.getNode("/rgatc/dialog-position", 1); +var property_Setting_AtcTextPosition = props.globals.getNode("/rgatc/atc-text-position", 1); +var property_Setting_AtcTextTransparency = props.globals.getNode("/rgatc/atc-text-transparency", 1); +var property_Setting_Callsign = props.globals.getNode("/rgatc/callsign", 1); +var property_Setting_CallsignMode = props.globals.getNode("/rgatc/callsign-mode", 1); +var property_Setting_IncludeManufacturer = props.globals.getNode("/rgatc/include-manufacturer", 1); +var property_Setting_PilotRequestMode = props.globals.getNode("/rgatc/pilot-request-mode", 1); +var property_Setting_PilotResponseMode = props.globals.getNode("/rgatc/pilot-response-mode", 1); +var property_Setting_AtcMessageMode = props.globals.getNode("/rgatc/atc-message-mode", 1); +var property_Setting_QnhUnitMeasure = props.globals.getNode("/rgatc/qnh", 1); +var property_Setting_AtcRadioMode = props.globals.getNode("/rgatc/atc-radio", 1); +var property_Setting_AircraftType = props.globals.getNode("/rgatc/aircraft-type", 1); +var property_Setting_SquawkingMode = props.globals.getNode("/rgatc/squawking", 1); +var property_Setting_SlopeAngle = props.globals.getNode("/rgatc/slope-angle", 1); +var property_Setting_TooLowWarningMode = props.globals.getNode("/rgatc/too-low-warning", 1); +var property_Setting_TerrainWarningMode = props.globals.getNode("/rgatc/terrain-warning", 1); +var property_Setting_MultiplayerChatEcho = props.globals.getNode("/rgatc/multiplayer-chat-echo", 1); + +var property_Aircraft_AltitudeFeet = props.globals.getNode("/position/altitude-ft"); +var property_Aircraft_AltitudeAglFeet = props.globals.getNode("/position/altitude-agl-ft"); +var property_Aircraft_HeadingDeg = props.globals.getNode("/orientation/heading-deg"); +var property_Aircraft_HeadingMagneticDeg = props.globals.getNode("/orientation/heading-magnetic-deg"); +var property_Aircraft_AirSpeedKnots = props.globals.getNode("/velocities/airspeed-kt"); +var property_Aircraft_GroundSpeedKnots = props.globals.getNode("/velocities/groundspeed-kt"); +var property_Aircraft_MachSpeed = props.globals.getNode("/velocities/mach"); + +var property_COM1_Serviceable = props.globals.getNode("/instrumentation/comm/serviceable"); +var property_COM1_Quality = props.globals.getNode("/instrumentation/comm/signal-quality-norm"); +var property_COM1_Volume = props.globals.getNode("/instrumentation/comm/volume"); +var property_COM1_VolumeSelected = props.globals.getNode("/instrumentation/comm/volume-selected"); +var property_COM1_PowerButton = props.globals.getNode("/instrumentation/comm/power-btn"); +var property_COM1_Operable = props.globals.getNode("/instrumentation/comm/operable"); +var property_COM1_AirportID = props.globals.getNode("/instrumentation/comm/airport-id"); +var property_COM1_StationName = props.globals.getNode("/instrumentation/comm/station-name"); +var property_COM1_Frequency = props.globals.getNode("/instrumentation/comm/frequencies/selected-mhz"); +var property_COM1_RealFrequency = props.globals.getNode("/instrumentation/comm/frequencies/selected-real-frequency-mhz"); +var property_COM1_Distance = props.globals.getNode("/instrumentation/comm/track-distance-m"); +var property_COM1_Bearing = props.globals.getNode("/instrumentation/comm/true-bearing-to-deg"); + +var property_COM2_Serviceable = props.globals.getNode("/instrumentation/comm[1]/serviceable"); +var property_COM2_Quality = props.globals.getNode("/instrumentation/comm[1]/signal-quality-norm"); +var property_COM2_Volume = props.globals.getNode("/instrumentation/comm[1]/volume"); +var property_COM2_VolumeSelected = props.globals.getNode("/instrumentation/comm[1]/volume-selected"); +var property_COM2_PowerButton = props.globals.getNode("/instrumentation/comm[1]/power-btn"); +var property_COM2_Operable = props.globals.getNode("/instrumentation/comm[1]/operable"); +var property_COM2_AirportID = props.globals.getNode("/instrumentation/comm[1]/airport-id"); +var property_COM2_StationName = props.globals.getNode("/instrumentation/comm[1]/station-name"); +var property_COM2_Frequency = props.globals.getNode("/instrumentation/comm[1]/frequencies/selected-mhz"); +var property_COM2_RealFrequency = props.globals.getNode("/instrumentation/comm[1]/frequencies/selected-real-frequency-mhz"); +var property_COM2_Distance = props.globals.getNode("/instrumentation/comm[1]/track-distance-m"); +var property_COM2_Bearing = props.globals.getNode("/instrumentation/comm[1]/true-bearing-to-deg"); + +var property_COM3_Serviceable = props.globals.getNode("/instrumentation/comm[2]/serviceable"); +var property_COM3_Quality = props.globals.getNode("/instrumentation/comm[2]/signal-quality-norm"); +var property_COM3_Volume = props.globals.getNode("/instrumentation/comm[2]/volume"); +var property_COM3_VolumeSelected = props.globals.getNode("/instrumentation/comm[2]/volume-selected"); +var property_COM3_PowerButton = props.globals.getNode("/instrumentation/comm[2]/power-btn"); +var property_COM3_Operable = props.globals.getNode("/instrumentation/comm[2]/operable"); +var property_COM3_AirportID = props.globals.getNode("/instrumentation/comm[2]/airport-id"); +var property_COM3_StationName = props.globals.getNode("/instrumentation/comm[2]/station-name"); +var property_COM3_Frequency = props.globals.getNode("/instrumentation/comm[2]/frequencies/selected-mhz"); +var property_COM3_RealFrequency = props.globals.getNode("/instrumentation/comm[2]/frequencies/selected-real-frequency-mhz"); +var property_COM3_Distance = props.globals.getNode("/instrumentation/comm[2]/track-distance-m"); +var property_COM3_Bearing = props.globals.getNode("/instrumentation/comm[2]/true-bearing-to-deg"); + +var property_Transponder1_Serviceable = props.globals.getNode("/instrumentation/transponder/serviceable"); +var property_Transponder1_Operable = props.globals.getNode("/instrumentation/transponder/operable"); +var property_Transponder1_KnobMode = props.globals.getNode("/instrumentation/transponder/inputs/knob-mode"); +var property_Transponder1_IdCode = props.globals.getNode("/instrumentation/transponder/id-code"); +var property_Transponder1_Ident = props.globals.getNode("/instrumentation/transponder/ident"); + +var property_Transponder2_Serviceable = props.globals.getNode("/instrumentation/transponder[1]/serviceable"); +var property_Transponder2_Operable = props.globals.getNode("/instrumentation/transponder[1]/operable"); +var property_Transponder2_KnobMode = props.globals.getNode("/instrumentation/transponder[1]/inputs/knob-mode"); +var property_Transponder2_IdCode = props.globals.getNode("/instrumentation/transponder[1]/id-code"); +var property_Transponder2_Ident = props.globals.getNode("/instrumentation/transponder[1]/ident"); + +var property_Transponder3_Serviceable = props.globals.getNode("/instrumentation/transponder[2]/serviceable"); +var property_Transponder3_Operable = props.globals.getNode("/instrumentation/transponder[2]/operable"); +var property_Transponder3_KnobMode = props.globals.getNode("/instrumentation/transponder[2]/inputs/knob-mode"); +var property_Transponder3_IdCode = props.globals.getNode("/instrumentation/transponder[2]/id-code"); +var property_Transponder3_Ident = props.globals.getNode("/instrumentation/transponder[2]/ident"); + +var property_RealWeather = props.globals.getNode("/environment/realwx/enabled"); + +var property_Weather_WindDirectionDeg = props.globals.getNode("/environment/wind-from-heading-deg"); +var property_Weather_WindSpeedKnots = props.globals.getNode("/environment/wind-speed-kt"); +var property_Weather_Temperature = props.globals.getNode("/environment/temperature-degc"); +var property_Weather_Dewpoint = props.globals.getNode("/environment/dewpoint-degc"); +var property_Weather_Visibility = props.globals.getNode("/environment/visibility-m"); +var property_Weather_Rain = props.globals.getNode("/environment/rain-norm"); +var property_Weather_Snow = props.globals.getNode("/environment/snow-norm"); +var property_Weather_CloudsCoverage = props.globals.getNode("/environment/clouds/layer/coverage"); +var property_Weather_CloudsElevationFeet = props.globals.getNode("/environment/clouds/layer/elevation-ft"); +var property_Weather_QnhInHg = props.globals.getNode("/environment/pressure-sea-level-inhg"); + +var property_Weather_Metar_WindDirectionDeg = props.globals.getNode("/environment/metar/base-wind-dir-deg"); +var property_Weather_Metar_WindSpeedKnots = props.globals.getNode("/environment/metar/base-wind-speed-kt"); +var property_Weather_Metar_Temperature = props.globals.getNode("/environment/metar/temperature-degc"); +var property_Weather_Metar_Dewpoint = props.globals.getNode("/environment/metar/dewpoint-degc"); +var property_Weather_Metar_Visibility = props.globals.getNode("/environment/metar/max-visibility-m"); +var property_Weather_Metar_Rain = props.globals.getNode("/environment/metar/rain-norm"); +var property_Weather_Metar_Snow = props.globals.getNode("/environment/metar/snow-norm"); +var property_Weather_Metar_SnowCover = props.globals.getNode("/environment/metar/snow-cover"); +var property_Weather_Metar_CloudsCoverage = props.globals.getNode("/environment/metar/clouds/layer/coverage"); +var property_Weather_Metar_CloudsElevationFeet = props.globals.getNode("/environment/metar/clouds/layer/elevation-ft"); +var property_Weather_Metar_QnhInHg = props.globals.getNode("/environment/metar/pressure-sea-level-inhg"); + +var property_AtcRunway = props.globals.getNode("/sim/atc/runway"); + +var property_Autopilot_RouteManagerActive = props.globals.getNode("/autopilot/route-manager/active"); +var property_Autopilot_RouteManagerDepartureRunway = props.globals.getNode("/autopilot/route-manager/departure/runway"); +var property_Autopilot_RouteManagerRouteNum = props.globals.getNode("/autopilot/route-manager/route/num"); +var property_Autopilot_RouteManagerCurrentWayPoint = props.globals.getNode("/autopilot/route-manager/current-wp"); +var property_Autopilot_RouteManagerCruiseAltitudeFeet = props.globals.getNode("/autopilot/route-manager/cruise/altitude-ft"); + +var property_ClosestAirportId = props.globals.getNode("/sim/airport/closest-airport-id"); +var property_TimeGmtString = props.globals.getNode("/sim/time/gmt-string"); + +var property_Multiplay_Chat = props.globals.getNode("/sim/multiplay/chat"); + +var property_Canvas_Width = props.globals.getNode("/sim/gui/canvas/size"); +var property_Canvas_Height = props.globals.getNode("/sim/gui/canvas/size[1]"); + +var property_Simulator_Freeze = props.globals.getNode("/sim/freeze/master"); +var property_Simulator_Replay = props.globals.getNode("/sim/replay/replay-state"); diff --git a/gui/dialogs/about-dialog.xml b/gui/dialogs/about-dialog.xml new file mode 100644 index 0000000..4275a7e --- /dev/null +++ b/gui/dialogs/about-dialog.xml @@ -0,0 +1,69 @@ + + + + + about-dialog + 4 + vbox + center + 300 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gui/dialogs/help-dialog.xml b/gui/dialogs/help-dialog.xml new file mode 100644 index 0000000..0fa3095 --- /dev/null +++ b/gui/dialogs/help-dialog.xml @@ -0,0 +1,121 @@ + + + + + help-dialog + 4 + vbox + center + 300 + + + hbox + + + + 1 + + + + + + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gui/dialogs/set-aircraft-type-dialog.xml b/gui/dialogs/set-aircraft-type-dialog.xml new file mode 100644 index 0000000..979b0ab --- /dev/null +++ b/gui/dialogs/set-aircraft-type-dialog.xml @@ -0,0 +1,53 @@ + + + + + set-aircraft-type-dialog + 4 + vbox + center + 350 + + + + + + + + + + + + + + + + + + + + diff --git a/gui/dialogs/settings-dialog.xml b/gui/dialogs/settings-dialog.xml new file mode 100644 index 0000000..5f77773 --- /dev/null +++ b/gui/dialogs/settings-dialog.xml @@ -0,0 +1,563 @@ + + + + + + settings-dialog + 4 + vbox + center + 300 + + + hbox + + 1 + + + + + + 1 + + + + + + + hbox + 8 + + + vbox + top + + + table + top + + + 0 + 0 + left + + + + + dialog-position-combo + 0 + 1 + left + /rgatc/dialog-position + Top Left + Top Right + Bottom Left + Bottom Right + false + 180 + fill + + dialog-apply + + + + + 1 + 0 + left + + + + + atc-text-position-combo + 1 + 1 + left + /rgatc/atc-text-position + Top Left + Top Center + Top Right + Middle Left + Middle Center + Middle Right + Bottom Left + Bottom Center + Bottom Right + false + 180 + fill + + dialog-apply + + + + + 2 + 0 + left + + + + + atc-text-transparency-combo + 2 + 1 + left + /rgatc/atc-text-transparency + Off + Very low + Low + Medium + High + Very high + false + 180 + fill + + dialog-apply + + + + + 3 + 0 + left + + + + + 3 + 1 + 180 + left + /rgatc/callsign + true + + dialog-apply + + + + + 4 + 0 + left + + + + + callsign-mode-combo + 4 + 1 + left + /rgatc/callsign-mode + Complete + Last three letters + First and last two letters + false + 180 + fill + + dialog-apply + + + + + 5 + 0 + left + + + + + include-manufacturer-combo + 5 + 1 + left + /rgatc/include-manufacturer + Yes + No + false + 180 + fill + + dialog-apply + + + + + 6 + 0 + left + + + + + qnh-combo + 6 + 1 + left + /rgatc/qnh + hPa + inHg + hPa and inHg + false + 180 + fill + + dialog-apply + + + + + 7 + 0 + left + + + + + aircraft-type-combo + 7 + 1 + left + /rgatc/aircraft-type + Auto + Small single engine + Small multi engine + Executive turboprop/jet + Business jet + Airline jet + Large/military jet + Special military + false + 180 + fill + + dialog-apply + + + + + 8 + 0 + left + + + + + squawking-combo + 8 + 1 + left + /rgatc/squawking + On + Off + false + 180 + fill + + dialog-apply + + + + + + + + + + vbox + top + + + table + top + + + 0 + 0 + left + + + + + open-dialog-startup-combo + 0 + 1 + left + /rgatc/open-dialog-startup + On + Off + false + 180 + fill + + dialog-apply + + + + + 1 + 0 + left + + + + + pilot-request-mode-combo + 1 + 1 + left + /rgatc/pilot-request-mode + Disabled + Voice only + Text only + Voice and text + false + 180 + fill + + dialog-apply + + + + + 2 + 0 + left + + + + + pilot-response-mode-combo + 2 + 1 + left + /rgatc/pilot-response-mode + Disabled + Voice only + Text only + Voice and text + false + 180 + fill + + dialog-apply + + + + + 3 + 0 + left + + + + + atc-message-mode-combo + 3 + 1 + left + /rgatc/atc-message-mode + Voice only + Text only + Voice and text + false + 180 + fill + + dialog-apply + + + + + 4 + 0 + left + + + + + atc-radio-combo + 4 + 1 + left + /rgatc/atc-radio + Auto + COM1 + COM2 + COM3 + false + 180 + fill + + dialog-apply + + + + + 5 + 0 + left + + + + + too-low-combo + 5 + 1 + left + /rgatc/too-low-warning + On + Off + false + 180 + fill + + dialog-apply + + + + + 6 + 0 + left + + + + + terrain-combo + 6 + 1 + left + /rgatc/terrain-warning + On + Off + false + 180 + fill + + dialog-apply + + + + + 7 + 0 + left + + + + + multiplayer-chat-combo + 7 + 1 + left + /rgatc/multiplayer-chat-echo + Off + Important messages only + All messages + false + 180 + fill + + dialog-apply + + + + + 8 + 0 + left + + + + + 8 + 1 + 40 + left + + /rgatc/slope-angle + true + + dialog-apply + + + + + + + + + + + + hbox + + + + + + + diff --git a/rgatc.nas b/rgatc.nas new file mode 100644 index 0000000..3ce51dc --- /dev/null +++ b/rgatc.nas @@ -0,0 +1,7157 @@ +# +# Red Griffin ATC - Speaking Air Traffic Controller for FlightGear +# +# Written and developer by Antonello Biancalana (Red Griffin, IK0TOJ) +# +# Copyright (C) 2019-2021 Antonello Biancalana +# +# rgatc.nas +# +# Main program +# +# Version 2.3.0 - 7 May 2021 +# +# Red Griffin ATC is an Open Source project and it is licensed +# under the Gnu Public License v3 (GPLv3) +# + +var rgatcKeyboardListener = setlistener("/devices/status/keyboard/event", func(event) +{ + if(!event.getNode("pressed").getValue()) + return; + + var key = event.getNode("key").getValue(); + var shift = event.getNode("modifier/shift").getValue(); + var ctrl = event.getNode("modifier/ctrl").getValue(); + var minCruiseAltidude = getMinCruiseAltitude(); + + if(key == last_key) + return; + + if(isAtcEnabled() == 0) + { + showPopup(RGAtcName ~ " is not enabled.\nTurn it on from the menu"); + + return; + } + + last_key = key; + + if(key == binding_key_dialog) + { + if(initialized == 0) + initRgATC(); + + if(!rgatcTimer.isRunning) + rgatcTimer.start(); + + if(ctrl == 0) + { + last_key = 0; + + if(dialogOpened == 0) + openATCDialog(); + else + closeATCDialog(); + } + else + updateATC(update_popup); + + return; + } + else if(ctrl == 1 and shift == 0) + { + if(key == binding_key_msg1) + pilotRequest(atcMessageType[0]); + else if(key == binding_key_msg2) + pilotRequest(atcMessageType[1]); + else if(key == binding_key_msg3) + pilotRequest(atcMessageType[2]); + else if(key == binding_key_msg4) + pilotRequest(atcMessageType[3]); + else if(key == binding_key_request_ctr) + pilotRequest(message_request_ctr); + else if(key == binding_key_repeat_last_atc_message) + pilotRequest(message_say_again); + } + else if(ctrl == 1 and shift == 1) + { + if(key == binding_key_flight_level_1 and aircraft_status == status_flying and flightLevel1 >= minCruiseAltidude) + { + requestedAltitude = flightLevel1; + + pilotRequest(message_request_fl); + } + else if(key == binding_key_flight_level_2 and aircraft_status == status_flying and flightLevel2 >= minCruiseAltidude) + { + requestedAltitude = flightLevel2; + + pilotRequest(message_request_fl); + } + else if(key == binding_key_flight_level_3 and aircraft_status == status_flying and flightLevel3 >= minCruiseAltidude and property_Aircraft_AltitudeFeet.getValue() > flightLevel3) + { + requestedAltitude = flightLevel3; + + pilotRequest(message_request_fl); + } + else if(key == binding_key_abort_approach) + pilotRequest(message_abort_approach); + } +}, 1); + +var rgatcTimer = maketimer(timer_interval, func() +{ + var isTerrainSafe = 1; + var radioIsTunedToApprovedCtrRadio = 0; + var minCruiseAltidude = getMinCruiseAltitude(); + + if(isSimulationPaused() == 1 or isAtcEnabled() == 0) + return; + + if(initialized == 0) + initRgATC(); + + updateATC((dialogOpened == 1) ? update_dialog : update_data_only); + + if(atc_callback_wait_seconds != auto_reply_off) + { + atc_callback_seconds_counter += timer_interval; + + if(atc_callback_seconds_counter >= atc_callback_wait_seconds) + { + atc_callback_seconds_counter = 0; + + atc_callback_wait_seconds = auto_reply_off; + + atcAutoMessage(); + } + } + + if(pilot_message_wait_seconds > 0) + { + pilot_message_counter += timer_interval; + + if(pilot_message_counter >= pilot_message_wait_seconds) + { + pilot_message_wait_seconds = -1; + + atcReplyToRequest(pilotMessageType); + + pilotMessageType = message_none; + } + } + + if(pilot_response_wait_seconds > 0) + { + pilot_response_counter += timer_interval; + + if(pilot_response_counter >= pilot_response_wait_seconds) + { + pilot_response_wait_seconds = -1; + + pilotResponse(pilotResponseType); + + pilotResponseType = message_none; + } + } + + key_press_counter += timer_interval; + ctr_update_counter += timer_interval; + ctr_check_counter += timer_interval; + + if(aircraft_status == status_flying or aircraft_status == status_took_off) + flight_time_seconds += timer_interval; + + if(key_press_counter > reset_key_interval) + { + key_press_counter = 0; + + last_key = 0; + } + + radioIsTunedToApprovedCtrRadio = isRadioTunedToApprovedCtrRadio(); + + if(ctr_check_counter > ctr_check_interval) + { + if(currentCtr != nil and approvedCtr == nil and aircraft_status == status_flying and radioIsTunedToApprovedCtrRadio == 1) + { + atcReplyToRequest(message_not_in_this_ctr); + } + + ctr_check_counter = 0; + } + + if(ctr_update_counter > ctr_update_interval) + { + if(approvedCtr != nil) + { + currentCtr = getCtrData(airportinfo(approvedCtr.ident)); + + if(currentCtr.distance > (currentCtr.range - ctr_leaving_range)) + { + if(radioIsTunedToApprovedCtrRadio == 1) + atcReplyToRequest(message_leaving_ctr); + + ctr_leaving_warning = 1; + + approvedCtr = nil; + + altitude_check_counter = 0; + + resetAircraftStatus(); + + setCtrButtons(); + } + } + else + currentCtr = getNearbyCtr(ctr_search_range); + + ctr_update_counter = 0; + + var aircraftPosition = geo.aircraft_position(); + var terrainInfo = geodinfo(aircraftPosition.lat(), aircraftPosition.lon()); + isTerrainSafe = isTerrainSafeAhead(); + + if(terrainInfo != nil) + altitudeFromTerrain = property_Aircraft_AltitudeFeet.getValue() - (terrainInfo[0] * M2FT); + else + altitudeFromTerrain = -1; + + if((altitudeFromTerrain < min_altitude_from_terrain or isTerrainSafe == 0) and terrainWarning == 0 and (aircraft_status == status_flying or aircraft_status == status_requested_approach or aircraft_status == status_requested_ils) and flight_time_seconds > take_off_max_seconds) + { + if(approvedCtr.ident == currentCtr.ident and radioIsTunedToApprovedCtrRadio == 1) + { + if(altitudeFromTerrain > min_altitude_too_low_warning) + { + if(altitudeFromTerrain < min_altitude_from_terrain and tooLowWarningMode == "On") + atcReplyToRequest(message_flying_too_low); + else if(isTerrainSafe == 0 and terrainWarningMode == "On") + atcReplyToRequest(message_terrain_ahead); + } + + terrainWarning = 1; + terrain_warning_counter = 0; + } + } + + if(aircraft_status == status_flying) + { + var heading = property_Aircraft_HeadingDeg.getValue(); + + flightLevel2 = normalizeAltitudeHeading(property_Aircraft_AltitudeFeet.getValue(), heading, minCruiseAltidude); + + flightLevel1 = flightLevel2 + flight_level_step; + + flightLevel3 = flightLevel2 - flight_level_step; + + if(flightLevel2 < minCruiseAltidude) + flightLevel2 = normalizeAltitudeHeading(minCruiseAltidude, heading, minCruiseAltidude); + + if(flightLevel3 < minCruiseAltidude) + flightLevel3 = normalizeAltitudeHeading(minCruiseAltidude, heading, minCruiseAltidude); + } + } + + if(terrainWarning == 1) + { + terrain_warning_counter += timer_interval; + + if(terrain_warning_counter >= terrain_warning_interval) + { + if(pilot_message_wait_seconds > 0) + pilot_message_wait_seconds += 10; + + if(altitude_change_wait_seconds > 0) + altitude_change_wait_seconds += 15; + + altitude_check_counter = 0; + + if(altitudeFromTerrain > min_altitude_too_low_warning) + { + if(altitudeFromTerrain < min_altitude_from_terrain) + atcReplyToRequest(message_flying_too_low); + else if(isTerrainSafe == 0) + atcReplyToRequest(message_terrain_ahead); + else + terrainWarning = 0; + } + else + terrainWarning = 0; + + terrain_warning_counter = 0; + } + } + + if(assignedAltitude != -1 and aircraft_status == status_flying) + { + altitude_check_counter += timer_interval; + + if(approvedCtr != nil) + { + if(altitude_check_counter >= altitude_check_interval and radioIsTunedToApprovedCtrRadio == 1) + { + var fpalt = getFlightPlanAltitude(); + + if(fpalt != -1 and assignedAltitude != fpalt) + { + atcReplyToRequest(message_change_altitude); + } + else + { + if(property_Aircraft_HeadingDeg.getValue() > 180) + altitudeZone = altitude_zone_even; + else + altitudeZone = altitude_zone_odd; + + if(currentAltitudeZone != altitudeZone) + { + currentAltitudeZone = altitudeZone; + + atcReplyToRequest(message_change_altitude); + } + else if(abs(property_Aircraft_AltitudeFeet.getValue() - assignedAltitude) > assigned_altitude_delta) + atcReplyToRequest(message_check_altitude); + } + + altitude_check_counter = 0; + + altitude_check_interval = flightLevelChangeSeconds(assignedAltitude); + } + } + } + + if(altitude_change_wait_seconds > 0) + { + altitude_change_counter += timer_interval; + + if(approvedCtr != nil) + { + if(altitude_change_counter >= altitude_change_wait_seconds and aircraft_status == status_flying and radioIsTunedToApprovedCtrRadio == 1) + { + altitude_change_wait_seconds = -1; + + atcReplyToRequest(message_change_altitude); + } + } + } + + if(aircraft_status == status_requested_approach or aircraft_status == status_requested_ils) + { + approach_check_counter += timer_interval; + + if(approach_check_counter > approach_check_interval and radioIsTunedToApprovedCtrRadio == 1) + { + assistedAtcApproach(); + + approach_check_counter = 0; + } + } + + if(squawkingMode == "On") + { + if(aircraft_status == status_flying or aircraft_status == status_requested_approach or aircraft_status == status_requested_ils) + { + squawk_check_counter += timer_interval; + + if(checkTransponderIdent(selectedTransponder) == 1) + squawkIdentButtonPushed = 1; + + if(squawk_check_counter > squawk_check_interval) + { + if(squawkIdent != squawk_ident_off) + { + if(checkTransponder(selectedTransponder) == 1 and squawkIdentButtonPushed == 1) + setSquawkIdentMode(squawk_ident_off); + else + atcReplyToRequest(message_check_transponder); + } + else if(checkTransponder(selectedTransponder) == 0) + atcReplyToRequest(message_check_transponder); + + squawk_check_counter = 0; + } + } + } +}); + +var initRgATC = func() +{ + initSettings(); + + var aircraftDescription = split(" ", getprop("/sim/description")); + + RGAtcName = getprop(RGAtcAddonProp ~ "name"); + RGAtcVersion = getprop(RGAtcAddonProp ~ "version"); + + setRGTitle(); + + if(size(aircraftDescription) > 0) + aircraftManufacturer = aircraftDescription[0]; + else + aircraftManufacturer = ""; + + rgatcTimer.start(); + + initialized = 1; + + setsize(radioButton, max_radios); + setsize(radioButtonFrequency, max_radios); + + for(var i = 0; i < max_radios; i += 1) + { + radioButton[i] = nil; + radioButtonFrequency[i] = 0; + } + + var pos = geo.aircraft_position(); + + var range = min_airport_range; + + if(currentCtr != nil) + range += int((currentCtr.range / 1.5) / 10); + + var airport = findAirportsWithinRange(pos, range); + + if(size(airport) > 0) + { + currentAirport = airport[0]; + + getAvailableRadios(); + + currentRadioStationId = currentAirport.id; + } + + aircraftIsDeparting = 1; + approachStatus = approach_status_none; + approach_check_interval = approach_check_interval_initial; + + currentCtr = getNearbyCtr(ctr_search_range); + + (atcCallsignText, atcCallsignVoice) = getCallSignForAtc(1); + + pilotVoice = getPilotVoice(); + + initAtcVoice(); + + print(RGAtcName ~ " successfully initialized and ready"); + + RGAtcEnabled = 1; + + clearAtcLog(); +} + +var enableAtc = func() +{ + if(!rgatcTimer.isRunning) + rgatcTimer.start(); + + RGAtcEnabled = 1; + + openATCDialog(); + + showPopup(RGAtcName ~ " is on"); +} + +var disableAtc = func() +{ + if(rgatcTimer.isRunning) + rgatcTimer.stop(); + + RGAtcEnabled = 0; + + closeATCDialog(); + + showPopup(RGAtcName ~ " is off"); +} + +var isAtcEnabled = func() +{ + return RGAtcEnabled; +} + +var toggleAtc = func() +{ + if(isAtcEnabled() == 1) + disableAtc(); + else + enableAtc(); +} + +var setRGTitle = func() +{ + RGAtcTitle = "Red Griffin ATC"; + + if(RGAtcName != nil and RGAtcName != "") + { + RGAtcTitle = RGAtcName; + + if(RGAtcVersion != nil and RGAtcVersion != "") + RGAtcTitle ~= " " ~ RGAtcVersion; + } + else + RGAtcName = RGAtcTitle; + + RGAtcTitle ~= " - Aircraft: " ~ aircraftType; + + if(dlgWindow != nil) + dlgWindow.setTitle(RGAtcTitle); +} + +var initRgATCDialog = func() +{ + dlgWindow = canvas.Window.new([dialogWidth, dialogHeight], "dialog") + .setTitle(RGAtcTitle); + + dlgWindow.del = func() + { + dialogInitialized = 0; + dialogOpened = 0; + + call(canvas.Window.del, [], me); + }; + + dlgCanvas = dlgWindow.createCanvas().set("background", canvas.style.getColor("bg_color")); + dlgCanvas.setColorBackground(0.5, 0.5, 0.5, 0.9); + + dlgRoot = dlgCanvas.createGroup(); + + dlgLayout = canvas.VBoxLayout.new(); + + dlgCanvas.setLayout(dlgLayout); + + txtAirport = dlgRoot.createChild("text") + .setText("") + .setFont("LiberationFonts/LiberationSans-Bold.ttf") + .setFontSize(14, 0.9) + .setColor(1,1,1,1) + .setAlignment("left-center") + .setTranslation(10, 20); + + txtAircraftPosition = dlgRoot.createChild("text") + .setText("") + .setFont("LiberationFonts/LiberationSans-Bold.ttf") + .setFontSize(14, 0.9) + .setColor(1,1,1,1) + .setAlignment("left-center") + .setTranslation(10, 36); + + txtCurrentCtr = dlgRoot.createChild("text") + .setText("") + .setFont("LiberationFonts/LiberationSans-Bold.ttf") + .setFontSize(14, 0.9) + .setColor(0.6,1,1,1) + .setAlignment("left-center") + .setTranslation(10, 60); + + txtCurrentCtrSpecs = dlgRoot.createChild("text") + .setText("") + .setFont("LiberationFonts/LiberationSans-Bold.ttf") + .setFontSize(14, 0.9) + .setColor(0.6,1,1,1) + .setAlignment("left-center") + .setTranslation(10, 76); + + txtCurrentRadio = dlgRoot.createChild("text") + .setText("") + .setFont("LiberationFonts/LiberationSans-Bold.ttf") + .setFontSize(14, 0.9) + .setColor(1,1,0,1) + .setAlignment("left-center") + .setTranslation(10, 100); + + txtCurrentRadioSpecs = dlgRoot.createChild("text") + .setText("") + .setFont("LiberationFonts/LiberationSans-Bold.ttf") + .setFontSize(14, 0.9) + .setColor(1,1,0,1) + .setAlignment("left-center") + .setTranslation(10, 116); + + var buttonBox = canvas.HBoxLayout.new(); + + var middleBox = canvas.HBoxLayout.new(); + + var messageBox = canvas.VBoxLayout.new(); + + var topButtonBox = canvas.HBoxLayout.new(); + + btnRepeatATCMessage = canvas.gui.widgets.Button.new(dlgRoot, canvas.style, {}) + .setText("R") + .setFixedSize(repeatBtnWidth, 26); + + btnRepeatATCMessage.hide(); + + btnRepeatATCMessage.listen("clicked", func + { + pilotRequest(message_say_again); + + dlgWindow.clearFocus(); + }); + + btnRepeatATCMessage.hide(); + + btnMessage[0] = canvas.gui.widgets.Button.new(dlgRoot, canvas.style, {}) + .setText("") + .setFixedSize((dialogWidth / 2) - 20, 26); + + btnMessage[0].listen("clicked", func + { + pilotRequest(atcMessageType[0]); + + dlgWindow.clearFocus(); + }); + + btnMessage[1] = canvas.gui.widgets.Button.new(dlgRoot, canvas.style, {}) + .setText("") + .setFixedSize((dialogWidth / 2) - 20, 26); + + btnMessage[1].listen("clicked", func + { + pilotRequest(atcMessageType[1]); + + dlgWindow.clearFocus(); + }); + + btnMessage[2] = canvas.gui.widgets.Button.new(dlgRoot, canvas.style, {}) + .setText("") + .setFixedSize((dialogWidth / 2) - 20, 26); + + btnMessage[2].listen("clicked", func + { + pilotRequest(atcMessageType[2]); + + dlgWindow.clearFocus(); + }); + + btnMessage[3] = canvas.gui.widgets.Button.new(dlgRoot, canvas.style, {}) + .setText("") + .setFixedSize((dialogWidth / 2) - 20, 26); + + btnMessage[3].listen("clicked", func + { + pilotRequest(atcMessageType[3]); + + dlgWindow.clearFocus(); + }); + + for(var i = 0; i < 4; i += 1) + btnMessage[i].hide(); + + topButtonBox.addItem(btnRepeatATCMessage); + topButtonBox.addItem(btnMessage[0]); + + messageBox.addItem(topButtonBox); + messageBox.addItem(btnMessage[1]); + messageBox.addItem(btnMessage[2]); + messageBox.addItem(btnMessage[3]); + + radioBox = canvas.VBoxLayout.new(); + + radioBox.hide(); + + radioScroll = canvas.gui.widgets.ScrollArea.new(dlgRoot, canvas.style, {size: [(dialogWidth / 2) - 20, 80]}); + radioScroll.setColorBackground(1.0, 1.0, 0.9, 0.9); + + radioBox.addItem(radioScroll, 1); + + radioScrollContent = radioScroll.getContent() + .set("font", "LiberationFonts/LiberationSans-Bold.ttf") + .set("character-size", 16) + .set("alignment", "left-center"); + + middleBox.addItem(messageBox); + middleBox.addItem(radioBox); + + btnRequestCtr = canvas.gui.widgets.Button.new(dlgRoot, canvas.style, {}) + .setText("Request CTR") + .setFixedSize(114, 26); + + btnRequestCtr.setEnabled(0); + + btnRequestCtr.listen("clicked", func + { + pilotRequest(message_request_ctr); + + dlgWindow.clearFocus(); + }); + + var minCruiseAltidude = getMinCruiseAltitude(); + + btnRequestFlightLevel1 = canvas.gui.widgets.Button.new(dlgRoot, canvas.style, {}) + .setText("--") + .setFixedSize(58, 26); + + btnRequestFlightLevel1.setEnabled(0); + + btnRequestFlightLevel1.listen("clicked", func + { + if(flightLevel1 >= minCruiseAltidude) + { + requestedAltitude = flightLevel1; + + pilotRequest(message_request_fl); + } + + dlgWindow.clearFocus(); + }); + + btnRequestFlightLevel2 = canvas.gui.widgets.Button.new(dlgRoot, canvas.style, {}) + .setText("--") + .setFixedSize(58, 26); + + btnRequestFlightLevel2.setEnabled(0); + + btnRequestFlightLevel2.listen("clicked", func + { + if(flightLevel2 >= minCruiseAltidude) + { + requestedAltitude = flightLevel2; + + pilotRequest(message_request_fl); + } + + dlgWindow.clearFocus(); + }); + + btnRequestFlightLevel3 = canvas.gui.widgets.Button.new(dlgRoot, canvas.style, {}) + .setText("--") + .setFixedSize(58, 26); + + btnRequestFlightLevel3.setEnabled(0); + + btnRequestFlightLevel3.listen("clicked", func + { + if(flightLevel3 >= minCruiseAltidude) + { + requestedAltitude = flightLevel3; + + pilotRequest(message_request_fl); + } + + dlgWindow.clearFocus(); + }); + + btnAbortApproach = canvas.gui.widgets.Button.new(dlgRoot, canvas.style, {}) + .setText("--") + .setFixedSize(140, 26); + + btnAbortApproach.setEnabled(0); + + btnAbortApproach.listen("clicked", func + { + pilotRequest(message_abort_approach); + + dlgWindow.clearFocus(); + }); + + btnAvailableRadio = canvas.gui.widgets.Button.new(dlgRoot, canvas.style, {}) + .setText("Radios") + .setFixedSize(74, 26); + + btnAvailableRadio.setEnabled(0); + + btnAvailableRadio.listen("clicked", func + { + availableRadioDialog(); + + dlgWindow.clearFocus(); + }); + + var btnClose = canvas.gui.widgets.Button.new(dlgRoot, canvas.style, {}) + .setText("Close") + .setFixedSize(70, 26); + + btnClose.listen("clicked", func + { + closeATCDialog(); + }); + + setApproachButtons(); + + buttonBox.addStretch(1); + buttonBox.addItem(btnRequestCtr); + buttonBox.addStretch(1); + buttonBox.addItem(btnAbortApproach); + buttonBox.addItem(btnRequestFlightLevel1); + buttonBox.addStretch(1); + buttonBox.addItem(btnRequestFlightLevel2); + buttonBox.addStretch(1); + buttonBox.addItem(btnRequestFlightLevel3); + buttonBox.addStretch(1); + buttonBox.addItem(btnAvailableRadio); + buttonBox.addStretch(1); + buttonBox.addItem(btnClose); + buttonBox.addStretch(1); + + dlgLayout.addStretch(1); + dlgLayout.addItem(middleBox); + dlgLayout.addItem(buttonBox); + + dialogInitialized = 1; + + setDialogPosition(); + + showRepeatATCMessageButton(0); + + updateATC(update_dialog); +} + +var setAtcTextPosition = func() +{ + if(atcTextPosition == "Top Left") + { + atc_popup_x_position = 20; + atc_popup_y_position = -(10 + menu_bar_height); + atc_popup_align = "left"; + } + else if(atcTextPosition == "Top Center") + { + atc_popup_x_position = nil; + atc_popup_y_position = -(10 + menu_bar_height); + atc_popup_align = "center"; + } + else if(atcTextPosition == "Top Right") + { + atc_popup_x_position = -20; + atc_popup_y_position = -(10 + menu_bar_height); + atc_popup_align = "left"; + } + else if(atcTextPosition == "Middle Left") + { + atc_popup_x_position = 20; + atc_popup_y_position = nil; + atc_popup_align = "left"; + } + else if(atcTextPosition == "Middle Center") + { + atc_popup_x_position = nil; + atc_popup_y_position = nil; + atc_popup_align = "center"; + } + else if(atcTextPosition == "Middle Right") + { + atc_popup_x_position = -20; + atc_popup_y_position = nil; + atc_popup_align = "left"; + } + else if(atcTextPosition == "Bottom Left") + { + atc_popup_x_position = 20; + atc_popup_y_position = 10 + menu_bar_height; + atc_popup_align = "left"; + } + else if(atcTextPosition == "Bottom Center") + { + atc_popup_x_position = nil; + atc_popup_y_position = 10 + menu_bar_height; + atc_popup_align = "center"; + } + else if(atcTextPosition == "Bottom Right") + { + atc_popup_x_position = -20; + atc_popup_y_position = 10 + menu_bar_height; + atc_popup_align = "left"; + } + else + { + atc_popup_x_position = nil; + atc_popup_y_position = -(10 + menu_bar_height); + atc_popup_align = "center"; + } + + if(atcTextTransparency == "Off") + popup_window_bg_color[3] = 1; + else if(atcTextTransparency == "Very low") + popup_window_bg_color[3] = 0.8; + else if(atcTextTransparency == "Low") + popup_window_bg_color[3] = 0.6; + else if(atcTextTransparency == "Medium") + popup_window_bg_color[3] = 0.4; + else if(atcTextTransparency == "High") + popup_window_bg_color[3] = 0.2; + else if(atcTextTransparency == "Very high") + popup_window_bg_color[3] = 0; + else + popup_window_bg_color[3] = 0.4; +} + +var setDialogPosition = func() +{ + var canvasWidth = property_Canvas_Width.getValue(); + var canvasHeight = property_Canvas_Height.getValue(); + + if(canvasWidth != nil and canvasHeight != nil) + { + if(dialogPosition == "Top Left") + { + dialogPosX = 0; + dialogPosY = menu_bar_height; + } + else if(dialogPosition == "Top Right") + { + dialogPosX = canvasWidth - maxDialogWidth; + dialogPosY = menu_bar_height; + } + else if(dialogPosition == "Bottom Left") + { + dialogPosX = 0; + dialogPosY = canvasHeight - maxDialogHeight; + } + else if(dialogPosition == "Bottom Right") + { + dialogPosX = canvasWidth - maxDialogWidth; + dialogPosY = canvasHeight - maxDialogHeight; + } + else + { + dialogPosX = 0; + dialogPosY = menu_bar_height; + } + } + else + { + dialogPosX = 0; + dialogPosY = menu_bar_height; + } + + if(dlgWindow != nil and dialogInitialized == 1) + dlgWindow.setPosition(dialogPosX, dialogPosY); +} + +var setApproachButtons = func() +{ + if(dialogOpened == 0) + return; + + if(aircraft_status == status_requested_approach or aircraft_status == status_requested_ils or aircraft_status == status_cleared_for_land_approach or aircraft_status == status_cleared_for_land_ils) + { + btnRequestFlightLevel1.setEnabled(0); + btnRequestFlightLevel2.setEnabled(0); + btnRequestFlightLevel3.setEnabled(0); + + btnRequestFlightLevel1.hide(); + btnRequestFlightLevel2.hide(); + btnRequestFlightLevel3.hide(); + + btnAbortApproach.setEnabled(1); + + btnAbortApproach.show(); + + if(aircraft_status == status_requested_approach) + btnAbortApproach.setText("Abort Approach"); + else if(aircraft_status == status_requested_ils) + btnAbortApproach.setText("Abort ILS"); + else if(aircraft_status == status_cleared_for_land_approach or aircraft_status == status_cleared_for_land_ils) + btnAbortApproach.setText("Abort Landing"); + else + { + btnAbortApproach.setEnabled(0); + btnAbortApproach.hide(); + } + } + else + { + btnAbortApproach.setEnabled(0); + + btnAbortApproach.hide(); + + btnRequestFlightLevel1.setEnabled(1); + btnRequestFlightLevel2.setEnabled(1); + btnRequestFlightLevel3.setEnabled(1); + + btnRequestFlightLevel1.show(); + btnRequestFlightLevel2.show(); + btnRequestFlightLevel3.show(); + } +} + +var setCtrButtons = func() +{ + if(dialogOpened == 0) + return; + + if(selectedComFrequency > 0) + btnRequestCtr.setEnabled(1); + else + btnRequestCtr.setEnabled(0); + + if(aircraft_status == status_flying) + { + if(approvedCtr != nil) + { + btnRequestFlightLevel1.show(); + btnRequestFlightLevel2.show(); + btnRequestFlightLevel3.show(); + } + else + { + btnRequestFlightLevel1.hide(); + btnRequestFlightLevel2.hide(); + btnRequestFlightLevel3.hide(); + } + } +} + +var openATCDialog = func() +{ + if(isAtcEnabled() == 0) + { + showPopup(RGAtcName ~ " is not enabled.\nTurn it on from the menu"); + + return; + } + + if(initialized == 0) + initRgATC(); + + if(dlgWindow == nil or dialogInitialized == 0) + initRgATCDialog(); + + if(dlgWindow != nil and dialogInitialized == 1) + { + if(dialogOpened == 0) + { + dlgWindow.show(); + + dlgWindow.clearFocus(); + + setRGTitle(); + + dialogOpened = 1; + + updateATC(update_dialog); + + updateRadioList(); + + setApproachButtons(); + + setCtrButtons(); + } + else + closeATCDialog(); + } +} + +var closeATCDialog = func() +{ + if(initialized == 0) + initRgATC(); + + if(dlgWindow == nil or dialogInitialized == 0) + initRgATCDialog(); + + if(dialogInitialized == 1 and dialogOpened == 1 and dlgWindow != nil) + { + dlgWindow.hide(); + + dialogOpened = 0; + + dlgWindow.clearFocus(); + } +} + +var openAtcLogDialog = func() +{ + if(atcLogWindow == nil) + { + atcLogWindow = canvas.Window.new([320, 180], "dialog") + .setTitle(RGAtcName ~ ": Log"); + + var atcLogCanvas = atcLogWindow.createCanvas().set("background", canvas.style.getColor("bg_color")); + atcLogCanvas.setColorBackground(0.4, 0.4, 0.4, 0.9); + + var atcLogRoot = atcLogCanvas.createGroup(); + + var atcLogLayout = canvas.VBoxLayout.new(); + + atcLogCanvas.setLayout(atcLogLayout); + + atcLogScroll = canvas.gui.widgets.ScrollArea.new(atcLogRoot, canvas.style, {}); + atcLogScroll.setColorBackground(1.0, 1.0, 0.9, 0.9); + atcLogScroll.setFixedSize(320, 148); + + atcLogLayout.addItem(atcLogScroll, 1); + + atcLogScrollContent = atcLogScroll.getContent() + .set("font", "LiberationFonts/LiberationSans-Bold.ttf") + .set("character-size", 16) + .set("alignment", "left-center"); + + txtAtcLog = canvas.gui.widgets.Label.new(atcLogScrollContent, canvas.style, {}); + + var btnClear = canvas.gui.widgets.Button.new(atcLogRoot, canvas.style, {}) + .setText("Clear") + .setFixedSize(75, 26); + + btnClear.listen("clicked", func + { + clearAtcLog(); + }); + + var btnClose = canvas.gui.widgets.Button.new(atcLogRoot, canvas.style, {}) + .setText("Close") + .setFixedSize(75, 26); + + btnClose.listen("clicked", func + { + atcLogWindow.hide(); + + atcLogOpened = 0; + }); + + var buttonBox = canvas.HBoxLayout.new(); + + buttonBox.addStretch(1); + buttonBox.addItem(btnClear); + buttonBox.addStretch(1); + buttonBox.addItem(btnClose); + buttonBox.addStretch(1); + + atcLogLayout.addStretch(1); + atcLogLayout.addItem(buttonBox); + } + else + atcLogWindow.show(); + + atcLogOpened = 1; + + txtAtcLog.setText(atcLogText); + + atcLogWindow.raise(1); + + atcLogScroll.scrollTo(0, 32768); + + atcLogWindow.clearFocus(); +} + +var addAtcLog = func(text) +{ + rowlen = 45; + + text = string.replace(text, "\n", " "); + var word = split(" ", text); + var wlen = size(word); + var row = property_TimeGmtString.getValue() ~ "Z: "; + + for(var i = 0; i < wlen; i += 1) + { + if(size(row) + size(word[i]) <= rowlen) + row ~= word[i] ~ " "; + else + { + atcLogText ~= row ~ "\n"; + + row = word[i] ~ " "; + } + } + + atcLogText ~= row ~ "\n\n"; + + if(txtAtcLog != nil) + txtAtcLog.setText(atcLogText); + + if(atcLogOpened == 1 and atcLogWindow != nil and atcLogScroll != nil) + atcLogScroll.scrollTo(0, 32768); +} + +var clearAtcLog = func() +{ + atcLogText = "\n"; + + if(txtAtcLog != nil) + txtAtcLog.setText(atcLogText); + + if(atcLogOpened == 1 and atcLogWindow != nil and atcLogScroll != nil) + atcLogScroll.scrollTo(0, 32768); +} + +var updateATC = func(update_mode) +{ + var type = nil; + var aircraftPosition = ""; + var txt = ""; + var degTag = "°"; + var popupText = RGAtcTitle ~ "\n\n"; + + if(update_mode == update_dialog) + degTag = "°"; + else + degTag = "°"; + + if(property_COM1_Serviceable != nil) + { + if(property_COM1_Quality != nil) + com1quality = property_COM1_Quality.getValue(); + else + com1quality = 5; + + com1volume = getRadioVolume(property_COM1_Volume, property_COM1_VolumeSelected); + + com1serviceable = property_COM1_Serviceable.getValue(); + + if(property_COM1_PowerButton != nil) + com1PowerStatus = property_COM1_PowerButton.getValue(); + else + com1PowerStatus = 1; + + if(property_COM1_Operable != nil) + com1Operable = property_COM1_Operable.getValue(); + else + com1Operable = 1; + } + else + { + com1quality = 0; + com1volume = 0; + com1serviceable = 0; + com1PowerStatus = 0; + com1Operable = 0; + } + + if(property_COM2_Serviceable != nil) + { + if(property_COM2_Quality != nil) + com2quality = property_COM2_Quality.getValue(); + else + com2quality = 5; + + com2volume = getRadioVolume(property_COM2_Volume, property_COM2_VolumeSelected); + + com2serviceable = property_COM1_Serviceable.getValue(); + + if(property_COM2_PowerButton != nil) + com2PowerStatus = property_COM2_PowerButton.getValue(); + else + com2PowerStatus = 1; + + if(property_COM2_Operable != nil) + com2Operable = property_COM2_Operable.getValue(); + else + com2Operable = 1; + } + else + { + com2quality = 0; + com2volume = 0; + com2serviceable = 0; + com2PowerStatus = 0; + com2Operable = 0; + } + + if(property_COM3_Serviceable != nil) + { + if(property_COM3_Quality != nil) + com3quality = property_COM3_Quality.getValue(); + else + com3quality = 5; + + com3volume = getRadioVolume(property_COM3_Volume, property_COM3_VolumeSelected); + + com3serviceable = property_COM3_Serviceable.getValue(); + + if(property_COM3_PowerButton != nil) + com3PowerStatus = property_COM3_PowerButton.getValue(); + else + com3PowerStatus = 1; + + if(property_COM3_Operable != nil) + com3Operable = property_COM3_Operable.getValue(); + else + com3Operable = 1; + } + else + { + com3quality = 0; + com3volume = 0; + com3serviceable = 0; + com3PowerStatus = 0; + com3Operable = 0; + } + + if(com1serviceable == 1 and com1PowerStatus == 1 and com1Operable == 1 and (atcRadioMode == "Auto" or atcRadioMode == "COM1")) + { + if(property_COM1_StationName != nil) + selectedComStationType = getRadioType(property_COM1_StationName.getValue()); + else + { + selectedComStationType = radio_station_type_unknown; + com1serviceable = 0; + } + + if(property_COM1_AirportID != nil) + selectedComAirportId = property_COM1_AirportID.getValue(); + else + { + selectedComAirportId = ""; + com1serviceable = 0; + } + + if(property_COM1_StationName != nil) + { + if(selectedComAirportId != "") + selectedComStationName = getRadioFullName(selectedComAirportId, property_COM1_StationName.getValue()); + else + selectedComStationName = property_COM1_StationName.getValue(); + } + else + { + selectedComStationName = ""; + com1serviceable = 0; + } + + selectedComFrequency = getRadioFrequency(property_COM1_Frequency, property_COM1_RealFrequency); + + if(selectedComFrequency <= 0) + com1serviceable = 0; + + if(property_COM1_Distance != nil) + selectedComStationDistance = property_COM1_Distance.getValue(); + else + { + selectedComStationDistance = ""; + com1serviceable = 0; + } + + if(property_COM1_Bearing != nil) + selectedComStationBearing = property_COM1_Bearing.getValue(); + else + { + selectedComStationBearing = ""; + com1serviceable = 0; + } + + if(com1serviceable == 1) + { + selectedComRadio = "COM1"; + + selectedComSignalQuality = com1quality; + selectedComVolume = com1volume; + selectedComServiceable = com1serviceable; + selectedComServiceableProperty = property_COM1_Serviceable; + selectedComPowerStatus = com1PowerStatus; + selectedComOperable = com1Operable; + } + else + { + selectedComRadio = ""; + + selectedComServiceableProperty = nil; + + selectedComSignalQuality = 0; + } + } + else if(com2serviceable == 1 and com2PowerStatus == 1 and com2Operable == 1 and (atcRadioMode == "Auto" or atcRadioMode == "COM2")) + { + if(property_COM2_StationName != nil) + selectedComStationType = getRadioType(property_COM2_StationName.getValue()); + else + { + selectedComStationType = radio_station_type_unknown; + com2serviceable = 0; + } + + if(property_COM2_AirportID != nil) + selectedComAirportId = property_COM2_AirportID.getValue(); + else + { + selectedComAirportId = ""; + com2serviceable = 0; + } + + if(property_COM2_StationName != nil) + { + if(selectedComAirportId != "") + selectedComStationName = getRadioFullName(selectedComAirportId, property_COM2_StationName.getValue()); + else + selectedComStationName = property_COM2_StationName.getValue(); + } + else + { + selectedComStationName = ""; + com2serviceable = 0; + } + + selectedComFrequency = getRadioFrequency(property_COM2_Frequency, property_COM2_RealFrequency); + + if(selectedComFrequency <= 0) + com2serviceable = 0; + + if(property_COM2_Distance != nil) + selectedComStationDistance = property_COM2_Distance.getValue(); + else + { + selectedComStationDistance = ""; + com2serviceable = 0; + } + + if(property_COM2_Bearing != nil) + selectedComStationBearing = property_COM2_Bearing.getValue(); + else + { + selectedComStationBearing = ""; + com2serviceable = 0; + } + + if(com2serviceable == 1) + { + selectedComRadio = "COM2"; + + selectedComSignalQuality = com2quality; + selectedComVolume = com2volume; + selectedComServiceable = com2serviceable; + selectedComServiceableProperty = property_COM2_Serviceable; + selectedComPowerStatus = com2PowerStatus; + selectedComOperable = com2Operable; + } + else + { + selectedComRadio = ""; + + selectedComServiceableProperty = nil; + + selectedComSignalQuality = 0; + } + } + else if(com3serviceable == 1 and com3PowerStatus == 1 and com3Operable == 1 and (atcRadioMode == "Auto" or atcRadioMode == "COM3")) + { + if(property_COM3_StationName != nil) + selectedComStationType = getRadioType(property_COM3_StationName.getValue()); + else + { + selectedComStationType = radio_station_type_unknown; + com3serviceable = 0; + } + + if(property_COM3_AirportID != nil) + selectedComAirportId = property_COM3_AirportID.getValue(); + else + { + selectedComAirportId = ""; + com3serviceable = 0; + } + + if(property_COM3_StationName != nil) + { + if(selectedComAirportId != "") + selectedComStationName = getRadioFullName(selectedComAirportId, property_COM3_StationName.getValue()); + else + selectedComStationName = property_COM3_StationName.getValue(); + } + else + { + selectedComStationName = ""; + com3serviceable = 0; + } + + selectedComFrequency = getRadioFrequency(property_COM3_Frequency, property_COM3_RealFrequency); + + if(selectedComFrequency <= 0) + com3serviceable = 0; + + if(property_COM3_Distance != nil) + selectedComStationDistance = property_COM3_Distance.getValue(); + else + { + selectedComStationDistance = ""; + com3serviceable = 0; + } + + if(property_COM3_Bearing != nil) + selectedComStationBearing = property_COM3_Bearing.getValue(); + else + { + selectedComStationBearing = ""; + com3serviceable = 0; + } + + if(com3serviceable == 1) + { + selectedComRadio = "COM3"; + + selectedComSignalQuality = com3quality; + selectedComVolume = com3volume; + selectedComServiceable = com3serviceable; + selectedComServiceableProperty = property_COM3_Serviceable; + selectedComPowerStatus = com3PowerStatus; + selectedComOperable = com3Operable; + } + else + { + selectedComRadio = ""; + + selectedComServiceableProperty = nil; + + selectedComSignalQuality = 0; + } + } + else + { + selectedComSignalQuality = 0; + selectedComAirportId = ""; + selectedComStationName = ""; + selectedComFrequency = 0; + selectedComStationDistance = ""; + selectedComStationBearing = ""; + + if(property_COM1_Serviceable != nil) + { + selectedComRadio = "COM1"; + selectedComVolume = com1volume; + selectedComServiceable = com1serviceable; + selectedComServiceableProperty = property_COM1_Serviceable; + selectedComPowerStatus = com1PowerStatus; + selectedComOperable = com1Operable; + } + else + { + selectedComRadio = ""; + selectedComVolume = ""; + selectedComServiceable = 0; + selectedComServiceableProperty = nil; + selectedComPowerStatus = 0; + selectedComOperable = 0; + } + } + + if(selectedComStationType != radio_station_type_unknown) + selectedComStationName = normalizeRadioStationName(selectedComStationName); + else + selectedComStationName = atcMessageAction.unknown_radio_type; + + if(selectedComAirportId == "") + selectedComAirportId = atcMessageAction.bad_airport_radio; + + if(selectedComFrequency <= 0) + selectedComFrequency = 999.99; + + if(selectedComStationDistance == "") + selectedComStationDistance = 9999; + + if(selectedComStationBearing == "") + selectedComStationBearing = 999; + + selectedTransponder = getOperatingTransponder(); + + var pos = geo.aircraft_position(); + + var range = min_airport_range; + + if(currentCtr != nil) + range += int((currentCtr.range / 1.5) / 10); + + if(update_mode == update_dialog) + setCtrButtons(); + + var airport = findAirportsWithinRange(pos, range); + var altitude = property_Aircraft_AltitudeAglFeet.getValue(); + + if(size(airport) > 0 and aircraft_status != status_requested_approach and aircraft_status != status_requested_ils) + { + if(update_mode == update_dialog) + txtAirport.setText(airport[0].id ~ " " ~ airport[0].name); + else if(update_mode == update_popup) + popupText ~= airport[0].id ~ " " ~ airport[0].name ~ "\n"; + + var aPos = getPositionInAirport(airport[0], pos); + + if(aPos == position_ground) + { + aircraftPosition = "Ground"; + + if(aircraft_status == status_cleared_for_land_approach or aircraft_status == status_cleared_for_land_ils) + { + aircraft_status = status_landed; + + cancelAtcPendingMessage(); + + setAtcAutoCallbackAfterSeconds(welcome_airport_secs); + } + else if(aircraft_status != status_landed and aircraft_status != status_cleared_for_takeoff) + aircraft_status = status_going_around; + + assignedAltitude = -1; + } + else if(aPos == position_flying) + { + aircraftPosition = "Flying over"; + airportRunwayInUse = ""; + airportRunwayInUseILS = ""; + + if(aircraft_status == status_cleared_for_takeoff) + { + aircraft_status = status_took_off; + flight_time_seconds = 0; + + cancelAtcPendingMessage(); + + setAtcAutoCallbackAfterSeconds(wait_after_take_off); + } + else if(aircraft_status == status_going_around) + aircraft_status = status_flying; + } + else if(aPos == position_runway) + aircraftPosition = "Runway " ~ currentRunway; + else + aircraftPosition = "???"; + + if(aPos == position_runway) + { + atcMessageType[0] = message_none; + atcMessageType[1] = message_none; + atcMessageType[2] = message_none; + atcMessageType[3] = message_none; + + if(nearRunway == 1) + { + aircraftPosition = "Near " ~ aircraftPosition; + + atcMessageType[0] = message_radio_check; + atcMessageType[1] = message_departure_information; + + if(aircraft_status == status_cleared_for_takeoff) + atcMessageType[2] = message_abort_departure; + else + atcMessageType[2] = message_ready_for_departure; + + atcMessageType[3] = message_none; + } + else if(alignedOnRunway == 1) + { + aircraftPosition ~= " - Aligned"; + + atcMessageType[0] = message_radio_check; + atcMessageType[1] = message_departure_information; + + if(aircraft_status == status_cleared_for_takeoff) + atcMessageType[2] = message_abort_departure; + else + atcMessageType[2] = message_ready_for_departure; + + atcMessageType[3] = message_none; + } + else + { + aircraftPosition = aircraftPosition; + + atcMessageType[0] = message_radio_check; + atcMessageType[1] = message_departure_information; + atcMessageType[2] = message_request_taxi; + + if(aircraft_status == status_cleared_for_takeoff) + atcMessageType[3] = message_abort_departure; + else + atcMessageType[3] = message_ready_for_departure; + } + + if(aircraft_status == status_cleared_for_land_approach or aircraft_status == status_cleared_for_land_ils) + { + aircraft_status = status_landed; + + cancelAtcPendingMessage(); + + setAtcAutoCallbackAfterSeconds(welcome_airport_secs); + } + + assignedAltitude = -1; + } + else if(aPos == position_flying) + { + var approachingRunway = ""; + var distance = -1; + var degreeDiff = 0; + var turnToDiff = ""; + var posTag = ""; + var slopeCourseMarker = ""; + + (approachingRunway, distance) = getApproachingRunway(currentAirport); + + if(approachingRunway != "") + { + var course = 0; + var dist = 0; + + var alignPoint = geo.Coord.new().set_latlon(currentAirport.runways[approachingRunway].lat, currentAirport.runways[approachingRunway].lon); + + (course, dist) = courseAndDistance(alignPoint); + + alignPoint.apply_course_distance(currentAirport.runways[approachingRunway].heading, -(dist * NM2M)); + + (course, dist) = courseAndDistance(alignPoint); + + (degreeDiff, turnToDiff) = degreesDifference(currentAirport.runways[approachingRunway].heading, course); + + dist = int(dist * NM2M); + + slopeCourseMarker = " ["; + altMarker = ""; + + altSlope = altitudeApproachSlope(currentAirport.elevation, distance); + altitudeFt = property_Aircraft_AltitudeFeet.getValue(); + + altOk = 0; + crsOk = 0; + + if(altitudeFt > altSlope) + { + altMarker = "v"; + altOk = 0; + } + else if(altitudeFt < altSlope) + { + altMarker = "^"; + altOk = 0; + } + else + { + altMarker = "o"; + altOk = 1; + } + + if(dist > 3) + { + if(dist > 60) + dist = 60; + + if(turnToDiff == "left") + slopeCourseMarker ~= "<"; + else + slopeCourseMarker ~= altMarker; + + if(dist > 10) + { + for(var n = 0; n < dist; n += 30) + slopeCourseMarker ~= "="; + } + + if(turnToDiff == "right") + slopeCourseMarker ~= ">"; + else + slopeCourseMarker ~= altMarker; + + crsOk = 0; + } + else + { + slopeCourseMarker ~= altMarker; + crsOk = 1; + } + + if(altOk == 1 and crsOk == 1) + slopeCourseMarker ~= "ok"; + + slopeCourseMarker ~= "]"; + + aircraftPosition = sprintf("APPR Runway %s%s DST %.1f nm AGL %.1f ft (%.1f m)", approachingRunway, slopeCourseMarker, distance, altitude, altitude * FT2M); + } + else + aircraftPosition = sprintf("Flying over @ AGL %.1f ft (%.1f m)", altitude, altitude * FT2M); + + (airportRunwayInUse, airportRunwayInUseILS) = runwayInUse(airportinfo(selectedComAirportId), runway_landing); + + atcMessageType[0] = message_radio_check; + atcMessageType[1] = message_request_approach; + + if(airportRunwayInUseILS != "") + { + atcMessageType[2] = message_request_ils; + atcMessageType[3] = message_airfield_in_sight; + } + else + { + atcMessageType[2] = message_airfield_in_sight; + atcMessageType[3] = message_none; + } + + if(aircraft_status == status_cleared_for_takeoff) + { + aircraft_status = status_took_off; + flight_time_seconds = 0; + + cancelAtcPendingMessage(); + + setAtcAutoCallbackAfterSeconds(wait_after_take_off); + } + } + else if(aPos == position_ground) + { + var speed = property_Aircraft_GroundSpeedKnots.getValue(); + + aircraftPosition ~= sprintf(" @ %.1f kt (%.1f km/h)", speed, speed * KT2KMH); + + atcMessageType[0] = message_radio_check; + atcMessageType[1] = message_departure_information; + atcMessageType[2] = message_engine_start; + atcMessageType[3] = message_request_taxi; + } + + if(airportRunwayInUse != "" and aPos != position_flying) + aircraftPosition ~= " - Departure runway " ~ airportRunwayInUse; + + if(update_mode == update_dialog) + txtAircraftPosition.setText(aircraftPosition); + else if(update_mode == update_popup) + popupText ~= aircraftPosition ~ "\n\n"; + + currentAirport = airport[0]; + + if(update_mode == update_dialog) + { + btnAvailableRadio.setEnabled(1); + + if(selectedComAirportId != "" or currentCtr != nil) + btnRequestCtr.setEnabled(1); + else + btnRequestCtr.setEnabled(0); + } + } + else + { + var upperText = ""; + var bottomText = ""; + var altitude = property_Aircraft_AltitudeFeet.getValue(); + var airSpeed = property_Aircraft_AirSpeedKnots.getValue(); + + if(patternPoint != nil and approachPoint != nil and (aircraft_status == status_requested_approach or aircraft_status == status_requested_ils)) + { + var courseToPoint = nil; + var distanceToPoint = 0; + + (courseToPoint, distanceToPoint) = courseAndDistance(patternPoint); + + upperText = sprintf("PTTN: HDG %d%s - DST %.2f nm - ALT %d ft", courseToPoint, degTag, distanceToPoint, altitude); + + (courseToPoint, distanceToPoint) = courseAndDistance(approachPoint); + + bottomText = sprintf("APPR: HDG %d%s - DST %.2f nm - IAS %d kt - Runway %s", courseToPoint, degTag, distanceToPoint, airSpeed, airportLandingRunway); + } + else + { + var agl = property_Aircraft_AltitudeAglFeet.getValue(); + var heading = property_Aircraft_HeadingDeg.getValue(); + var groundSpeed = property_Aircraft_GroundSpeedKnots.getValue(); + var mach = property_Aircraft_MachSpeed.getValue(); + + upperText = sprintf("ALT %d ft (%d m) - AGL %d ft (%d m) - HDG %d%s", altitude, altitude * FT2M, agl, agl * FT2M, heading, degTag); + bottomText = sprintf("IAS %d kt (%d km/h) - SPD %d kt (%d km/h) - Mach %.2f", airSpeed, airSpeed * KT2KMH, groundSpeed, groundSpeed * 1.852, mach); + } + + if(update_mode == update_dialog) + { + if(txtAirport != nil) + txtAirport.setText(upperText); + + if(txtAircraftPosition != nil) + txtAircraftPosition.setText(bottomText); + } + else if(update_mode == update_popup) + popupText ~= upperText ~ "\n" ~ bottomText ~ "\n\n"; + + currentAirport = nil; + } + + if(currentCtr != nil) + { + if(currentCtr.status != ctr_status_outside) + { + var frequency = 0; + var ctrDistance = 0; + var ctrStatus = ""; + + txt = sprintf("CTR: %s %s", currentCtr.ident, currentCtr.airport); + + if(update_mode == update_dialog) + txtCurrentCtr.setText(txt); + else if(update_mode == update_popup) + popupText ~= txt ~ "\n"; + + var radio = getCtrRadio(currentCtr); + + if(radio != nil) + frequency = radio.frequency; + else + frequency = 0; + + if(currentCtr.status == ctr_status_inside) + { + ctrDistance = currentCtr.distance; + + if(approvedCtr != nil and approvedCtr.ident == currentCtr.ident) + ctrStatus = "Approved"; + else + ctrStatus = "Inside"; + } + else if(currentCtr.status == ctr_status_in_range) + { + ctrDistance = currentCtr.distance_from_range; + ctrStatus = "Flying to"; + } + + txt = sprintf("RNG %d nm DST %.2f nm CRS %d%s - %.3f MHz - %s", currentCtr.range, ctrDistance, currentCtr.course, degTag, frequency, ctrStatus); + + if(update_mode == update_dialog) + txtCurrentCtrSpecs.setText(txt); + else if(update_mode == update_popup) + popupText ~= txt ~ "\n\n"; + } + else + { + if(update_mode == update_dialog) + { + txtCurrentCtr.setText("CTR: --"); + txtCurrentCtrSpecs.setText("--"); + } + else if(update_mode == update_popup) + popupText ~= "\nCTR: --\n\n"; + } + } + else + { + if(update_mode == update_dialog) + { + txtCurrentCtr.setText("CTR: --"); + txtCurrentCtrSpecs.setText("--"); + } + else if(update_mode == update_popup) + popupText ~= "\nCTR: --\n\n"; + } + + var aircraftPosition = ""; + + if(radioSignalQuality() > 0 and selectedComVolume >= 0.1) + { + if(btnAvailableRadio != nil) + btnAvailableRadio.setEnabled(1); + + if(selectedComAirportId != currentRadioStationId) + { + getAvailableRadios(); + + radioListHasChanged = 1; + + currentRadioStationId = selectedComAirportId; + + (atcCallsignText, atcCallsignVoice) = getCallSignForAtc(1); + + showRepeatATCMessageButton(0); + } + + if(altitude > min_ground_altitude) + { + (airportRunwayInUse, airportRunwayInUseILS) = runwayInUse(airportinfo(selectedComAirportId), runway_landing); + + atcMessageType[0] = message_radio_check; + atcMessageType[1] = message_request_approach; + + if(aircraft_status == status_requested_ils or aircraft_status == status_cleared_for_land_ils) + { + atcMessageType[2] = message_request_ils; + atcMessageType[3] = message_ils_established; + } + else + { + if(airportRunwayInUseILS != "") + { + atcMessageType[2] = message_request_ils; + atcMessageType[3] = message_airfield_in_sight; + } + else + { + atcMessageType[2] = message_airfield_in_sight; + atcMessageType[3] = message_none; + } + } + } + + txt = sprintf("%s: %s %s", selectedComRadio, selectedComAirportId, selectedComStationName); + + if(update_mode == update_dialog) + txtCurrentRadio.setText(txt); + else if(update_mode == update_popup) + popupText ~= txt ~ "\n"; + + txt = sprintf("%.3f MHz - Distance: %.2f nm @ %d%s - Quality: %d", selectedComFrequency, selectedComStationDistance * M2NM , int(selectedComStationBearing), degTag, radioSignalQuality()); + + if(update_mode == update_dialog) + txtCurrentRadioSpecs.setText(txt); + else if(update_mode == update_popup) + popupText ~= txt ~ "\n"; + + if(update_mode == update_dialog) + { + var wh = dialogHeight; + var minCruiseAltidude = getMinCruiseAltitude(); + + for(var i = 0; i < size(atcMessageType); i += 1) + { + if(atcMessageType[i] != message_none) + { + wh += 32; + + var btnTag = getMessageText(atcMessageType[i]); + + if(btnTag != "") + { + btnMessage[i].setText(btnTag); + + btnMessage[i].show(); + } + } + else + btnMessage[i].hide(); + } + + if(radioListHasChanged == 1) + { + radioBox.show(); + + updateRadioList(); + + radioListHasChanged = 0; + + showRepeatATCMessageButton(0); + } + + radioBox.show(); + + if(aircraft_status == status_flying) + { + if(flightLevel1 >= minCruiseAltidude) + { + btnRequestFlightLevel1.setText("FL" ~ getFlightLevelCode(flightLevel1)); + btnRequestFlightLevel1.setEnabled(1); + } + else + { + btnRequestFlightLevel1.setText("--"); + btnRequestFlightLevel1.setEnabled(0); + } + + if(flightLevel2 >= minCruiseAltidude) + { + btnRequestFlightLevel2.setText("FL" ~ getFlightLevelCode(flightLevel2)); + btnRequestFlightLevel2.setEnabled(1); + } + else + { + btnRequestFlightLevel2.setText("--"); + btnRequestFlightLevel2.setEnabled(0); + } + + if(flightLevel3 >= minCruiseAltidude and flightLevel3 != flightLevel2) + { + btnRequestFlightLevel3.setText("FL" ~ getFlightLevelCode(flightLevel3)); + btnRequestFlightLevel3.setEnabled(1); + } + else + { + btnRequestFlightLevel3.setText("--"); + btnRequestFlightLevel3.setEnabled(0); + } + } + else + { + btnRequestFlightLevel1.setText("--"); + btnRequestFlightLevel1.setEnabled(0); + + btnRequestFlightLevel2.setText("--"); + btnRequestFlightLevel2.setEnabled(0); + + btnRequestFlightLevel3.setText("--"); + btnRequestFlightLevel3.setEnabled(0); + } + + if(dialogInitialized == 1 and dialogOpened == 1 and dlgWindow != nil) + dlgWindow.setSize(dialogWidth, wh); + } + else if(update_mode == update_popup) + { + var minCruiseAltidude = getMinCruiseAltitude(); + + for(var i = 0; i < size(atcMessageType); i += 1) + { + if(atcMessageType[i] != message_none) + popupText ~= sprintf("\n %s", i+4, getMessageText(atcMessageType[i])); + } + + if(lastAtcText != "" or lastAtcVoice != "") + popupText ~= "\n Repeat last ATC message"; + + popupText ~= "\n Request CTR"; + + if(aircraft_status == status_flying) + { + popupText ~= "\n"; + + if(flightLevel1 >= minCruiseAltidude) + popupText ~= " Request FL" ~ getFlightLevelCode(flightLevel1) ~ "\n"; + + if(flightLevel2 >= minCruiseAltidude) + popupText ~= " Request FL" ~ getFlightLevelCode(flightLevel2) ~ "\n"; + + if(flightLevel3 >= minCruiseAltidude and flightLevel3 != flightLevel2) + popupText ~= " Request FL" ~ getFlightLevelCode(flightLevel3) ~ "\n"; + } + else if(aircraft_status == status_requested_approach) + popupText ~= "\n Abort Approach"; + else if(aircraft_status == status_requested_ils) + popupText ~= "\n Abort ILS"; + else if(aircraft_status == status_cleared_for_land_approach or aircraft_status == status_cleared_for_land_ils) + popupText ~= "\n Abort Landing"; + + showPopup(popupText); + } + } + else + { + if(selectedComServiceableProperty == nil) + txt = atcMessageAction.bad_radio_data; + else if(selectedComServiceable == 0 or selectedComPowerStatus == 0 or selectedComOperable == 0) + txt = atcMessageAction.turn_radio_on; + else if(selectedComVolume < 0.1) + { + if(selectedComRadio != "") + txt = selectedComRadio ~ ": "; + else + txt = ""; + + txt ~= atcMessageAction.radio_volume_up; + } + else if(radioSignalQuality() == 0) + { + if(selectedComRadio != "") + txt = selectedComRadio ~ ": "; + else + txt = ""; + + txt ~= atcMessageAction.no_radio_tuned; + } + else + txt = atcMessageAction.bad_radio_data; + + if(update_mode == update_dialog) + txtCurrentRadio.setText(txt); + else if(update_mode == update_popup) + popupText ~= txt ~ "\n"; + + if(update_mode == update_dialog) + { + txtCurrentRadioSpecs.setText("--"); + + btnRequestFlightLevel1.setText("--"); + btnRequestFlightLevel1.setEnabled(0); + + btnRequestFlightLevel2.setText("--"); + btnRequestFlightLevel2.setEnabled(0); + + btnRequestFlightLevel3.setText("--"); + btnRequestFlightLevel3.setEnabled(0); + } + + selectedComStationType = radio_station_type_unknown; + + if(update_mode == update_dialog) + clearATCButtons(); + else if(update_mode == update_popup) + showPopup(popupText); + + if(radioBox != nil) + radioBox.hide(); + + getAvailableRadios(); + + radioListHasChanged = 1; + + (atcCallsignText, atcCallsignVoice) = getCallSignForAtc(1); + + showRepeatATCMessageButton(0); + } + + if(dialogInitialized == 1 and dialogOpened == 1 and dlgWindow != nil) + dlgWindow.clearFocus(); + + if(atcLogOpened == 1 and atcLogWindow != nil) + atcLogWindow.clearFocus(); +} + +var getPositionInAirport = func(airport, pos) +{ + var distance = 9999; + var course = 0; + var dist = 0; + var runwayPos = 0; + var position = position_ground; + var degreeDiff = 360; + var turnToDiff = ""; + + currentRunway = ""; + alignedOnRunway = 0; + nearRunway = 0; + + if(airport == nil) + return position_unknown; + + if(property_Aircraft_AltitudeAglFeet.getValue() > min_ground_altitude) + return position_flying; + + if(size(airport.runways) > 0) + { + var aircraftHeading = property_Aircraft_HeadingDeg.getValue(); + + foreach(var runway; keys(airport.runways)) + { + min_distance = airport.runways[runway].width * 1.5; + min_near_distance = min_distance + airport.runways[runway].width * 2; + var angleDeviation = abs(airport.runways[runway].heading - aircraftHeading); + + runwayPos = geo.Coord.new().set_latlon(airport.runways[runway].lat, airport.runways[runway].lon); + runwayLength = airport.runways[runway].length; + + if(airport.runways[runway].stopway > 0) + { + runwayPos.apply_course_distance(airport.runways[runway].heading, -airport.runways[runway].stopway); + runwayLength += airport.runways[runway].stopway; + } + + if(airport.runways[runway].threshold > 0) + { + runwayPos.apply_course_distance(airport.runways[runway].heading, -airport.runways[runway].threshold); + runwayLength += airport.runways[runway].threshold; + } + + if(airport.runways[runway].reciprocal.stopway > 0) + { + runwayPos.apply_course_distance(airport.runways[runway].heading, -airport.runways[runway].reciprocal.stopway); + runwayLength += airport.runways[runway].reciprocal.stopway; + } + + if(airport.runways[runway].reciprocal.threshold > 0) + { + runwayPos.apply_course_distance(airport.runways[runway].heading, -airport.runways[runway].reciprocal.threshold); + runwayLength += airport.runways[runway].reciprocal.threshold; + } + + dist = minPathDistance(pos, runwayPos, airport.runways[runway].heading, runwayLength / 2, min_distance); + + if(dist < min_near_distance) + { + position = position_runway; + currentRunway = runway; + nearRunway = 1; + } + + if(dist < min_distance and dist < distance) + { + distance = dist; + position = position_runway; + currentRunway = runway; + nearRunway = 0; + } + } + + if(position == position_runway) + { + (degreeDiff, turnToDiff) = degreesDifference(aircraftHeading, airport.runways[currentRunway].heading); + + if(degreeDiff < max_runway_alignment_degrees) + alignedOnRunway = 1; + else + alignedOnRunway = 0; + } + } + + return position; +} + +var runwayInUse = func(airport, runway_type) +{ + var degreesBest = 360; + var lengthBest = 0; + var degreeDiff = 360; + var turnToDiff = ""; + + var windDirection = 0; + + if(isRealMeteoEnabled() == 1) + { + if(property_Weather_Metar_WindDirectionDeg != nil) + windDirection = property_Weather_Metar_WindDirectionDeg.getValue(); + else + windDirection = 0; + } + else + { + if(property_Weather_WindDirectionDeg != nil) + windDirection = property_Weather_WindDirectionDeg.getValue(); + else + windDirection = 0; + } + + var atcRunway = property_AtcRunway.getValue(); + + if(airport == nil) + return ["", nil]; + + airportRunway = ""; + airportRunwayILS = ""; + + if(property_Autopilot_RouteManagerActive.getValue() and property_Autopilot_RouteManagerDepartureRunway.getValue() != "" and runway_type == runway_take_off) + { + airportRunway = property_Autopilot_RouteManagerDepartureRunway.getValue(); + } + else if(atcRunway != "" and airport.runways[atcRunway] != nil) + { + airportRunway = atcRunway; + + if(airport.runways[airportRunway].ils_frequency_mhz != nil) + airportRunwayILS = airport.runways[airportRunway].id; + } + else + { + foreach(var runway; keys(airport.runways)) + { + var runwayDeg = airport.runways[runway].heading; + (degreeDiff, turnToDiff) = degreesDifference(runwayDeg, windDirection); + + if(degreeDiff < degreesBest or (degreeDiff == degreesBest and airport.runways[runway].length > lengthBest)) + { + airportRunway = airport.runways[runway].id; + + degreesBest = degreeDiff; + + lengthBest = airport.runways[runway].length; + } + } + } + + if(airportRunwayILS == "") + { + degreesBest = 360; + lengthBest = 0; + degreeDiff = 360; + + foreach(var runway; keys(airport.runways)) + { + var runwayDeg = airport.runways[runway].heading; + (degreeDiff, turnToDiff) = degreesDifference(runwayDeg, windDirection); + + if(airport.runways[runway].ils_frequency_mhz != nil and (degreeDiff < degreesBest or (degreeDiff == degreesBest and airport.runways[runway].length > lengthBest))) + { + airportRunwayILS = airport.runways[runway].id; + + degreesBest = degreeDiff; + + lengthBest = airport.runways[runway].length; + } + } + } + + return [airportRunway, airportRunwayILS]; +} + +var getApproachingRunway = func(airport) +{ + var degreesBest = 360; + var lengthBest = 0; + var heading = property_Aircraft_HeadingDeg.getValue(); + var approachingRunway = ""; + var distance = 9999; + var degreeDiff = 0; + var turnToDiff = ""; + var runwayPos = nil; + var runwayVector = nil; + + if(airport == nil) + return ["", 0]; + + foreach(var runway; keys(airport.runways)) + { + if(courseWithinDegrees(heading, airport.runways[runway].heading, max_runway_align_angle) == 1) + { + runwayPos = geo.Coord.new().set_latlon(airport.runways[runway].lat, airport.runways[runway].lon); + + if(airport.runways[runway].stopway > 0) + runwayPos.apply_course_distance(airport.runways[runway].heading, -airport.runways[runway].stopway); + + if(airport.runways[runway].threshold > 0) + runwayPos.apply_course_distance(airport.runways[runway].heading, -airport.runways[runway].threshold); + + if(airport.runways[runway].reciprocal.stopway > 0) + runwayPos.apply_course_distance(airport.runways[runway].heading, -airport.runways[runway].reciprocal.stopway); + + if(airport.runways[runway].reciprocal.threshold > 0) + runwayPos.apply_course_distance(airport.runways[runway].heading, -airport.runways[runway].reciprocal.threshold); + + (course, dist) = courseAndDistance(runwayPos); + + if(courseWithinDegrees(heading, course, max_runway_align_angle) == 1) + { + runwayVector = runwayPos; + + runwayVector.apply_course_distance(airport.runways[runway].heading, -(dist * NM2M)); + + (courseVector, distVector) = courseAndDistance(runwayVector); + + if(distVector < distance) + { + distance = distVector; + + approachingRunway = runway; + } + } + } + } + + return [approachingRunway, distance]; +} + +var clearATCButtons = func() +{ + if(btnMessage[0] == nil) + return; + + btnMessage[0].hide(); + btnMessage[1].hide(); + btnMessage[2].hide(); + btnMessage[3].hide(); + + if(dialogInitialized == 1 and dialogOpened == 1 and dlgWindow != nil) + dlgWindow.setSize(dialogWidth, dialogHeight); +} + +var showRepeatATCMessageButton = func(enable) +{ + var w = (dialogWidth / 2) - 20; + + if(btnRepeatATCMessage != nil) + { + if(enable == 1) + { + btnRepeatATCMessage.show(); + + w = (dialogWidth / 2) - 28 - repeatBtnWidth; + } + else + { + lastAtcText = ""; + lastAtcVoice = ""; + + btnRepeatATCMessage.hide(); + } + } + + if(btnMessage[0] != nil) + btnMessage[0].setFixedSize(w, 26); +} + +var availableRadioDialog = func() +{ + if(size(availableRadio) == 0) + { + showPopup(RGAtcName ~ ": " ~ atcMessageAction.no_radio_available ~ "."); + + return; + } + + if(selectedComStationType != radio_station_type_unknown and selectedComAirportId != "") + airport = airportinfo(selectedComAirportId); + else if(currentAirport != nil) + airport = currentAirport; + else + { + showPopup(RGAtcName ~ ": " ~ atcMessageAction.no_radio_available ~ "."); + + return; + } + + var h = (size(availableRadio) * 14) + 120; + + var (width, height) = (320, h); + + var radioWindow = canvas.Window.new([width,height], "dialog") + .setTitle(RGAtcName ~ ": Available Radios"); + + var radioCanvas = radioWindow.createCanvas().set("background", canvas.style.getColor("bg_color")); + radioCanvas.setColorBackground(0.4, 0.4, 0.4, 0.9); + + var radioRoot = radioCanvas.createGroup(); + + var radioLayout = canvas.VBoxLayout.new(); + + radioCanvas.setLayout(radioLayout); + + var btnRadioClose = canvas.gui.widgets.Button.new(radioRoot, canvas.style, {}) + .setText("Close") + .setFixedSize(75, 26); + + btnRadioClose.listen("clicked", func + { + radioWindow.hide(); + }); + + radioLayout.addStretch(1); + radioLayout.addItem(btnRadioClose); + + var txtAirport = radioRoot.createChild("text") + .setText(airport.name) + .setFont("LiberationFonts/LiberationSans-Bold.ttf") + .setFontSize(14, 0.9) + .setColor(1, 1, 1, 1) + .setAlignment("left-center") + .setTranslation(10, 20); + + var txtComTitle = radioRoot.createChild("text") + .setText("Communication Radios") + .setFont("LiberationFonts/LiberationSans-Bold.ttf") + .setFontSize(14, 0.9) + .setColor(1, 1, 0, 1) + .setAlignment("left-center") + .setTranslation(10, 48); + + var txtRadios = radioRoot.createChild("text") + .setText("") + .setFont("LiberationFonts/LiberationSans-Bold.ttf") + .setFontSize(14, 0.9) + .setColor(1, 1, 1, 1) + .setAlignment("left") + .setTranslation(10, 88); + + var radioDesc = ""; + var i = 0; + + for(i = 0; i < size(availableRadio); i += 1) + { + var radio = availableRadio[i]; + + radioDesc ~= sprintf("%s: %.3f MHz\n", radio.ident, radio.frequency); + } + + txtRadios.setText(radioDesc); + + radioWindow.raise(1); + + radioWindow.clearFocus(); +} + +var updateRadioList = func() +{ + var vndx = 0; + var voiceIsValid = 0; + + getAvailableRadios(); + + numRadios = size(availableRadio); + + if(numRadios == 0) + return; + + stationVoice = {}; + + radioList = canvas.VBoxLayout.new(); + + for(var i = 0; i < numRadios; i += 1) + { + var radio = availableRadio[i]; + + radioButton[i] = canvas.gui.widgets.Button.new(radioScrollContent, canvas.style, {}) + .setText(sprintf("%s: %.3f MHz", radio.ident, radio.frequency)) + .setFixedSize((dialogWidth / 2) - 4, 24); + + radioButton[i].show(); + + radioButtonFrequency[i] = radio.frequency; + + radioList.addItem(radioButton[i]); + + stationVoice[radio.frequency] = getSynthVoice(radio.frequency); + } + + radioList.addStretch(1); + + radioScroll.setLayout(radioList); + + for(; i < max_radios; i += 1) + { + if(radioButton[i] != nil) + { + radioButton[i].hide(); + radioButton[i] = nil; + } + } + + if(numRadios > 0) + { + radioButton[0].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[0]); + }); + } + + if(numRadios > 1) + { + radioButton[1].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[1]); + }); + } + + if(numRadios > 2) + { + radioButton[2].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[2]); + }); + } + + if(numRadios > 3) + { + radioButton[3].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[3]); + }); + } + + if(numRadios > 4) + { + radioButton[4].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[4]); + }); + } + + if(numRadios > 5) + { + radioButton[5].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[5]); + }); + } + + if(numRadios > 6) + { + radioButton[6].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[6]); + }); + } + + if(numRadios > 7) + { + radioButton[7].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[7]); + }); + } + + if(numRadios > 8) + { + radioButton[8].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[8]); + }); + } + + if(numRadios > 9) + { + radioButton[9].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[9]); + }); + } + + if(numRadios > 10) + { + radioButton[10].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[10]); + }); + } + + if(numRadios > 11) + { + radioButton[11].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[11]); + }); + } + + if(numRadios > 12) + { + radioButton[12].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[12]); + }); + } + + if(numRadios > 13) + { + radioButton[13].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[13]); + }); + } + + if(numRadios > 14) + { + radioButton[14].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[14]); + }); + } + + if(numRadios > 15) + { + radioButton[15].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[15]); + }); + } + + if(numRadios > 16) + { + radioButton[16].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[16]); + }); + } + + if(numRadios > 17) + { + radioButton[17].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[17]); + }); + } + + if(numRadios > 18) + { + radioButton[18].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[18]); + }); + } + + if(numRadios > 19) + { + radioButton[19].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[19]); + }); + } + + if(numRadios > 20) + { + radioButton[20].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[20]); + }); + } + + if(numRadios > 21) + { + radioButton[21].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[21]); + }); + } + + if(numRadios > 22) + { + radioButton[22].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[22]); + }); + } + + if(numRadios > 23) + { + radioButton[23].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[23]); + }); + } + + if(numRadios > 24) + { + radioButton[24].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[24]); + }); + } + + if(numRadios > 25) + { + radioButton[25].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[25]); + }); + } + + if(numRadios > 26) + { + radioButton[26].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[26]); + }); + } + + if(numRadios > 27) + { + radioButton[27].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[27]); + }); + } + + if(numRadios > 28) + { + radioButton[28].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[28]); + }); + } + + if(numRadios > 29) + { + radioButton[29].listen("clicked", func() + { + setCurrentComRadioFrequency(radioButtonFrequency[29]); + }); + } +} + +var setCurrentComRadioFrequency = func(frequency) +{ + if(selectedComRadio == "COM1") + { + if(property_COM1_RealFrequency != nil) + property_COM1_RealFrequency.setValue(frequency); + + if(property_COM1_Frequency != nil) + property_COM1_Frequency.setValue(frequency); + } + else if(selectedComRadio == "COM2") + { + if(property_COM2_RealFrequency != nil) + property_COM2_RealFrequency.setValue(frequency); + + if(property_COM2_Frequency != nil) + property_COM2_Frequency.setValue(frequency); + } + else if(selectedComRadio == "COM3") + { + if(property_COM3_RealFrequency != nil) + property_COM3_RealFrequency.setValue(frequency); + + if(property_COM3_Frequency != nil) + property_COM3_Frequency.setValue(frequency); + } + + if(dialogInitialized == 1 and dialogOpened == 1 and dlgWindow != nil) + { + dlgWindow.clearFocus(); + + showRepeatATCMessageButton(0); + } +} + +var showPopup = func(text) +{ + var window = screen.window.new(atc_popup_x_position, atc_popup_y_position, 20, 8); + + window.bg = popup_window_bg_color; + window.fg = popup_window_fg_atc_color; + window.align = atc_popup_align; + + window.write(text); +} + +var atcReplyToRequest = func(messageType) +{ + var text = ""; + var voice = ""; + var signal = -1; + var extraText = ""; + var extraVoice = ""; + var towerContactText = ""; + var towerContactVoice = ""; + var minCruiseAltidude = getMinCruiseAltitude(); + + if(initialized == 0) + initRgATC(); + + if(isRadioServiceable() == 0) + return; + + if(messageType == message_none or selectedComAirportId == "") + return; + + multiplayMessageType = message_type_local; + + (atcCallsignText, atcCallsignVoice) = getCallSignForAtc(0); + + if(messageType == message_say_again) + { + if(lastAtcText == "" and lastAtcVoice == "") + return; + + multiplayMessageType = message_type_local; + + text = lastAtcText; + + voice = lastAtcVoice; + + pilotResponseType = message_roger; + } + else if(messageType == message_radio_check) + { + multiplayMessageType = message_type_local; + + signal = radioSignalQuality(); + + var atisRadio = getRadio(radio_station_type_atis, radio_type_exact_match); + + if(atisRadio != nil) + { + extraText = sprintf(atcMessageReply.radio_available_at, + "\nATIS", + sprintf("%.3f", atisRadio.frequency) + ); + + extraVoice = sprintf(atcMessageReply.radio_available_at, + "\nA T I S", + spellToPhonetic(sprintf("%.3f", atisRadio.frequency), spell_number) + ); + } + + text = sprintf(atcMessageReply.radio_check, + atcCallsignText, + selectedComStationName, + sprintf("%d", signal), + extraText + ); + + voice = sprintf(atcMessageReply.radio_check, + atcCallsignVoice, + selectedComStationName, + spellToPhonetic(sprintf("%d", signal), spell_number), + extraVoice + ); + + pilotResponseType = message_none; + } + else if(messageType == message_request_ctr) + { + var ctrData = getCtrData(airportinfo(selectedComAirportId)); + var radio = nil; + + multiplayMessageType = message_type_local; + + if(getCtrData != nil) + { + radio = getCtrRadio(ctrData); + + if(radio != nil) + { + if(approvedCtr != nil and approvedCtr.ident == ctrData.ident) + { + (text, voice) = getCtrAtcMessage(ctr_already_approved); + + pilotResponseType = message_roger; + } + else if(ctrData.status == ctr_status_in_range or ctrData.status == ctr_status_inside) + { + if(selectedComAirportId == ctrData.ident and selectedComFrequency == radio.frequency) + { + (text, voice) = getCtrAtcMessage(ctr_request_approved); + + currentCtr = ctrData; + approvedCtr = ctrData; + ctr_leaving_warning = 0; + altitude_check_counter = 0; + + altitude_change_wait_seconds = int(rand() * max_altitude_change_secs) + min_altitude_change_secs; + assignedAltitude = -1; + aircraftIsDeparting = 0; + + resetAircraftStatus(); + + pilotResponseType = message_ctr_approved; + } + else + { + text = sprintf("%s, %s, ", + atcCallsignText, + selectedComStationName + ); + + voice = sprintf("%s, %s, ", + atcCallsignVoice, + selectedComStationName + ); + + text ~= sprintf(atcMessageReply.contact_radio, + normalizeRadioStationName(radio.name), + sprintf("%.3f", radio.frequency) + ); + + voice ~= sprintf(atcMessageReply.contact_radio, + normalizeRadioStationName(radio.name), + spellToPhonetic(sprintf("%.3f", radio.frequency), spell_number) + ); + + + pilotResponseType = message_roger; + } + } + else + { + (text, voice) = getCtrAtcMessage(ctr_request_denied); + + assignedAltitude = -1; + + pilotResponseType = message_roger; + } + } + else + { + (text, voice) = getCtrAtcMessage(ctr_request_denied); + + assignedAltitude = -1; + + pilotResponseType = message_roger; + } + } + else + { + (text, voice) = getCtrAtcMessage(ctr_request_denied); + + assignedAltitude = -1; + + pilotResponseType = message_roger; + } + + setApproachButtons(); + + setCtrButtons(); + } + else if(messageType == message_engine_start) + { + if(checkRadioIsType(radio_station_type_ground) == 0) + return; + + var airport = ""; + + multiplayMessageType = message_type_local; + + if(selectedComAirportId == property_ClosestAirportId.getValue()) + { + airport = airportinfo(selectedComAirportId); + (airportRunwayInUse, airportRunwayInUseILS) = runwayInUse(airport, runway_take_off); + + (qnhValue, qnhLiteralValue) = getQNH(); + + text = sprintf(atcMessageReply.engine_start, + atcCallsignText, + selectedComStationName, + airportRunwayInUse, + "QNH", + qnhValue + ); + + voice = sprintf(atcMessageReply.engine_start, + atcCallsignVoice, + selectedComStationName, + spellToPhonetic(airportRunwayInUse, spell_runway), + "Q N H", + qnhLiteralValue + ); + + aircraftIsDeparting = 1; + + pilotResponseType = message_engine_start; + } + else + { + reason = " "; + + if(rand() < 0.5) + reason ~= atcMessageAction.unable_approve; + else + reason ~= atcMessageAction.negative; + + reason ~= " " ~ atcMessageAction.startup ~ "."; + + text = sprintf(atcMessageReply.not_in_this_airfield, + atcCallsignText, + selectedComStationName, + reason + ); + + voice = sprintf(atcMessageReply.not_in_this_airfield, + atcCallsignVoice, + selectedComStationName, + reason + ); + + pilotResponseType = message_roger; + } + + setApproachButtons(); + } + else if(messageType == message_departure_information) + { + if(checkRadioIsType(radio_station_type_ground) == 0) + return; + + var airport = ""; + + multiplayMessageType = message_type_local; + + if(selectedComAirportId == property_ClosestAirportId.getValue()) + { + airport = airportinfo(selectedComAirportId); + (airportRunwayInUse, airportRunwayInUseILS) = runwayInUse(airport, runway_take_off); + var currentTime = substr(property_TimeGmtString.getValue(), 0, 5) ~ "Z"; + + if(selectedComAirportId != departureInformationAirport) + { + departureInformationAirport = selectedComAirportId; + + letter = chr(int(rand() * (size(phoneticLetter) - 1)) + 65); + + departureInformation = phoneticLetter[letter]; + } + + text = sprintf(atcMessageReply.departure_information, + atcCallsignText, + selectedComStationName, + airportRunwayInUse, + getMeteoText(meteo_type_full, 0), + currentTime, + departureInformation + ); + + voice = sprintf(atcMessageReply.departure_information, + atcCallsignVoice, + selectedComStationName, + spellToPhonetic(airportRunwayInUse, spell_runway), + getMeteoText(meteo_type_full, 1), + spellToPhonetic(currentTime, spell_number), + departureInformation + ); + + pilotResponseType = message_departure_information; + + aircraftIsDeparting = 1; + } + else + { + text = sprintf(atcMessageReply.not_in_this_airfield, + atcCallsignText, + selectedComStationName, + "" + ); + + voice = sprintf(atcMessageReply.not_in_this_airfield, + atcCallsignVoice, + selectedComStationName, + "" + ); + + pilotResponseType = message_roger; + } + + setApproachButtons(); + } + else if(messageType == message_request_taxi) + { + if(checkRadioIsType(radio_station_type_ground) == 0) + return; + + var airport = ""; + + multiplayMessageType = message_type_important; + + if(selectedComAirportId == property_ClosestAirportId.getValue()) + { + var towerRadio = getRadio(radio_station_type_tower, radio_type_any); + var reportTag = ""; + var reportVoice = ""; + + if(towerRadio == nil) + { + showPopup(RGAtcName ~ ": " ~ atcMessageAction.tower_not_reachable ~ "."); + + return; + } + + if(selectedComFrequency == towerRadio.frequency) + { + reportTag = atcMessageReply.report_ready_departure; + + reportVoice = reportTag; + } + else + { + reportTag = sprintf(atcMessageAction.contact_when_ready, + normalizeRadioStationName(towerRadio.name), + sprintf("%.3f", towerRadio.frequency) + ); + + reportVoice = sprintf(atcMessageAction.contact_when_ready, + normalizeRadioStationName(towerRadio.name), + spellToPhonetic(sprintf("%.3f", towerRadio.frequency), spell_number) + ); + } + + airport = airportinfo(selectedComAirportId); + (airportRunwayInUse, airportRunwayInUseILS) = runwayInUse(airport, runway_take_off); + + extraText = ""; + extraVoice = ""; + + if(squawkingMode == "On") + { + squawkCode = getSquawkCode(); + squawkChange = 1; + + extraText ~= sprintf(" Squawk %s.", squawkCode); + extraVoice ~= sprintf(" Squawk %s.", spellToPhonetic(squawkCode, spell_number)); + + setSquawkIdentMode(squawk_ident_off); + } + else + { + extraText = "."; + extraVoice = "."; + } + + if(departureInformation != "") + { + if(squawkingMode == "Off") + { + extraText ~= "."; + extraVoice ~= "."; + } + + extraText ~= sprintf("\nYou have information %s.", + departureInformation + ); + + extraVoice ~= sprintf("\nYou have information %s.", + departureInformation + ); + } + + text = sprintf(atcMessageReply.request_taxi, + atcCallsignText, + selectedComStationName, + airportRunwayInUse, + reportTag, + extraText + ); + + voice = sprintf(atcMessageReply.request_taxi, + atcCallsignVoice, + selectedComStationName, + spellToPhonetic(airportRunwayInUse, spell_runway), + reportVoice, + extraVoice + ); + + aircraftIsDeparting = 1; + + pilotResponseType = message_request_taxi; + } + else + { + reason = " "; + + if(rand() < 0.5) + reason ~= atcMessageAction.unable_approve; + else + reason ~= atcMessageAction.negative; + + reason ~= " " ~ atcMessageAction.taxi_request ~ "."; + + text = sprintf(atcMessageReply.not_in_this_airfield, + atcCallsignText, + selectedComStationName, + reason + ); + + voice = sprintf(atcMessageReply.not_in_this_airfield, + atcCallsignVoice, + selectedComStationName, + reason + ); + + pilotResponseType = message_roger; + } + + setApproachButtons(); + } + else if(messageType == message_ready_for_departure) + { + if(checkRadioIsType(radio_station_type_tower) == 0) + return; + + var airport = nil; + + multiplayMessageType = message_type_important; + + if(selectedComAirportId == airportinfo().id) + { + airport = airportinfo(selectedComAirportId); + (airportRunwayInUse, airportRunwayInUseILS) = runwayInUse(airport, runway_take_off); + + if(nearRunway == 1) + { + extraText = atcMessageAction.lineup_and_wait; + extraVoice = atcMessageAction.lineup_and_wait; + } + else + { + extraText = ""; + extraVoice = ""; + } + + if(currentRunway == airportRunwayInUse) + { + text = sprintf(atcMessageReply.ready_departure, + atcCallsignText, + selectedComStationName, + extraText, + airportRunwayInUse + ); + + voice = sprintf(atcMessageReply.ready_departure, + atcCallsignVoice, + selectedComStationName, + extraVoice, + spellToPhonetic(airportRunwayInUse, spell_runway) + ); + + if(squawkingMode == "On" and squawkChange == 1) + { + squawkCode = getSquawkCode(); + + text ~= sprintf(" Squawk %s.", squawkCode); + + voice ~= sprintf(" Squawk %s.", spellToPhonetic(squawkCode, spell_number)); + + setSquawkIdentMode(squawk_ident_off); + } + + aircraft_status = status_ready_for_departure; + + cancelAtcPendingMessage(); + + setAtcAutoCallbackAfterSeconds(int(rand() * max_cleared_takeoff_secs) + min_cleared_takeoff_secs); + + pilotResponseType = message_wait_for_departure; + } + else + { + text = sprintf(atcMessageReply.wrong_runway, + atcCallsignText, + selectedComStationName, + airportRunwayInUse + ); + + voice = sprintf(atcMessageReply.wrong_runway, + atcCallsignVoice, + selectedComStationName, + spellToPhonetic(airportRunwayInUse, spell_runway) + ); + + pilotResponseType = message_roger; + } + + aircraftIsDeparting = 1; + } + else + { + reason = " "; + + if(rand() < 0.5) + reason ~= atcMessageAction.unable_approve; + else + reason ~= atcMessageAction.negative; + + reason ~= " " ~ atcMessageAction.departure_request ~ "."; + + text = sprintf(atcMessageReply.not_in_this_airfield, + atcCallsignText, + selectedComStationName, + reason + ); + + voice = sprintf(atcMessageReply.not_in_this_airfield, + atcCallsignVoice, + selectedComStationName, + reason + ); + + pilotResponseType = message_roger; + } + + setApproachButtons(); + } + else if(messageType == message_abort_departure) + { + if(checkRadioIsType(radio_station_type_tower) == 0) + return; + + multiplayMessageType = message_type_important; + + airport = airportinfo(selectedComAirportId); + (airportRunwayInUse, airportRunwayInUseILS) = runwayInUse(airport, runway_take_off); + + text = sprintf(atcMessageReply.abort_departure, + atcCallsignText, + selectedComStationName, + airportRunwayInUse + ); + + voice = sprintf(atcMessageReply.abort_departure, + atcCallsignVoice, + selectedComStationName, + spellToPhonetic(airportRunwayInUse, spell_runway) + ); + + aircraft_status = status_going_around; + + aircraftIsDeparting = 0; + + pilotResponseType = message_going_around; + + setApproachButtons(); + } + else if(messageType == message_request_approach or messageType == message_request_ils) + { + var towerRadio = nil; + var initialReportLetter = "R"; + var finalTurn = ""; + var ilsText = ""; + var ilsVoice = ""; + + if(isRadioTunedToApprovedCtrRadio() == 0) + { + atcReplyToRequest(message_not_in_this_ctr); + + return; + } + + if(checkRadioIsType(radio_station_type_approach) == 0) + return; + + multiplayMessageType = message_type_important; + + if(approvedCtr != nil) + airport = airportinfo(approvedCtr.ident); + else + airport = airportinfo(selectedComAirportId); + + (airportLandingRunway, airportRunwayInUseILS) = runwayInUse(airport, runway_landing); + + if(messageType == message_request_ils) + { + patternFormat = atcMessageReply.request_pattern_ils; + approachFormat = atcMessageReply.request_ils; + + ilsText = "ILS"; + ilsVoice = "I L S"; + + airportLandingRunway = airportRunwayInUseILS; + } + else + { + patternFormat = atcMessageReply.request_pattern_approach; + approachFormat = atcMessageReply.request_approach; + + ilsText = ""; + ilsVoice = ""; + } + + var (courseToRunway, distanceToRunway) = courseAndDistance(airport.runways[airportLandingRunway]); + + approachPoint = geo.Coord.new().set_latlon(airport.runways[airportLandingRunway].lat, + airport.runways[airportLandingRunway].lon); + + approachPoint.apply_course_distance(airport.runways[airportLandingRunway].heading, approach_point_distance * NM2M); + + var heading = property_Aircraft_HeadingMagneticDeg.getValue(); + + patternPoint = geo.Coord.new().set_latlon(approachPoint.lat(), + approachPoint.lon()); + + if(geo.normdeg(courseToRunway - heading) < 180) + { + patternCircuit = atcMessageAction.right_tag; + + courseToApproachPoint = geo.normdeg(airport.runways[airportLandingRunway].heading - 90); + } + else + { + patternCircuit = atcMessageAction.left_tag; + + courseToApproachPoint = geo.normdeg(airport.runways[airportLandingRunway].heading + 90); + } + + if(messageType == message_request_approach) + finalTurn = patternCircuit; + else + finalTurn = ""; + + patternPoint.apply_course_distance(courseToApproachPoint, pattern_point_distance * NM2M); + + var (courseToPattern, distanceToPattern) = courseAndDistance(patternPoint); + var (courseToApproach, distanceToApproach) = courseAndDistance(approachPoint); + + airportElevation = airport.elevation * M2FT; + + approachAltitude = altitudeApproachSlope(airport.elevation, abs(approach_point_distance), 1); + + var cruiseAltitude = approachAltitude; + + var altitudeInstructionText = ""; + var altitudeInstructionVoice = ""; + + if(distanceToPattern > min_distance_for_altitude_change) + { + var altSteps = int(distanceToPattern / miles_altitude_step); + + cruiseAltitude += (feet_altitude_step * altSteps); + + cruiseAltitude = normalizeAltitudeHeading(cruiseAltitude, courseToPattern, approachAltitude); + + if(property_Aircraft_AltitudeFeet.getValue() > cruiseAltitude) + actionTag = atcMessageAction.descend; + else + actionTag = atcMessageAction.climb; + + altitudeInstructionText = sprintf(atcMessageAction.altitude_change, + actionTag, + sprintf("%d", cruiseAltitude) + ); + + altitudeInstructionVoice = sprintf(atcMessageAction.altitude_change, + actionTag, + spellToPhonetic(sprintf("%d", cruiseAltitude), spell_number_to_literal) + ); + + assignedAltitude = cruiseAltitude; + + altitude_check_interval = flightLevelChangeSeconds(assignedAltitude); + } + + if(distanceToPattern < distanceToRunway or distanceToApproach < distanceToRunway) + { + # Route plane to runway approach point + + (courseToApproach, distanceToApproach) = courseAndDistance(approachPoint); + + text = sprintf(approachFormat, + atcCallsignText, + selectedComStationName, + altitudeInstructionText, + sprintf("%d", courseToApproach), + sprintf("%d", distanceToApproach), + finalTurn, + ilsText, + airportLandingRunway, + sprintf("%d", approachAltitude), + getMeteoText(meteo_type_qnh, 0) + ); + + voice = sprintf(approachFormat, + atcCallsignVoice, + selectedComStationName, + altitudeInstructionVoice, + spellToPhonetic(sprintf("%d", courseToApproach), spell_number), + spellToPhonetic(sprintf("%d", distanceToApproach), spell_number_to_literal), + finalTurn, + ilsVoice, + spellToPhonetic(airportLandingRunway, spell_runway), + spellToPhonetic(sprintf("%d", approachAltitude), spell_number_to_literal), + getMeteoText(meteo_type_qnh, 1) + ); + + assignedAltitude = approachAltitude; + + altitude_check_interval = flightLevelChangeSeconds(assignedAltitude); + + approachStatus = approach_status_to_approach; + approach_check_counter = 0; + } + else if(distanceToApproach > 3) + { + # Route plane to pattern point + + text = sprintf(patternFormat, + atcCallsignText, + selectedComStationName, + altitudeInstructionText, + sprintf("%d", courseToPattern), + sprintf("%d", distanceToPattern), + patternCircuit, + sprintf("%d", courseToApproachPoint), + finalTurn, + ilsText, + airportLandingRunway, + sprintf("%d", approachAltitude), + getMeteoText(meteo_type_qnh, 0) + ); + + voice = sprintf(patternFormat, + atcCallsignVoice, + selectedComStationName, + altitudeInstructionVoice, + spellToPhonetic(sprintf("%d", courseToPattern), spell_number), + spellToPhonetic(sprintf("%d", distanceToPattern), spell_number_to_literal), + patternCircuit, + spellToPhonetic(sprintf("%d", courseToApproachPoint), spell_number), + finalTurn, + ilsVoice, + spellToPhonetic(airportLandingRunway, spell_runway), + spellToPhonetic(sprintf("%d", approachAltitude), spell_number_to_literal), + getMeteoText(meteo_type_qnh, 1) + ); + + approachStatus = approach_status_to_pattern; + approach_check_counter = 0; + } + else + { + # Route plane to approach point + + text = sprintf(approachFormat, + atcCallsignText, + selectedComStationName, + altitudeInstructionText, + sprintf("%d", courseToApproachPoint), + sprintf("%d", distanceToApproach), + finalTurn, + ilsText, + airportLandingRunway, + sprintf("%d", approachAltitude), + getMeteoText(meteo_type_qnh, 0) + ); + + voice = sprintf(approachFormat, + atcCallsignVoice, + selectedComStationName, + altitudeInstructionVoice, + spellToPhonetic(sprintf("%d", courseToApproachPoint), spell_number), + spellToPhonetic(sprintf("%d", distanceToApproach), spell_number_to_literal), + finalTurn, + ilsVoice, + spellToPhonetic(airportLandingRunway, spell_runway), + spellToPhonetic(sprintf("%d", approachAltitude), spell_number_to_literal), + getMeteoText(meteo_type_qnh, 1) + ); + + approachStatus = approach_status_to_approach; + approach_check_counter = 0; + } + + if(messageType == message_request_approach) + pilotResponseType = message_approved_approach; + else + pilotResponseType = message_approved_ils; + + if(approvedCtr == nil or approvedCtr.ident != currentCtr.ident) + { + (text, voice) = getCtrAtcMessage(ctr_request_denied); + + assignedAltitude = -1; + + pilotResponseType = message_roger; + } + else + { + if(messageType == message_request_approach) + aircraft_status = status_requested_approach; + else + aircraft_status = status_requested_ils; + + aircraftIsDeparting = 0; + } + + setApproachButtons(); + + setCtrButtons(); + + cancelAtcPendingMessage(); + + approach_check_interval = approach_check_interval_initial; + } + else if(messageType == message_approach_route_instructions) + { + text = sprintf(atcMessageReply.approach_route_instructions, + atcCallsignText, + selectedComStationName, + approachRouteTextInstructions + ); + + voice = sprintf(atcMessageReply.approach_route_instructions, + atcCallsignVoice, + selectedComStationName, + approachRouteVoiceInstructions + ); + + multiplayMessageType = message_type_local; + + pilotResponseType = message_approach_route_instructions; + } + else if(messageType == message_airfield_in_sight or messageType == message_ils_established) + { + if(checkRadioIsType(radio_station_type_tower) == 0) + return; + + multiplayMessageType = message_type_important; + + if(aircraft_status == status_requested_approach or aircraft_status == status_requested_ils or aircraft_status == status_cleared_for_land_approach or aircraft_status == status_cleared_for_land_ils) + { + airport = airportinfo(selectedComAirportId); + + (airportLandingRunway, airportRunwayInUseILS) = runwayInUse(airport, runway_landing); + + if(aircraft_status == status_requested_ils or aircraft_status == status_cleared_for_land_ils) + landingRunway = airportRunwayInUseILS; + else + landingRunway = airportLandingRunway; + + text = sprintf(atcMessageReply.airfield_in_sight, + atcCallsignText, + selectedComStationName, + getMeteoText(meteo_type_wind, 0), + landingRunway + ); + + voice = sprintf(atcMessageReply.airfield_in_sight, + atcCallsignVoice, + selectedComStationName, + getMeteoText(meteo_type_wind, 1), + spellToPhonetic(landingRunway, spell_runway) + ); + + if(aircraft_status == status_requested_ils) + aircraft_status = status_cleared_for_land_ils; + else + aircraft_status = status_cleared_for_land_approach; + + setApproachButtons(); + + cancelAtcPendingMessage(); + + setAtcAutoCallbackAfterSeconds(land_check_secs); + + aircraftIsDeparting = 0; + + pilotResponseType = message_cleared_landing; + } + else + { + text = sprintf(atcMessageReply.not_allowed_to_land, + atcCallsignText, + selectedComStationName + ); + + voice = sprintf(atcMessageReply.not_allowed_to_land, + atcCallsignVoice, + selectedComStationName + ); + + setApproachButtons(); + + pilotResponseType = message_roger; + } + + if(approvedCtr == nil or approvedCtr.ident != currentCtr.ident) + { + (text, voice) = getCtrAtcMessage(ctr_request_denied); + + assignedAltitude = -1; + + pilotResponseType = message_roger; + + setApproachButtons(); + + setCtrButtons(); + } + } + else if(messageType == message_flying_too_low) + { + multiplayMessageType = message_type_local; + + text = sprintf(atcMessageReply.flying_too_low, + atcCallsignText + ); + + voice = sprintf(atcMessageReply.flying_too_low, + atcCallsignVoice + ); + + pilotResponseType = message_none; + } + else if(messageType == message_terrain_ahead) + { + multiplayMessageType = message_type_local; + + text = sprintf(atcMessageReply.terrain_ahead, + atcCallsignText + ); + + voice = sprintf(atcMessageReply.terrain_ahead, + atcCallsignVoice + ); + + pilotResponseType = message_none; + } + else if(messageType == message_leaving_ctr) + { + multiplayMessageType = message_type_local; + + var nearestCtr = getNearbyCtr(ctr_search_range); + + if(nearestCtr != nil) + { + var radio = getCtrRadio(nearestCtr); + + extraText = sprintf(atcMessageAction.contact_ctr, + nearestCtr.airport, + "CTR", + sprintf("%.3f", radio.frequency) + ); + + extraVoice = sprintf(atcMessageAction.contact_ctr, + nearestCtr.airport, + "C T R", + spellToPhonetic(sprintf("%.3f", radio.frequency), spell_number) + ); + } + + text = sprintf(atcMessageReply.leaving_ctr, + atcCallsignText, + selectedComStationName, + "CTR", + extraText + ); + + voice = sprintf(atcMessageReply.leaving_ctr, + atcCallsignVoice, + selectedComStationName, + "C T R", + extraVoice + ); + + aircraftIsDeparting = 0; + + pilotResponseType = message_roger; + + resetAircraftStatus(); + + setApproachButtons(); + } + else if(messageType == message_not_in_this_ctr) + { + multiplayMessageType = message_type_local; + + text = sprintf(atcMessageReply.not_in_this_ctr, + atcCallsignText, + selectedComStationName, + "CTR", + "CTR" + ); + + voice = sprintf(atcMessageReply.not_in_this_ctr, + atcCallsignVoice, + selectedComStationName, + "C T R", + "C T R" + ); + + aircraftIsDeparting = 0; + + pilotResponseType = message_roger; + + resetAircraftStatus(); + + setApproachButtons(); + } + if(messageType == message_request_fl) + { + multiplayMessageType = message_type_important; + + text = sprintf(atcMessageReply.fl_approved, + atcCallsignText, + selectedComStationName, + "FL", + getFlightLevelCode(requestedAltitude) + ); + + voice = sprintf(atcMessageReply.fl_approved, + atcCallsignVoice, + selectedComStationName, + "Flight Level", + spellToPhonetic(getFlightLevelCode(requestedAltitude), spell_number) + ); + + resetAircraftStatus(); + + setApproachButtons(); + + setCtrButtons(); + + assignedAltitude = requestedAltitude; + + altitude_check_interval = flightLevelChangeSeconds(assignedAltitude); + + pilotResponseType = message_fl_approved; + + if(approvedCtr == nil or approvedCtr.ident != currentCtr.ident) + { + (text, voice) = getCtrAtcMessage(ctr_request_denied); + + assignedAltitude = -1; + + pilotResponseType = message_roger; + } + } + else if(messageType == message_change_altitude) + { + multiplayMessageType = message_type_important; + + assignedAltitude = getFlightPlanAltitude(); + + if(assignedAltitude == -1) + { + assignedAltitude = normalizeAltitudeHeading(property_Aircraft_AltitudeFeet.getValue(), property_Aircraft_HeadingDeg.getValue(), minCruiseAltidude); + + if(rand() < 0.5 and (assignedAltitude - flight_level_step) >= minCruiseAltidude) + assignedAltitude -= flight_level_step; + } + + if(property_Aircraft_AltitudeFeet.getValue() > assignedAltitude) + actionTag = atcMessageAction.descend; + else + actionTag = atcMessageAction.climb; + + text = sprintf(atcMessageReply.change_altitude, + atcCallsignText, + selectedComStationName, + actionTag, + sprintf("%d", assignedAltitude) + ); + + voice = sprintf(atcMessageReply.change_altitude, + atcCallsignVoice, + selectedComStationName, + actionTag, + spellToPhonetic(sprintf("%d", assignedAltitude), spell_number_to_literal) + ); + + altitude_check_interval = flightLevelChangeSeconds(assignedAltitude); + + pilotResponseType = message_change_altitude; + } + else if(messageType == message_check_altitude) + { + multiplayMessageType = message_type_local; + + if(property_Aircraft_AltitudeFeet.getValue() > assignedAltitude) + actionTag = atcMessageAction.descend; + else + actionTag = atcMessageAction.climb; + + text = sprintf(atcMessageReply.check_altitude, + atcCallsignText, + selectedComStationName, + actionTag, + sprintf("%d", assignedAltitude) + ); + + voice = sprintf(atcMessageReply.check_altitude, + atcCallsignVoice, + selectedComStationName, + actionTag, + spellToPhonetic(sprintf("%d", assignedAltitude), spell_number_to_literal) + ); + + altitude_check_interval = flightLevelChangeSeconds(assignedAltitude); + + pilotResponseType = message_change_altitude; + } + else if(messageType == message_check_transponder) + { + multiplayMessageType = message_type_local; + + if(squawkIdent != squawk_ident_code) + { + if(squawkCode == "") + squawkCode = getSquawkCode(); + + extraText = sprintf("%s and ", squawkCode); + + extraVoice = sprintf("%s and ", spellToPhonetic(squawkCode, spell_number)); + + setSquawkIdentMode(squawk_ident_code); + } + else + { + extraText = ""; + extraVoice = ""; + + setSquawkIdentMode(squawk_ident_only); + } + + text = sprintf(atcMessageReply.check_transponder, + atcCallsignText, + selectedComStationName, + extraText + ); + + voice = sprintf(atcMessageReply.check_transponder, + atcCallsignVoice, + selectedComStationName, + extraVoice + ); + + pilotResponseType = message_check_transponder; + } + else if(messageType == message_abort_approach) + { + var msg = ""; + var rwy = ""; + + multiplayMessageType = message_type_important; + + if(aircraft_status == status_requested_approach or aircraft_status == status_requested_ils) + { + msg = atcMessageReply.abort_approach; + rwy = airportLandingRunway; + } + else if(aircraft_status == status_cleared_for_land_approach or aircraft_status == status_cleared_for_land_ils) + { + msg = atcMessageReply.abort_landing; + rwy = landingRunway; + } + else + return; + + text = sprintf(msg, + atcCallsignText, + selectedComStationName, + rwy + ); + + voice = sprintf(msg, + atcCallsignVoice, + selectedComStationName, + spellToPhonetic(rwy, spell_runway) + ); + + aircraftIsDeparting = 0; + approachStatus = approach_status_none; + approach_check_interval = approach_check_interval_initial; + + resetAircraftStatus(); + + setApproachButtons(); + + pilotResponseType = message_going_around; + } + + if(text != "" or voice != "") + atcMessage(text, voice); +} + +var atcAutoMessage = func() +{ + var text = ""; + var voice = ""; + var minCruiseAltidude = getMinCruiseAltitude(); + + if(isRadioServiceable() == 0) + return; + + multiplayMessageType = message_type_local; + + (atcCallsignText, atcCallsignVoice) = getCallSignForAtc(0); + + if(aircraft_status == status_ready_for_departure) + { + multiplayMessageType = message_type_important; + + text = sprintf(atcMessageReply.cleared_for_takeoff, + atcCallsignText, + selectedComStationName, + airportRunwayInUse, + getMeteoText(meteo_type_qnh, 0) + ); + + voice = sprintf(atcMessageReply.cleared_for_takeoff, + atcCallsignVoice, + selectedComStationName, + spellToPhonetic(airportRunwayInUse, spell_runway), + getMeteoText(meteo_type_qnh, 1) + ); + + aircraft_status = status_cleared_for_takeoff; + + cancelAtcPendingMessage(); + + setAtcAutoCallbackAfterSeconds(max_departure_secs); + + departure_extra_time = 0; + + approvedCtr = currentCtr; + altitude_check_counter = 0; + + aircraftIsDeparting = 1; + + setApproachButtons(); + + setCtrButtons(); + + pilotResponseType = message_cleared_take_off; + } + else if(aircraft_status == status_cleared_for_takeoff) + { + multiplayMessageType = message_type_important; + + if(departure_extra_time == 0 and alignedOnRunway == 1) + { + addSecondsToAtcAutoCallback(extra_departure_secs); + + departure_extra_time = 1; + } + else + { + text = sprintf(atcMessageReply.vacate_runway, + atcCallsignText, + selectedComStationName + ); + + voice = sprintf(atcMessageReply.vacate_runway, + atcCallsignVoice, + selectedComStationName + ); + + cancelAtcPendingMessage(); + + setAtcAutoCallbackAfterSeconds(max_take_off_secs); + } + + approvedCtr = currentCtr; + altitude_check_counter = 0; + aircraftIsDeparting = 1; + + setApproachButtons(); + + setCtrButtons(); + + pilotResponseType = message_roger; + } + else if(aircraft_status == status_took_off) + { + var airport = airportinfo(); + var extraText = ""; + var extraVoice = ""; + + multiplayMessageType = message_type_local; + + aircraftIsDeparting = 1; + + var cruiseAltitude = getFlightPlanAltitude(); + + if(cruiseAltitude == -1) + cruiseAltitude = normalizeAltitudeHeading(airport.elevation * M2FT, airport.runways[airportRunwayInUse].heading, minCruiseAltidude); + + var radio = getCtrRadio(currentCtr); + + if(radio.frequency != selectedComFrequency) + { + extraText = sprintf(atcMessageReply.contact_radio, + normalizeRadioStationName(radio.name), + sprintf("%.3f", radio.frequency) + ); + + extraVoice = sprintf(atcMessageReply.contact_radio, + normalizeRadioStationName(radio.name), + spellToPhonetic(sprintf("%.3f", radio.frequency), spell_number) + ); + } + + if(squawkingMode == "On") + { + if(checkTransponder(selectedTransponder) == 0) + { + if(squawkCode == "") + squawkCode = getSquawkCode(); + + if(extraText != "") + { + extraText ~= "."; + extraVoice ~= "."; + } + + extraText ~= " " ~ sprintf(atcMessageAction.check_transponder, squawkCode); + + extraVoice ~= " " ~ sprintf(atcMessageAction.check_transponder, spellToPhonetic(squawkCode, spell_number)); + + setSquawkIdentMode(squawk_ident_code); + } + } + + text = sprintf(atcMessageReply.leaving_airport, + atcCallsignText, + selectedComStationName, + getMeteoText(meteo_type_wind, 0), + sprintf("%d", cruiseAltitude), + extraText + ); + + voice = sprintf(atcMessageReply.leaving_airport, + atcCallsignVoice, + selectedComStationName, + getMeteoText(meteo_type_wind, 1), + spellToPhonetic(sprintf("%d", cruiseAltitude), spell_number_to_literal), + extraVoice + ); + + cancelAtcPendingMessage(); + + aircraft_status = status_flying; + approachStatus = approach_status_none; + approach_check_interval = approach_check_interval_initial; + + approvedCtr = currentCtr; + assignedAltitude = cruiseAltitude; + altitude_check_counter = 0; + altitude_check_interval = flightLevelChangeSeconds(assignedAltitude); + + setApproachButtons(); + + setCtrButtons(); + + pilotResponseType = message_leaving_airport; + } + else if(aircraft_status == status_cleared_for_land_approach or aircraft_status == status_cleared_for_land_ils) + { + var approachingRunway = ""; + var distance = 9999; + + multiplayMessageType = message_type_important; + + (approachingRunway, distance) = getApproachingRunway(currentAirport); + + airport = airportinfo(selectedComAirportId); + + (airportLandingRunway, airportRunwayInUseILS) = runwayInUse(airport, runway_landing); + + if(aircraft_status == status_cleared_for_land_ils) + landingRunway = airportRunwayInUseILS; + else + landingRunway = airportLandingRunway; + + if(approachingRunway != "" and approachingRunway != landingRunway) + { + text = sprintf(atcMessageReply.wrong_approach_runway, + atcCallsignText, + selectedComStationName, + landingRunway + ); + + voice = sprintf(atcMessageReply.wrong_approach_runway, + atcCallsignVoice, + selectedComStationName, + spellToPhonetic(landingRunway, spell_runway) + ); + + pilotResponseType = message_wilco; + } + else + pilotResponseType = message_none; + + aircraftIsDeparting = 0; + + cancelAtcPendingMessage(); + + setAtcAutoCallbackAfterSeconds(land_check_secs); + + setApproachButtons(); + } + else if(aircraft_status == status_landed) + { + airport = airportinfo(); + + multiplayMessageType = message_type_important; + + text = sprintf(atcMessageReply.welcome_to_airport, + atcCallsignText, + selectedComStationName, + airport.name + ); + + voice = sprintf(atcMessageReply.welcome_to_airport, + atcCallsignVoice, + selectedComStationName, + airport.name + ); + + cancelAtcPendingMessage(); + + aircraft_status = status_going_around; + + assignedAltitude = -1; + aircraftIsDeparting = 0; + approachStatus = approach_status_none; + approach_check_interval = approach_check_interval_initial; + squawkCode = ""; + squawkChange = 0; + + setSquawkIdentMode(squawk_ident_off); + + setApproachButtons(); + + pilotResponseType = message_roger; + } + + if(text != "" or voice != "") + atcMessage(text, voice); +} + +var pilotRequest = func(messageType) +{ + if(isRadioServiceable() == 0) + return; + + if(isSimulationPaused() == 1) + return; + + var text = ""; + var voice = ""; + + multiplayMessageType = message_type_local; + + if(messageType == message_say_again) + { + multiplayMessageType = message_type_local; + + text = sprintf(pilotMessageRequest.say_again, + selectedComStationName, + atcCallsignText + ); + + voice = sprintf(pilotMessageRequest.say_again, + selectedComStationName, + atcCallsignVoice + ); + } + else if(messageType == message_radio_check) + { + multiplayMessageType = message_type_local; + + text = sprintf(pilotMessageRequest.radio_check, + selectedComStationName, + atcCallsignText, + sprintf("%.3f", selectedComFrequency) + ); + + voice = sprintf(pilotMessageRequest.radio_check, + selectedComStationName, + atcCallsignVoice, + spellToPhonetic(sprintf("%.3f", selectedComFrequency), spell_number) + ); + } + else if(messageType == message_engine_start) + { + multiplayMessageType = message_type_local; + + text = sprintf(pilotMessageRequest.engine_start, + selectedComStationName, + atcCallsignText + ); + + voice = sprintf(pilotMessageRequest.engine_start, + selectedComStationName, + atcCallsignVoice + ); + } + else if(messageType == message_departure_information) + { + multiplayMessageType = message_type_local; + + text = sprintf(pilotMessageRequest.departure_information, + selectedComStationName, + atcCallsignText + ); + + voice = sprintf(pilotMessageRequest.departure_information, + selectedComStationName, + atcCallsignVoice + ); + } + else if(messageType == message_request_taxi) + { + multiplayMessageType = message_type_important; + + if(departureInformation != "") + { + extraText = sprintf(" with information %s", + departureInformation + ); + + extraVoice = extraText; + } + else + { + extraText = ""; + extraVoice = ""; + } + + text = sprintf(pilotMessageRequest.request_taxi, + selectedComStationName, + atcCallsignText, + extraText + ); + + voice = sprintf(pilotMessageRequest.request_taxi, + selectedComStationName, + atcCallsignVoice, + extraVoice + ); + } + else if(messageType == message_ready_for_departure) + { + multiplayMessageType = message_type_important; + + text = sprintf(pilotMessageRequest.ready_departure, + selectedComStationName, + atcCallsignText, + currentRunway + ); + + voice = sprintf(pilotMessageRequest.ready_departure, + selectedComStationName, + atcCallsignVoice, + spellToPhonetic(currentRunway, spell_runway) + ); + + if(squawkingMode == "On" and squawkCode == "") + squawkChange = 1; + } + else if(messageType == message_abort_departure) + { + multiplayMessageType = message_type_important; + + text = sprintf(pilotMessageRequest.abort_departure, + selectedComStationName, + atcCallsignText, + currentRunway + ); + + voice = sprintf(pilotMessageRequest.abort_departure, + selectedComStationName, + atcCallsignVoice, + spellToPhonetic(currentRunway, spell_runway) + ); + } + else if(messageType == message_request_approach) + { + multiplayMessageType = message_type_important; + + text = sprintf(pilotMessageRequest.request_approach, + selectedComStationName, + atcCallsignText + ); + + voice = sprintf(pilotMessageRequest.request_approach, + selectedComStationName, + atcCallsignVoice + ); + } + else if(messageType == message_request_ils) + { + multiplayMessageType = message_type_important; + + text = sprintf(pilotMessageRequest.request_ils, + selectedComStationName, + atcCallsignText, + "ILS" + ); + + voice = sprintf(pilotMessageRequest.request_ils, + selectedComStationName, + atcCallsignVoice, + "I L S" + ); + } + else if(messageType == message_airfield_in_sight) + { + multiplayMessageType = message_type_important; + + text = sprintf(pilotMessageRequest.airfield_in_sight, + selectedComStationName, + atcCallsignText + ); + + voice = sprintf(pilotMessageRequest.airfield_in_sight, + selectedComStationName, + atcCallsignVoice + ); + } + else if(messageType == message_ils_established) + { + multiplayMessageType = message_type_important; + + text = sprintf(pilotMessageRequest.ils_established, + selectedComStationName, + atcCallsignText, + "ILS", + airportRunwayInUseILS + ); + + voice = sprintf(pilotMessageRequest.ils_established, + selectedComStationName, + atcCallsignVoice, + "I L S", + spellToPhonetic(airportRunwayInUseILS, spell_runway) + ); + } + else if(messageType == message_request_ctr) + { + multiplayMessageType = message_type_local; + + text = sprintf(pilotMessageRequest.request_ctr, + selectedComStationName, + atcCallsignText, + "CTR" + ); + + voice = sprintf(pilotMessageRequest.request_ctr, + selectedComStationName, + atcCallsignVoice, + "C T R" + ); + } + else if(messageType == message_request_fl) + { + multiplayMessageType = message_type_important; + + text = sprintf(pilotMessageRequest.request_fl, + selectedComStationName, + atcCallsignText, + "FL", + getFlightLevelCode(requestedAltitude) + ); + + voice = sprintf(pilotMessageRequest.request_fl, + selectedComStationName, + atcCallsignVoice, + "Flight Level", + spellToPhonetic(getFlightLevelCode(requestedAltitude), spell_number) + ); + } + else if(messageType == message_abort_approach) + { + multiplayMessageType = message_type_important; + + if(aircraft_status == status_requested_approach) + { + text = sprintf(pilotMessageRequest.abort_approach, + selectedComStationName, + atcCallsignText, + airportLandingRunway + ); + + voice = sprintf(pilotMessageRequest.abort_approach, + selectedComStationName, + atcCallsignVoice, + spellToPhonetic(airportLandingRunway, spell_runway) + ); + } + else if(aircraft_status == status_requested_ils) + { + text = sprintf(pilotMessageRequest.abort_ils, + selectedComStationName, + atcCallsignText, + "ILS", + airportLandingRunway + ); + + voice = sprintf(pilotMessageRequest.abort_ils, + selectedComStationName, + atcCallsignVoice, + "I L S", + spellToPhonetic(airportLandingRunway, spell_runway) + ); + } + else if(aircraft_status == status_cleared_for_land_approach or aircraft_status == status_cleared_for_land_ils) + { + text = sprintf(pilotMessageRequest.abort_landing, + selectedComStationName, + atcCallsignText, + landingRunway + ); + + voice = sprintf(pilotMessageRequest.abort_landing, + selectedComStationName, + atcCallsignVoice, + spellToPhonetic(landingRunway, spell_runway) + ); + } + } + else + return; + + if(text != "" or voice != "") + { + cancelAtcPendingMessage(); + + var secs = 0; + + pilotMessageType = messageType; + + if(pilotRequestMode != "Disabled") + secs = int(size(text) / 12) + 1; + + if((pilotRequestMode == "Voice only" or pilotRequestMode == "Voice and text") and voice != "") + { + speak(voice, pilotVoice['text'], pilotVoice['type']); + + secs += 2; + } + + echoMultiplayerChat(text, multiplayMessageType); + + if((pilotRequestMode == "Text only" or pilotRequestMode == "Voice and text") and text != "") + { + var window = screen.window.new(atc_popup_x_position, atc_popup_y_position, 10, secs); + + window.bg = popup_window_bg_color; + window.fg = popup_window_fg_pilot_color; + window.align = atc_popup_align; + + window.write(text); + + addAtcLog(text); + } + + setPilotMessageSeconds(secs + pilot_message_pause_atc_seconds); + + autoATCMessageDelay(secs + pilot_message_pause_atc_seconds); + } +} + +var pilotResponse = func(messageType) +{ + var text = ""; + var voice = ""; + var extraText = ""; + var extraVoice = ""; + var initialReportLetter = "R"; + var radio = nil; + + if(initialized == 0) + initRgATC(); + + if(isRadioServiceable() == 0) + return; + + if(messageType == message_none or selectedComAirportId == "") + return; + + multiplayMessageType = message_type_local; + + (atcCallsignText, atcCallsignVoice) = getCallSignForAtc(0); + + if(messageType == message_roger) + { + multiplayMessageType = message_type_local; + + text = sprintf(pilotMessageResponse.roger, + selectedComStationName, + atcCallsignText + ); + + voice = sprintf(pilotMessageResponse.roger, + selectedComStationName, + atcCallsignVoice + ); + } + else if(messageType == message_wilco) + { + multiplayMessageType = message_type_local; + + text = sprintf(pilotMessageResponse.wilco, + selectedComStationName, + atcCallsignText + ); + + voice = sprintf(pilotMessageResponse.wilco, + selectedComStationName, + atcCallsignVoice + ); + } + else if(messageType == message_departure_information) + { + if(departureInformation == "") + return; + + multiplayMessageType = message_type_local; + + text = sprintf(pilotMessageResponse.departure_information, + selectedComStationName, + atcCallsignText, + departureInformation + ); + + voice = sprintf(pilotMessageResponse.departure_information, + selectedComStationName, + atcCallsignVoice, + departureInformation + ); + } + else if(messageType == message_engine_start) + { + multiplayMessageType = message_type_local; + + text = sprintf(pilotMessageResponse.engine_start, + selectedComStationName, + atcCallsignText, + airportRunwayInUse + ); + + voice = sprintf(pilotMessageResponse.engine_start, + selectedComStationName, + atcCallsignVoice, + spellToPhonetic(airportRunwayInUse, spell_runway) + ); + } + else if(messageType == message_ctr_approved) + { + multiplayMessageType = message_type_local; + + if(squawkingMode == "On") + { + if(squawkChange == 1) + { + extraText = sprintf(", Squawk %s and IDENT", squawkCode); + extraVoice = sprintf(", Squawk %s and ident", spellToPhonetic(squawkCode, spell_number)); + + setSquawkIdentMode(squawk_ident_code); + } + else + { + extraText = ", Squawk IDENT"; + extraVoice = ", Squawk ident"; + + setSquawkIdentMode(squawk_ident_only); + } + + squawkChange = 0; + } + else + { + extraText = ""; + extraVoice = ""; + } + + text = sprintf(pilotMessageResponse.approved_ctr, + selectedComStationName, + atcCallsignText, + "CTR", + extraText + ); + + voice = sprintf(pilotMessageResponse.approved_ctr, + selectedComStationName, + atcCallsignVoice, + "C T R", + extraVoice + ); + } + else if(messageType == message_request_taxi) + { + multiplayMessageType = message_type_important; + + if(squawkingMode == "On") + { + extraText = sprintf(", Squawk %s", squawkCode); + extraVoice = sprintf(", Squawk %s", spellToPhonetic(squawkCode, spell_number)); + + squawkChange = 0; + } + else + { + extraText = ""; + extraVoice = ""; + } + + text = sprintf(pilotMessageResponse.taxi, + selectedComStationName, + atcCallsignText, + airportRunwayInUse, + extraText + ); + + voice = sprintf(pilotMessageResponse.taxi, + selectedComStationName, + atcCallsignVoice, + spellToPhonetic(airportRunwayInUse, spell_runway), + extraVoice + ); + } + else if(messageType == message_wait_for_departure) + { + multiplayMessageType = message_type_important; + + if(nearRunway == 1) + { + extraText = atcMessageAction.lineup_and_wait; + extraVoice = atcMessageAction.lineup_and_wait; + } + else + { + extraText = ""; + extraVoice = ""; + } + + text = sprintf(pilotMessageResponse.wait_departure, + selectedComStationName, + atcCallsignText, + extraText, + airportRunwayInUse + ); + + voice = sprintf(pilotMessageResponse.wait_departure, + selectedComStationName, + atcCallsignVoice, + extraVoice, + spellToPhonetic(airportRunwayInUse, spell_runway) + ); + + if(squawkingMode == "On" and squawkChange == 1) + { + text ~= sprintf(". Squawk %s.", squawkCode); + + voice ~= sprintf(". Squawk %s.", spellToPhonetic(squawkCode, spell_number)); + + squawkChange = 0; + } + } + else if(messageType == message_cleared_take_off) + { + multiplayMessageType = message_type_important; + + text = sprintf(pilotMessageResponse.cleared_take_off, + selectedComStationName, + atcCallsignText, + airportRunwayInUse + ); + + voice = sprintf(pilotMessageResponse.cleared_take_off, + selectedComStationName, + atcCallsignVoice, + spellToPhonetic(airportRunwayInUse, spell_runway) + ); + } + else if(messageType == message_leaving_airport) + { + radio = getCtrRadio(currentCtr); + + multiplayMessageType = message_type_local; + + if(radio != nil and radio.frequency != selectedComFrequency) + { + extraText = sprintf(atcMessageReply.contact_radio, + normalizeRadioStationName(radio.name), + sprintf("%.3f", radio.frequency) + ); + + extraVoice = sprintf(atcMessageReply.contact_radio, + normalizeRadioStationName(radio.name), + spellToPhonetic(sprintf("%.3f", radio.frequency), spell_number) + ); + } + + if(squawkingMode == "On") + { + if(checkTransponder(selectedTransponder) == 0) + { + if(squawkCode == "") + squawkCode = getSquawkCode(); + + if(extraText != "") + { + extraText ~= "."; + extraVoice ~= "."; + } + + extraText ~= " " ~ sprintf(atcMessageAction.check_transponder, squawkCode); + + extraVoice ~= " " ~ sprintf(atcMessageAction.check_transponder, spellToPhonetic(squawkCode, spell_number)); + + setSquawkIdentMode(squawk_ident_code); + } + else + setSquawkIdentMode(squawk_ident_off); + } + + text = sprintf(pilotMessageResponse.leaving_airport, + selectedComStationName, + atcCallsignText, + sprintf("%d", assignedAltitude), + extraText + ); + + voice = sprintf(pilotMessageResponse.leaving_airport, + selectedComStationName, + atcCallsignVoice, + spellToPhonetic(sprintf("%d", assignedAltitude), spell_number_to_literal), + extraVoice + ); + + altitude_check_interval = flightLevelChangeSeconds(assignedAltitude); + } + else if(messageType == message_approved_approach) + { + multiplayMessageType = message_type_important; + + text = sprintf(pilotMessageResponse.approved_approach, + selectedComStationName, + atcCallsignText, + airportLandingRunway + ); + + voice = sprintf(pilotMessageResponse.approved_approach, + selectedComStationName, + atcCallsignVoice, + spellToPhonetic(airportLandingRunway, spell_runway) + ); + } + else if(messageType == message_approved_ils) + { + multiplayMessageType = message_type_important; + + text = sprintf(pilotMessageResponse.approved_ils, + selectedComStationName, + atcCallsignText, + "ILS", + airportLandingRunway + ); + + voice = sprintf(pilotMessageResponse.approved_ils, + selectedComStationName, + atcCallsignVoice, + "I L S", + spellToPhonetic(airportLandingRunway, spell_runway) + ); + } + else if(messageType == message_approach_route_instructions) + { + multiplayMessageType = message_type_local; + + text = sprintf(pilotMessageResponse.approach_route_instructions, + selectedComStationName, + atcCallsignText, + approachRouteTextInstructions + ); + + voice = sprintf(pilotMessageResponse.approach_route_instructions, + selectedComStationName, + atcCallsignVoice, + approachRouteVoiceInstructions + ); + } + else if(messageType == message_cleared_landing) + { + multiplayMessageType = message_type_important; + + text = sprintf(pilotMessageResponse.cleared_landing, + selectedComStationName, + atcCallsignText, + landingRunway + ); + + voice = sprintf(pilotMessageResponse.cleared_landing, + selectedComStationName, + atcCallsignVoice, + spellToPhonetic(landingRunway, spell_runway) + ); + } + else if(messageType == message_fl_approved) + { + multiplayMessageType = message_type_important; + + text = sprintf(pilotMessageResponse.approved_fl, + selectedComStationName, + atcCallsignText, + "FL", + getFlightLevelCode(requestedAltitude) + ); + + voice = sprintf(pilotMessageResponse.approved_fl, + selectedComStationName, + atcCallsignVoice, + "Flight Level", + spellToPhonetic(getFlightLevelCode(requestedAltitude), spell_number) + ); + } + else if(messageType == message_change_altitude) + { + var actionTag = ""; + + multiplayMessageType = message_type_important; + + if(property_Aircraft_AltitudeFeet.getValue() > assignedAltitude) + actionTag = atcMessageAction.descend; + else + actionTag = atcMessageAction.climb; + + text = sprintf(pilotMessageResponse.change_altitude, + selectedComStationName, + atcCallsignText, + actionTag, + sprintf("%d", assignedAltitude) + ); + + voice = sprintf(pilotMessageResponse.change_altitude, + selectedComStationName, + atcCallsignVoice, + actionTag, + spellToPhonetic(sprintf("%d", assignedAltitude), spell_number_to_literal) + ); + + altitude_check_interval = flightLevelChangeSeconds(assignedAltitude); + } + else if(messageType == message_check_transponder) + { + if(squawkIdent == squawk_ident_code) + { + extraText = sprintf("%s and ", squawkCode); + + extraVoice = sprintf("%s and ", spellToPhonetic(squawkCode, spell_number)); + } + else + { + extraText = ""; + extraVoice = ""; + } + + text = sprintf(pilotMessageResponse.check_transponder, + selectedComStationName, + atcCallsignText, + extraText + ); + + voice = sprintf(pilotMessageResponse.check_transponder, + selectedComStationName, + atcCallsignVoice, + extraVoice + ); + } + else if(messageType == message_going_around) + { + multiplayMessageType = message_type_important; + + text = sprintf(pilotMessageResponse.going_around, + selectedComStationName, + atcCallsignText + ); + + voice = sprintf(pilotMessageResponse.going_around, + selectedComStationName, + atcCallsignVoice + ); + } + else if(messageType == message_contact_radio) + { + multiplayMessageType = message_type_local; + + if(contactRadio != nil) + { + text = sprintf(pilotMessageResponse.contact_radio, + atcCallsignText, + selectedComStationName, + normalizeRadioStationName(contactRadio.name), + sprintf("%.3f", contactRadio.frequency) + ); + + voice = sprintf(pilotMessageResponse.contact_radio, + atcCallsignVoice, + selectedComStationName, + normalizeRadioStationName(contactRadio.name), + spellToPhonetic(sprintf("%.3f", contactRadio.frequency), spell_number) + ); + } + } + + pilotResponseType = message_none; + + pilot_response_wait_seconds = -1; + + if(text != "" or voice != "") + { + var secs = 0; + + if(pilotResponseMode != "Disabled") + secs = int(size(text) / 12) + 1; + + if((pilotResponseMode == "Voice only" or pilotResponseMode == "Voice and text") and voice != "") + { + speak(voice, pilotVoice['text'], pilotVoice['type']); + + secs += 2; + } + + if((pilotResponseMode == "Text only" or pilotResponseMode == "Voice and text") and text != "") + { + var window = screen.window.new(atc_popup_x_position, atc_popup_y_position, 10, secs); + + window.bg = popup_window_bg_color; + window.fg = popup_window_fg_pilot_color; + window.align = atc_popup_align; + + window.write(text); + + addAtcLog(text); + } + + autoATCMessageDelay(secs); + + echoMultiplayerChat(text, multiplayMessageType); + } +} + +var atcMessage = func(text, voice) +{ + var secs = int(size(voice) / 12) + 1; + + if((atcMessageMode == "Voice only" or atcMessageMode == "Voice and text") and voice != "") + { + if(stationVoice[selectedComFrequency] != nil) + speak(voice, stationVoice[selectedComFrequency]['text'], stationVoice[selectedComFrequency]['type']); + else + showPopup(atcMessageAction.inconsistent_radio_data); + } + + if((atcMessageMode == "Text only" or atcMessageMode == "Voice and text") and text != "") + { + var window = screen.window.new(atc_popup_x_position, atc_popup_y_position, 10, secs); + + window.bg = popup_window_bg_color; + window.fg = popup_window_fg_atc_color; + window.align = atc_popup_align; + + window.write(text); + + addAtcLog(text); + } + + autoATCMessageDelay(secs); + + echoMultiplayerChat(text, multiplayMessageType); + + lastAtcText = text; + lastAtcVoice = voice; + + showRepeatATCMessageButton(1); + + pilot_response_counter = 0; + + if(pilotResponseType != message_none) + pilot_response_wait_seconds = secs + pilot_response_pause_atc_seconds; + else + pilot_response_wait_seconds = -1; +} + +var echoMultiplayerChat = func(text, type) +{ + if(multiplayerChatEcho == "Off") + return; + + var airport = airportinfo(selectedComAirportId); + + var message = "[" ~ RGAtcName; + + if(airport != nil) + message ~= "@" ~ airport.id; + + message ~= "] "; + + message ~= text; + + if((multiplayerChatEcho == "Important messages only" and type == message_type_important) or (multiplayerChatEcho == "All messages")) + property_Multiplay_Chat.setValue(message); +} + +var assistedAtcApproach = func() +{ + var courseToPoint = nil; + var distanceToPoint = nil; + var degreeDiff = 0; + var turnToDiff = ""; + var requiredSpeed = 0; + var actionTag = ""; + var aircraftHeading = property_Aircraft_HeadingDeg.getValue(); + var point = nil; + + if(approachStatus == approach_status_none or approachStatus == approach_status_landing) + return; + + if(approachStatus == approach_status_to_pattern) + { + (courseToPoint, distanceToPoint) = courseAndDistance(patternPoint); + + requiredSpeed = pattern_speed; + } + else + { + (courseToPoint, distanceToPoint) = courseAndDistance(approachPoint); + + requiredSpeed = approach_speed; + } + + if(distanceToPoint < abs(approach_point_distance / 2)) + approach_check_interval = approach_check_interval_near_point; + + if(distanceToPoint < approach_turn_distance) + { + if(approachStatus == approach_status_to_pattern) + approachStatus = approach_status_to_approach; + else + approachStatus = approach_status_to_final; + + approach_check_interval = approach_check_interval_final; + } + + if(approachStatus == approach_status_to_pattern or approachStatus == approach_status_to_approach) + { + approachRouteTextInstructions = ""; + approachRouteVoiceInstructions = ""; + + if(courseWithinDegrees(aircraftHeading, courseToPoint, 10) == 0) + { + (degreeDiff, turnToDiff) = degreesDifference(aircraftHeading, courseToPoint); + + approachRouteTextInstructions = sprintf(atcMessageReply.turn_to_heading, + turnToDiff, + sprintf("%d", courseToPoint) + ); + + approachRouteVoiceInstructions = sprintf(atcMessageReply.turn_to_heading, + turnToDiff, + spellToPhonetic(sprintf("%d", courseToPoint), spell_number) + ); + } + + if(distanceToPoint < abs(approach_point_distance / 2) and abs(property_Aircraft_AltitudeFeet.getValue() - approachAltitude) > (assigned_altitude_delta / 2)) + { + if(approachRouteTextInstructions != "") + { + approachRouteTextInstructions ~= ". "; + approachRouteVoiceInstructions ~= ". "; + } + + if(property_Aircraft_AltitudeFeet.getValue() > approachAltitude) + actionTag = atcMessageAction.descend; + else + actionTag = atcMessageAction.climb; + + approachRouteTextInstructions ~= sprintf("%s and maintain %s", + actionTag, + sprintf("%d", approachAltitude) + ); + + approachRouteVoiceInstructions ~= sprintf("%s and maintain %s", + actionTag, + spellToPhonetic(sprintf("%d", approachAltitude), + spell_number_to_literal) + ); + } + + if(distanceToPoint < abs(approach_point_distance / 2) and abs(property_Aircraft_AirSpeedKnots.getValue() - requiredSpeed) > approach_speed_delta) + { + if(approachRouteTextInstructions != "") + { + approachRouteTextInstructions ~= ". "; + approachRouteVoiceInstructions ~= ". "; + } + + if(property_Aircraft_AirSpeedKnots.getValue() > requiredSpeed) + actionTag = atcMessageAction.reduce; + else + actionTag = atcMessageAction.increase; + + approachRouteTextInstructions ~= sprintf("%s speed %s knots", + actionTag, + sprintf("%d", requiredSpeed) + ); + + approachRouteVoiceInstructions ~= sprintf("%s speed %s knots", + actionTag, + spellToPhonetic(sprintf("%d", requiredSpeed), + spell_number_to_literal) + ); + } + + if(approachRouteTextInstructions != "") + atcReplyToRequest(message_approach_route_instructions); + } + else if(approachStatus == approach_status_to_final) + { + var initialReportLetter = "R"; + var contactMsgText = ""; + var contactMsgVoice = ""; + var towerContactText = ""; + var towerContactVoice = ""; + + airport = airportinfo(selectedComAirportId); + + runwayHeading = airport.runways[airportLandingRunway].heading; + + (degreeDiff, turnToDiff) = degreesDifference(aircraftHeading, runwayHeading); + + approachRouteTextInstructions = sprintf(atcMessageReply.turn_to_final, + turnToDiff, + sprintf("%d", runwayHeading), + airportLandingRunway + ); + + approachRouteVoiceInstructions = sprintf(atcMessageReply.turn_to_final, + turnToDiff, + spellToPhonetic(sprintf("%d", runwayHeading), spell_number), + spellToPhonetic(airportLandingRunway, spell_runway) + ); + + if(abs(property_Aircraft_AirSpeedKnots.getValue() - final_speed) > approach_speed_delta) + { + if(approachRouteTextInstructions != "") + { + approachRouteTextInstructions ~= ". "; + approachRouteVoiceInstructions ~= ". "; + } + + if(property_Aircraft_AirSpeedKnots.getValue() > final_speed) + actionTag = atcMessageAction.reduce; + else + actionTag = atcMessageAction.increase; + + approachRouteTextInstructions ~= sprintf("%s speed %s knots", + actionTag, + sprintf("%d", final_speed) + ); + + approachRouteVoiceInstructions ~= sprintf("%s speed %s knots", + actionTag, + spellToPhonetic(sprintf("%d", final_speed), spell_number_to_literal) + ); + } + + if(isRadioFrequencyOfType(selectedComFrequency, radio_station_type_tower) == 0) + { + towerRadio = getRadio(radio_station_type_tower, radio_type_any); + + if(towerRadio == nil) + { + showPopup(RGAtcName ~ ": " ~ atcMessageAction.tower_not_reachable ~ "."); + + return; + } + + if(selectedComFrequency != towerRadio.frequency) + { + towerContactText = sprintf(atcMessageReply.contact_radio, + normalizeRadioStationName(towerRadio.name), + sprintf("%.3f", towerRadio.frequency) + ); + + towerContactText ~= " and "; + + towerContactVoice = sprintf(atcMessageReply.contact_radio, + normalizeRadioStationName(towerRadio.name), + spellToPhonetic(sprintf("%.3f", towerRadio.frequency), spell_number) + ); + + towerContactVoice ~= " and "; + + initialReportLetter = "r"; + } + } + + if(aircraft_status == status_requested_approach) + { + contactMsgText = sprintf(atcMessageReply.report_airfield_in_sight, + initialReportLetter + ); + + contactMsgText = towerContactText ~ contactMsgText; + + contactMsgVoice = sprintf(atcMessageReply.report_airfield_in_sight, + initialReportLetter + ); + + contactMsgVoice = towerContactVoice ~ contactMsgVoice; + } + else + { + contactMsgText = sprintf(atcMessageReply.report_established_ils, + initialReportLetter, + "ILS", + airportLandingRunway + ); + + contactMsgText = towerContactText ~ contactMsgText; + + contactMsgVoice = sprintf(atcMessageReply.report_established_ils, + initialReportLetter, + "I L S", + spellToPhonetic(airportLandingRunway, spell_runway) + ); + + contactMsgVoice = towerContactVoice ~ contactMsgVoice; + } + + approachRouteTextInstructions ~= "\n" ~ contactMsgText; + approachRouteVoiceInstructions ~= "\n" ~ contactMsgVoice; + + atcReplyToRequest(message_approach_route_instructions); + + approachStatus = approach_status_landing; + } +} + +var getCallSign = func(mode) +{ + var cs = property_Setting_Callsign.getValue(); + + if(mode != "Complete" and size(cs) > 3) + { + if(mode == "Last three letters") + cs = substr(cs, size(cs) - 3); + else + cs = left(cs, 1) ~ substr(cs, size(cs) - 2); + } + + return cs; +} + +var getCallSignForAtc = func(initial) +{ + var cs = property_Setting_Callsign.getValue(); + var atcText = ""; + var atcVoice = ""; + + if(includeManufacturer == "Yes" and aircraftManufacturer != "") + { + atcText ~= aircraftManufacturer ~ " "; + atcVoice ~= aircraftManufacturer ~ " "; + } + + if(initial == 0) + cs = getCallSign(callsignMode); + + atcText ~= cs; + atcVoice ~= spellToPhonetic(cs, spell_text); + + return [atcText, atcVoice]; +} + +var checkRadioIsType = func(radioType) +{ + if(selectedComStationType == radioType) + return 1; + + var requestedRadio = nil; + var towerRadio = nil; + var i = 0; + var check = 0; + var radio = nil; + + for(i = 0; i < size(availableRadio); i += 1) + { + radio = availableRadio[i]; + + if(radio.type == radioType and requestedRadio == nil) + requestedRadio = radio; + + if(radio.type == radio_station_type_tower and towerRadio == nil) + towerRadio = radio; + } + + if(requestedRadio != nil) + radio = requestedRadio; + else if(towerRadio != nil) + radio = towerRadio; + else + radio = nil; + + if(radio != nil) + { + if(selectedComFrequency == radio.frequency) + return 1; + + if(radio == towerRadio and selectedComStationType == radio_station_type_tower) + return 1; + + var text = sprintf(atcMessageReply.wrong_radio, + atcCallsignText, + selectedComStationName, + normalizeRadioStationName(radio.name), + sprintf("%.3f", radio.frequency) + ); + + var voice = sprintf(atcMessageReply.wrong_radio, + atcCallsignVoice, + selectedComStationName, + normalizeRadioStationName(radio.name), + spellToPhonetic(sprintf("%.3f", radio.frequency), spell_number) + ); + + pilotResponseType = message_contact_radio; + contactRadio = radio; + + atcMessage(text, voice); + + check = 0; + } + else + check = 1; + + return check; +} + +var getAvailableRadios = func() +{ + availableRadio = {}; + + if(selectedComStationType != nil and selectedComStationType != radio_station_type_unknown and selectedComAirportId != "") + airport = airportinfo(selectedComAirportId); + else if(currentAirport != nil) + airport = currentAirport; + else + return; + + if(size(airport.comms()) == 0) + return; + + var i = 0; + var radioType = radio_station_type_unknown; + + foreach(var radio; airport.comms()) + { + radioType = getRadioType(radio.ident); + + radioData = {name:getRadioFullName(airport.id, radio.ident), + airport:airport.name, + location:split(" ", airport.name)[0], + ident:radio.ident, + frequency:radio.frequency, + type:radioType + }; + + availableRadio[i] = radioData; + + i += 1; + } +} + +var getRadio = func(radioType, type) +{ + var requestedRadio = nil; + var i = 0; + var radio = nil; + var nradio = size(availableRadio); + + if(nradio > 0) + { + for(i = 0; i < nradio; i += 1) + { + radio = availableRadio[i]; + + if(radio.type == radioType and requestedRadio == nil) + requestedRadio = radio; + } + + if(requestedRadio == nil and type == radio_type_any) + requestedRadio = availableRadio[0]; + } + + return requestedRadio; +} + +var getRadioType = func(radioIdent) +{ + if(radioIdent == nil) + return radio_station_type_unknown; + + var radioType = radio_station_type_unknown; + var name = string.lc(radioIdent); + + if(find("TWR", radioIdent) != -1 or find("tower", name) != -1) + radioType = radio_station_type_tower; + else if(find("APP", radioIdent) != -1 or find("approach", name) != -1) + radioType = radio_station_type_approach; + else if(find("GND", radioIdent) != -1 or find("ground", name) != -1 or find("grd", name) != -1) + radioType = radio_station_type_ground; + else if(find("ARR", radioIdent) != -1 or find("arrival", name) != -1 or find("director", name) != -1) + radioType = radio_station_type_approach; + else if(find("DEP", radioIdent) != -1 or find("departure", name) != -1) + radioType = radio_station_type_departure; + else if(find("DEL", radioIdent) != -1 or find("delivery", name) != -1 or find("clnc", name) != -1) + radioType = radio_station_type_clearance; + else if(find("apron", name) != -1 or find("APR", radioIdent) != -1) + radioType = radio_station_type_approach; + else if(find("traffic", name) != -1) + radioType = radio_station_type_approach; + else if(find("ATIS", radioIdent) != -1) + radioType = radio_station_type_atis; + else if(find("AFIS", radioIdent) != -1 or find("SERVICE", radioIdent) != -1) + radioType = radio_station_type_atis; + else if(find("CTAF", radioIdent) != -1) + radioType = radio_station_type_ground; + else if(find("CON", radioIdent) != -1) + radioType = radio_station_type_approach; + else if(find("radio", name) != -1 or find("rdo", name) != -1) + radioType = radio_station_type_tower; + else if(find("info", name) != -1 or find("ATC", radioIdent) != -1) + radioType = radio_station_type_tower; + else if(find("unicom", name) != -1) + radioType = radio_station_type_tower; + else if(find("centre", name) != -1 or find("cntr", name) != -1 or find("ctr", name) != -1) + radioType = radio_station_type_tower; + else if(find("MF", radioIdent) != -1 or find("MULT", radioIdent) != -1) + radioType = radio_station_type_tower; + else if(find("FSS", radioIdent) != -1 or find("FIS", radioIdent) != -1 or find("FS", radioIdent) != -1) + radioType = radio_station_type_tower; + else if(find("start", name) != -1 or find("taxi", name) != -1) + radioType = radio_station_type_ground; + else + radioType = radio_station_type_tower; + + return radioType; +} + +var getRadioFullName = func(airportID, radioName) +{ + if(airportID == nil or radioName == nil) + return ""; + + if(airportID == "" or radioName == "") + return ""; + + var airport = airportinfo(airportID); + var radioFullName = ""; + + if(airport != nil) + { + var airportCity = split(" ", airport.name)[0]; + + if(string.lc(airportCity) != string.lc(split(" ", radioName)[0])) + radioFullName = airportCity ~ " "; + + radioFullName ~= radioName; + } + else + radioFullName = ""; + + return radioFullName; +} + +var getAirportRadio = func(airport, radioType) +{ + var requestedRadio = nil; + var i = 0; + var radio = nil; + + if(airport == nil) + return nil; + + var nradio = size(airport.comms()); + + if(nradio > 0) + { + foreach(radio; airport.comms()) + { + if(getRadioType(radio.ident) == radioType and requestedRadio == nil) + requestedRadio = radio; + } + + if(requestedRadio == nil) + { + foreach(radio; airport.comms()) + { + if(getRadioType(radio.ident) == radio_station_type_tower and requestedRadio == nil) + requestedRadio = radio; + } + } + + if(requestedRadio == nil) + requestedRadio = airport.comms()[0]; + } + + if(requestedRadio != nil) + { + requestedRadio.name = getRadioFullName(airport.id, requestedRadio.ident); + requestedRadio.airport = airport.name; + requestedRadio.location = split(" ", airport.name)[0]; + } + + return requestedRadio; +} + +var isRadioFrequencyOfType = func(frequency, radioType) +{ + var result = 0; + var i = 0; + var radio = nil; + var nradio = size(availableRadio); + + if(nradio > 0) + { + for(i = 0; i < nradio and result == 0; i += 1) + { + radio = availableRadio[i]; + + if(radio.type == radioType and radio.frequency == frequency) + result = 1; + } + } + + return result; +} + +var getRadioVolume = func(volumeProperty, volumeSelectedProperty) +{ + var commVolume = 0; + + if(volumeProperty != nil) + commVolume = volumeProperty.getValue(); + + if(commVolume == 0 and volumeSelectedProperty != nil) + commVolume = volumeSelectedProperty.getValue(); + + return commVolume; +} + +var getRadioFrequency = func(frequency, realFrequency) +{ + var commFrequency = 0; + + if(realFrequency != nil) + commFrequency = realFrequency.getValue(); + + if(commFrequency == 0 and frequency != nil) + commFrequency = frequency.getValue(); + + return commFrequency; +} + +var isRadioServiceable = func() +{ + var msg = ""; + + if(selectedComServiceableProperty == nil) + msg = atcMessageAction.bad_radio_data; + else if(selectedComServiceable == 0 or selectedComPowerStatus == 0 or selectedComOperable == 0) + msg = atcMessageAction.turn_radio_on; + else if(selectedComVolume < 0.1) + { + if(selectedComRadio != "") + msg = selectedComRadio ~ ": "; + else + msg = ""; + + msg ~= atcMessageAction.radio_volume_up; + } + else if(radioSignalQuality() == 0) + { + if(selectedComRadio != "") + msg = selectedComRadio ~ ": "; + else + msg = ""; + + msg ~= atcMessageAction.no_radio_tuned; + } + + if(msg != "") + { + showPopup(RGAtcName ~ ": " ~ msg); + + return 0; + } + + return 1; +} + +var isRadioTunedToApprovedCtrRadio = func() +{ + var radio = nil; + var isTuned = 0; + + if(approvedCtr == nil) + return 0; + + radio = getCtrRadio(approvedCtr); + + if(radio.frequency == selectedComFrequency) + isTuned = 1; + + return isTuned; +} + +var isRealMeteoEnabled = func() +{ + return property_RealWeather.getValue(); +} + +var getMeteoText = func(meteoType, voice) +{ + var meteo = ""; + var windFromDegrees = 0; + var windSpeed = 0; + var temperature = 0; + var dewpoint = 0; + var visibility = 0; + var rain = 0; + var snow = 0; + var clouds = ""; + var cloudsElevation = 0; + + if(isRealMeteoEnabled() == 1) + { + windFromDegrees = int(property_Weather_Metar_WindDirectionDeg.getValue()); + windSpeed = int(property_Weather_Metar_WindSpeedKnots.getValue()); + temperature = int(property_Weather_Metar_Temperature.getValue()); + dewpoint = int(property_Weather_Metar_Dewpoint.getValue()); + visibility = int(property_Weather_Metar_Visibility.getValue() / 1000); + + if(property_Weather_Metar_Rain != nil) + rain = property_Weather_Metar_Rain.getValue(); + else + rain = 0; + + if(property_Weather_Metar_Snow != nil) + snow = property_Weather_Metar_Snow.getValue(); + else + snow = 0; + + if(property_Weather_Metar_CloudsCoverage != nil) + clouds = property_Weather_Metar_CloudsCoverage.getValue(); + else + clouds = "clear"; + + if(property_Weather_Metar_CloudsElevationFeet != nil) + cloudsElevation = property_Weather_Metar_CloudsElevationFeet.getValue(); + else + cloudsElevation = 0; + } + else + { + windFromDegrees = int(property_Weather_WindDirectionDeg.getValue()); + windSpeed = int(property_Weather_WindSpeedKnots.getValue()); + temperature = int(property_Weather_Temperature.getValue()); + dewpoint = int(property_Weather_Dewpoint.getValue()); + visibility = int(property_Weather_Visibility.getValue() / 1000); + + if(property_Weather_Rain != nil) + rain = property_Weather_Rain.getValue(); + else + rain = 0; + + if(property_Weather_Snow != nil) + snow = property_Weather_Snow.getValue(); + else + snow = 0; + + if(property_Weather_CloudsCoverage != nil) + clouds = property_Weather_CloudsCoverage.getValue(); + else + clouds = "clear"; + + if(property_Weather_CloudsElevationFeet != nil) + cloudsElevation = property_Weather_CloudsElevationFeet.getValue(); + else + cloudsElevation = 0; + } + + (qnhValue, qnhLiteralValue) = getQNH(); + + if(windSpeed > 0) + { + if(voice == 0) + { + meteo = sprintf(meteoMessage.wind_report, + sprintf("%d", windFromDegrees), + sprintf("%d", windSpeed) + ); + } + else + { + meteo = sprintf(meteoMessage.wind_report, + spellToPhonetic(sprintf("%d", windFromDegrees), spell_number), + spellToPhonetic(sprintf("%d", windSpeed), spell_number) + ); + } + } + else + meteo = meteoMessage.wind_calm; + + if(meteoType == meteo_type_full) + { + meteo ~= ", "; + + if(voice == 0) + { + meteo ~= sprintf(meteoMessage.full, + "QNH", + qnhValue, + sprintf("%d", temperature), + sprintf("%d", dewpoint), + sprintf("%d", visibility) + ); + } + else + { + meteo ~= sprintf(meteoMessage.full, + "Q N H", + qnhLiteralValue, + spellToPhonetic(sprintf("%d", temperature), spell_number), + spellToPhonetic(sprintf("%d", dewpoint), spell_number), + spellToPhonetic(sprintf("%d", visibility), spell_number) + ); + } + + if(clouds != "clear") + { + meteo ~= ", "; + + if(voice == 0) + { + meteo ~= sprintf(meteoMessage.cloud_report, + clouds, + sprintf("%d", cloudsElevation) + ); + } + else + { + meteo ~= sprintf(meteoMessage.cloud_report, + clouds, + spellToPhonetic(sprintf("%d", cloudsElevation), spell_number_to_literal) + ); + } + } + else + meteo ~= ", " ~ meteoMessage.sky_clear; + + if(rain > 0) + { + var rainTag = ""; + + if(rain < 0.3) + rainTag = meteoMessage.light; + else if(rain < 0.6) + rainTag = meteoMessage.moderate; + else + rainTag = meteoMessage.heavy; + + meteo ~= ", "; + + meteo ~= sprintf(meteoMessage.rain_report, + rainTag + ); + } + + if(snow > 0) + { + var snowTag = ""; + + if(snow < 0.3) + snowTag = meteoMessage.light; + else if(snow < 0.6) + snowTag = meteoMessage.moderate; + else + snowTag = meteoMessage.heavy; + + meteo ~= ", "; + + meteo ~= sprintf(meteoMessage.snow_report, + snowTag + ); + + if(isRealMeteoEnabled() == 1 and property_Weather_Metar_SnowCover != nil) + { + if(property_Weather_Metar_SnowCover.getValue() > 0) + meteo ~= " " ~ meteoMessage.cover; + } + } + } + else if(meteoType == meteo_type_qnh) + { + meteo ~= ", "; + + if(voice == 0) + { + meteo ~= sprintf(meteoMessage.qnh_report, + "QNH", + qnhValue + ); + } + else + { + meteo ~= sprintf(meteoMessage.qnh_report, + "Q N H", + qnhLiteralValue + ); + } + } + + return meteo; +} + +var radioSignalQuality = func() +{ + var signal = 0; + + if(selectedComSignalQuality == nil) + return 0; + + if(selectedComSignalQuality > 0) + { + if(selectedComSignalQuality < 0.05) + signal = 0; + else if(selectedComSignalQuality < 0.2) + signal = 1; + else if(selectedComSignalQuality < 0.3) + signal = 2; + else if(selectedComSignalQuality < 0.4) + signal = 3; + else if(selectedComSignalQuality < 0.5) + signal = 4; + else + signal = 5; + } + else + signal = 0; + + return signal; +} + +var minPathDistance = func(pos, pathPos, pathHeading, pathLength, minDistance) +{ + var minDist = 9999; + var course = 0; + var dist = 0; + var step = minDistance / 4; + var cDist = 0; + var cPos = pathPos; + + for(cDist = 0; cDist < pathLength; cDist += step) + { + cPos.apply_course_distance(pathHeading, step); + + (course, dist) = courseAndDistance(pos, cPos); + + if(dist < minDist) + minDist = dist; + } + + return minDist * NM2M; +} + +var normalizeAltitudeHeading = func(altitude, heading, minAltitude) +{ + var normalizedAltitude = altitude; + + if(normalizedAltitude < minAltitude) + normalizedAltitude = minAltitude; + + var normalizedAltitude = int(normalizedAltitude / 1000) * 1000; + + if(heading < 180) + { + if(math.mod(int(normalizedAltitude / 1000), 2) == 0) + normalizedAltitude += 1000; + } + else + { + if(math.mod(int(normalizedAltitude / 1000), 2) == 1) + normalizedAltitude += 1000; + } + + normalizedAltitude += 500; + + return normalizedAltitude; +} + +var getFlightPlanAltitude = func() +{ + var altitude = -1; + var distance = 9999; + var minCruiseAltidude = getMinCruiseAltitude(); + + if(!property_Autopilot_RouteManagerActive.getValue()) + return -1; + + var wpnum = property_Autopilot_RouteManagerRouteNum.getValue() - 1; + + for(var i = property_Autopilot_RouteManagerCurrentWayPoint.getValue(); i < wpnum; i += 1) + { + var prop = sprintf("/autopilot/route-manager/route/wp[%d]/", i); + + var wpalt = getprop(prop ~ "altitude-ft"); + + if(wpalt > 0) + { + var (wpcourse, wpdist) = courseAndDistance(geo.Coord.new().set_latlon(getprop(prop ~ "latitude-deg"), getprop(prop ~ "longitude-deg"))); + + if(wpdist < distance and wpdist < flight_plan_min_distance) + { + distance = wpdist; + + altitude = wpalt; + } + } + } + + if(altitude == -1) + { + altitude = property_Autopilot_RouteManagerCruiseAltitudeFeet.getValue(); + + if(altitude < minCruiseAltidude) + altitude = normalizeAltitudeHeading(property_Aircraft_AltitudeFeet.getValue(), heading, minCruiseAltidude); + } + + return math.round(altitude, 100); +} + +var getFlightLevelCode = func(level) +{ + var len = 0; + + if(level >= 10000) + len = 3; + else if(level >= 1000) + len = 2; + else + len = 1; + + return substr(sprintf("%d", level), 0, len); +} + +var flightLevelChangeSeconds = func(finalAltitude) +{ + var altitudeChange = abs(property_Aircraft_AltitudeFeet.getValue() - finalAltitude); + + return int((altitudeChange / flight_level_rate) * 60); +} + +var getMinCruiseAltitude = func() +{ + var minCruiseAltidude = min_cruise_altitude; + var safeAltitude = property_Aircraft_AltitudeFeet.getValue() - property_Aircraft_AltitudeAglFeet.getValue() + min_safe_altitude; + + if(minCruiseAltidude < safeAltitude) + minCruiseAltidude = safeAltitude; + + return minCruiseAltidude; +} + +var courseWithinDegrees = func(course, degrees, range) +{ + var inRange = 0; + var degreeDiff = 360; + var turnToDiff = ""; + + (degreeDiff, turnToDiff) = degreesDifference(course, degrees); + + if(degreeDiff <= (range / 2)) + inRange = 1; + + return inRange; +} + +var degreesDifference = func(fromDegrees, toDegrees) +{ + var degreeDiff = 0; + var turnToDiff = ""; + + degreeDiff = int(math.mod(((toDegrees - fromDegrees) + 180), 360) - 180); + + if(degreeDiff == 0) + turnToDiff = ""; + else if(degreeDiff < 0) + turnToDiff = "left"; + else + turnToDiff = "right"; + + return [abs(degreeDiff), turnToDiff]; +} + +var resetAircraftStatus = func() +{ + if(property_Aircraft_AltitudeAglFeet.getValue() > min_ground_altitude) + aircraft_status = status_flying; + else + aircraft_status = status_going_around; +} + +var spellToPhonetic = func(text, spellMode) +{ + var phoneticText = ""; + var length = size(text); + + if(spellMode == spell_number_to_literal) + phoneticText = numberToLiteral(int(text)); + else + { + for(var i = 0; i < length; i += 1) + { + var character = chr(text[i]); + + if(string.isalpha(text[i])) + { + character = chr(string.toupper(text[i])); + + if(spellMode == spell_text or spellMode == spell_number) + phoneticText ~= phoneticLetter[character] ~ " "; + else if(spellMode == spell_runway) + { + var rwTag = ""; + + if(character == "L") + rwTag = "left"; + else if(character == "R") + rwTag = "right"; + else if(character == "C") + rwTag = "center"; + else + rwTag = character; + + phoneticText ~= rwTag ~ " "; + } + } + else if(string.isdigit(text[i])) + phoneticText ~= phoneticDigit[text[i] - 48] ~ " "; + else if(character == ".") + phoneticText ~= "decimal"; + else if(character == "-") + { + if(spellMode == spell_number) + phoneticText ~= "minus"; + } + else if(character == "/") + { + # ignore slash + } + else if(character == "\n") + { + phoneticText ~= " "; + } + else + phoneticText ~= character; + + if(i < length - 1) + phoneticText ~= " "; + } + } + + return phoneticText; +} + +var numberToLiteral = func(number) +{ + var text = ""; + var digit = 0; + var tens = 0; + var units = 0; + + digit = int(number / 1000); + + if(digit > 0) + { + if(digit < 20) + text ~= phoneticNumber[digit]; + else + { + tens = int(digit / 10); + + if(tens > 0) + text ~= phoneticTen[tens] ~ " "; + + units = digit - (tens * 10); + + if(units < 10 and units > 0) + text ~= phoneticNumber[units]; + } + + text ~= " Thousand "; + } + + number -= digit * 1000; + + digit = int(number / 100); + + if(digit > 0) + text ~= phoneticNumber[digit] ~ " Hundred "; + + number -= digit * 100; + + if(number > 0) + { + if(size(text) > 0) + text ~= "and "; + + if(number < 20) + text ~= phoneticNumber[number]; + else + { + digit = int(number / 10); + + if(digit > 0) + text ~= phoneticTen[digit] ~ " "; + + number -= digit * 10; + + if(number < 10 and number > 0) + text ~= phoneticNumber[number]; + } + } + + return text; +} + +var getMessageText = func(messageType) +{ + var message = ""; + + if(messageType == message_radio_check) + message = atcMessageRequest.radio_check; + else if(messageType == message_engine_start) + message = atcMessageRequest.engine_start; + else if(messageType == message_departure_information) + message = atcMessageRequest.departure_information; + else if(messageType == message_request_taxi) + message = atcMessageRequest.request_taxi; + else if(messageType == message_ready_for_departure) + message = atcMessageRequest.ready_departure; + else if(messageType == message_abort_departure) + message = atcMessageRequest.abort_departure; + else if(messageType == message_request_approach) + message = atcMessageRequest.request_approach; + else if(messageType == message_request_ils) + message = atcMessageRequest.request_ils; + else if(messageType == message_airfield_in_sight) + message = atcMessageRequest.airfield_in_sight; + else if(messageType == message_ils_established) + message = atcMessageRequest.ils_established; + + return message; +} + +var normalizeRadioStationName = func(text) +{ + if(text == nil or text == "") + return ""; + + var word = split(" ", text); + var wlen = size(word); + var wspace = wlen - 1; + var stationName = ""; + + for(var i = 0; i < wlen; i += 1) + { + var w = string.lc(word[i]); + + if(w == "twr") + w = "tower"; + else if(w == "app") + w = "approach"; + else if(w == "apron") + w = "approach On"; + else if(w == "gnd") + w = "ground"; + else if(w == "gnd/apron") + w = "ground"; + else if(w == "arr") + w = "arrival"; + else if(w == "dep") + w = "departure"; + else if(w == "del") + w = "delivery"; + else if(w == "clnc") + w = "clearance"; + else if(w == "ctaf") + w = "CTAF"; + else if(w == "awos") + w = "AWOS"; + else if(w == "afis") + w = "AFIS"; + else if(w == "atis") + w = "ATIS"; + else if(w == "unicom") + w = "Universal communications"; + + stationName ~= string.uc(left(w, 1)) ~ substr(w, 1) ; + + if(i < wspace) + stationName ~= " "; + } + + return stationName; +} + +var setPilotMessageSeconds = func(delay) +{ + pilot_message_wait_seconds = delay; + + pilot_message_counter = 0; +} + +var cancelPilotPendingMessage = func() +{ + pilot_message_wait_seconds = -1; + pilot_message_counter = 0; + + pilot_response_wait_seconds = -1; + pilot_response_counter = 0; +} + +var setAtcAutoCallbackAfterSeconds = func(delay) +{ + atc_callback_wait_seconds = delay; + + atc_callback_seconds_counter = 0; +} + +var addSecondsToAtcAutoCallback = func(delay) +{ + atc_callback_wait_seconds += delay; +} + +var cancelAtcPendingMessage = func() +{ + atc_callback_seconds_counter = 0; + + altitude_check_counter = 0; + + altitude_change_counter = 0; +} + +var getNearbyCtr = func(range) +{ + var airport = nil; + var nearByAirports = nil; + var minDistance = range; + var nearestCtr = nil; + var ctrData = nil; + var radio = nil; + + airport = airportinfo(); + + if(airport != nil) + { + ctrData = getCtrData(airport); + + if(ctrData != nil and ctrData.status == ctr_status_inside) + { + if(approvedCtr != nil) + { + if(ctrData.ident != approvedCtr.ident or isRadioTunedToApprovedCtrRadio == 0) + return ctrData; + } + else + return ctrData; + } + } + + nearByAirports = findAirportsWithinRange(range); + + foreach(airport; nearByAirports) + { + ctrData = getCtrData(airport); + + if(ctrData != nil) + { + if(approvedCtr != nil and ctrData.ident == approvedCtr.ident) + { + # ignore currently approved CTR + } + else if(ctrData.status == ctr_status_inside) + { + nearestCtr = ctrData; + + minDistance = 0; + } + else if(ctrData.status == ctr_status_in_range and ctrData.distance_from_range < minDistance) + { + minDistance = ctrData.distance_from_range; + + nearestCtr = ctrData; + } + } + } + + return nearestCtr; +} + +var getCtrData = func(airport) +{ + var course = 0; + var distance = 0; + var range = 0; + var rangeDistance = 0; + var status = ctr_status_outside; + var aircraftHeading = property_Aircraft_HeadingDeg.getValue(); + + if(airport == nil) + return nil; + + var nradios = size(airport.comms()); + + if(nradios == 0) + return nil; + + var pos = geo.Coord.new().set_latlon(airport.lat, airport.lon); + + (course, distance) = courseAndDistance(pos); + + if(nradios > 5) + range = ctr_range_wide; + else if(nradios > 1) + range = ctr_range_medium; + else + range = ctr_range_short; + + if(distance < range) + { + status = ctr_status_inside; + + rangeDistance = 0; + } + else if(courseWithinDegrees(aircraftHeading, course, ctr_maximum_range_angle) == 1) + { + if((distance - range) < ctr_maximum_range_distance) + { + status = ctr_status_in_range; + + rangeDistance = distance - range; + } + else + { + status = ctr_status_outside; + + rangeDistance = 0; + } + } + else + { + status = ctr_status_outside; + + rangeDistance = 0; + } + + var ctrData = { + ident:airport.id, + airport:airport.name, + lat:airport.lat, + lon:airport.lon, + range:range, + course:course, + distance:distance, + distance_from_range:rangeDistance, + status:status + }; + + return ctrData; +} + +var getCtrRadio = func(ctr) +{ + var radioType = radio_station_type_approach; + var radio = nil; + + if(ctr == nil) + return nil; + + if(aircraftIsDeparting == 1) + radioType = radio_station_type_departure; + + radio = getAirportRadio(airportinfo(ctr.ident), radioType); + + if(getRadioType(radio.ident) != radioType) + radio = getAirportRadio(airportinfo(ctr.ident), radio_station_type_approach); + + return radio; +} + +var getQNH = func() +{ + var qnhinhg = 0; + var qnhhpa = 0; + var qnhValue = ""; + var qnhLiteralValue = ""; + + if(isRealMeteoEnabled() == 1) + { + if(property_Weather_QnhInHg != nil) + qnhinhg = property_Weather_Metar_QnhInHg.getValue(); + else + qnhinhg = 0; + } + else + { + if(property_Weather_QnhInHg != nil) + qnhinhg = property_Weather_QnhInHg.getValue(); + else + qnhinhg = 0; + } + + qnhhpa = int(qnhinhg / 0.02953); + + if(qnhUnitMeasure == "hPa") + { + qnhValue = sprintf("%d hPa", qnhhpa); + qnhLiteralValue = spellToPhonetic(sprintf("%d", qnhhpa), spell_number) ~ " hecto pascal"; + } + else if(qnhUnitMeasure == "inHg") + { + qnhValue = sprintf("%.2f inHg", qnhinhg); + qnhLiteralValue = spellToPhonetic(sprintf("%.2f" ,qnhinhg), spell_number) ~ " inches of mercury"; + } + else + { + qnhValue = sprintf("%d hPa or %.2f inHg", qnhhpa, qnhinhg); + qnhLiteralValue = spellToPhonetic(sprintf("%d", qnhhpa), spell_number) ~ " hecto pascal or "; + qnhLiteralValue ~= spellToPhonetic(sprintf("%.2f", qnhinhg), spell_number) ~ " inches of mercury"; + } + + return [qnhValue, qnhLiteralValue]; +} + +var isInsideCtr = func(airport) +{ + if(airport == nil) + return 0; + + var ctrData = getCtrData(airport); + var isInside = 0; + + if(ctrData != nil and ctrData.status == ctr_status_inside) + isInside = 1; + else + isInside = 0; + + return isInside; +} + +var getCtrAtcMessage = func(request) +{ + var text = ""; + var voice = ""; + var extraText = ""; + var extraVoice = ""; + + (atcCallsignText, atcCallsignVoice) = getCallSignForAtc(0); + + if(request == ctr_request_approved) + { + if(squawkingMode == "On") + { + var code = getSquawkCode(); + + if(code != squawkCode) + { + squawkCode = code; + + extraText = sprintf(", Squawk %s and IDENT", squawkCode); + extraVoice = sprintf(", Squawk %s and ident", spellToPhonetic(squawkCode, spell_number)); + + squawkChange = 1; + + setSquawkIdentMode(squawk_ident_code); + } + else + { + extraText = ", Squawk IDENT"; + extraVoice = ", Squawk ident"; + + squawkChange = 0; + + setSquawkIdentMode(squawk_ident_only); + } + } + else + { + extraText = ""; + extraVoice = ""; + } + + text = sprintf(atcMessageReply.ctr_approved, + atcCallsignText, + selectedComStationName, + "CTR", + extraText + ); + + voice = sprintf(atcMessageReply.ctr_approved, + atcCallsignVoice, + selectedComStationName, + "C T R", + extraVoice + ); + } + else if(request == ctr_already_approved) + { + if(squawkingMode == "On") + { + if(squawkCode == "") + squawkCode = getSquawkCode(); + + extraText = sprintf(", Squawk %s", squawkCode); + extraVoice = sprintf(", Squawk %s", spellToPhonetic(squawkCode, spell_number)); + + setSquawkIdentMode(squawk_ident_code); + } + else + { + extraText = ""; + extraVoice = ""; + + setSquawkIdentMode(squawk_ident_off); + } + + text = sprintf(atcMessageReply.ctr_already_approved, + atcCallsignText, + selectedComStationName, + "CTR", + extraText + ); + + voice = sprintf(atcMessageReply.ctr_already_approved, + atcCallsignVoice, + selectedComStationName, + "C T R", + extraVoice + ); + } + else + { + text = sprintf(atcMessageReply.ctr_not_approved, + atcCallsignText, + selectedComStationName, + "CTR", + "CTR" + ); + + voice = sprintf(atcMessageReply.ctr_not_approved, + atcCallsignVoice, + selectedComStationName, + "C T R", + "C T R" + ); + } + + return [text, voice]; +} + +var isTerrainSafeAhead = func() +{ + var safe = 0; + var aircraftPosition = geo.aircraft_position(); + var pathPosition = geo.aircraft_position().apply_course_distance(property_Aircraft_HeadingDeg.getValue(), min_safety_distance_from_terrain_miles * NM2M); + + var intersection = get_cart_ground_intersection({ + "x":aircraftPosition.x(), + "y":aircraftPosition.y(), + "z":aircraftPosition.z() + }, + { + "x":pathPosition.x()-aircraftPosition.x(), + "y":pathPosition.y()-aircraftPosition.y(), + "z":pathPosition.z()-aircraftPosition.z() + } + ); + + if(intersection == nil) + safe = 1; + else + { + var terrainPos = geo.Coord.new(); + + terrainPos.set_latlon(intersection.lat, intersection.lon, intersection.elevation); + + var maxDist = aircraftPosition.direct_distance_to(pathPosition); + var terrainDist = aircraftPosition.direct_distance_to(terrainPos); + + if(terrainDist < maxDist) + safe = 0; + else + safe = 1; + } + + return safe; +} + +var isSimulationPaused = func() +{ + var paused = 0; + + if(property_Simulator_Freeze.getValue() == 1 or property_Simulator_Replay.getValue() == 1) + paused = 1; + + return paused; +} + +var altitudeApproachSlope = func(altitude, distance, roundHundred = 0) +{ + if(altitude < 0 or distance < 0) + return -1; + + slopeRadians = approach_slope_angle * D2R; + ralt = math.sin(slopeRadians); + rdist = math.cos(slopeRadians); + + slopeAltitude = ((distance / rdist) * ralt) * NM2FT; + + slopeAltitude += altitude * M2FT; + + if(roundHundred == 1) + slopeAltitude = (100 * int(slopeAltitude / 100)); + + return slopeAltitude; +} + +var getSquawkCode = func() +{ + code = squawkCode; + + if(code == "" or rand() < 0.3) + { + codeOk = 0; + + while(codeOk == 0) + { + tempCode = int(rand() * 7776) + 1; + + codeOk = 1; + + foreach(var c; reservedSquawkCodes) + { + if(tempCode == c) + codeOk = 0; + } + + newCode = sprintf("0000%d", tempCode); + + newCode = substr(newCode, size(newCode) - 4); + clen = size(newCode); + + for(var i = 0; i < clen; i += 1) + { + if(int(chr(newCode[i])) > 7) + codeOk = 0; + } + } + + code = newCode; + } + + return code; +} + +var getOperatingTransponder = func() +{ + if(property_Transponder1_Serviceable != nil) + { + if(property_Transponder1_Serviceable.getValue() == 1 and property_Transponder1_Operable.getValue() == 1 and property_Transponder1_KnobMode.getValue() > 3) + return 1; + } + + if(property_Transponder2_Serviceable != nil) + { + if(property_Transponder2_Serviceable.getValue() == 1 and property_Transponder2_Operable.getValue() == 1 and property_Transponder2_KnobMode.getValue() > 3) + return 2; + } + + if(property_Transponder3_Serviceable != nil) + { + if(property_Transponder3_Serviceable.getValue() == 1 and property_Transponder3_Operable.getValue() == 1 and property_Transponder3_KnobMode.getValue() > 3) + return 3; + } + + return 0; +} + +var checkTransponder = func(transponder) +{ + var serviceable = nil; + var operable = nil; + var idcode = nil; + + if(transponder == 1 and property_Transponder1_Serviceable != nil) + { + serviceable = property_Transponder1_Serviceable.getValue(); + operable = property_Transponder1_Operable.getValue(); + idcode = property_Transponder1_IdCode.getValue(); + } + else if(transponder == 2 and property_Transponder2_Serviceable != nil) + { + serviceable = property_Transponder2_Serviceable.getValue(); + operable = property_Transponder2_Operable.getValue(); + idcode = property_Transponder2_IdCode.getValue(); + } + else if(transponder == 3 and property_Transponder3_Serviceable != nil) + { + serviceable = property_Transponder3_Serviceable.getValue(); + operable = property_Transponder3_Operable.getValue(); + idcode = property_Transponder3_IdCode.getValue(); + } + else + return 0; + + if(serviceable == 0) + return 0; + + if(operable == 0) + return 0; + + if(idcode != squawkCode) + return 0; + + return 1; +} + +var checkTransponderIdent = func(transponder) +{ + var ident = 0; + + if(transponder == 1 and property_Transponder1_Ident != nil) + ident = property_Transponder1_Ident.getValue(); + else if(transponder == 2 and property_Transponder2_Ident != nil) + ident = property_Transponder2_Ident.getValue(); + else if(transponder == 3 and property_Transponder3_Ident != nil) + ident = property_Transponder3_Ident.getValue(); + else + return 0; + + return ident; +} + +var setSquawkIdentMode = func(mode) +{ + squawkIdent = mode; + + if(mode == squawk_ident_off) + squawkIdentButtonPushed = 0; + + squawk_check_counter = 0; +} + +var getPilotVoice = func() +{ + var done = 0; + var i = 0; + var pvoice = ""; + var ptype = ""; + var vdesc = ""; + + while(done == 0) + { + if(i == 0) + vprop = "/sim/sound/voices/voice"; + else + vprop = sprintf("/sim/sound/voices/voice[%d]", i); + + vdesc = vprop ~ "/desc"; + + if(getprop(vdesc) == nil) + { + done = 1; + + pvoice = "/sim/sound/voices/pilot"; + } + else + { + if(string.lc(getprop(vdesc)) == "pilot") + { + pvoice = props.globals.getNode(vprop ~ "/text"); + + if(getprop(sprintf("%s/festival", vprop)) == 1) + { + if(string.match(getprop(sprintf("%s/preamble", vprop)), "*(audio_mode 'async)*") == 1) + ptype = "festival-async"; + else + ptype = "festival"; + } + else + ptype = "flite"; + + done = 1; + } + } + + i += 1; + } + + return { text:pvoice, type:ptype }; +} + +var initAtcVoice = func() +{ + synthVoice = []; + var done = 0; + var i = 0; + var vdesc = ""; + + synthVoice = []; + usedSynthVoice = []; + stationVoice = {}; + stationVoicePool = []; + + while(done == 0) + { + if(i == 0) + vprop = "/sim/sound/voices/voice"; + else + vprop = sprintf("/sim/sound/voices/voice[%d]", i); + + vdesc = vprop ~ "/desc"; + + if(getprop(vdesc) == nil) + done = 1; + else + { + if(string.lc(getprop(vdesc)) != "pilot") + { + var pvoice = {}; + + pvoice['text'] = props.globals.getNode(vprop ~ "/text"); + + if(getprop(sprintf("/sim/sound/voices/voice[%d]/festival", i)) == 1) + { + if(string.match(getprop(sprintf("/sim/sound/voices/voice[%d]/preamble", i)), "*(audio_mode 'async)*") == 1) + pvoice['type'] = "festival-async"; + else + pvoice['type'] = "festival"; + } + else + pvoice['type'] = "flite"; + + append(synthVoice, pvoice); + } + } + + i += 1; + } +} + +var getSynthVoice = func(frequency) +{ + var voiceIsValid = 0; + var svoice = {}; + var i = 0; + var vndx = 0; + var svsize = size(synthVoice); + var usvsize = size(usedSynthVoice); + var svpsize = size(stationVoicePool); + + if(frequency == "") + { + if(svsize > 0) + return synthVoice[0]; + else + return { text:"/sim/sound/voices/voice/atc", type:"flite" }; + } + + if(svpsize > 0) + { + for(i = 0; i < svpsize; i += 1) + { + svoice = stationVoicePool[i]; + + if(svoice['frequency'] == frequency) + return svoice; + } + } + + voiceIsValid = 0; + + while(voiceIsValid == 0) + { + vndx = int(rand() * svsize); + + voiceIsValid = 1; + + foreach(var usv; usedSynthVoice) + { + if(usv['index'] == vndx) + voiceIsValid = 0; + } + } + + svoice = {}; + + svoice['index'] = vndx; + svoice['text'] = synthVoice[vndx]['text']; + svoice['type'] = synthVoice[vndx]['type']; + svoice['frequency'] = frequency; + + append(usedSynthVoice, svoice); + + append(stationVoicePool, svoice); + + if(size(usedSynthVoice) == svsize) + usedSynthVoice = []; + + return svoice; +} + +var speak = func(text, voice, type) +{ + if(type == "festival-async") + { + var tpart = split(",", text); + + foreach(var t; tpart) + { + var tpart1 = split("\n", t); + + foreach(var t1; tpart1) + voice.setValue(t1 ~ "."); + } + } + else + voice.setValue(text); +} + +var autoATCMessageDelay = func(seconds) +{ + ctr_update_counter -= seconds; + ctr_check_counter -= seconds; + + terrain_warning_counter -= seconds; + + if(terrain_warning_counter < 0) + terrain_warning_counter = 0; + + altitude_check_counter -= seconds; + + if(altitude_check_counter < 0) + altitude_check_counter = 0; + + squawk_check_counter -= seconds; + + if(squawk_check_counter < 0) + squawk_check_counter = 0; + + approach_check_counter -= seconds; + + if(approach_check_counter < 0) + approach_check_counter = 0; +} diff --git a/settings.nas b/settings.nas new file mode 100644 index 0000000..6eacca9 --- /dev/null +++ b/settings.nas @@ -0,0 +1,485 @@ +# +# Red Griffin ATC - Speaking Air Traffic Controller for FlightGear +# +# Written and developer by Antonello Biancalana (Red Griffin, IK0TOJ) +# +# Copyright (C) 2019-2021 Antonello Biancalana +# +# settings.nas +# +# Global variables for Red Griffin ATC (rgatc.nas) +# +# Version 2.3.0 - 7 May 2021 +# +# Red Griffin ATC is an Open Source project and it is licensed +# under the Gnu Public License v3 (GPLv3) +# + +var rgatcPropNode = "/rgatc"; + +var default_setting_open_dialog_startup = "Off"; +var default_setting_dialog_position = "Bottom Left"; +var default_setting_atc_text_position = "Top Center"; +var default_setting_atc_text_transparency = "Medium"; +var default_setting_callsign = property_MultiplayCallsign.getValue(); +var default_setting_callsign_mode = "Complete"; +var default_setting_include_manufacturer = "Yes"; +var default_setting_pilot_request_mode = "Voice and text"; +var default_setting_pilot_response_mode = "Voice and text"; +var default_setting_atc_message_mode = "Voice and text"; +var default_setting_qnh = "hPa and inHg"; +var default_setting_atc_radio = "Auto"; +var default_setting_aircraft_type = "Auto"; +var default_setting_squawking = "On"; +var default_setting_slope_angle = 3.0; +var default_setting_too_low_warning = "On"; +var default_setting_terrain_warning = "On"; +var default_setting_multiplayer_chat_echo = "Off"; + +var settingsFileName = getprop("/sim/fg-home") ~ "/Export/RedGriffinATC-config.xml"; + +var settings = nil; + +var initSettings = func() +{ + if(default_setting_callsign == "" or default_setting_callsign == nil) + default_setting_callsign = "RG-ATC"; + + loadSettings(); + + if(settings == nil or property_Setting_DialogPosition.getValue() == "" or property_Setting_DialogPosition.getValue() == nil) + resetSettings(); +} + +var resetSettings = func() +{ + property_Setting_OpenDialogStartup.setValue(default_setting_open_dialog_startup); + property_Setting_DialogPosition.setValue(default_setting_dialog_position); + property_Setting_AtcTextPosition.setValue(default_setting_atc_text_position); + property_Setting_AtcTextTransparency.setValue(default_setting_atc_text_transparency); + property_Setting_Callsign.setValue(default_setting_callsign); + property_Setting_CallsignMode.setValue(default_setting_callsign_mode); + property_Setting_IncludeManufacturer.setValue(default_setting_include_manufacturer); + property_Setting_PilotRequestMode.setValue(default_setting_pilot_request_mode); + property_Setting_PilotResponseMode.setValue(default_setting_pilot_response_mode); + property_Setting_AtcMessageMode.setValue(default_setting_atc_message_mode); + property_Setting_QnhUnitMeasure.setValue(default_setting_qnh); + property_Setting_AtcRadioMode.setValue(default_setting_atc_radio); + property_Setting_AircraftType.setValue(default_setting_aircraft_type); + property_Setting_SquawkingMode.setValue(default_setting_squawking); + property_Setting_SlopeAngle.setValue(default_setting_slope_angle); + property_Setting_TooLowWarningMode.setValue(default_setting_too_low_warning); + property_Setting_TerrainWarningMode.setValue(default_setting_terrain_warning); + property_Setting_MultiplayerChatEcho.setValue(default_setting_multiplayer_chat_echo); + + applySettings(); +} + +var applySettings = func() +{ + openDialogStartup = property_Setting_OpenDialogStartup.getValue(); + dialogPosition = property_Setting_DialogPosition.getValue(); + atcTextPosition = property_Setting_AtcTextPosition.getValue(); + atcTextTransparency = property_Setting_AtcTextTransparency.getValue(); + callsign = property_Setting_Callsign.getValue(); + callsignMode = property_Setting_CallsignMode.getValue(); + includeManufacturer = property_Setting_IncludeManufacturer.getValue(); + pilotRequestMode = property_Setting_PilotRequestMode.getValue(); + pilotResponseMode = property_Setting_PilotResponseMode.getValue(); + atcMessageMode = property_Setting_AtcMessageMode.getValue(); + qnhUnitMeasure = property_Setting_QnhUnitMeasure.getValue(); + atcRadioMode = property_Setting_AtcRadioMode.getValue(); + aircraftType = getAircraftType(); + squawkingMode = property_Setting_SquawkingMode.getValue(); + slopeAngle = property_Setting_SlopeAngle.getValue(); + tooLowWarningMode = property_Setting_TooLowWarningMode.getValue(); + terrainWarningMode = property_Setting_TerrainWarningMode.getValue(); + multiplayerChatEcho = property_Setting_MultiplayerChatEcho.getValue(); + + if(openDialogStartup == nil or openDialogStartup == "") + { + openDialogStartup = default_setting_open_dialog_startup; + + property_Setting_OpenDialogStartup.setValue(default_setting_open_dialog_startup); + } + + if(dialogPosition == nil or dialogPosition == "") + { + dialogPosition = default_setting_dialog_position; + + property_Setting_DialogPosition.setValue(default_setting_dialog_position); + } + + if(atcTextPosition == nil or atcTextPosition == "") + { + atcTextPosition = default_setting_atc_text_position; + + property_Setting_AtcTextPosition.setValue(default_setting_atc_text_position); + } + + if(atcTextTransparency == nil or atcTextTransparency == "") + { + atcTextTransparency = default_setting_atc_text_transparency; + + property_Setting_AtcTextTransparency.setValue(default_setting_atc_text_transparency); + } + + if(callsign == nil or callsign == "") + { + callsign = default_setting_callsign; + + property_Setting_Callsign.setValue(default_setting_callsign); + } + + if(callsignMode == nil or callsignMode == "") + { + callsignMode = default_setting_callsign_mode; + + property_Setting_CallsignMode.setValue(default_setting_callsign_mode); + } + + if(includeManufacturer == nil or includeManufacturer == "") + { + includeManufacturer = default_setting_include_manufacturer; + + property_Setting_IncludeManufacturer.setValue(default_setting_include_manufacturer); + } + + if(pilotRequestMode == nil or pilotRequestMode == "") + { + pilotRequestMode = default_setting_pilot_request_mode; + + property_Setting_PilotRequestMode.setValue(default_setting_pilot_request_mode); + } + + if(pilotResponseMode == nil or pilotResponseMode == "") + { + pilotResponseMode = default_setting_pilot_response_mode; + + property_Setting_PilotResponseMode.setValue(default_setting_pilot_response_mode); + } + + if(atcMessageMode == nil or atcMessageMode == "") + { + atcMessageMode = default_setting_atc_message_mode; + + property_Setting_AtcMessageMode.setValue(default_setting_atc_message_mode); + } + + if(qnhUnitMeasure == nil or qnhUnitMeasure == "") + { + qnhUnitMeasure = default_setting_qnh; + + property_Setting_QnhUnitMeasure.setValue(default_setting_qnh); + } + + if(atcRadioMode == nil or atcRadioMode == "") + { + atcRadioMode = default_setting_atc_radio; + + property_Setting_AtcRadioMode.setValue(default_setting_atc_radio); + } + + if(aircraftType == nil or aircraftType == "") + { + property_Setting_AircraftType.setValue(default_setting_aircraft_type); + + aircraftType = getAircraftType(); + } + + if(squawkingMode == nil or squawkingMode == "") + { + squawkingMode = default_setting_squawking; + + property_Setting_SquawkingMode.setValue(default_setting_squawking); + } + + if(slopeAngle == nil or slopeAngle == "") + { + slopeAngle = default_setting_slope_angle; + + property_Setting_SlopeAngle.setValue(default_setting_slope_angle); + } + + if(num(slopeAngle) < 2 or num(slopeAngle) > 8) + { + slopeAngle = default_setting_slope_angle; + + property_Setting_SlopeAngle.setValue(default_setting_slope_angle); + } + + if(slopeAngle == nil or slopeAngle == "" or num(slopeAngle) == nil) + { + slopeAngle = default_setting_slope_angle; + + property_Setting_SlopeAngle.setValue(default_setting_slope_angle); + } + + if(tooLowWarningMode == nil or tooLowWarningMode == "") + { + tooLowWarningMode = default_setting_too_low_warning; + + property_Setting_TooLowWarningMode.setValue(default_setting_too_low_warning); + } + + if(terrainWarningMode == nil or terrainWarningMode == "") + { + terrainWarningMode = default_setting_terrain_warning; + + property_Setting_TerrainWarningMode.setValue(default_setting_terrain_warning); + } + + if(multiplayerChatEcho == nil or multiplayerChatEcho == "") + { + multiplayerChatEcho = default_setting_multiplayer_chat_echo; + + property_Setting_MultiplayerChatEcho.setValue(default_setting_multiplayer_chat_echo); + } + + property_Setting_Callsign.setValue(string.uc(callsign)); + + property_MultiplayCallsign.setValue(string.uc(callsign)); + property_UserCallsign.setValue(string.uc(callsign)); + + (atcCallsignText, atcCallsignVoice) = getCallSignForAtc(1); + + approach_slope_angle = num(slopeAngle); + + setAtcTextPosition(); + + setDialogPosition(); + + setAircraftType(); + + saveSettings(); + + if(aircraftType == aircraft_type_unknown) + gui.showDialog("set-aircraft-type-dialog"); +} + +var saveSettings = func() +{ + settings = props.globals.getNode(rgatcPropNode); + + io.write_properties(settingsFileName, settings); +} + +var loadSettings = func() +{ + settings = io.read_properties(settingsFileName, rgatcPropNode); + + if(settings != nil) + applySettings(); + + return settings; +} + +var setAircraftType = func() +{ + var atype = getAircraftType(); + + if(atype == aircraft_type_small_single_engine) + { + min_cruise_altitude = 3500; + + pattern_speed = 100; + approach_speed = 90; + final_speed = 70; + flight_level_rate = 1000; + + approach_point_distance = -10; + pattern_point_distance = -3; + approach_turn_distance = 0.8; + + altitude_check_interval = 90; + } + else if(atype == aircraft_type_small_multi_engine) + { + min_cruise_altitude = 3500; + + pattern_speed = 120; + approach_speed = 100; + final_speed = 85; + flight_level_rate = 1000; + + approach_point_distance = -10; + pattern_point_distance = -3; + approach_turn_distance = 1.0; + + altitude_check_interval = 90; + } + else if(atype == aircraft_type_executive_turboprop_jet) + { + min_cruise_altitude = 5500; + + pattern_speed = 160; + approach_speed = 140; + final_speed = 120; + flight_level_rate = 1200; + + approach_point_distance = -12; + pattern_point_distance = -5; + approach_turn_distance = 1.8; + + altitude_check_interval = 75; + } + else if(atype == aircraft_type_business_jet) + { + min_cruise_altitude = 5500; + + pattern_speed = 170; + approach_speed = 150; + final_speed = 130; + flight_level_rate = 1500; + + approach_point_distance = -15; + pattern_point_distance = -5; + approach_turn_distance = 1.8; + + altitude_check_interval = 45; + } + else if(atype == aircraft_type_airline_jet) + { + min_cruise_altitude = 7500; + + pattern_speed = 180; + approach_speed = 160; + final_speed = 140; + flight_level_rate = 1500; + + approach_point_distance = -15; + pattern_point_distance = -6; + approach_turn_distance = 2.3; + + altitude_check_interval = 45; + } + else if(atype == aircraft_type_large_military_jet) + { + min_cruise_altitude = 8500; + + pattern_speed = 210; + approach_speed = 190; + final_speed = 150; + flight_level_rate = 1500; + + approach_point_distance = -15; + pattern_point_distance = -7; + approach_turn_distance = 2.3; + + altitude_check_interval = 45; + } + else if(atype == aircraft_type_special_military) + { + min_cruise_altitude = 8500; + + pattern_speed = 210; + approach_speed = 190; + final_speed = 150; + flight_level_rate = 2000; + + approach_point_distance = -15; + pattern_point_distance = -8; + approach_turn_distance = 2.3; + + altitude_check_interval = 45; + } + else + { + min_cruise_altitude = 3500; + + pattern_speed = 100; + approach_speed = 90; + final_speed = 70; + flight_level_rate = 1000; + + approach_point_distance = -10; + pattern_point_distance = -3; + approach_turn_distance = 0.8; + + altitude_check_interval = 90; + } + + setRGTitle(); +} + +var getAircraftType = func() +{ + var aType = property_Setting_AircraftType.getValue(); + + if(aType == "Auto") + { + if(isTagDefined("fighter") == 1 or isTagDefined("interceptor") == 1 or isTagDefined("combat") == 1) + { + if(isTagDefined("bomber") == 1 or isTagDefined("tanker") == 1) + aType = aircraft_type_large_military_jet; + else + aType = aircraft_type_special_military; + } + else if(isTagDefined("piston") == 1 or isTagDefined("propeller") == 1) + { + if(isTagDefined("single-engine") == 1 or isTagDefined("1-engine") == 1) + aType = aircraft_type_small_single_engine; + else if(isTagDefined("twin-engine") == 1 or isTagDefined("2-engine") == 1 or + isTagDefined("4-engine") == 1 or isTagDefined("four-engine") == 1 ) + aType = aircraft_type_small_multi_engine; + else if(isTagDefined("turboprop") == 1) + aType = aircraft_type_executive_turboprop_jet; + else + aType = aircraft_type_small_single_engine; + } + else if(isTagDefined("jet") == 1) + { + if(isTagDefined("turboprop") == 1) + aType = aircraft_type_executive_turboprop_jet; + else if(isTagDefined("bizjet") == 1 or isTagDefined("business") == 1) + aType = aircraft_type_business_jet; + else if(isTagDefined("cargo") == 1 or isTagDefined("tanker") == 1) + aType = aircraft_type_large_military_jet; + else if(isTagDefined("transport") == 1 or isTagDefined("passenger") == 1) + aType = aircraft_type_airline_jet; + else + aType = aircraft_type_business_jet; + } + else if(isTagDefined("supersonic") == 1 or isTagDefined("turbojet") == 1) + aType = aircraft_type_large_military_jet; + else if(isTagDefined("turboprop") == 1) + aType = aircraft_type_executive_turboprop_jet; + else if(isTagDefined("bizjet") == 1 or isTagDefined("business") == 1) + aType = aircraft_type_business_jet; + else + aType = aircraft_type_unknown; + } + + return aType; +} + +var isTagDefined = func(tag) +{ + var tagdef = 0; + var done = 0; + var i = 0; + var ndx = ""; + var property = ""; + + while(tagdef == 0 and done == 0) + { + if(i > 0) + ndx = sprintf("[%d]", i); + else + ndx = ""; + + property = getprop(sprintf("/sim/tags/tag%s", ndx)); + + if(property != nil) + { + if(property == tag) + tagdef = 1; + } + else + done = 1; + + i += 1; + } + + return tagdef; +}