From 4a35fa861c881c9d5174467b7041b081146fcc0c Mon Sep 17 00:00:00 2001
From: Joshua Davidson <joshuadavidson2000@gmail.com>
Date: Sun, 31 Dec 2017 09:06:20 -0500
Subject: [PATCH] A32X: Randomize DU Test times

---
 Models/Instruments/Lower-ECAM/Lower-ECAM.nas |  7 +++++--
 Models/Instruments/ND/canvas/ND.nas          | 18 ++++++++++++------
 Models/Instruments/PFD/PFD.nas               | 19 ++++++++++++-------
 Models/Instruments/Upper-ECAM/Upper-ECAM.nas |  7 +++++--
 revision.txt                                 |  2 +-
 5 files changed, 35 insertions(+), 18 deletions(-)

diff --git a/Models/Instruments/Lower-ECAM/Lower-ECAM.nas b/Models/Instruments/Lower-ECAM/Lower-ECAM.nas
index 0e66cbfb..ae38b4a8 100644
--- a/Models/Instruments/Lower-ECAM/Lower-ECAM.nas
+++ b/Models/Instruments/Lower-ECAM/Lower-ECAM.nas
@@ -65,6 +65,7 @@ setprop("/controls/flight/spoiler-r4-failed", 0);
 setprop("/controls/flight/spoiler-r5-failed", 0);
 setprop("/instrumentation/du/du4-test", 0);
 setprop("/instrumentation/du/du4-test-time", 0);
+setprop("/instrumentation/du/du4-test-amount", 0);
 
 var canvas_lowerECAM_base = {
 	init: func(canvas_group, file) {
@@ -91,17 +92,19 @@ var canvas_lowerECAM_base = {
 		if (getprop("/systems/electrical/bus/ac2") >= 110) {
 			if (getprop("/systems/acconfig/autoconfig-running") != 1 and getprop("/instrumentation/du/du4-test") != 1) {
 				setprop("/instrumentation/du/du4-test", 1);
+				setprop("/instrumentation/du/du4-test-amount", math.round((rand() * 5 ) + 35, 0.1));
 				setprop("/instrumentation/du/du4-test-time", getprop("/sim/time/elapsed-sec"));
 			} else if (getprop("/systems/acconfig/autoconfig-running") == 1 and getprop("/instrumentation/du/du4-test") != 1) {
 				setprop("/instrumentation/du/du4-test", 1);
-				setprop("/instrumentation/du/du4-test-time", getprop("/sim/time/elapsed-sec") - 35);
+				setprop("/instrumentation/du/du4-test-amount", math.round((rand() * 5 ) + 35, 0.1));
+				setprop("/instrumentation/du/du4-test-time", getprop("/sim/time/elapsed-sec") - 30);
 			}
 		} else if (getprop("/systems/electrical/ac1-src") == "XX" or getprop("/systems/electrical/ac2-src") == "XX") {
 			setprop("/instrumentation/du/du4-test", 0);
 		}
 		
 		if (getprop("/systems/electrical/bus/ac2") >= 110 and getprop("/controls/lighting/DU/du4") > 0) {
-			if (getprop("/instrumentation/du/du4-test-time") + 40 >= elapsedtime) {
+			if (getprop("/instrumentation/du/du4-test-time") + getprop("/instrumentation/du/du4-test-amount") >= elapsedtime) {
 				lowerECAM_apu.page.hide();
 				lowerECAM_eng.page.hide();
 				lowerECAM_fctl.page.hide();
diff --git a/Models/Instruments/ND/canvas/ND.nas b/Models/Instruments/ND/canvas/ND.nas
index 31bcd00f..f23feb85 100644
--- a/Models/Instruments/ND/canvas/ND.nas
+++ b/Models/Instruments/ND/canvas/ND.nas
@@ -17,8 +17,10 @@ var ND_2_test = nil;
 var elapsedtime = 0;
 setprop("/instrumentation/du/du2-test", 0);
 setprop("/instrumentation/du/du2-test-time", 0);
+setprop("/instrumentation/du/du2-test-amount", 0);
 setprop("/instrumentation/du/du5-test", 0);
 setprop("/instrumentation/du/du5-test-time", 0);
+setprop("/instrumentation/du/du5-test-amount", 0);
 
 var nd_display = {};
 
@@ -79,10 +81,12 @@ var canvas_nd_base = {
 		if (getprop("/systems/electrical/bus/ac-ess-shed") >= 110) {
 			if (getprop("/systems/acconfig/autoconfig-running") != 1 and getprop("/instrumentation/du/du2-test") != 1) {
 				setprop("/instrumentation/du/du2-test", 1);
+				setprop("/instrumentation/du/du2-test-amount", math.round((rand() * 5 ) + 35, 0.1));
 				setprop("/instrumentation/du/du2-test-time", getprop("/sim/time/elapsed-sec"));
 			} else if (getprop("/systems/acconfig/autoconfig-running") == 1 and getprop("/instrumentation/du/du2-test") != 1) {
 				setprop("/instrumentation/du/du2-test", 1);
-				setprop("/instrumentation/du/du2-test-time", getprop("/sim/time/elapsed-sec") - 35);
+				setprop("/instrumentation/du/du2-test-amount", math.round((rand() * 5 ) + 35, 0.1));
+				setprop("/instrumentation/du/du2-test-time", getprop("/sim/time/elapsed-sec") - 30);
 			}
 		} else {
 			setprop("/instrumentation/du/du2-test", 0);
@@ -90,20 +94,22 @@ var canvas_nd_base = {
 		if (getprop("/systems/electrical/bus/ac2") >= 110) {
 			if (getprop("/systems/acconfig/autoconfig-running") != 1 and getprop("/instrumentation/du/du5-test") != 1) {
 				setprop("/instrumentation/du/du5-test", 1);
+				setprop("/instrumentation/du/du5-test-amount", math.round((rand() * 5 ) + 35, 0.1));
 				setprop("/instrumentation/du/du5-test-time", getprop("/sim/time/elapsed-sec"));
 			} else if (getprop("/systems/acconfig/autoconfig-running") == 1 and getprop("/instrumentation/du/du5-test") != 1) {
 				setprop("/instrumentation/du/du5-test", 1);
-				setprop("/instrumentation/du/du5-test-time", getprop("/sim/time/elapsed-sec") - 35);
+				setprop("/instrumentation/du/du5-test-amount", math.round((rand() * 5 ) + 35, 0.1));
+				setprop("/instrumentation/du/du5-test-time", getprop("/sim/time/elapsed-sec") - 30);
 			}
 		} else {
 			setprop("/instrumentation/du/du5-test", 0);
 		}
 		
 		if (getprop("/systems/electrical/bus/ac-ess-shed") >= 110 and getprop("/controls/lighting/DU/du2") > 0) {
-			if (getprop("/instrumentation/du/du2-test-time") + 38.5 >= elapsedtime and getprop("/modes/cpt-du-xfr") != 1) {
+			if (getprop("/instrumentation/du/du2-test-time") + getprop("/instrumentation/du/du2-test-amount") >= elapsedtime and getprop("/modes/cpt-du-xfr") != 1) {
 				ND_1.page.hide();
 				ND_1_test.page.show();
-			} else if (getprop("/instrumentation/du/du1-test-time") + 39.5 >= elapsedtime and getprop("/modes/cpt-du-xfr") == 1) {
+			} else if (getprop("/instrumentation/du/du1-test-time") + getprop("/instrumentation/du/du1-test-amount") >= elapsedtime and getprop("/modes/cpt-du-xfr") == 1) {
 				ND_1.page.hide();
 				ND_1_test.page.show();
 			} else {
@@ -116,10 +122,10 @@ var canvas_nd_base = {
 			ND_1.page.hide();
 		}
 		if (getprop("/systems/electrical/bus/ac2") >= 110 and getprop("/controls/lighting/DU/du5") > 0) {
-			if (getprop("/instrumentation/du/du5-test-time") + 38.5 >= elapsedtime and getprop("/modes/fo-du-xfr") != 1) {
+			if (getprop("/instrumentation/du/du5-test-time") + getprop("/instrumentation/du/du6-test-amount") >= elapsedtime and getprop("/modes/fo-du-xfr") != 1) {
 				ND_2.page.hide();
 				ND_2_test.page.show();
-			} else if (getprop("/instrumentation/du/du6-test-time") + 39.5 >= elapsedtime and getprop("/modes/fo-du-xfr") == 1) {
+			} else if (getprop("/instrumentation/du/du6-test-time") + getprop("/instrumentation/du/du5-test-amount") >= elapsedtime and getprop("/modes/fo-du-xfr") == 1) {
 				ND_2.page.hide();
 				ND_2_test.page.show();
 			} else {
diff --git a/Models/Instruments/PFD/PFD.nas b/Models/Instruments/PFD/PFD.nas
index d8b28561..ce51e7dd 100644
--- a/Models/Instruments/PFD/PFD.nas
+++ b/Models/Instruments/PFD/PFD.nas
@@ -59,8 +59,10 @@ setprop("/instrumentation/pfd/track-hdg-diff", 0);
 setprop("/instrumentation/pfd/speed-lookahead", 0);
 setprop("/instrumentation/du/du1-test", 0);
 setprop("/instrumentation/du/du1-test-time", 0);
+setprop("/instrumentation/du/du1-test-amount", 0);
 setprop("/instrumentation/du/du6-test", 0);
 setprop("/instrumentation/du/du6-test-time", 0);
+setprop("/instrumentation/du/du6-test-amount", 0);
 setprop("/it-autoflight/internal/vert-speed-fpm-pfd", 0);
 setprop("/position/gear-agl-ft", 0);
 setprop("/controls/flight/aileron-input-fast", 0);
@@ -73,7 +75,6 @@ setprop("/instrumentation/adirs/ir[1]/aligned", 0);
 setprop("/instrumentation/adirs/ir[2]/aligned", 0);
 setprop("/controls/switching/ATTHDG", 0);
 setprop("/controls/switching/AIRDATA", 0);
-setprop("/testing", 0);
 
 var canvas_PFD_base = {
 	init: func(canvas_group, file) {
@@ -136,10 +137,12 @@ var canvas_PFD_base = {
 		if (getprop("/systems/electrical/bus/ac-ess") >= 110) {
 			if (getprop("/systems/acconfig/autoconfig-running") != 1 and getprop("/instrumentation/du/du1-test") != 1) {
 				setprop("/instrumentation/du/du1-test", 1);
+				setprop("/instrumentation/du/du1-test-amount", math.round((rand() * 5 ) + 35, 0.1));
 				setprop("/instrumentation/du/du1-test-time", getprop("/sim/time/elapsed-sec"));
 			} else if (getprop("/systems/acconfig/autoconfig-running") == 1 and getprop("/instrumentation/du/du1-test") != 1) {
 				setprop("/instrumentation/du/du1-test", 1);
-				setprop("/instrumentation/du/du1-test-time", getprop("/sim/time/elapsed-sec") - 35);
+				setprop("/instrumentation/du/du1-test-amount", math.round((rand() * 5 ) + 35, 0.1));
+				setprop("/instrumentation/du/du1-test-time", getprop("/sim/time/elapsed-sec") - 30);
 			}
 		} else {
 			setprop("/instrumentation/du/du1-test", 0);
@@ -147,20 +150,22 @@ var canvas_PFD_base = {
 		if (getprop("/systems/electrical/bus/ac2") >= 110) {
 			if (getprop("/systems/acconfig/autoconfig-running") != 1 and getprop("/instrumentation/du/du6-test") != 1) {
 				setprop("/instrumentation/du/du6-test", 1);
+				setprop("/instrumentation/du/du6-test-amount", math.round((rand() * 5 ) + 35, 0.1));
 				setprop("/instrumentation/du/du6-test-time", getprop("/sim/time/elapsed-sec"));
 			} else if (getprop("/systems/acconfig/autoconfig-running") == 1 and getprop("/instrumentation/du/du6-test") != 1) {
 				setprop("/instrumentation/du/du6-test", 1);
-				setprop("/instrumentation/du/du6-test-time", getprop("/sim/time/elapsed-sec") - 35);
+				setprop("/instrumentation/du/du6-test-amount", math.round((rand() * 5 ) + 35, 0.1));
+				setprop("/instrumentation/du/du6-test-time", getprop("/sim/time/elapsed-sec") - 30);
 			}
 		} else {
 			setprop("/instrumentation/du/du6-test", 0);
 		}
 		
 		if (getprop("/systems/electrical/bus/ac-ess") >= 110 and getprop("/controls/lighting/DU/du1") > 0) {
-			if (getprop("/instrumentation/du/du1-test-time") + 39.5 >= elapsedtime and getprop("/modes/cpt-du-xfr") != 1) {
+			if (getprop("/instrumentation/du/du1-test-time") + getprop("/instrumentation/du/du1-test-amount") >= elapsedtime and getprop("/modes/cpt-du-xfr") != 1) {
 				PFD_1.page.hide();
 				PFD_1_test.page.show();
-			} else if (getprop("/instrumentation/du/du2-test-time") + 38.5 >= elapsedtime and getprop("/modes/cpt-du-xfr") == 1) {
+			} else if (getprop("/instrumentation/du/du2-test-time") + getprop("/instrumentation/du/du2-test-amount") >= elapsedtime and getprop("/modes/cpt-du-xfr") == 1) {
 				PFD_1.page.hide();
 				PFD_1_test.page.show();
 			} else {
@@ -173,10 +178,10 @@ var canvas_PFD_base = {
 			PFD_1.page.hide();
 		}
 		if (getprop("/systems/electrical/bus/ac2") >= 110 and getprop("/controls/lighting/DU/du6") > 0) {
-			if (getprop("/instrumentation/du/du6-test-time") + 39.5 >= elapsedtime and getprop("/modes/fo-du-xfr") != 1) {
+			if (getprop("/instrumentation/du/du6-test-time") + getprop("/instrumentation/du/du6-test-amount") >= elapsedtime and getprop("/modes/fo-du-xfr") != 1) {
 				PFD_2.page.hide();
 				PFD_2_test.page.show();
-			} else if (getprop("/instrumentation/du/du5-test-time") + 38.5 >= elapsedtime and getprop("/modes/fo-du-xfr") == 1) {
+			} else if (getprop("/instrumentation/du/du5-test-time") + getprop("/instrumentation/du/du5-test-amount") >= elapsedtime and getprop("/modes/fo-du-xfr") == 1) {
 				PFD_2.page.hide();
 				PFD_2_test.page.show();
 			} else {
diff --git a/Models/Instruments/Upper-ECAM/Upper-ECAM.nas b/Models/Instruments/Upper-ECAM/Upper-ECAM.nas
index 577cbf84..8282f3a6 100644
--- a/Models/Instruments/Upper-ECAM/Upper-ECAM.nas
+++ b/Models/Instruments/Upper-ECAM/Upper-ECAM.nas
@@ -26,6 +26,7 @@ setprop("/ECAM/Upper/N1thr[1]", 0);
 setprop("/ECAM/Upper/N1ylim", 0);
 setprop("/instrumentation/du/du3-test", 0);
 setprop("/instrumentation/du/du3-test-time", 0);
+setprop("/instrumentation/du/du3-test-amount", 0);
 
 var canvas_upperECAM_base = {
 	init: func(canvas_group, file) {
@@ -52,17 +53,19 @@ var canvas_upperECAM_base = {
 		if (getprop("/systems/electrical/bus/ac-ess") >= 110) {
 			if (getprop("/systems/acconfig/autoconfig-running") != 1 and getprop("/instrumentation/du/du3-test") != 1) {
 				setprop("/instrumentation/du/du3-test", 1);
+				setprop("/instrumentation/du/du3-test-amount", math.round((rand() * 5 ) + 35, 0.1));
 				setprop("/instrumentation/du/du3-test-time", getprop("/sim/time/elapsed-sec"));
 			} else if (getprop("/systems/acconfig/autoconfig-running") == 1 and getprop("/instrumentation/du/du3-test") != 1) {
 				setprop("/instrumentation/du/du3-test", 1);
-				setprop("/instrumentation/du/du3-test-time", getprop("/sim/time/elapsed-sec") - 35);
+				setprop("/instrumentation/du/du3-test-amount", math.round((rand() * 5 ) + 35, 0.1));
+				setprop("/instrumentation/du/du3-test-time", getprop("/sim/time/elapsed-sec") - 30);
 			}
 		} else {
 			setprop("/instrumentation/du/du3-test", 0);
 		}
 		
 		if (getprop("/systems/electrical/bus/ac-ess") >= 110 and getprop("/controls/lighting/DU/du3") > 0) {
-			if (getprop("/instrumentation/du/du3-test-time") + 39 >= elapsedtime) {
+			if (getprop("/instrumentation/du/du3-test-time") + getprop("/instrumentation/du/du3-test-amount") >= elapsedtime) {
 				upperECAM_cfm_eis2.page.hide();
 				upperECAM_iae_eis2.page.hide();
 				upperECAM_test.page.show();
diff --git a/revision.txt b/revision.txt
index a266a87e..35d9e748 100644
--- a/revision.txt
+++ b/revision.txt
@@ -1 +1 @@
-4213
\ No newline at end of file
+4214
\ No newline at end of file