1
0
Fork 0

#705: add sanity checks to fuel tank update

Just ignore incomplete tanks (without essential properties like "level_lbs")
and avoid Nasal run-time errors.
This commit is contained in:
ThorstenB 2012-04-22 15:19:20 +02:00
parent 870dccf632
commit ed0d58cd75

View file

@ -28,11 +28,13 @@ var update = func {
var selected_tanks = []; var selected_tanks = [];
foreach (var t; tanks) { foreach (var t; tanks) {
var cap = t.getNode("capacity-gal_us",0); var cap = t.getNode("capacity-gal_us",0);
if ((cap!=nil) and (cap.getValue() > 0.01) and t.getNode("selected").getBoolValue()) var selected = t.getNode("selected");
if ((cap!=nil) and (cap.getValue() > 0.01) and (t.getNode("level-lbs") != nil) and
(selected != nil) and selected.getBoolValue())
append(selected_tanks, t); append(selected_tanks, t);
} }
# Subtract fuel from tanks, set auxilliary properties. Set out-of-fuel # Subtract fuel from tanks, set auxiliary properties. Set out-of-fuel
# when any one tank is dry. # when any one tank is dry.
var out_of_fuel = 0; var out_of_fuel = 0;
if (size(selected_tanks) == 0) { if (size(selected_tanks) == 0) {
@ -40,10 +42,14 @@ var update = func {
} else { } else {
var fuel_per_tank = consumed_fuel / size(selected_tanks); var fuel_per_tank = consumed_fuel / size(selected_tanks);
foreach (var t; selected_tanks) { foreach (var t; selected_tanks) {
var lbs = t.getNode("level-lbs").getValue(); var lbs = t.getNode("level-lbs");
lbs = lbs - fuel_per_tank; lbs.setDoubleValue(lbs.getValue() - fuel_per_tank);
t.getNode("level-lbs").setDoubleValue(lbs); var empty = t.getNode("empty");
if( t.getNode("empty").getBoolValue() ) { if (empty == nil)
empty = (lbs.getValue() <= 0);
else
empty = empty.getBoolValue();
if( empty ) {
# 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())