diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 36aa0d3..09352e8 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # FlightGear Landing Rate addon Show your landing stats. Depending on your rate of descent on touching the ground it rates your landing as Excellent, Good, Acceptable, or Bad. -Slightly modified by PO to make it compatible with more recent version of FG. +Slightly modified by PO to make it compatible with more recent version of FG. ![Example](https://i.imgur.com/PwOQYFI.jpg) @@ -11,11 +11,11 @@ FlightGear 2018.1 version. ### Install Procedures -Unzip landing_rate folder to any place you want. e.g C:\Users\USERNAME\Documents\FlightGear\Addons\landing_rate +Unzip landing_rate folder to any place you want. e.g C:\Users\USERNAME\FlightGear\Addons\landing_rate Then add this command line to your FlightGear Shortcut : ---addon="C:\Users\USERNAME\Documents\FlightGear\Addons\landing_rate" +--addon="C:\Users\USERNAME\FlightGear\Addons\landing_rate" Remember to replace USERNAME with your OS username. Note that this command line must have the correct path to the landing_rate folder. @@ -32,8 +32,8 @@ If you're using an incompatible aircraft a message will be show. And the addon w If you want, you can activate it. And a message will be sent by multiplayer chat showing your landing stats. -To enable it go to landing_rate folder and open config.xml. Find sharemp line. +To enable it go to landing_rate folder and open addon-config.xml. Find sharemp line. ```0``` -Change sharemp value ( 1 for yes and 0 for no ). Restart your simulator. Done. +Change sharemp value (1 for yes and 0 for no). Restart your simulator. Done. diff --git a/addon-config.xml b/addon-config.xml new file mode 100755 index 0000000..2dd0fdd --- /dev/null +++ b/addon-config.xml @@ -0,0 +1,13 @@ + + + + + + + + 0 + + + + + diff --git a/addon-main.nas b/addon-main.nas new file mode 100755 index 0000000..628df15 --- /dev/null +++ b/addon-main.nas @@ -0,0 +1,155 @@ +var LOG_ALERT = 5; +var COLOR_WHITE = { r: 1, g: 1, b: 1 }; +var COLOR_RED = { r: 1, g: 0, b: 0 }; +var COLOR_ORANGE = { r: 1, g: .65, b: 0 }; +var COLOR_YELLOW = { r: 1, g: .95, b: 0 }; +var COLOR_LIME = { r: .64, g: 1, b: 0 }; +var COLOR_GREEN = { r: 0, g: 1, b: 0 }; + +var LANDING_RANK = [ + { + name : "Bad", + minFpm : 600, + color : COLOR_RED, + }, + { + name : "Acceptable", + minFpm : 400, + color : COLOR_ORANGE, + }, + { + name : "Good", + minFpm : 200, + color : COLOR_YELLOW, + }, + { + name : "Very Good", + minFpm : 100, + color : COLOR_LIME, + }, + { + name : "Excellent", + minFpm : 0, + color : COLOR_GREEN, + }, +]; + +var window = screen.window.new(10, 10, 3, 10); # create new window object, x = 10, y = 10, maxlines = 3, autoscroll = 10 +window.bg = [0, 0, 0, .5]; # black alpha .5 background +var aglFt = 20; # agl trigger temporary 20. + +var initLandingRateTimer = func (addon) { + var addonNodePath = addon.node.getPath(); + + var landingRateProps = [ # addon props array + addonNodePath ~ "/addon-devel/rate-fpm", + addonNodePath ~ "/addon-devel/rate-mts", + addonNodePath ~ "/addon-devel/g-force", + addonNodePath ~ "/addon-devel/landed", + addonNodePath ~ "/addon-devel/altTrig", + ]; + + # init addon props array + foreach (var prop; landingRateProps) { + props.globals.initNode(prop, 0, nil); + } + + var gearProps = [ # gear props array + "/gear/gear[0]/wow", + "/gear/gear[1]/wow", + "/gear/gear[2]/wow", + ]; + + # set gear props listeners + foreach (var prop; gearProps) { + setlistener(prop, func (node) { + var isLanded = node.getBoolValue() and !getprop(addonNodePath ~ "/addon-devel/landed"); + setprop(addonNodePath ~ "/addon-devel/landed", isLanded); + }, 0, 0); # startup = 0 (default), runtime = 0 (only when value change) + } + + # setting up altTrigg timer + var altTrigger = maketimer(1, func { + if (getprop("/position/altitude-agl-ft") > aglFt) { + setprop(addonNodePath ~ "/addon-devel/altTrig", 1); + } + }); + altTrigger.start(); # starting alt trigg list + + # setting up message listener, send message when land + setlistener(addonNodePath ~ "/addon-devel/landed", func (node) { + if (node.getValue() and getprop(addonNodePath ~ "/addon-devel/altTrig")) { + setprop(addonNodePath ~ "/addon-devel/altTrig", 0); + + sendLandingMessage( + addon, + getprop("/accelerations/pilot-gdamped"), + getprop("/instrumentation/vertical-speed-indicator/indicated-speed-fpm"), + getprop("/instrumentation/vertical-speed-indicator/indicated-speed-mps") + ); + } + }); +}; + +var sendLandingMessage = func (addon, g, fpm, mps) { + var fpmAbsolute = math.abs(fpm); # get fpm with no minus sign + + # send message by landing rate, using LANDING_RANK table + foreach (var rank; LANDING_RANK) { + if (fpmAbsolute >= rank.minFpm) { + printScreenMsg( + addon, + sprintf("%s Landing! Fpm: %.3f Mps: %.3f G-Force: %.1f", rank.name, fpm, mps, g), + rank.color + ); + + break; + } + } +}; + +var printScreenMsg = func (addon, msg, color) { + window.write(msg, color.r, color.g, color.b); # print message with color arg. + logprint(LOG_ALERT, "Last Land: ", msg); # print message in case user need it later + + # send mp message if allowed + if (getprop(addon.node.getPath() ~ "/addon-devel/sharemp")) { + setprop("/sim/multiplay/chat", "My landing rate was: " ~ msg); + } +}; + +var printPersistentScreenMsg = func (msg, color, time) { + window.autoscroll = time; # setting message to be show for "time"" seconds + window.write(msg, color.r, color.g, color.b); # print message with color arg. +}; + +var checkCompatibility = func { + # checking nil props + if (getprop("/accelerations/pilot-gdamped") == nil or + getprop("/instrumentation/vertical-speed-indicator/indicated-speed-fpm") == nil or + getprop("/instrumentation/vertical-speed-indicator/indicated-speed-mps") == nil + ) { + # prints persistent message, white, 30 sec + printPersistentScreenMsg("Aircraft not compatible with Landing Rate addon. Sorry about that.", COLOR_WHITE, 30); + + # die addon, quit script with custom message. + die("Landing Rate addon shutdown. Aircraft not compatible with Landing Rate addon. Sorry about that."); + } + + printPersistentScreenMsg("Landing Rate Addon Loaded", COLOR_WHITE, 20); # success + logprint(LOG_ALERT, "Landing Rate addon loaded."); # success +}; + +var main = func (addon) { + # Must be _setlistener because removelistener doesn't work well with setlistener + var fdmInitListener = _setlistener("/sim/signals/fdm-initialized", func { + if (getprop("/sim/signals/fdm-initialized")) { + # checking compatibility, set agl trigger by current agl. + checkCompatibility(); + aglFt = getprop("/position/altitude-agl-ft") + 6; + + initLandingRateTimer(addon); # init addon + removelistener(fdmInitListener); + } + }); +}; diff --git a/addon-metadata.xml b/addon-metadata.xml new file mode 100755 index 0000000..4fdd5c2 --- /dev/null +++ b/addon-metadata.xml @@ -0,0 +1,75 @@ + + + + FlightGear add-on metadata + 1 + + + + org.flightgear.addons.landing-rate + Landing Rate + 1.0.0 + + + + BR-RVD + + + + 2018.1.0 + none + + Show your landing stats + + This add-on, after landing, shows the rate of how softly you landed. + + + + + + Pokaż statystyki lądowania + + + + Ten dodatek po wylądowaniu pokazuje statystyki, jak miękko wylądowałeś. + + + + + + GNU GPL version 3 or later + + + + LICENSE + + + https://www.gnu.org/licenses/gpl-3.0.html + + + + + https://github.com/RenanMsV/landing_rate + + + + https://github.com/RenanMsV/landing_rate + + + + https://github.com/RenanMsV/landing_rate + + + + https://github.com/RenanMsV/landing_rate + + + + + landing + rate + stats + + + diff --git a/landing_rate/addon-config.xml b/landing_rate/addon-config.xml deleted file mode 100644 index fb3ae80..0000000 --- a/landing_rate/addon-config.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - landing_rate - 0.3 - BR-RVD - Show your landing stats! - #first_release - 0 - - - - \ No newline at end of file diff --git a/landing_rate/addon-main.nas b/landing_rate/addon-main.nas deleted file mode 100644 index 2a5b102..0000000 --- a/landing_rate/addon-main.nas +++ /dev/null @@ -1,60 +0,0 @@ -SHARE_RATE_MP = getprop("sim/addons/landing-rate/sharemp"); # send mp message when land - -#-------------------------------------------------- - -landing_rank = [ ["Excellent", 0, [0, 1, 0]],["Very Good", 100, [0, 1, 0]], ["Good", 200, [1, 0.90, 0]], ["Acceptable", 400, [1, .64, 0]], ["Bad", 600, [1, 0, 0]] ]; # [description, minFPM, [r, g, b]] - -var window = screen.window.new(10, 10, 3, 10); # create new window object. 750, 10 : Lower Right -window.bg = [0,0,0,.5]; # black alpha .5 background -var agl_ft = 20; # agl trigger temporary 20. -var agl_list = _setlistener("sim/signals/fdm-initialized", func { removelistener(agl_list); maketimer(0.1, func () { checkCompatibility(); agl_ft = getprop("position/altitude-agl-ft") + 6; }, 3); } ); # setting up agl listener, checking compatibility, set agl trigger by current agl. - -var init_landing_rate_timer = func { - gear_props = ["gear/gear[0]/wow", "gear/gear[1]/wow", "gear/gear[2]/wow"]; # gear props array - landing_rate_props = ["sim/addons/landing-rate/rate-fpm", "sim/addons/landing-rate/rate-mts", "sim/addons/landing-rate/g-force", "sim/addons/landing-rate/landed", "sim/addons/landing-rate/altTrig"]; # addon props array - forindex (var i; landing_rate_props) props.globals.initNode(landing_rate_props[i], 0, nil); # init addon props array - forindex(var i; gear_props) _setlistener(gear_props[i], func { if(getprop(gear_props[i]) and !getprop("sim/addons/landing-rate/landed")) setprop("sim/addons/landing-rate/landed", 1); else setprop("sim/addons/landing-rate/landed", 0); }); # set gear props listeners - altTrigger = maketimer(1, func () {if (getprop("position/altitude-agl-ft") > agl_ft) setprop("sim/addons/landing-rate/altTrig", 1); }); # setting up altTrigg timer - altTrigger.start(); # starting alt trigg list - message = _setlistener("sim/addons/landing-rate/landed", func { if(getprop("sim/addons/landing-rate/landed") and getprop("sim/addons/landing-rate/altTrig")) { setprop("sim/addons/landing-rate/altTrig", 0); send_landing_message(getprop("accelerations/pilot-gdamped"), getprop("instrumentation/vertical-speed-indicator/indicated-speed-fpm"), getprop("instrumentation/vertical-speed-indicator/indicated-speed-mps")); } }); # setting up message listener, send message when land -} - -var send_landing_message = func (g, fpm, mps){ - f = fpm * -1; # get fpm with no (-) - forindex(var i; landing_rank){ - index = (size(landing_rank) - 1) - i; # from last to first array index - if(f >= landing_rank[index][1]) return print_screen_msg(landing_rank[index][0] ~ " Landing! Fpm: " ~ sprintf("%.3f", fpm) ~ " Mps: " ~ sprintf("%.3f", mps) ~ " G-Force: " ~ sprintf("%.1f", g), landing_rank[index][2]); # send message by landing rate, using landing_rank table - } -} - -var print_screen_msg = func (msg, indexColor) { - window.write(msg, indexColor[0], indexColor[1], indexColor[2]); # print message with color arg. - print("Last Land: " ~ msg); # print message in case user need it later - if (SHARE_RATE_MP) send_mp_msg(msg); # send mp message if allowed -} - -var send_mp_msg = func (msg) { - setprop("sim/multiplay/chat", "My landing rate was: " ~ msg); -} - -var print_persistent_screen_msg = func (msg, indexColor, time) { - window.autoscroll = time; # setting message to be show for 30 seconds - window.write(msg, indexColor[0], indexColor[1], indexColor[2]); # print message with color arg. - maketimer(0.1, func(){window.autoscroll = 10;}, time); # setting message to be show for 10 seconds (default) -} - -var checkCompatibility = func { - if(getprop("accelerations/pilot-gdamped") == nil or getprop("instrumentation/vertical-speed-indicator/indicated-speed-fpm") == nil or getprop("instrumentation/vertical-speed-indicator/indicated-speed-mps") == nil) { # checking nil props - print_persistent_screen_msg("Aircraft not compatible with Landing Rate addon. Sorry about that.", [1, 1, 1], 30); # prints persistent message, white, 30 sec - die("Landing Rate addon shutdown. Aircraft not compatible with Landing Rate addon. Sorry about that."); # die addon, quit script with custom message. - } - print_persistent_screen_msg("Landing Rate Addon Loaded", [1,1,1], 20); # success - print("Landing Rate addon loaded."); # success -} - -var main = func ( root ) { - var fdm_init_listener = _setlistener("/sim/signals/fdm-initialized", func { - removelistener(fdm_init_listener); - init_landing_rate_timer(); # init addon - }); -}; # main () diff --git a/landing_rate/addon-metadata.xml b/landing_rate/addon-metadata.xml deleted file mode 100644 index 929d22f..0000000 --- a/landing_rate/addon-metadata.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - FlightGear add-on metadata - 1 - - - - org.flightgear.addons.landing_rate - landing_rate - 0.0.2 - all - landing_rate - landing_rate - -