//create access to all the parts set comms to ship:partstagged("antenna"). set probe to ship:partstagged("core"). set battlist to ship:partsdubbed("z-200 rechargeable battery bank"). set caplist to ship:partsdubbed("cap-101 capacitor"). set goolist to ship:partstagged("goo"). // program behavior variables set predeploylowerheight to 3000. set deploylowerheight to 2500. set maxdropspeed to 12. set commtimeout to 15. set transmissiontimeout to 5. set lowbattlvl to 50. clearscreen. abort off. print "[" + time:clock + "] Program running... confirming systems". if comms:length = 0 { print "[" + time:clock + "] Comunication antenna not found". abort on. }. if probe:length = 0 { print "[" + time:clock + "] Control core not found". abort on. }. if battlist:length < 4 { print "[" + time:clock + "] " + battlist:length + " Battery(s) found". }. if caplist:length < 3 { print "[" + time:clock + "] " + caplist:length + " Capacitor(s) found". }. if goolist:length < 2 { print "[" + time:clock + "] " + goolist:length + " Goo canister(s) found". }. // only continue execution if we found all the parts we need // missing batteries, capacitors or science experiments won't cause any errors if abort { print "[" + time:clock + "] Unable to continue execution". // program execution ends } else { print "[" + time:clock + "] Operational systems confirmed". for batt in battlist { set batt:resources[0]:enabled to true. }. print "[" + time:clock + "] All batteries enabled". Print "[" + time:clock + "] First lower atmospheric experiment run commencing". toggle AG4. // goo containers are only run once per atmosphere level (lower/ground) for goo in goolist { // we don't care which goo pod is run - if a goo container is unused, it will have an event available if goo:getmodule("modulescienceexperiment"):allevents:length { goo:getmodule("modulescienceexperiment"):doevent("observe mystery goo"). }. }. Print "[" + time:clock + "] Awaiting data transmission". set timer to time:seconds. set nodata to false. // until the comms message changes from "idle", nothing is being transmitted until comms[0]:getmodule("modulertdatatransmitter"):getfield("comms") = "uploading data..." { // keep tabs on our power status - release capcitor charge as necessary if ship:resources[0]:amount < lowbattlvl { set discharged to false. for cap in caplist { if cap:getmodule("dischargecapacitor"):getfield("status") = "ready" { cap:getmodule("dischargecapacitor"):doevent("discharge capacitor"). Print "[" + time:clock + "] Power levels low, discharging capacitor " + cap:tag. set discharged to true. break. } }. if not discharged { Print "[" + time:clock + "] All capacitors drained". }. }. // keeps tabs on our connection to Mission Control if probe[0]:getmodule("modulespu"):getfield("spu") <> "operational." { Print "[" + time:clock + "] Connection lost". shutdown. }. // if the user recycles all experiments, no data will be sent if time:seconds - timer > commtimeout { set nodata to true. break. } wait 0.001. }. if nodata { // aborts the second run as well - no data means no data for this entire biome level Print "[" + time:clock + "] Aborting lower atmospheric runs due to no data to transmit". } else { Print "[" + time:clock + "] Data transmission has begun". abort off. until abort { if ship:resources[0]:amount < lowbattlvl { set discharged to false. for cap in caplist { if cap:getmodule("dischargecapacitor"):getfield("status") = "ready" { cap:getmodule("dischargecapacitor"):doevent("discharge capacitor"). Print "[" + time:clock + "] Power levels low, discharging capacitor " + cap:tag. set discharged to true. break. } }. if not discharged { Print "[" + time:clock + "] All capacitors drained". }. }. if probe[0]:getmodule("modulespu"):getfield("spu") <> "operational." { Print "[" + time:clock + "] Connection lost". shutdown. }. wait 0.01. }. Print "[" + time:clock + "] Data transmission has ended". if probe[0]:getmodule("modulespu"):getfield("spu") <> "operational." { Print "[" + time:clock + "] Connection lost". shutdown. }. // if we'haven't landed yet, take a second run for additional data if ship:verticalspeed < 0 { Print "[" + time:clock + "] Second lower atmospheric experiment run commencing". toggle AG4. Print "[" + time:clock + "] Awaiting data transmission". set timer to time:seconds. set nodata to false. until comms[0]:getmodule("modulertdatatransmitter"):getfield("comms") = "uploading data..." { if ship:resources[0]:amount < lowbattlvl { set discharged to false. for cap in caplist { if cap:getmodule("dischargecapacitor"):getfield("status") = "ready" { cap:getmodule("dischargecapacitor"):doevent("discharge capacitor"). Print "[" + time:clock + "] Power levels low, discharging capacitor " + cap:tag. set discharged to true. break. } }. if not discharged { Print "[" + time:clock + "] All capacitors drained". }. }. if probe[0]:getmodule("modulespu"):getfield("spu") <> "operational." { Print "[" + time:clock + "] Connection lost". shutdown. }. if time:seconds - timer > commtimeout { set nodata to true. break. } wait 0.001. }. if nodata { Print "[" + time:clock + "] Aborting second lower atmospheric run due to no data to transmit". } else { Print "[" + time:clock + "] Data transmission has begun". abort off. until abort { if ship:resources[0]:amount < lowbattlvl { set discharged to false. for cap in caplist { if cap:getmodule("dischargecapacitor"):getfield("status") = "ready" { cap:getmodule("dischargecapacitor"):doevent("discharge capacitor"). Print "[" + time:clock + "] Power levels low, discharging capacitor " + cap:tag. set discharged to true. break. }. }. if not discharged { Print "[" + time:clock + "] All capacitors drained". }. }. if probe[0]:getmodule("modulespu"):getfield("spu") <> "operational." { Print "[" + time:clock + "] Connection lost". shutdown. }. wait 0.01. }. Print "[" + time:clock + "] Data transmission has ended". }. }. }. // go into a wait state if we haven't landed during the last transmission sequence if ship:verticalspeed < 0 { Print "[" + time:clock + "] Awaiting landing". until ship:verticalspeed >= 0 { if ship:resources[0]:amount < lowbattlvl { set discharged to false. for cap in caplist { if cap:getmodule("dischargecapacitor"):getfield("status") = "ready" { cap:getmodule("dischargecapacitor"):doevent("discharge capacitor"). Print "[" + time:clock + "] Power levels low, discharging capacitor " + cap:tag. set discharged to true. break. } }. if not discharged { Print "[" + time:clock + "] All capacitors drained". }. }. if probe[0]:getmodule("modulespu"):getfield("spu") <> "operational." { Print "[" + time:clock + "] Connection lost". shutdown. }. wait 0.001. }. }. Print "[" + time:clock + "] Landing confirmed. First ground level experiment run commencing". toggle AG4. for goo in goolist { if goo:getmodule("modulescienceexperiment"):allevents:length { goo:getmodule("modulescienceexperiment"):doevent("observe mystery goo"). }. }. Print "[" + time:clock + "] Awaiting data transmission". set timer to time:seconds. set nodata to false. until comms[0]:getmodule("modulertdatatransmitter"):getfield("comms") = "uploading data..." { if ship:resources[0]:amount < lowbattlvl { set discharged to false. for cap in caplist { if cap:getmodule("dischargecapacitor"):getfield("status") = "ready" { cap:getmodule("dischargecapacitor"):doevent("discharge capacitor"). Print "[" + time:clock + "] Power levels low, discharging capacitor " + cap:tag. set discharged to true. break. } }. if not discharged { Print "[" + time:clock + "] All capacitors drained". }. }. if probe[0]:getmodule("modulespu"):getfield("spu") <> "operational." { Print "[" + time:clock + "] Connection lost". shutdown. }. if time:seconds - timer > commtimeout { set nodata to true. break. } wait 0.001. }. if nodata { Print "[" + time:clock + "] Aborting ground level runs due to no data to transmit". } else { Print "[" + time:clock + "] Data transmission has begun". abort off. until abort { if ship:resources[0]:amount < lowbattlvl { set discharged to false. for cap in caplist { if cap:getmodule("dischargecapacitor"):getfield("status") = "ready" { cap:getmodule("dischargecapacitor"):doevent("discharge capacitor"). Print "[" + time:clock + "] Power levels low, discharging capacitor " + cap:tag. set discharged to true. break. } }. if not discharged { Print "[" + time:clock + "] All capacitors drained". }. }. if probe[0]:getmodule("modulespu"):getfield("spu") <> "operational." { Print "[" + time:clock + "] Connection lost". shutdown. }. wait 0.01. }. Print "[" + time:clock + "] Data transmission has ended". if alt:radar > 0 { Print "[" + time:clock + "] Second ground level experiment run commencing". toggle AG4. Print "[" + time:clock + "] Awaiting data transmission". set timer to time:seconds. set nodata to false. until comms[0]:getmodule("modulertdatatransmitter"):getfield("comms") = "uploading data..." { if ship:resources[0]:amount < lowbattlvl { set discharged to false. for cap in caplist { if cap:getmodule("dischargecapacitor"):getfield("status") = "ready" { cap:getmodule("dischargecapacitor"):doevent("discharge capacitor"). Print "[" + time:clock + "] Power levels low, discharging capacitor " + cap:tag. set discharged to true. break. } }. if not discharged { Print "[" + time:clock + "] All capacitors drained". }. }. if probe[0]:getmodule("modulespu"):getfield("spu") <> "operational." { Print "[" + time:clock + "] Connection lost". shutdown. }. if time:seconds - timer > commtimeout { set nodata to true. break. } wait 0.001. }. if nodata { Print "[" + time:clock + "] Aborting second ground level run due to no data to transmit". } else { Print "[" + time:clock + "] Data transmission has begun". abort off. until abort { if ship:resources[0]:amount < lowbattlvl { set discharged to false. for cap in caplist { if cap:getmodule("dischargecapacitor"):getfield("status") = "ready" { cap:getmodule("dischargecapacitor"):doevent("discharge capacitor"). Print "[" + time:clock + "] Power levels low, discharging capacitor " + cap:tag. set discharged to true. break. }. }. if not discharged { Print "[" + time:clock + "] All capacitors drained". }. }. if probe[0]:getmodule("modulespu"):getfield("spu") <> "operational." { Print "[" + time:clock + "] Connection lost". shutdown. }. wait 0.01. }. Print "[" + time:clock + "] Data transmission has ended". }. }. }. Print "[" + time:clock + "] All events have executed". abort off. }.