Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // we need this for when there are mutliple drop pods on the aircraft
- declare parameter podnum.
- function LogData {
- parameter text.
- // print to both the console and log
- print "[" + time:clock + "] " + text.
- log "[" + time:clock + "] " + text to droplog.
- // make a copy on the local KSC archive in case we lose connection
- // be sure we don't try to do this while not in contact with KSC!
- if addons:rt:haskscconnection(ship) { copy droplog to 0. }.
- }.
- function BattStatusCheck {
- parameter lowbattlvl.
- // only bother if all capacitors are not discharged and electric charge has fallen below danger levels
- if not discharged and ship:resources[0]:amount < lowbattlvl {
- // if a capacitor is discharging, check that it is done
- if capactive > -1 {
- if caplist[capactive]:getmodule("dischargecapacitor"):getfield("status") = "discharged!" { set capactive to -1. }.
- } else {
- set capnum to 0.
- until capnum = caplist:length {
- if caplist[capnum]:getmodule("dischargecapacitor"):getfield("status") = "ready" {
- // tweak the discharge rate down so batteries do not fill up before capacitor finishes discharging, wasting energy
- caplist[capnum]:getmodule("dischargecapacitor"):setfield("percent power", 50).
- caplist[capnum]:getmodule("dischargecapacitor"):doevent("discharge capacitor").
- // remember which capacitor is actively discharging
- set capactive to capnum.
- LogData("Power levels low, discharging capacitor " + caplist[capnum]:tag).
- break.
- }.
- set capnum to capnum + 1.
- }.
- // was that all of them?
- if capnum = caplist:length {
- set discharged to true.
- LogData("All capacitors drained").
- }.
- }.
- }.
- }.
- function BeginTransmission {
- LogData("Awaiting data transmission").
- local timer is time:seconds.
- // until the comms message changes from "idle", nothing is being transmitted
- until comms:getmodule("modulertdatatransmitter"):getfield("comms") <> "idle" {
- // keep tabs on our power status - release capcitor charge as necessary
- BattStatusCheck(lowbattlvlnorm).
- // keeps tabs on our connection to Mission Control
- if not addons:rt:haskscconnection(ship) {
- LogData("Connection lost").
- return false.
- }.
- // if the user recycles all experiments, no data will be sent
- if time:seconds - timer > commtimeout {
- return false.
- }
- wait 0.001.
- }.
- // we are transmitting!
- return true.
- }.
- function MonitorTransmission {
- LogData("Data transmission has begun").
- // keep an eye on the comm status and if it stays idle for too long we're done transmitting
- until time:seconds - transtime > transmissiontimeout {
- BattStatusCheck(lowbattlvltrans).
- if not addons:rt:haskscconnection(ship) {
- LogData("Connection lost").
- return false.
- }.
- // if there was a period of idleness broken by a new transmission, reset the time-out counter
- if transtime < time:seconds and comms:getmodule("modulertdatatransmitter"):getfield("comms") = "uploading data..." {
- lock transtime to time:seconds.
- }.
- // comms have fallen silent, start the time-out counter
- if transtime = time:seconds and comms:getmodule("modulertdatatransmitter"):getfield("comms") = "idle" {
- set transtime to time:seconds.
- }.
- wait 0.001.
- }.
- // re-lock the time-out timer to the current time so it's always 0
- lock transtime to time:seconds.
- LogData("Data transmission has ended").
- // do a check of comm status as we exit
- return addons:rt:haskscconnection(ship).
- }.
- function DoExperimentRun {
- parameter name.
- LogData("First " + name + " experiment run commencing").
- toggle AG4.
- // goo containers are only used once per run
- 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"):hasevent("observe mystery goo") {
- goo:getmodule("modulescienceexperiment"):doevent("observe mystery goo").
- break.
- }.
- }.
- if not BeginTransmission() {
- // aborts the second run as well - no data means no data for this entire biome level
- LogData("Aborting " + name + " runs due to no data to transmit").
- return false.
- } else {
- if not MonitorTransmission() {
- return false.
- }.
- // take a second run for any additional data
- LogData("Second " + name + " experiment run commencing").
- toggle AG4.
- if not BeginTransmission() {
- LogData("Aborting second " + name + " run due to no data to transmit").
- return false.
- } else {
- if not MonitorTransmission() {
- return false.
- }.
- }.
- }.
- // a good run!
- return true.
- }.
- function Main {
- // let user know what is available for program use
- LogData("Program running... confirming systems").
- LogData(battlist:length + " Battery(s) found").
- LogData(caplist:length + " Capacitor(s) found").
- LogData(goolist:length + " Goo canister(s) found").
- LogData("Operational systems confirmed, awaiting deployment").
- // no need to monitor systems as we are connected to power of mothership
- until not decoupler:getmodule("moduleanchoreddecoupler"):hasevent("decouple") { wait 1.}.
- LogData("Pod deployed, awaiting chute deployment").
- // wait for chute to open
- until lochute:getmodule("realchutemodule"):hasevent("cut chute") {
- wait 0.001.
- }.
- LogData("Chute deployment confirmed. Awaiting full deployment").
- // turn on all batteries
- for batt in battlist {
- set batt:resources[0]:enabled to true.
- }.
- LogData("All batteries enabled").
- // wait for full deployment and reduced vertical speed
- until alt:radar < deploylowerheight and ship:verticalspeed*-1 < maxdropspeed {
- BattStatusCheck(lowbattlvlnorm).
- wait 0.001.
- }.
- LogData("Full chute deployment confirmed").
- comms:getmodule("modulertantenna"):doevent("activate").
- LogData("Communications antenna deployed. Awaiting connection").
- // can we connect to KSC?
- set timer to time:seconds.
- until addons:rt:haskscconnection(ship) {
- BattStatusCheck(lowbattlvlnorm).
- if time:seconds - timer > commtimeout {
- LogData("Communications link failed to connect to KSC!").
- return false.
- }
- wait 0.001.
- }.
- LogData("Communications link established").
- // begin run, check for connection if something went wrong
- if not DoExperimentRun("lower atmospheric") {
- if not addons:rt:haskscconnection(ship) {
- return false.
- }.
- }.
- // wait for landing
- LogData("Awaiting landing").
- until ship:verticalspeed >= 0 {
- BattStatusCheck(lowbattlvlnorm).
- if not addons:rt:haskscconnection(ship) {
- LogData("Connection lost").
- return false.
- }.
- wait 0.001.
- }.
- LogData("Landing confirmed").
- // one last run
- if not DoExperimentRun("ground level") {
- if not addons:rt:haskscconnection(ship) {
- return false.
- }.
- }.
- return true.
- }.
- //create access to all the parts
- set hichute to ship:partstagged("hi" + podnum)[0].
- set lochute to ship:partstagged("lo" + podnum)[0].
- set comms to ship:partstagged("antenna" + podnum)[0].
- set probe to ship:partstagged("core" + podnum)[0].
- set decoupler to ship:partstagged("drop" + podnum)[0].
- set battlist to ship:partsdubbed("battery" + podnum).
- set caplist to ship:partsdubbed("capacitor" + podnum).
- set goolist to ship:partstagged("goo" + podnum).
- // program behavior variables
- set deploylowerheight to 3000.
- set maxdropspeed to 12.
- set commtimeout to 30.
- set transmissiontimeout to 15.
- set lowbattlvlnorm to 25. // for when no data is being transmitted
- set lowbattlvltrans to 150. // for when data is being transmitted
- set capactive to -1.
- set discharged to false.
- lock transtime to time:seconds.
- clearscreen.
- abort off.
- if Main() {
- LogData("All events have executed").
- }.
- // send stats
- set battremaining to 0.
- set capremaining to 0.
- for batt in battlist {
- set battremaining to battremaining + batt:resources[0]:amount.
- }.
- for cap in caplist {
- set capremaining to capremaining + cap:resources[0]:amount.
- }.
- print "Power remaining: " + round(battremaining) + "/825".
- print "Capacitor remaining: " + round(capremaining) + "/3200".
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement