#Initialise
var engine1  = engines.Jet.new(0, 0, 0.01, 5.21, 3, 4, 2, 4);
var engine2  = engines.Jet.new(1, 0, 0.01, 5.21, 3, 4, 2, 4);
var engine3  = engines.Jet.new(2, 0, 0.01, 5.21, 3, 4, 2, 4);
var engine4  = engines.Jet.new(3, 0, 0.01, 5.21, 3, 4, 2, 4);
var engine5  = engines.Jet.new(4, 0, 0.01, 5.21, 3, 4, 2, 4);
var engine6  = engines.Jet.new(5, 0, 0.01, 5.21, 3, 4, 2, 4);
var engine7  = engines.Jet.new(6, 0, 0.01, 5.21, 3, 4, 2, 4);
var engine8  = engines.Jet.new(7, 0, 0.01, 5.21, 3, 4, 2, 4);
var engine9  = engines.Jet.new(8, 0, 0.01, 5.21, 3, 4, 2, 4);
var engine10 = engines.Jet.new(9, 0, 0.01, 5.21, 3, 4, 2, 4);

engine1.init();
engine2.init();
engine3.init();
engine4.init();
engine5.init();
engine6.init();
engine7.init();
engine8.init();
engine9.init();
engine10.init();

props.globals.initNode("/sim/autostart/started", 0, "BOOL");

var eng1fuelon  = func { setprop("/controls/engines/engine[0]/cutoff", 0); }
var eng2fuelon  = func { setprop("/controls/engines/engine[1]/cutoff", 0); }
var eng3fuelon  = func { setprop("/controls/engines/engine[2]/cutoff", 0); }
var eng4fuelon  = func { setprop("/controls/engines/engine[3]/cutoff", 0); }
var eng5fuelon  = func { setprop("/controls/engines/engine[4]/cutoff", 0); }
var eng6fuelon  = func { setprop("/controls/engines/engine[5]/cutoff", 0); }
var eng7fuelon  = func { setprop("/controls/engines/engine[6]/cutoff", 0); }
var eng8fuelon  = func { setprop("/controls/engines/engine[7]/cutoff", 0); }
var eng9fuelon  = func { setprop("/controls/engines/engine[8]/cutoff", 0); }
var eng10fuelon = func { setprop("/controls/engines/engine[9]/cutoff", 0); }

var eng1fueloff  = func { setprop("/controls/engines/engine[0]/cutoff", 1); }
var eng2fueloff  = func { setprop("/controls/engines/engine[1]/cutoff", 1); }
var eng3fueloff  = func { setprop("/controls/engines/engine[2]/cutoff", 1); }
var eng4fueloff  = func { setprop("/controls/engines/engine[3]/cutoff", 1); }
var eng5fueloff  = func { setprop("/controls/engines/engine[4]/cutoff", 1); }
var eng6fueloff  = func { setprop("/controls/engines/engine[5]/cutoff", 1); }
var eng7fueloff  = func { setprop("/controls/engines/engine[6]/cutoff", 1); }
var eng8fueloff  = func { setprop("/controls/engines/engine[7]/cutoff", 1); }
var eng9fueloff  = func { setprop("/controls/engines/engine[8]/cutoff", 1); }
var eng10fueloff = func { setprop("/controls/engines/engine[9]/cutoff", 1); }

var eng1starter  = func { setprop("/controls/engines/engine[0]/starter", 1); }
var eng2starter  = func { setprop("/controls/engines/engine[1]/starter", 1); }
var eng3starter  = func { setprop("/controls/engines/engine[2]/starter", 1); }
var eng4starter  = func { setprop("/controls/engines/engine[3]/starter", 1); }
var eng5starter  = func { setprop("/controls/engines/engine[4]/starter", 1); }
var eng6starter  = func { setprop("/controls/engines/engine[5]/starter", 1); }
var eng7starter  = func { setprop("/controls/engines/engine[6]/starter", 1); }
var eng8starter  = func { setprop("/controls/engines/engine[7]/starter", 1); }
var eng9starter  = func { setprop("/controls/engines/engine[8]/starter", 1); }
var eng10starter = func { setprop("/controls/engines/engine[9]/starter", 1); }

var eng1start = func {
  gui.popupTip("*** Engine start Left 1 interior ***");
  eng1fueloff();
  eng1starter();
  settimer(eng1fuelon, 2);
  setprop("/controls/engines/engine[0]/condition", 1);
}

var eng2start = func {
  gui.popupTip("*** Engine start Left 2 ***");
  eng2fueloff();
  eng2starter();
  settimer(eng2fuelon, 2);
  setprop("/controls/engines/engine[1]/condition", 1);
}

var eng3start = func {
  gui.popupTip("*** Engine start Left 3 ***");
  eng3fueloff();
  eng3starter();
  settimer(eng3fuelon, 2);
  setprop("/controls/engines/engine[2]/condition", 1);
}

var eng4start = func {
  gui.popupTip("*** Engine start Left 4 exterior ***");
  eng4fueloff();
  eng4starter();
  settimer(eng4fuelon, 2);
  setprop("/controls/engines/engine[3]/condition", 1);
}

var eng5start = func {
  gui.popupTip("*** Engine start Right 1 interior ***");
  eng5fueloff();
  eng5starter();
  settimer(eng5fuelon, 2);
  setprop("/controls/engines/engine[4]/condition", 1);
}

var eng6start = func {
  gui.popupTip("*** Engine start Right 2 ***");
  eng6fueloff();
  eng6starter();
  settimer(eng6fuelon, 2);
  setprop("/controls/engines/engine[5]/condition", 1);
}

var eng7start = func {
  gui.popupTip("*** Engine start Right 3 ***");
  eng7fueloff();
  eng7starter();
  settimer(eng7fuelon, 2);
  setprop("/controls/engines/engine[6]/condition", 1);
}

var eng8start = func {
  gui.popupTip("*** Engine start Right 4 exterior ***");
  eng8fueloff();
  eng8starter();
  settimer(eng8fuelon, 2);
  setprop("/controls/engines/engine[7]/condition", 1);
}

var eng9start = func {
  gui.popupTip("*** Engine start Left rear ***");
  eng9fueloff();
  eng9starter();
  settimer(eng9fuelon, 2);
  setprop("/controls/engines/engine[8]/condition", 1);
}

var eng10start = func {
  gui.popupTip("*** Engine start Right rear ***");
  eng10fueloff();
  eng10starter();
  settimer(eng10fuelon, 2);
  setprop("/controls/engines/engine[9]/condition", 1);
}

var engstart = func {
  settimer(eng1start,   2);
  settimer(eng5start,   4);
  settimer(eng2start,   6);
  settimer(eng6start,   8);
  settimer(eng3start,  10);
  settimer(eng7start,  12);
  settimer(eng4start,  14);
  settimer(eng8start,  16);
  settimer(eng9start,  18);
  settimer(eng10start, 20);
}

var engstop = func {
  eng1fueloff();
  setprop("/controls/engines/engine[0]/throttle", 0);
  setprop("/controls/engines/engine[0]/condition", 0);
  eng2fueloff();
  setprop("/controls/engines/engine[1]/throttle", 0);
  setprop("/controls/engines/engine[1]/condition", 0);
  eng3fueloff();
  setprop("/controls/engines/engine[2]/throttle", 0);
  setprop("/controls/engines/engine[2]/condition", 0);
  eng4fueloff();
  setprop("/controls/engines/engine[3]/throttle", 0);
  setprop("/controls/engines/engine[3]/condition", 0);
  eng5fueloff();
  setprop("/controls/engines/engine[4]/throttle", 0);
  setprop("/controls/engines/engine[4]/condition", 0);
  eng6fueloff();
  setprop("/controls/engines/engine[5]/throttle", 0);
  setprop("/controls/engines/engine[5]/condition", 0);
  eng7fueloff();
  setprop("/controls/engines/engine[6]/throttle", 0);
  setprop("/controls/engines/engine[6]/condition", 0);
  eng8fueloff();
  setprop("/controls/engines/engine[7]/throttle", 0);
  setprop("/controls/engines/engine[7]/condition", 0);
  eng9fueloff();
  setprop("/controls/engines/engine[8]/throttle", 0);
  setprop("/controls/engines/engine[8]/condition", 0);
  eng10fueloff();
  setprop("/controls/engines/engine[9]/throttle", 0);
  setprop("/controls/engines/engine[9]/condition", 0);
}

var autostart = func {
  var startstatus = getprop("/sim/autostart/started");
  if ( startstatus == 0 ) {
    gui.popupTip("Autostarting...");
    setprop("/sim/model/autostart", 1);
    setprop("/sim/autostart/started", 1);
    setprop("/controls/electric/battery-switch", 1);
    settimer(engstart, 0.4);
    gui.popupTip("Starting Engines");
  }
  if ( startstatus == 1 ) {
    gui.popupTip("Shutting Down...");
    setprop("/sim/model/autostart", 0);
    setprop("/sim/autostart/started", 0);
    engstop();
  }
}

var autostop = func {
   engstopf();
   apufueloff();
}
