- s/aircraft/tanker/ (patch inspired by Alexis BORY :-)
- add support for /systems/refuel/serviceable flag (can be set to false by the aircraft as long as the door over the boom entry is closed, etc.)
This commit is contained in:
parent
c108d87b31
commit
6a7dc46bd2
1 changed files with 18 additions and 25 deletions
|
@ -13,6 +13,7 @@
|
||||||
var UPDATE_PERIOD = 0.3;
|
var UPDATE_PERIOD = 0.3;
|
||||||
|
|
||||||
var enabled = nil;
|
var enabled = nil;
|
||||||
|
var serviceable = nil;
|
||||||
var fuel_freeze = nil;
|
var fuel_freeze = nil;
|
||||||
var ai_enabled = nil;
|
var ai_enabled = nil;
|
||||||
var engines = nil;
|
var engines = nil;
|
||||||
|
@ -27,18 +28,16 @@ var init_prop = func(node, prop, val, type = "double") {
|
||||||
var n = node.getNode(prop);
|
var n = node.getNode(prop);
|
||||||
if (n != nil) {
|
if (n != nil) {
|
||||||
var v = n.getValue();
|
var v = n.getValue();
|
||||||
if (v != nil) {
|
if (v != nil)
|
||||||
val = v;
|
val = v;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
node = node.getNode(prop, 1);
|
node = node.getNode(prop, 1);
|
||||||
if (type == "double") {
|
if (type == "double")
|
||||||
node.setDoubleValue(val);
|
node.setDoubleValue(val);
|
||||||
} elsif (type == "bool") {
|
elsif (type == "bool")
|
||||||
node.setBoolValue(val);
|
node.setBoolValue(val);
|
||||||
} elsif (type == "int") {
|
elsif (type == "int")
|
||||||
node.setIntValue(val);
|
node.setIntValue(val);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,25 +46,23 @@ var update_loop = func {
|
||||||
# check for contact with tanker aircraft
|
# check for contact with tanker aircraft
|
||||||
var tankers = [];
|
var tankers = [];
|
||||||
if (ai_enabled) {
|
if (ai_enabled) {
|
||||||
var ac = aimodelsN.getChildren("aircraft");
|
var ac = aimodelsN.getChildren("tanker");
|
||||||
var mp = aimodelsN.getChildren("multiplayer");
|
var mp = aimodelsN.getChildren("multiplayer");
|
||||||
|
|
||||||
foreach (var a; ac ~ mp) {
|
foreach (var a; ac ~ mp) {
|
||||||
var contact = a.getNode("refuel/contact", 1).getValue();
|
var contact = a.getNode("refuel/contact", 1).getValue();
|
||||||
var tanker = a.getNode("tanker", 1).getValue();
|
var tanker = a.getNode("tanker", 1).getValue();
|
||||||
|
|
||||||
if (tanker and contact) {
|
if (tanker and contact)
|
||||||
append(tankers, a);
|
append(tankers, a);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var refueling = size(tankers) > 0;
|
var refueling = serviceable and size(tankers) > 0;
|
||||||
refuelingN.setBoolValue(refueling);
|
refuelingN.setBoolValue(refueling);
|
||||||
|
|
||||||
if (fuel_freeze) {
|
if (fuel_freeze)
|
||||||
return settimer(update_loop, UPDATE_PERIOD);
|
return settimer(update_loop, UPDATE_PERIOD);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# sum up consumed fuel
|
# sum up consumed fuel
|
||||||
|
@ -90,9 +87,8 @@ var update_loop = func {
|
||||||
var selected_tanks = [];
|
var selected_tanks = [];
|
||||||
foreach (var t; tanks) {
|
foreach (var t; tanks) {
|
||||||
var cap = t.getNode("capacity-gal_us", 1).getValue();
|
var cap = t.getNode("capacity-gal_us", 1).getValue();
|
||||||
if (cap != nil and cap > 0.01 and t.getNode("selected", 1).getBoolValue()) {
|
if (cap != nil and cap > 0.01 and t.getNode("selected", 1).getBoolValue())
|
||||||
append(selected_tanks, t);
|
append(selected_tanks, t);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -111,11 +107,10 @@ var update_loop = func {
|
||||||
lbs = 0;
|
lbs = 0;
|
||||||
# Kill the engines if we're told to, otherwise simply
|
# Kill the engines if we're told to, otherwise simply
|
||||||
# deselect the tank.
|
# deselect the tank.
|
||||||
if (t.getNode("kill-when-empty", 1).getBoolValue()) {
|
if (t.getNode("kill-when-empty", 1).getBoolValue())
|
||||||
out_of_fuel = 1;
|
out_of_fuel = 1;
|
||||||
} else {
|
else
|
||||||
t.getNode("selected", 1).setBoolValue(0);
|
t.getNode("selected", 1).setBoolValue(0);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var gals = lbs / ppg;
|
var gals = lbs / ppg;
|
||||||
|
@ -132,9 +127,8 @@ var update_loop = func {
|
||||||
var capacity = t.getNode("capacity-gal_us").getValue() * ppg;
|
var capacity = t.getNode("capacity-gal_us").getValue() * ppg;
|
||||||
var lbs = t.getNode("level-gal_us").getValue() * ppg;
|
var lbs = t.getNode("level-gal_us").getValue() * ppg;
|
||||||
|
|
||||||
if (lbs < capacity) {
|
if (lbs < capacity)
|
||||||
available += 1;
|
available += 1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (available > 0) {
|
if (available > 0) {
|
||||||
|
@ -147,9 +141,8 @@ var update_loop = func {
|
||||||
var lbs = t.getNode("level-gal_us").getValue() * ppg;
|
var lbs = t.getNode("level-gal_us").getValue() * ppg;
|
||||||
|
|
||||||
lbs += fuel_per_tank;
|
lbs += fuel_per_tank;
|
||||||
if (lbs > capacity) {
|
if (lbs > capacity)
|
||||||
lbs = capacity;
|
lbs = capacity;
|
||||||
}
|
|
||||||
|
|
||||||
t.getNode("level-gal_us").setDoubleValue(lbs / ppg);
|
t.getNode("level-gal_us").setDoubleValue(lbs / ppg);
|
||||||
t.getNode("level-lbs").setDoubleValue(lbs);
|
t.getNode("level-lbs").setDoubleValue(lbs);
|
||||||
|
@ -173,18 +166,17 @@ var update_loop = func {
|
||||||
setprop("/consumables/fuel/total-fuel-lbs", lbs);
|
setprop("/consumables/fuel/total-fuel-lbs", lbs);
|
||||||
setprop("/consumables/fuel/total-fuel-norm", gals / cap);
|
setprop("/consumables/fuel/total-fuel-norm", gals / cap);
|
||||||
|
|
||||||
foreach (var e; engines) {
|
foreach (var e; engines)
|
||||||
e.getNode("out-of-fuel", 1).setBoolValue(out_of_fuel);
|
e.getNode("out-of-fuel", 1).setBoolValue(out_of_fuel);
|
||||||
}
|
|
||||||
settimer(update_loop, UPDATE_PERIOD);
|
settimer(update_loop, UPDATE_PERIOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
setlistener("/sim/signals/fdm-initialized", func {
|
setlistener("/sim/signals/fdm-initialized", func {
|
||||||
if (contains(globals, "fuel") and typeof(fuel) == "hash") {
|
if (contains(globals, "fuel") and typeof(fuel) == "hash")
|
||||||
fuel.loop = func {} # kill $FG_ROOT/Nasal/fuel.nas' loop
|
fuel.loop = func {} # kill $FG_ROOT/Nasal/fuel.nas' loop
|
||||||
}
|
|
||||||
|
|
||||||
refuelingN = props.globals.getNode("/systems/refuel/contact", 1);
|
refuelingN = props.globals.getNode("/systems/refuel/contact", 1);
|
||||||
refuelingN.setBoolValue(0);
|
refuelingN.setBoolValue(0);
|
||||||
|
@ -208,6 +200,7 @@ setlistener("/sim/signals/fdm-initialized", func {
|
||||||
|
|
||||||
setlistener("sim/freeze/fuel", func { fuel_freeze = cmdarg().getBoolValue() }, 1);
|
setlistener("sim/freeze/fuel", func { fuel_freeze = cmdarg().getBoolValue() }, 1);
|
||||||
setlistener("sim/ai/enabled", func { ai_enabled = cmdarg().getBoolValue() }, 1);
|
setlistener("sim/ai/enabled", func { ai_enabled = cmdarg().getBoolValue() }, 1);
|
||||||
|
setlistener("systems/refuel/serviceable", func { serviceable = cmdarg().getBoolValue() }, 1);
|
||||||
update_loop();
|
update_loop();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue