2017-07-07 14:32:39 +00:00
# A3XX Fire System
# Jonathan Redpath
2019-01-01 06:03:06 +00:00
# Copyright (c) 2019 Joshua Davidson (it0uchpods)
2017-07-13 17:30:33 +00:00
2017-07-07 14:32:39 +00:00
#############
# Init Vars #
#############
2018-09-29 23:48:17 +00:00
var level = 0;
var fwdsquib = 0;
var aftsquib = 0;
var fwddet = 0;
var aftdet = 0;
var test = 0;
var guard1 = 0;
var guard2 = 0;
var dischpb1 = 0;
var dischpb2 = 0;
var smokedet1 = 0;
var smokedet2 = 0;
var bottleIsEmpty = 0;
var WeCanExt = 0;
var test2 = 0;
var state = 0;
var dc1 = 0;
var dc2 = 0;
var dcbat = 0;
var pause = 0;
2019-04-15 18:58:54 +00:00
var et = 0;
var elapsedTime = props.globals.getNode("/sim/time/elapsed-sec");
var apuTestBtn = props.globals.getNode("/controls/fire/apu-test-btn", 1);
2019-04-17 16:40:49 +00:00
var testBtn = props.globals.getNode("/controls/fire/test-btn-1", 1);
var testBtn2 = props.globals.getNode("/controls/fire/test-btn-2", 1);
2019-04-15 18:58:54 +00:00
var eng1FireWarn = props.globals.initNode("/systems/fire/engine1/warning-active", 0, "BOOL");
var eng2FireWarn = props.globals.initNode("/systems/fire/engine2/warning-active", 0, "BOOL");
var apuFireWarn = props.globals.initNode("/systems/fire/apu/warning-active", 0, "BOOL");
2019-04-22 19:56:31 +00:00
var eng1AgentTimer = props.globals.initNode("/systems/fire/engine1/agent-timer", 0, "INT");
var eng2AgentTimer = props.globals.initNode("/systems/fire/engine2/agent-timer", 0, "INT");
var apuAgentTimer = props.globals.initNode("/systems/fire/apu/agent-timer", 0, "INT");
2019-04-15 18:58:54 +00:00
var wow = props.globals.getNode("/fdm/jsbsim/position/wow", 1);
var dcbatNode = props.globals.getNode("systems/electrical/bus/dcbat", 1);
var dcessNode = props.globals.getNode("systems/electrical/bus/dc-ess", 1);
2019-04-22 19:56:31 +00:00
var apuBleedNode = props.globals.getNode("/systems/apu/bleed-used", 1);
var apuMaster = props.globals.getNode("/controls/APU/master", 1);
2017-07-11 18:52:21 +00:00
2017-07-07 14:32:39 +00:00
var fire_init = func {
2017-09-21 17:03:32 +00:00
setprop("/controls/OH/protectors/fwddisch", 0);
setprop("/controls/OH/protectors/aftdisch", 0);
2017-09-21 19:07:54 +00:00
setprop("/systems/failures/cargo-fwd-fire", 0);
setprop("/systems/failures/cargo-aft-fire", 0);
2017-07-07 14:32:39 +00:00
setprop("/systems/fire/cargo/fwdsquib", 0);
setprop("/systems/fire/cargo/aftsquib", 0);
setprop("/systems/fire/cargo/bottlelevel", 100);
setprop("/systems/fire/cargo/test", 0);
setprop("/controls/fire/cargo/test", 0);
setprop("/controls/fire/cargo/fwddisch", 0); # pushbutton
setprop("/controls/fire/cargo/aftdisch", 0);
setprop("/controls/fire/cargo/fwddischLight", 0);
setprop("/controls/fire/cargo/aftdischLight", 0);
setprop("/controls/fire/cargo/fwdsmokeLight", 0);
setprop("/controls/fire/cargo/aftsmokeLight", 0);
setprop("/controls/fire/cargo/bottleempty", 0);
# status: 1 is ready, 0 is already disch
setprop("/controls/fire/cargo/status", 1);
setprop("/controls/fire/cargo/warnfwd", 0);
setprop("/controls/fire/cargo/warnaft", 0);
setprop("/controls/fire/cargo/squib1fault", 0);
setprop("/controls/fire/cargo/squib2fault", 0);
setprop("/controls/fire/cargo/detfault", 0);
setprop("/controls/fire/cargo/test/state", 0);
fire_timer.start();
}
##############
# Main Loops #
##############
2017-07-07 14:44:39 +00:00
var master_fire = func {
2017-07-11 18:52:21 +00:00
level = getprop("/systems/fire/cargo/bottlelevel");
fwdsquib = getprop("/systems/fire/cargo/fwdsquib");
aftsquib = getprop("/systems/fire/cargo/aftsquib");
2017-09-21 19:07:54 +00:00
fwddet = getprop("/systems/failures/cargo-fwd-fire");
aftdet = getprop("/systems/failures/cargo-aft-fire");
2017-07-11 18:52:21 +00:00
test = getprop("/controls/fire/cargo/test");
guard1 = getprop("/controls/fire/cargo/fwdguard");
guard2 = getprop("/controls/fire/cargo/aftguard");
dischpb1 = getprop("/controls/fire/cargo/fwddisch");
dischpb2 = getprop("/controls/fire/cargo/aftdisch");
smokedet1 = getprop("/controls/fire/cargo/fwdsmokeLight");
smokedet2 = getprop("/controls/fire/cargo/aftsmokeLight");
bottleIsEmpty = getprop("/controls/fire/cargo/bottleempty");
WeCanExt = getprop("/controls/fire/cargo/status");
test2 = getprop("/systems/fire/cargo/test");
state = getprop("/controls/fire/cargo/test/state");
dc1 = getprop("/systems/electrical/bus/dc1");
dc2 = getprop("/systems/electrical/bus/dc2");
2019-04-15 18:58:54 +00:00
dcbat = dcbatNode.getValue();
2017-07-11 18:52:21 +00:00
pause = getprop("/sim/freeze/master");
2017-07-07 14:32:39 +00:00
###############
# Discharging #
###############
if (dischpb1) {
if (WeCanExt == 1 and !fwdsquib and !bottleIsEmpty and (dc1 > 0 or dc2 > 0 or dcbat > 0)) {
setprop("/systems/fire/cargo/fwdsquib", 1);
}
}
2017-07-11 18:52:21 +00:00
if (dischpb1 and fwdsquib and !bottleIsEmpty and !pause) {
2017-09-21 17:03:32 +00:00
setprop("/systems/fire/cargo/bottlelevel", getprop("/systems/fire/cargo/bottlelevel") - 0.33);
2017-07-07 14:32:39 +00:00
}
if (dischpb2) {
if (WeCanExt == 1 and !aftsquib and !bottleIsEmpty and (dc1 > 0 or dc2 > 0 or dcbat > 0)) {
setprop("/systems/fire/cargo/aftsquib", 1);
}
2017-09-21 17:03:32 +00:00
}
if (dischpb2 and aftsquib and !bottleIsEmpty and !pause) {
setprop("/systems/fire/cargo/bottlelevel", getprop("/systems/fire/cargo/bottlelevel") - 0.33);
2017-07-07 14:32:39 +00:00
}
#################
# Test Sequence #
#################
2017-08-07 14:57:31 +00:00
if (test) {
2017-07-11 18:52:21 +00:00
setprop("/systems/fire/cargo/test", 1);
} else {
setprop("/systems/fire/cargo/test", 0);
}
2017-07-07 14:32:39 +00:00
if (test2 and state == 0) {
2017-10-16 14:07:32 +00:00
setprop("/controls/fire/cargo/fwddischLight", 1);
setprop("/controls/fire/cargo/aftdischLight", 1);
2017-07-11 18:52:21 +00:00
settimer(func(){
2017-10-16 14:07:32 +00:00
setprop("/controls/fire/cargo/fwddischLight", 0);
setprop("/controls/fire/cargo/aftdischLight", 0);
2017-07-11 18:52:21 +00:00
setprop("/controls/fire/cargo/test/state", 1);
2017-10-16 14:07:32 +00:00
}, 5);
2017-07-07 14:32:39 +00:00
} else if (test2 and state == 1) {
2017-10-16 14:07:32 +00:00
setprop("/controls/fire/cargo/fwdsmokeLight", 1);
setprop("/controls/fire/cargo/warnfwd", 1);
2017-07-07 14:32:39 +00:00
setprop("/controls/fire/cargo/aftsmokeLight", 1);
setprop("/controls/fire/cargo/warnaft", 1);
settimer(func(){
2017-10-16 14:07:32 +00:00
setprop("/controls/fire/cargo/fwdsmokeLight", 0);
2017-07-07 14:32:39 +00:00
setprop("/controls/fire/cargo/aftsmokeLight", 0);
2017-10-16 14:07:32 +00:00
setprop("/controls/fire/cargo/warnfwd", 0);
2017-07-07 14:32:39 +00:00
setprop("/controls/fire/cargo/warnaft", 0);
setprop("/controls/fire/cargo/test/state", 2);
2017-10-16 14:07:32 +00:00
}, 5);
} else if (test2 and state == 2) {
2017-09-21 17:03:32 +00:00
settimer(func(){
setprop("/controls/fire/cargo/test/state", 3);
2017-10-16 14:07:32 +00:00
}, 5);
2017-09-21 17:03:32 +00:00
} else if (test2 and state == 3) {
2017-10-16 14:07:32 +00:00
setprop("/controls/fire/cargo/fwdsmokeLight", 1);
setprop("/controls/fire/cargo/warnfwd", 1);
2017-09-21 17:03:32 +00:00
setprop("/controls/fire/cargo/aftsmokeLight", 1);
setprop("/controls/fire/cargo/warnaft", 1);
settimer(func(){
2017-10-16 14:07:32 +00:00
setprop("/controls/fire/cargo/fwdsmokeLight", 0);
2017-09-21 17:03:32 +00:00
setprop("/controls/fire/cargo/aftsmokeLight", 0);
2017-10-16 14:07:32 +00:00
setprop("/controls/fire/cargo/warnfwd", 0);
2017-09-21 17:03:32 +00:00
setprop("/controls/fire/cargo/warnaft", 0);
2017-07-07 14:32:39 +00:00
setprop("/systems/fire/cargo/test", 0);
2017-07-07 14:44:39 +00:00
setprop("/controls/fire/cargo/test", 0);
2017-07-07 14:32:39 +00:00
setprop("/controls/fire/cargo/test/state", 0);
2017-10-16 14:07:32 +00:00
}, 5);
2017-07-07 14:32:39 +00:00
}
##########
# Status #
##########
2017-09-21 17:03:32 +00:00
if (level < 0.1 and !test) {
2017-07-07 14:32:39 +00:00
setprop("/controls/fire/cargo/bottleempty", 1);
setprop("/controls/fire/cargo/status", 0);
setprop("/controls/fire/cargo/fwddischLight", 1);
setprop("/controls/fire/cargo/aftdischLight", 1);
2017-09-21 17:03:32 +00:00
} else if (!test) {
2017-07-07 14:32:39 +00:00
setprop("/controls/fire/cargo/bottleempty", 0);
setprop("/controls/fire/cargo/status", 1);
setprop("/controls/fire/cargo/fwddischLight", 0);
setprop("/controls/fire/cargo/aftdischLight", 0);
}
}
2019-01-22 11:16:54 +00:00
###################
# Detection Logic #
###################
setlistener("/systems/failures/cargo-fwd-fire", func() {
if (getprop("/systems/failures/cargo-fwd-fire")) {
setprop("/controls/fire/cargo/fwdsmokeLight", 1);
setprop("/controls/fire/cargo/warnfwd", 1);
} else {
setprop("/controls/fire/cargo/fwdsmokeLight", 0);
}
2019-04-15 18:58:54 +00:00
}, 0, 0);
2019-01-22 11:16:54 +00:00
setlistener("/systems/failures/cargo-aft-fire", func() {
if (getprop("/systems/failures/cargo-aft-fire")) {
setprop("/controls/fire/cargo/aftsmokeLight", 1);
setprop("/controls/fire/cargo/warnaft", 1);
} else {
setprop("/controls/fire/cargo/aftsmokeLight", 0);
}
2019-04-15 18:58:54 +00:00
}, 0, 0);
###################
# Engine Fire #
###################
var engFireDetectorUnit = {
sys: 0,
active: 0,
loopOne: 0,
loopTwo: 0,
condition: 100,
2019-04-19 16:40:20 +00:00
wow: "",
2019-04-15 18:58:54 +00:00
new: func(sys) {
var eF = {parents:[engFireDetectorUnit]};
eF.sys = sys;
eF.active = 0;
eF.loopOne = 0;
eF.loopTwo = 0;
2019-04-19 16:40:20 +00:00
eF.wow = props.globals.getNode("/fdm/jsbsim/position/wow", 1);
2019-04-15 18:58:54 +00:00
return eF;
},
update: func() {
2019-04-19 16:40:20 +00:00
if (me.condition == 0) { return; }
2019-04-15 18:58:54 +00:00
foreach(var detector; detectorLoops.vector) {
detector.updateTemp(detector.sys, detector.type);
}
2019-04-16 16:43:36 +00:00
if ((me.loopOne == 1 and me.loopTwo == 1) or ((me.loopOne == 9 or me.loopOne == 8) and me.loopTwo == 1) or (me.loopOne == 1 and (me.loopTwo == 9 or me.loopTwo == 8))) {
2019-04-15 18:58:54 +00:00
me.TriggerWarning(me.sys);
}
},
receiveSignal: func(type) {
2019-04-19 16:40:20 +00:00
if (type == 1 and me.loopOne != 9 and me.condition != 0) {
2019-04-15 18:58:54 +00:00
me.loopOne = 1;
2019-04-19 16:40:20 +00:00
} elsif (type == 2 and me.loopTwo != 9 and me.condition != 0) {
2019-04-15 18:58:54 +00:00
me.loopTwo = 1;
}
},
2019-04-19 16:40:20 +00:00
failUnit: func() {
me.condition = 0;
},
2019-04-15 18:58:54 +00:00
fail: func(loop) {
if (loop != 1 and loop != 2) { return; }
if (loop == 1) { me.loopOne = 9; }
else { me.loopTwo = 9; }
me.startFailTimer(loop);
},
2019-04-16 16:43:36 +00:00
noElec: func(loop) {
if (loop != 1 and loop != 2) { return; }
if (loop == 1) { me.loopOne = 8; }
else { me.loopTwo = 8; }
},
2019-04-15 18:58:54 +00:00
startFailTimer: func(loop) {
if (me.sys != 2) {
if (loop == 1) {
2019-04-16 15:42:59 +00:00
propsNasFireTime.vector[sys].setValue(elapsedTime.getValue());
2019-04-15 18:58:54 +00:00
} elsif (loop == 2) {
2019-04-16 15:42:59 +00:00
propsNasFireTime.vector[sys + 1].setValue(elapsedTime.getValue());
2019-04-15 18:58:54 +00:00
}
} else {
if (loop == 1) {
2019-04-16 15:42:59 +00:00
propsNasFireTime.vector[4].setValue(elapsedTime.getValue());
2019-04-15 18:58:54 +00:00
} elsif (loop == 2) {
2019-04-16 15:42:59 +00:00
propsNasFireTime.vector[5].setValue(elapsedTime.getValue());
2019-04-15 18:58:54 +00:00
}
}
if (!fireTimer.isRunning) {
fireTimer.start();
}
},
TriggerWarning: func(system) {
if (system == 0) {
eng1FireWarn.setBoolValue(1);
} elsif (system == 1) {
eng2FireWarn.setBoolValue(1);
} elsif (system == 2) {
apuFireWarn.setBoolValue(1);
2019-04-19 16:40:20 +00:00
if (me.wow.getValue() == 1) {
2019-04-22 19:56:31 +00:00
if (apuMaster.getBoolValue()) {
apuBleedNode.setValue(0);
apuMaster.setValue(0);
Listener = setlistener("/systems/apu/rpm", func() {
if (getprop("/systems/apu/rpm") == 0) {
extinguisherBottles.vector[4].discharge();
removelistener(Listener);
}
}, 0, 0);
} else {
extinguisherBottles.vector[4].discharge();
}
2019-04-15 18:58:54 +00:00
}
}
}
};
var detectorLoop = {
2019-04-16 15:22:06 +00:00
sys: 9,
2019-04-16 16:43:36 +00:00
type: 0,
2019-04-15 18:58:54 +00:00
temperature: "",
2019-04-16 15:22:06 +00:00
elecProp: "",
2019-04-16 16:43:36 +00:00
new: func(sys, type, temperature, elecProp) {
2019-04-15 18:58:54 +00:00
var dL = {parents:[detectorLoop]};
2019-04-16 15:22:06 +00:00
dL.sys = sys;
2019-04-16 16:43:36 +00:00
dL.type = type;
2019-04-15 18:58:54 +00:00
dL.temperature = temperature;
2019-04-16 15:22:06 +00:00
dL.elecProp = props.globals.getNode(elecProp, 1);
2019-04-15 18:58:54 +00:00
return dL;
},
updateTemp: func(system, typeLoop) {
var index = 0;
if (system == 1) { index += 2 }
elsif (system == 2) { index += 4 }
if (typeLoop == 1) { index += 1 }
2019-04-16 15:42:59 +00:00
if (propsNasFire.vector[index].getValue() > 250 and me.elecProp.getValue() >= 25) {
2019-04-19 16:40:20 +00:00
me.sendSignal(system, typeLoop);
2019-04-16 16:43:36 +00:00
} elsif (me.elecProp.getValue() < 25) {
engFireDetectorUnits.vector[system].noElec(typeLoop);
2019-04-15 18:58:54 +00:00
}
},
2019-04-16 16:43:36 +00:00
sendSignal: func(system, typeLoop) {
2019-04-19 16:40:20 +00:00
if (system == 0 and !getprop("/systems/failures/engine-left-fire")) { return; }
elsif (system == 1 and !getprop("/systems/failures/engine-right-fire")) { return; }
elsif (system == 2 and !getprop("/systems/failures/apu-fire")) { return; }
2019-04-16 15:42:59 +00:00
engFireDetectorUnits.vector[system].receiveSignal(typeLoop);
2019-04-15 18:58:54 +00:00
}
};
var extinguisherBottle = {
quantity: 100,
squib: 0,
2019-04-17 16:40:49 +00:00
number: 0,
2019-04-15 18:58:54 +00:00
lightProp: "",
elecProp: "",
2019-04-17 16:40:49 +00:00
failProp: "",
warningProp: "",
new: func(number, lightProp, elecProp, failProp, warningProp) {
2019-04-15 18:58:54 +00:00
var eB = {parents:[extinguisherBottle]};
eB.quantity = 100;
eB.squib = 0;
2019-04-17 16:40:49 +00:00
eB.number = number;
2019-04-15 18:58:54 +00:00
eB.lightProp = props.globals.getNode(lightProp, 1);
eB.elecProp = props.globals.getNode(elecProp, 1);
2019-04-17 16:40:49 +00:00
eB.failProp = props.globals.getNode(failProp, 1);
eB.warningProp = props.globals.getNode(warningProp, 1);
2019-04-15 18:58:54 +00:00
return eB;
},
emptyBottle: func() {
2019-04-17 16:40:49 +00:00
me.quantity -= 1;
if (me.quantity > 0) {
settimer(func() {
me.emptyBottle()
}, 0.05);
} else {
2019-04-15 18:58:54 +00:00
me.lightProp.setValue(1);
2019-04-17 16:40:49 +00:00
# make things interesting. If your fire won't go out you should play the lottery
if (me.number == 0) {
if (rand() < 0.75) {
me.failProp.setValue(0);
me.warningProp.setValue(0);
}
2019-04-19 16:40:20 +00:00
} elsif (me.number == 1) {
2019-04-17 16:40:49 +00:00
if (rand() < 0.98) {
me.failProp.setValue(0);
me.warningProp.setValue(0);
}
} elsif (me.number == 9) {
if (rand() <= 0.999) {
me.failProp.setValue(0);
me.warningProp.setValue(0);
}
}
2019-04-15 18:58:54 +00:00
}
},
discharge: func() {
if (me.elecProp.getValue() < 25) { return; }
me.squib = 1;
me.emptyBottle();
}
};
# If two loops fail within five seconds then assume there is a fire
var propsNasFireTime = std.Vector.new([
props.globals.getNode("/systems/fire/engine1/loop1-failtime", 1), props.globals.getNode("/systems/fire/engine1/loop2-failtime", 1),
props.globals.getNode("/systems/fire/engine2/loop1-failtime", 1), props.globals.getNode("/systems/fire/engine2/loop2-failtime", 1),
props.globals.getNode("/systems/fire/apu/loop1-failtime", 1), props.globals.getNode("/systems/fire/apu/loop2-failtime", 1)
]);
var checkTimeFire1 = func() {
et = elapsedTime.getValue();
2019-04-16 15:42:59 +00:00
var loop1 = propsNasFireTime.vector[0].getValue();
var loop2 = propsNasFireTime.vector[1].getValue();
2019-04-15 18:58:54 +00:00
if ((loop1 != 0 and et > loop1 + 5) or (loop2 != 0 and et > loop2 + 5)) {
fireTimer1.stop();
loop1.setValue(0);
loop2.setValue(0);
}
2019-04-16 15:42:59 +00:00
if (engFireDetectorUnits.vector[0].loop1 == 9 and engFireDetectorUnits.vector[0].loop2 == 9) {
2019-04-15 18:58:54 +00:00
fireTimer1.stop();
2019-04-16 15:42:59 +00:00
engFireDetectorUnits.vector[0].TriggerWarning(engFireDetectorUnits.vector[0].sys);
2019-04-15 18:58:54 +00:00
loop1.setValue(0);
loop2.setValue(0);
}
}
var checkTimeFire2 = func() {
et = elapsedTime.getValue();
2019-04-16 15:42:59 +00:00
var loop3 = propsNasFireTime.vector[2].getValue();
var loop4 = propsNasFireTime.vector[3].getValue();
2019-04-15 18:58:54 +00:00
if ((loop3 != 0 and et > loop3 + 5) or (loop4 != 0 and et > loop4 + 5)) {
fireTimer2.stop();
loop3.setValue(0);
loop4.setValue(0);
}
2019-04-16 15:42:59 +00:00
if (engFireDetectorUnits.vector[1].loop1 == 9 and engFireDetectorUnits.vector[1].loop2 == 9) {
2019-04-15 18:58:54 +00:00
fireTimer2.stop();
2019-04-16 15:42:59 +00:00
engFireDetectorUnits.vector[1].TriggerWarning(engFireDetectorUnits.vector[1].sys);
2019-04-15 18:58:54 +00:00
loop3.setValue(0);
loop4.setValue(0);
}
}
2019-04-19 16:40:20 +00:00
2019-04-15 18:58:54 +00:00
var checkTimeFire3 = func() {
et = elapsedTime.getValue();
2019-04-16 15:42:59 +00:00
var loop4 = propsNasFireTime.vector[3].getValue();
var loop5 = propsNasFireTime.vector[4].getValue();
2019-04-15 18:58:54 +00:00
if ((loop4 != 0 and et > loop4 + 5) or (loop5 != 0 and et > loop5 + 5)) {
fireTimer3.stop();
loop4.setValue(0);
loop5.setValue(0);
}
2019-04-16 15:42:59 +00:00
if (engFireDetectorUnits.vector[2].loop1 == 9 and engFireDetectorUnits.vector[2].loop2 == 9) {
2019-04-15 18:58:54 +00:00
fireTimer3.stop();
2019-04-16 15:42:59 +00:00
engFireDetectorUnits.vector[2].TriggerWarning(engFireDetectorUnits.vector[2].sys);
2019-04-15 18:58:54 +00:00
loop4.setValue(0);
loop5.setValue(0);
}
}
var fireTimer1 = maketimer(0.25, checkTimeFire1);
fireTimer1.simulatedTime = 1;
var fireTimer2 = maketimer(0.25, checkTimeFire2);
fireTimer2.simulatedTime = 1;
var fireTimer3 = maketimer(0.25, checkTimeFire3);
fireTimer3.simulatedTime = 1;
# Create engine fire systems
var engFireDetectorUnits = std.Vector.new([ engFireDetectorUnit.new(0), engFireDetectorUnit.new(1), engFireDetectorUnit.new(2) ]);
# Create detector loops
var detectorLoops = std.Vector.new([
2019-04-16 16:43:36 +00:00
detectorLoop.new(0, 1, "/systems/fire/engine1/temperature", "/systems/electrical/bus/dc-ess"), detectorLoop.new(0, 2, "/systems/fire/engine1/temperature", "/systems/electrical/bus/dc2"),
detectorLoop.new(1, 1, "/systems/fire/engine2/temperature", "/systems/electrical/bus/dc2"), detectorLoop.new(1, 2, "/systems/fire/engine2/temperature", "/systems/electrical/bus/dc-ess"),
detectorLoop.new(2, 1, "/systems/fire/apu/temperature", "/systems/electrical/bus/dcbat"), detectorLoop.new(2, 2, "/systems/fire/apu/temperature", "/systems/electrical/bus/dcbat")
2019-04-15 18:58:54 +00:00
]);
# Create extinguisher bottles
2019-04-17 16:40:49 +00:00
var extinguisherBottles = std.Vector.new([extinguisherBottle.new(0, "/systems/fire/engine1/disch1", "/systems/electrical/bus/dcbat", "/systems/failures/engine-left-fire", "/systems/fire/engine1/warning-active"), extinguisherBottle.new(1, "/systems/fire/engine1/disch2", "/systems/electrical/bus/dc2", "/systems/failures/engine-left-fire", "/systems/fire/engine1/warning-active"),
extinguisherBottle.new(0, "/systems/fire/engine2/disch1", "/systems/electrical/bus/dcbat", "/systems/failures/engine-right-fire", "/systems/fire/engine2/warning-active"), extinguisherBottle.new(1, "/systems/fire/engine2/disch2", "/systems/electrical/bus/dc2", "/systems/failures/engine-right-fire", "/systems/fire/engine2/warning-active"),
extinguisherBottle.new(9, "/systems/fire/apu/disch", "/systems/electrical/bus/dcbat", "/systems/failures/apu-fire", "/systems/fire/apu/warning-active") ]);
2019-04-15 18:58:54 +00:00
# Props.nas helper
var propsNasFire = std.Vector.new();
foreach (detectorLoop; detectorLoops.vector) {
propsNasFire.append(props.globals.getNode(detectorLoop.temperature));
};
# Setlistener helper
2019-04-17 16:40:49 +00:00
var createFireBottleListener = func(prop, fireBtnProp, index) {
2019-04-15 18:58:54 +00:00
if (index >= extinguisherBottles.size()) {
print("Error - calling listener on non-existent fire extinguisher bottle, index: " ~ index);
return;
}
setlistener(prop, func() {
2019-04-17 16:40:49 +00:00
if (getprop(prop) == 1 and getprop(fireBtnProp) == 1) {
2019-04-15 18:58:54 +00:00
extinguisherBottles.vector[index].discharge();
}
}, 0, 0);
}
# Listeners
2019-04-19 16:40:20 +00:00
setlistener("/controls/engines/engine[0]/fire-btn", func() {
if (getprop("/controls/engines/engine[0]/fire-btn") == 1) {
ecam.shutUpYou();
2019-04-22 19:56:31 +00:00
eng1AgentTimer.setValue(10);
createAgentTimerListener(1);
2019-04-19 16:40:20 +00:00
}
}, 0, 0);
2019-04-22 19:56:31 +00:00
var createAgentTimerListener = func(agent) {
var elapsedList = setlistener("/sim/time/elapsed-sec", func() {
if (agent == 1) {
if (eng1AgentTimer != 1) {
eng1AgentTimer.setValue(eng1AgentTimer.getValue() - 1);
} else {
eng1AgentTimer.setValue(0);
removelistener(elapsedList);
removeListener(createAgentTimerListener);
}
} elsif (agent == 2) {
if (eng2AgentTimer != 1) {
eng2AgentTimer.setValue(eng2AgentTimer.getValue() - 1);
} else {
eng2AgentTimer.setValue(0);
removelistener(elapsedList);
removeListener(createAgentTimerListener);
}
} elsif (agent == 3) {
if (apuAgentTimer != 1) {
eng1AgentTimer.setValue(apuAgentTimer.getValue() - 1);
} else {
apuAgentTimer.setValue(0);
removelistener(elapsedList);
removeListener(createAgentTimerListener);
}
}
}, 0, 0);
}
2019-04-19 16:40:20 +00:00
setlistener("/controls/engines/engine[1]/fire-btn", func() {
if (getprop("/controls/engines/engine[1]/fire-btn") == 1) {
ecam.shutUpYou();
2019-04-22 19:56:31 +00:00
eng2AgentTimer.setValue(10);
createAgentTimerListener(2);
2019-04-19 16:40:20 +00:00
}
}, 0, 0);
setlistener("/controls/APU/fire-btn", func() {
if (getprop("/controls/APU/fire-btn") == 1) {
ecam.shutUpYou();
2019-04-22 19:56:31 +00:00
apuAgentTimer.setValue(10);
createAgentTimerListener(3);
2019-04-19 16:40:20 +00:00
}
}, 0, 0);
2019-04-15 18:58:54 +00:00
2019-04-17 16:40:49 +00:00
setlistener("/controls/fire/test-btn-1", func() {
if (getprop("/systems/failures/engine-left-fire")) { return; }
2019-04-15 18:58:54 +00:00
if (testBtn.getValue() == 1) {
if (dcbatNode.getValue() > 25 or dcessNode.getValue() > 25) {
eng1FireWarn.setBoolValue(1);
} else {
eng1FireWarn.setBoolValue(0);
}
} else {
eng1FireWarn.setBoolValue(0);
2019-04-17 16:40:49 +00:00
}
}, 0, 0);
setlistener("/controls/fire/test-btn-2", func() {
if (getprop("/systems/failures/engine-right-fire")) { return; }
if (testBtn2.getValue() == 1) {
if (dcbatNode.getValue() > 25 or dcessNode.getValue() > 25) {
eng2FireWarn.setBoolValue(1);
} else {
eng2FireWarn.setBoolValue(0);
}
} else {
2019-04-15 18:58:54 +00:00
eng2FireWarn.setBoolValue(0);
}
}, 0, 0);
setlistener("/controls/fire/apu-test-btn", func() {
2019-04-17 16:40:49 +00:00
if (getprop("/systems/failures/apu-fire")) { return; }
2019-04-15 18:58:54 +00:00
if (apuTestBtn.getValue() == 1) {
if (dcbatNode.getValue() > 25 or dcessNode.getValue() > 25) {
apuFireWarn.setBoolValue(1);
} else {
apuFireWarn.setBoolValue(0);
}
} else {
apuFireWarn.setBoolValue(0);
}
}, 0, 0);
2019-01-22 11:16:54 +00:00
2019-04-17 16:40:49 +00:00
createFireBottleListener("/controls/engines/engine[0]/agent1-btn", "/controls/engines/engine[0]/fire-btn", 0);
createFireBottleListener("/controls/engines/engine[0]/agent2-btn", "/controls/engines/engine[0]/fire-btn", 1);
createFireBottleListener("/controls/engines/engine[1]/agent1-btn", "/controls/engines/engine[1]/fire-btn", 2);
createFireBottleListener("/controls/engines/engine[1]/agent2-btn", "/controls/engines/engine[1]/fire-btn", 3);
createFireBottleListener("/controls/APU/agent-btn", "/controls/APU/fire-btn", 4);
2019-04-16 15:42:59 +00:00
var updateUnits = func() {
foreach (var units; engFireDetectorUnits.vector) {
units.update();
}
}
2019-04-19 16:40:20 +00:00
2017-07-07 14:32:39 +00:00
###################
# Update Function #
###################
2019-04-19 16:40:20 +00:00
var update_fire = func() {
2017-07-07 14:32:39 +00:00
master_fire();
2019-04-16 15:42:59 +00:00
updateUnits();
2017-07-07 14:32:39 +00:00
}
2019-01-22 11:16:54 +00:00
var fire_timer = maketimer(0.2, update_fire);