From 1c77d670aa3178557417993c7d53f242061b30fc Mon Sep 17 00:00:00 2001 From: legoboyvdlp R Date: Sat, 23 May 2020 12:37:22 +0100 Subject: [PATCH] Load cost index automatically if you try to enter ZFW with no cost index set --- Nasal/FMGC/FMGC.nas | 5 +++++ Nasal/FMGC/mcdu-messages.nas | 17 +++++++++++------ Nasal/MCDU/FUELPRED.nas | 6 ++++++ Nasal/MCDU/INITB.nas | 6 ++++++ Nasal/MCDU/MCDU.nas | 4 +++- Nasal/Systems/save.nas | 4 +++- 6 files changed, 34 insertions(+), 8 deletions(-) diff --git a/Nasal/FMGC/FMGC.nas b/Nasal/FMGC/FMGC.nas index 662eb4b0..b9f269f0 100644 --- a/Nasal/FMGC/FMGC.nas +++ b/Nasal/FMGC/FMGC.nas @@ -1077,6 +1077,11 @@ setlistener("/FMGC/internal/fuel-calculating", func() { var timer30secLanding = maketimer(1, func() { if (pts.Sim.Time.elapsedSec.getValue() > getprop("/FMGC/internal/landing-time") + 30) { setprop("/FMGC/status/phase", 7); + if (getprop("/FMGC/internal/cost-index-set")) { + setprop("/FMGC/internal/last-cost-index", getprop("/FMGC/internal/cost-index")); + } else { + setprop("/FMGC/internal/last-cost-index", 0); + } setprop("/FMGC/internal/landing-time", -99); timer30secLanding.stop(); } diff --git a/Nasal/FMGC/mcdu-messages.nas b/Nasal/FMGC/mcdu-messages.nas index e306385f..07def26c 100644 --- a/Nasal/FMGC/mcdu-messages.nas +++ b/Nasal/FMGC/mcdu-messages.nas @@ -109,6 +109,12 @@ var scratchpadController = { me.empty(); me.update(); }, + override: func(str) { + if (me.scratchpad == "USING COST INDEX N") { + me.scratchpad = "USING COST INDEX " ~ str; + me.update(); + } + }, empty: func() { me.scratchpad = ""; me.update(); @@ -136,12 +142,11 @@ var scratchpadController = { var MessageController = { typeIMessages: std.Vector.new([ - TypeIMessage.new("AOC DISABLED"),TypeIMessage.new("AWY/WPT MISMATCH"),TypeIMessage.new("DEST/ALTN MISMATCH"), - TypeIMessage.new("DIR TO IN PROGRESS"),TypeIMessage.new("ENTRY OUT OF RANGE"),TypeIMessage.new("FORMAT ERROR"), - TypeIMessage.new("INSERT/ERASE TMPY FIRST"),TypeIMessage.new("LIST OF 20 IN USE"),TypeIMessage.new("PILOT ELEMENT RETAINED"), - TypeIMessage.new("NOT ALLOWED"),TypeIMessage.new("NOT IN DATA BASE"),TypeIMessage.new("ONLY SPD ENTRY ALLOWED"), - TypeIMessage.new("REVISION IN PROGRESS"),TypeIMessage.new("TMPY F-PLN EXISTS"), - TypeIMessage.new("SELECT DESIRED SYSTEM"),TypeIMessage.new("SELECT HDG/TRK FIRST"), + TypeIMessage.new("AOC DISABLED"),TypeIMessage.new("AWY/WPT MISMATCH"),TypeIMessage.new("DIR TO IN PROGRESS"), + TypeIMessage.new("ENTRY OUT OF RANGE"),TypeIMessage.new("FORMAT ERROR"),TypeIMessage.new("INSERT/ERASE TMPY FIRST"), + TypeIMessage.new("LIST OF 20 IN USE"),TypeIMessage.new("PILOT ELEMENT RETAINED"),TypeIMessage.new("NOT ALLOWED"), + TypeIMessage.new("NOT IN DATA BASE"),TypeIMessage.new("ONLY SPD ENTRY ALLOWED"),TypeIMessage.new("REVISION IN PROGRESS"), + TypeIMessage.new("TMPY F-PLN EXISTS"),TypeIMessage.new("SELECT DESIRED SYSTEM"),TypeIMessage.new("SELECT HDG/TRK FIRST"), TypeIMessage.new("USING COST INDEX N"),TypeIMessage.new("WAIT FOR SYSTEM RESPONSE"), ]), typeIIMessages: std.Vector.new([ diff --git a/Nasal/MCDU/FUELPRED.nas b/Nasal/MCDU/FUELPRED.nas index 37e4859c..1f95e189 100644 --- a/Nasal/MCDU/FUELPRED.nas +++ b/Nasal/MCDU/FUELPRED.nas @@ -142,6 +142,12 @@ var fuelPredInput = func(key, i) { if (scratchpad == "CLR") { mcdu_message(i, "NOT ALLOWED"); } else { + if (!getprop("/FMGC/internal/cost-index-set")) { + mcdu_message(i, "USING COST INDEX N", getprop("/FMGC/internal/last-cost-index")); + setprop("/FMGC/internal/cost-index-set", 1); + setprop("/FMGC/internal/cost-index", getprop("/FMGC/internal/last-cost-index")); + } + var tfs = size(scratchpad); if (tfs == 0) { var zfw = getprop("/fdm/jsbsim/inertia/weight-lbs") - getprop("/consumables/fuel/total-fuel-lbs"); diff --git a/Nasal/MCDU/INITB.nas b/Nasal/MCDU/INITB.nas index f12d6439..0dd306f0 100644 --- a/Nasal/MCDU/INITB.nas +++ b/Nasal/MCDU/INITB.nas @@ -148,6 +148,12 @@ var initInputB = func(key, i) { if (scratchpad == "CLR") { mcdu_message(i, "NOT ALLOWED"); } else { + if (!getprop("/FMGC/internal/cost-index-set")) { + mcdu_message(i, "USING COST INDEX N", getprop("/FMGC/internal/last-cost-index")); + setprop("/FMGC/internal/cost-index-set", 1); + setprop("/FMGC/internal/cost-index", getprop("/FMGC/internal/last-cost-index")); + } + var tfs = size(scratchpad); if (tfs == 0) { var zfw = getprop("/fdm/jsbsim/inertia/weight-lbs") - getprop("/consumables/fuel/total-fuel-lbs"); diff --git a/Nasal/MCDU/MCDU.nas b/Nasal/MCDU/MCDU.nas index 6a4e300a..8eaf94a8 100644 --- a/Nasal/MCDU/MCDU.nas +++ b/Nasal/MCDU/MCDU.nas @@ -59,6 +59,7 @@ var MCDU_reset = func(i) { setprop("/FMGC/internal/alt-set", 0); setprop("/FMGC/internal/cost-index", "0"); setprop("/FMGC/internal/cost-index-set", 0); + setprop("/FMGC/internal/last-cost-index", 0); setprop("/FMGC/internal/cruise-ft", 10000); setprop("/FMGC/internal/cruise-fl", 100); setprop("/FMGC/internal/cruise-lvl-set", 0); @@ -810,8 +811,9 @@ var button = func(btn, i) { } } -var mcdu_message = func(i, string) { +var mcdu_message = func(i, string, overrideStr = "") { mcdu_scratchpad.scratchpads[i].showTypeI(mcdu_scratchpad.MessageController.getTypeIMsgByText(string)); + mcdu_scratchpad.scratchpads[i].override(overrideStr); } var screenFlash = func(time, i) { diff --git a/Nasal/Systems/save.nas b/Nasal/Systems/save.nas index f1256ba5..35869a63 100644 --- a/Nasal/Systems/save.nas +++ b/Nasal/Systems/save.nas @@ -47,7 +47,9 @@ var default = [ "/controls/gear/brake-parking", # electrics "/systems/electrical/sources/bat-1/percent-calc", - "/systems/electrical/sources/bat-2/percent-calc" + "/systems/electrical/sources/bat-2/percent-calc", + # FMGC + "/FMGC/internal/last-cost-index", ]; var save = func (saved_props, file) {