From 6eec8c1fbaa9436a4f5039205cb930ee96fd2e56 Mon Sep 17 00:00:00 2001
From: Joshua Davidson <joshuadavidson2000@gmail.com>
Date: Sun, 18 Jun 2017 00:24:27 -0400
Subject: [PATCH] A3XX: Improve Autoland, Improve PFD annunciators

---
 Models/Instruments/PFD/PFD1.xml      | 153 +++++++++++++++++++--------
 Models/Instruments/PFD/PFD2.xml      | 153 +++++++++++++++++++--------
 Models/Instruments/PFD/res/pfd-3d.ac |  75 ++++++++++++-
 Nasal/FMGC-b.nas                     |  18 +++-
 Nasal/PFD_FMA.nas                    |   2 +-
 Systems/fmgc-b.xml                   |   6 +-
 6 files changed, 304 insertions(+), 103 deletions(-)

diff --git a/Models/Instruments/PFD/PFD1.xml b/Models/Instruments/PFD/PFD1.xml
index 25f0b947..f79b6019 100644
--- a/Models/Instruments/PFD/PFD1.xml
+++ b/Models/Instruments/PFD/PFD1.xml
@@ -213,25 +213,87 @@
 		<object-name>pitch-mode-armed-box</object-name>
 		<object-name>roll-mode-box</object-name>
 		<object-name>roll-mode-armed-box</object-name>
+        <object-name>pitch-mode-fma</object-name>
+        <object-name>roll-mode-fma</object-name>
+        <object-name>pitch-mode-armed-fma</object-name>
+        <object-name>pitch-mode-armed2-fma</object-name>
+        <object-name>roll-mode-armed-fma</object-name>
         <condition>
-			<or>
-				<equals>
-					<property>/it-autoflight/output/fd1</property>
-					<value>1</value>
-				</equals>
-				<equals>
-					<property>/it-autoflight/output/fd2</property>
-					<value>1</value>
-				</equals>
-				<equals>
-					<property>/it-autoflight/output/ap1</property>
-					<value>1</value>
-				</equals>
-				<equals>
-					<property>/it-autoflight/output/ap2</property>
-					<value>1</value>
-				</equals>
-			</or>
+			<and>
+				<or>
+					<equals>
+						<property>/it-autoflight/output/fd1</property>
+						<value>1</value>
+					</equals>
+					<equals>
+						<property>/it-autoflight/output/fd2</property>
+						<value>1</value>
+					</equals>
+					<equals>
+						<property>/it-autoflight/output/ap1</property>
+						<value>1</value>
+					</equals>
+					<equals>
+						<property>/it-autoflight/output/ap2</property>
+						<value>1</value>
+					</equals>
+				</or>
+				<not-equals>
+					<property>/modes/pfd/fma/pitch-mode</property>
+					<value>LAND</value>
+				</not-equals>
+				<not-equals>
+					<property>/modes/pfd/fma/pitch-mode</property>
+					<value>FLARE</value>
+				</not-equals>
+				<not-equals>
+					<property>/modes/pfd/fma/pitch-mode</property>
+					<value>ROLLOUT</value>
+				</not-equals>
+			</and>
+        </condition>
+    </animation>
+	
+    <animation>
+        <type>select</type>
+		<object-name>land-mode-box</object-name>
+		<object-name>land-mode-fma</object-name>
+		<object-name>landmask</object-name>
+        <condition>
+			<and>
+				<or>
+					<equals>
+						<property>/it-autoflight/output/fd1</property>
+						<value>1</value>
+					</equals>
+					<equals>
+						<property>/it-autoflight/output/fd2</property>
+						<value>1</value>
+					</equals>
+					<equals>
+						<property>/it-autoflight/output/ap1</property>
+						<value>1</value>
+					</equals>
+					<equals>
+						<property>/it-autoflight/output/ap2</property>
+						<value>1</value>
+					</equals>
+				</or>
+				<or>
+					<equals>
+						<property>/modes/pfd/fma/pitch-mode</property>
+						<value>LAND</value>
+					</equals>
+					<equals>
+						<property>/modes/pfd/fma/pitch-mode</property>
+						<value>FLARE</value>
+					</equals>
+					<equals>
+						<property>/modes/pfd/fma/pitch-mode</property>
+						<value>ROLLOUT</value>
+					</equals>
+				</or>
+			</and>
         </condition>
     </animation>
 	
@@ -1549,6 +1611,30 @@
         </font-resolution>
     </text>
 	
+    <text>
+        <name>land-mode-fma</name>
+        <offsets>
+            <x-m>0.00091828</x-m>
+            <y-m>-0.00521</y-m>
+            <z-m>0.0710781</z-m>
+        </offsets>
+        <alignment>center-center</alignment>
+        <axis-alignment>yz-plane</axis-alignment>
+        <type type="string">text-value</type>
+        <format type="string">%s</format>
+        <truncate type="bool">false</truncate>
+        <font type="string">helvetica_medium.txf</font>
+        <property>/modes/pfd/fma/pitch-mode</property>
+        <draw-text type="bool">true</draw-text>
+        <draw-alignment type="bool">false</draw-alignment>
+        <draw-boundingbox type="bool">false</draw-boundingbox>
+        <character-size>0.0055</character-size>
+        <font-resolution>
+            <width type="int">32</width>
+            <height type="int">32</height>
+        </font-resolution>
+    </text>
+	
     <text>
         <name>roll-mode-fma</name>
         <offsets>
@@ -1645,35 +1731,6 @@
         </font-resolution>
     </text>
 	
-    <animation>
-        <type>select</type>
-        <object-name>pitch-mode-fma</object-name>
-        <object-name>roll-mode-fma</object-name>
-        <object-name>pitch-mode-armed-fma</object-name>
-        <object-name>pitch-mode-armed2-fma</object-name>
-        <object-name>roll-mode-armed-fma</object-name>
-        <condition>
-			<or>
-				<equals>
-					<property>/it-autoflight/output/ap1</property>
-					<value>1</value>
-				</equals>
-				<equals>
-					<property>/it-autoflight/output/ap2</property>
-					<value>1</value>
-				</equals>
-				<equals>
-					<property>/it-autoflight/output/fd1</property>
-					<value>1</value>
-				</equals>
-				<equals>
-					<property>/it-autoflight/output/fd2</property>
-					<value>1</value>
-				</equals>
-			</or>
-        </condition>
-    </animation>
-	
     <animation>
         <type>select</type>
         <object-name>throttle-mode-box</object-name>
@@ -1724,6 +1781,7 @@
     <animation>
         <type>select</type>
         <object-name>pitch-mode-box</object-name>
+        <object-name>land-mode-box</object-name>
         <condition>
             <equals>
                 <property>/modes/pfd/fma/pitch-mode-box</property>
@@ -3149,6 +3207,7 @@
 		<object-name>mach-value</object-name>
 		<object-name>thrust-mode-fma</object-name>
         <object-name>pitch-mode-fma</object-name>
+        <object-name>land-mode-fma</object-name>
         <object-name>roll-mode-fma</object-name>
 		<object-name>athr-thrlvr-fma</object-name>
 		<diffuse>
diff --git a/Models/Instruments/PFD/PFD2.xml b/Models/Instruments/PFD/PFD2.xml
index 5eb0ac20..57a42e68 100644
--- a/Models/Instruments/PFD/PFD2.xml
+++ b/Models/Instruments/PFD/PFD2.xml
@@ -213,25 +213,87 @@
 		<object-name>pitch-mode-armed-box</object-name>
 		<object-name>roll-mode-box</object-name>
 		<object-name>roll-mode-armed-box</object-name>
+        <object-name>pitch-mode-fma</object-name>
+        <object-name>roll-mode-fma</object-name>
+        <object-name>pitch-mode-armed-fma</object-name>
+        <object-name>pitch-mode-armed2-fma</object-name>
+        <object-name>roll-mode-armed-fma</object-name>
         <condition>
-			<or>
-				<equals>
-					<property>/it-autoflight/output/fd1</property>
-					<value>1</value>
-				</equals>
-				<equals>
-					<property>/it-autoflight/output/fd2</property>
-					<value>1</value>
-				</equals>
-				<equals>
-					<property>/it-autoflight/output/ap1</property>
-					<value>1</value>
-				</equals>
-				<equals>
-					<property>/it-autoflight/output/ap2</property>
-					<value>1</value>
-				</equals>
-			</or>
+			<and>
+				<or>
+					<equals>
+						<property>/it-autoflight/output/fd1</property>
+						<value>1</value>
+					</equals>
+					<equals>
+						<property>/it-autoflight/output/fd2</property>
+						<value>1</value>
+					</equals>
+					<equals>
+						<property>/it-autoflight/output/ap1</property>
+						<value>1</value>
+					</equals>
+					<equals>
+						<property>/it-autoflight/output/ap2</property>
+						<value>1</value>
+					</equals>
+				</or>
+				<not-equals>
+					<property>/modes/pfd/fma/pitch-mode</property>
+					<value>LAND</value>
+				</not-equals>
+				<not-equals>
+					<property>/modes/pfd/fma/pitch-mode</property>
+					<value>FLARE</value>
+				</not-equals>
+				<not-equals>
+					<property>/modes/pfd/fma/pitch-mode</property>
+					<value>ROLLOUT</value>
+				</not-equals>
+			</and>
+        </condition>
+    </animation>
+	
+    <animation>
+        <type>select</type>
+		<object-name>land-mode-box</object-name>
+		<object-name>land-mode-fma</object-name>
+		<object-name>landmask</object-name>
+        <condition>
+			<and>
+				<or>
+					<equals>
+						<property>/it-autoflight/output/fd1</property>
+						<value>1</value>
+					</equals>
+					<equals>
+						<property>/it-autoflight/output/fd2</property>
+						<value>1</value>
+					</equals>
+					<equals>
+						<property>/it-autoflight/output/ap1</property>
+						<value>1</value>
+					</equals>
+					<equals>
+						<property>/it-autoflight/output/ap2</property>
+						<value>1</value>
+					</equals>
+				</or>
+				<or>
+					<equals>
+						<property>/modes/pfd/fma/pitch-mode</property>
+						<value>LAND</value>
+					</equals>
+					<equals>
+						<property>/modes/pfd/fma/pitch-mode</property>
+						<value>FLARE</value>
+					</equals>
+					<equals>
+						<property>/modes/pfd/fma/pitch-mode</property>
+						<value>ROLLOUT</value>
+					</equals>
+				</or>
+			</and>
         </condition>
     </animation>
 	
@@ -1549,6 +1611,30 @@
         </font-resolution>
     </text>
 	
+    <text>
+        <name>land-mode-fma</name>
+        <offsets>
+            <x-m>0.00091828</x-m>
+            <y-m>-0.00521</y-m>
+            <z-m>0.0710781</z-m>
+        </offsets>
+        <alignment>center-center</alignment>
+        <axis-alignment>yz-plane</axis-alignment>
+        <type type="string">text-value</type>
+        <format type="string">%s</format>
+        <truncate type="bool">false</truncate>
+        <font type="string">helvetica_medium.txf</font>
+        <property>/modes/pfd/fma/pitch-mode</property>
+        <draw-text type="bool">true</draw-text>
+        <draw-alignment type="bool">false</draw-alignment>
+        <draw-boundingbox type="bool">false</draw-boundingbox>
+        <character-size>0.0055</character-size>
+        <font-resolution>
+            <width type="int">32</width>
+            <height type="int">32</height>
+        </font-resolution>
+    </text>
+	
     <text>
         <name>roll-mode-fma</name>
         <offsets>
@@ -1645,35 +1731,6 @@
         </font-resolution>
     </text>
 	
-    <animation>
-        <type>select</type>
-        <object-name>pitch-mode-fma</object-name>
-        <object-name>roll-mode-fma</object-name>
-        <object-name>pitch-mode-armed-fma</object-name>
-        <object-name>pitch-mode-armed2-fma</object-name>
-        <object-name>roll-mode-armed-fma</object-name>
-        <condition>
-			<or>
-				<equals>
-					<property>/it-autoflight/output/ap1</property>
-					<value>1</value>
-				</equals>
-				<equals>
-					<property>/it-autoflight/output/ap2</property>
-					<value>1</value>
-				</equals>
-				<equals>
-					<property>/it-autoflight/output/fd1</property>
-					<value>1</value>
-				</equals>
-				<equals>
-					<property>/it-autoflight/output/fd2</property>
-					<value>1</value>
-				</equals>
-			</or>
-        </condition>
-    </animation>
-	
     <animation>
         <type>select</type>
         <object-name>throttle-mode-box</object-name>
@@ -1724,6 +1781,7 @@
     <animation>
         <type>select</type>
         <object-name>pitch-mode-box</object-name>
+        <object-name>land-mode-box</object-name>
         <condition>
             <equals>
                 <property>/modes/pfd/fma/pitch-mode-box</property>
@@ -3149,6 +3207,7 @@
 		<object-name>mach-value</object-name>
 		<object-name>thrust-mode-fma</object-name>
         <object-name>pitch-mode-fma</object-name>
+        <object-name>land-mode-fma</object-name>
         <object-name>roll-mode-fma</object-name>
 		<object-name>athr-thrlvr-fma</object-name>
 		<diffuse>
diff --git a/Models/Instruments/PFD/res/pfd-3d.ac b/Models/Instruments/PFD/res/pfd-3d.ac
index 9d986582..1104c871 100644
--- a/Models/Instruments/PFD/res/pfd-3d.ac
+++ b/Models/Instruments/PFD/res/pfd-3d.ac
@@ -1,8 +1,63 @@
 AC3Db
 MATERIAL "ac3dmat1" rgb 1 1 1  amb 0 0 0  emis 0.658824 0.670588 0.67451  spec 0 0 0  shi 128  trans 0
 MATERIAL "white" rgb 1 1 1  amb 1 1 1  emis 0.798 0.798 0.798  spec 0 0 0  shi 0  trans 0
+MATERIAL "ac3dmat0" rgb 0 0 0  amb 0 0 0  emis 0 0 0  spec 0 0 0  shi 0  trans 0
 OBJECT world
-kids 44
+kids 46
+OBJECT poly
+name "land-mode-box"
+loc 0.000386977 0.0698612 0.00523137
+data 6
+Circle
+texture "box.png"
+crease 30.000000
+numvert 16
+0 -0.00244377 -0.0145566
+0 -0.00244377 -0.0151633
+0 0.004665 -0.0151633
+0 0.004665 -0.0145566
+0 -0.00248282 0.0151633
+0 -0.00248282 0.0145566
+0 0.00462595 0.0145566
+0 0.00462595 0.0151633
+0 0.00457313 0.0145165
+0 0.00396641 0.0145165
+0 0.00396641 -0.0144955
+0 0.00457313 -0.0144955
+0 -0.00181733 0.0144925
+0 -0.00242404 0.0144925
+0 -0.00242402 -0.0145195
+0 -0.00181732 -0.0145195
+numsurf 4
+SURF 0x0
+mat 1
+refs 4
+0 0.654297 0.439453
+1 0.679687 0.439453
+2 0.679687 0.464844
+3 0.654297 0.464844
+SURF 0x0
+mat 1
+refs 4
+4 0.654297 0.439453
+5 0.679687 0.439453
+6 0.679687 0.464844
+7 0.654297 0.464844
+SURF 0x0
+mat 1
+refs 4
+8 0.654297 0.439453
+9 0.679687 0.439453
+10 0.679687 0.464844
+11 0.654297 0.464844
+SURF 0x0
+mat 1
+refs 4
+12 0.654297 0.439453
+13 0.679687 0.439453
+14 0.679687 0.464844
+15 0.654297 0.464844
+kids 0
 OBJECT poly
 name "target-alt-mng"
 loc 0.000960576 -0.000264099 -0.0431903
@@ -1141,3 +1196,21 @@ refs 4
 1 0.762653 0.461267
 0 0.510324 0.461267
 kids 0
+OBJECT poly
+name "landmask"
+loc 0.000382955 0.0654851 0.00520964
+crease 45.000000
+numvert 4
+0 -0.0115399 -0.00100451
+0 -0.0115399 0.00100451
+0 0.0115399 0.00100451
+0 0.0115399 -0.00100451
+numsurf 1
+SURF 0x30
+mat 2
+refs 4
+3 1 1
+2 0 1
+1 0 0
+0 1 0
+kids 0
diff --git a/Nasal/FMGC-b.nas b/Nasal/FMGC-b.nas
index d5cc4f4d..cda685e5 100644
--- a/Nasal/FMGC-b.nas
+++ b/Nasal/FMGC-b.nas
@@ -353,7 +353,6 @@ var vertical = func {
 		thrustmode();
 	} else if (vertset == 6) {
 		setprop("/it-autoflight/output/vert", 6);
-		setprop("/it-autoflight/mode/vert", "LAND");
 		setprop("/it-autoflight/mode/arm", " ");
 		thrustmode();
 		mng_sys_stop();
@@ -629,6 +628,9 @@ var thrustmode = func {
 	var calt = getprop("/instrumentation/altimeter/indicated-altitude-ft");
 	var alt = getprop("/it-autoflight/internal/alt");
 	var vertm = getprop("/it-autoflight/output/vert");
+	var gearagl = getprop("/position/gear-agl-ft");
+	var ap1 = getprop("/it-autoflight/output/ap1");
+	var ap2 = getprop("/it-autoflight/output/ap2");
 	if (vertm == 4) {
 		if (calt < alt) {
 			setprop("/it-autoflight/output/thr-mode", 2);
@@ -724,19 +726,27 @@ var make_appr_active = func {
 
 # Autoland Stage 1 Logic (Land)
 var aland = func {
-	var ap1 = getprop("/it-autoflight/output/ap1");
-	var ap2 = getprop("/it-autoflight/output/ap2");
+	if (getprop("/position/gear-agl-ft") <= 300) {
+		setprop("/it-autoflight/mode/vert", "LAND");
+	}
 	if (getprop("/position/gear-agl-ft") <= 100) {
-		setprop("/it-autoflight/input/lat", 4);
 		setprop("/it-autoflight/input/vert", 6);
 	}
 }
 
 var aland1 = func {
 	var aglal = getprop("/position/gear-agl-ft");
+	if (aglal <= 80 and aglal > 5) {
+		setprop("/it-autoflight/input/lat", 4);
+	}
 	if (aglal <= 50 and aglal > 5) {
 		setprop("/it-autoflight/mode/vert", "FLARE");
 	}
+	if (aglal <= 18 and aglal > 5) {
+		thrustmodet.stop();
+		setprop("/it-autoflight/output/thr-mode", 1);
+		setprop("/it-autoflight/mode/thr", "RETARD");
+	}
 	var gear1 = getprop("/gear/gear[1]/wow");
 	var gear2 = getprop("/gear/gear[2]/wow");
 	if (gear1 == 1 or gear2 == 1) {
diff --git a/Nasal/PFD_FMA.nas b/Nasal/PFD_FMA.nas
index 2cdb4963..17be541c 100644
--- a/Nasal/PFD_FMA.nas
+++ b/Nasal/PFD_FMA.nas
@@ -6,7 +6,7 @@ setprop("/it-autoflight/internal/alt", 10000);
 
 # Speed or Mach?
 var speedmach = func {
-	if ((getprop("/it-autoflight/output/vert") == 4) or (getprop("/it-autoflight/output/vert") == 7) or (getprop("/it-autoflight/output/vert") == 8)) {
+	if ((getprop("/it-autoflight/output/vert") == 4) or (getprop("/it-autoflight/output/vert") == 6) or (getprop("/it-autoflight/output/vert") == 7) or (getprop("/it-autoflight/output/vert") == 8)) {
 		if (getprop("/it-autoflight/output/fd1") == 0 and getprop("/it-autoflight/output/fd2") == 0 and getprop("/it-autoflight/output/ap1") == 0 and getprop("/it-autoflight/output/ap2") == 0) {
 			speedmach_b();
 		} else {
diff --git a/Systems/fmgc-b.xml b/Systems/fmgc-b.xml
index fac4aac2..c5e0c5f9 100644
--- a/Systems/fmgc-b.xml
+++ b/Systems/fmgc-b.xml
@@ -114,9 +114,9 @@
                     <entry><ind> 50</ind><dep>-500</dep></entry>
                     <entry><ind> 40</ind><dep>-400</dep></entry>
                     <entry><ind> 30</ind><dep>-300</dep></entry>
-                    <entry><ind> 20</ind><dep>-200</dep></entry>
-                    <entry><ind> 10</ind><dep>-150</dep></entry>
-                    <entry><ind>  5</ind><dep>-100</dep></entry>
+                    <entry><ind> 20</ind><dep>-180</dep></entry>
+                    <entry><ind> 10</ind><dep>-100</dep></entry>
+                    <entry><ind>  5</ind><dep> -70</dep></entry>
                 </table>
             </expression>
         </input>