Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //CoyLaunch Master Script
- SET scriptVersion TO "0.1.0".
- //TODO:
- // - Get vehicle type
- // - Get desired apoapsis
- // - Copy relevant scripts
- // - Run launch for that vehicle type
- //HOW TO IMPLEMENT:
- // - Use thrust plate tag to determine vehicle type
- // - Use declared apoapsis
- // - Copy over sburn script if necessary
- // - Copy over launch staging script
- // - Copy over readout script
- // - Copy over engine tag script
- // - Run engine tag script + shutdown all engines
- // - Perform countdown + liftoff
- // - Run launch script
- // - Run readout script
- // - Kill everything when desapo reached
- DECLARE targetAlt.
- SET TERMINAL:WIDTH TO 50.
- SET TERMINAL:HEIGHT TO 25.
- CLEARSCREEN.
- PRINT "========COYOTE MLS LAUNCH CONTROLLER SCRIPT=======".
- PRINT "----------------------" + scriptVersion + "----------------------".
- WAIT 0.25.
- PRINT "Initializing...".
- //~~~~~Variables~~~~~
- SET countdown TO 10. //Length of countdown. Minimum of five seconds required.
- SET CDmessage TO " ". //Holds messages for countdown loop
- SET nextLine TO 7. //Handles event log printing after liftoff
- SET fairingSep TO FALSE. //Variable to view fairing separation status; false = still attached
- SET BECOtimer TO 10000. //Marks BECO time
- SET S1ECOtimer TO 10000. //Marks S1ECO time
- SET SBSepLevel TO 0. //Percent of fuel desired for booster RTLS.
- SET S1SepLevel TO 0. //Percent of fuel desired for first stage RTLS.
- SET activeStage TO "1". //Variable to view active stage
- SET updateRes TO 10. //Determines how many refreshes per second for the readout script
- //~~~~~Script management and more variables~~~~~
- IF SHIP:PARTSTAGGED("Mk1"):LENGTH > 0 {
- SET opMode TO "1".
- COPY CMLS1.ksm FROM 0.
- } ELSE IF SHIP:PARTSTAGGED("Mk1R"):LENGTH > 0 {
- SET opMode TO "1R".
- COPY CMLS1.ksm FROM 0.
- // COPY CMLSSBURN FROM 0.
- // COPY CMLSSBURN TO 2.
- // DELETE CMLSSBURN FROM 1.
- SET S1SepLevel TO 15.
- } ELSE IF SHIP:PARTSTAGGED("Mk2"):LENGTH > 0 {
- SET opMode TO "2".
- COPY CMLS2.ksm FROM 0.
- SET activeStage TO "1B".
- } ELSE IF SHIP:PARTSTAGGED("Mk2RB"):LENGTH > 0 {
- SET opMode TO "2RB".
- COPY CMLS2.ksm FROM 0.
- // COPY CMLSSBURN TO 3.
- // COPY CMLSSBURN TO 4.
- // DELETE CMLSSBURN FROM 1.
- SET activeStage TO "1B".
- SET SBSepLevel TO 15.
- } ELSE IF SHIP:PARTSTAGGED("Mk2R"):LENGTH > 0 {
- SET opMode TO "2R".
- COPY CMLS2.ksm FROM 0.
- // COPY CMLSSBURN TO 2.
- // COPY CMLSSBURN TO 3.
- // COPY CMLSSBURN TO 4.
- // DELETE CMLSSBURN FROM 1.
- SET activeStage TO "1B".
- SET SBSepLevel TO 15.
- SET S1SepLevel TO 20.
- }. //IF
- SWITCH TO 0.
- RUN CMLSeng. //Tags all engines and shuts down any running
- SWITCH TO 1.
- //~~~~~Parts~~~~~
- SET interStage TO SHIP:PARTSTAGGED("intstage")[0]. //Interstage fairing and decoupler between first and second stage
- SET fairingShell TO SHIP:PARTSTAGGED("fairinghalf"). //Both fairing halves
- IF opMode = "2RB" OR opMode = "2R" {
- SET SBAnt TO SHIP:PARTSTAGGED("SBAnt"). //Small omnidirectional antennae for booster communication
- }. //IF opMode antenna
- IF opMode = "1R" OR opMode = "2R" {
- SET S1Ant TO SHIP:PARTSTAGGED("S1Ant")[0]. //Small omnidirectional antenna for first stage communication
- SET S1finHinges TO SHIP:PARTSTAGGED("S1FinHinge").
- }. //IF opMode antenna
- SET S2Ant TO SHIP:PARTSTAGGED("S2Ant")[0]. //Small omnidirectional antenna for second stage communication
- SET lClamps TO SHIP:PARTSDUBBED("launchclamp1"). //Launch clamps holding first stage/boosters down
- FOR part IN lClamps {
- part:GETMODULE("RefuelingPump"):DOEVENT("Toggle Pump"). //Turn on fuel pump to keep stage topped off
- }. //FOR lClamps pump
- SET S2Tank TO SHIP:PARTSTAGGED("S2Tank")[0].
- SET S1Tank TO SHIP:PARTSTAGGED("S1Tank")[0].
- IF opMode = "1" OR opMode = "1R" {
- FOR res IN S1Tank:RESOURCES {
- IF res:NAME = "LQDOXYGEN" {
- SET S1LOX TO res.
- SET loxCap TO S1LOX:CAPACITY.
- }. //IF res
- }. //FOR res
- LOCK loxAmount TO S1LOX:AMOUNT.
- } ELSE IF opMode = "2" OR opMode = "2RB" OR opMode = "2R" {
- SET SBDecouplers TO SHIP:PARTSTAGGED("SBDecoup").
- SET LBTank[0] TO SHIP:PARTSTAGGED("LBTankA")[0].
- SET LBTank[1] TO SHIP:PARTSTAGGED("LBTankB")[0].
- SET RBTank[0] TO SHIP:PARTSTAGGED("RBTankA")[0].
- SET RBTank[1] TO SHIP:PARTSTAGGED("RBTankB")[0].
- FOR res IN LBTank[0]:RESOURCES {
- IF res:NAME = "LQDOXYGEN" {
- SET LBLOX[0] TO res.
- }. //IF res
- }. //FOR res
- FOR res IN LBTank[1]:RESOURCES {
- IF res:NAME = "LQDOXYGEN" {
- SET LBLOX[1] TO res.
- }. //IF res
- }. //FOR res
- FOR res IN RBTank[0]:RESOURCES {
- IF res:NAME = "LQDOXYGEN" {
- SET RBLOX[0] TO res.
- }. //IF res
- }. //FOR res
- FOR res IN RBTank[1]:RESOURCES {
- IF res:NAME = "LQDOXYGEN" {
- SET RBLOX[1] TO res.
- }. //IF res
- }. //FOR res
- SET loxCap TO (LBLOX[0]:CAPACITY + LBLOX[1]:CAPACITY + RBLOX[0]:CAPACITY + RBLOX[1]:CAPACITY).
- LOCK loxAmount TO MIN((LBLOX[0]:AMOUNT + LBLOX[1]:AMOUNT),(RBLOX[0]:AMOUNT + RBLOX[1]:AMOUNT)).
- }. //IF-ELSE loxCap
- LOCK loxRemaining TO (loxAmount / (loxCap + 0.01)). //Locks percentage of fuel left in stage +0.01 to avoid divide by zero/NaN
- PRINT "Awaiting launch. Press Action Group 0 to start " + countdown + "-second countdown".
- AG10 OFF.
- WAIT UNTIL AG10.
- //~~~~~Countdown sequence~~~~~
- PRINT "Countdown sequence started".
- UNTIL countdown = 0 { //Countdown loop
- IF countdown = 3 {
- FOR eng IN engAll {
- eng:GETMODULE("ModuleEnginesFX"):DOEVENT("Activate Engine").
- }. //FOR eng
- SET message TO " Main Engine Start".
- SET BEItime to TIME:SECONDS. //Records BEI time
- } ELSE IF countdown = 2 {
- SET message TO " All engines healthy".
- SAS ON.
- } ELSE IF countdown = 1 {
- SET message TO " Releasing clamps".
- } ELSE {
- SET message TO " ".
- }. //IF countdown message
- PRINT "T-" + countdown + message.
- SET countdown TO countdown - 1.
- WAIT 1.
- }. //UNTIL countdown
- FOR PART IN lClamps { //Loop to release launch clamps
- PART:GETMODULE("launchclamp"):DOEVENT("release clamp").
- }. //FOR lClamps release
- SET launchTime TO TIME:SECONDS. //Records liftoff time
- LOCK missionClock TO ROUND((TIME:SECONDS - launchTime), 1). //Sets missionClock to T-0 and starts counting, rounded to tenths of a second
- CLEARSCREEN.
- PRINT "============COYOTE MEDIUM LAUNCH SYSTEM===========" AT(0,0).
- PRINT "ASL: " AT(0,2). //Altitude above sea level readout at 6,2
- PRINT "VEL: " AT(16,2). //Surface or orbital velocity readout at 22,2
- PRINT "CLK: " AT(33,2). //Mission clock readout at 39,2
- PRINT "STG: " AT(0,3). //Current stage readout at 6,3
- PRINT "SFL: " AT(16,3). //Stage fuel level readout at 22,3
- PRINT "FRG: " AT(33,3). //Fairing status readout at 39,3
- PRINT "-------------------EVENT LOG----------------------" AT(0,5).
- PRINT "T-" + ROUND(ABS(BEItime - launchTime),2) + " BEI" AT(0,nextLine). //Time of BEI, will be negative
- SET nextLine TO nextLine + 1.
- PRINT "T+0.0 Liftoff" AT(0,nextLine).
- SET nextLine TO nextLine + 1.
- IF opMode = "1" OR opMode = "1R" {
- RUN CMLS1.ksm.
- } ELSE IF opMode = "2" OR opMode = "2RB" OR opMode = "2R" {
- RUN CMLS2.
- }.
- UNTIL SHIP:APOAPSIS >= (targetAlt * 1000) {
- PRINT FLOOR(SHIP:ALTITUDE) + " " AT(6,2).
- IF ALTITUDE <=50000 { //Prints surface velocity below 50km, orbital above
- PRINT ROUND(VELOCITY:SURFACE:MAG,1) + " " AT(22,2).
- } ELSE {
- PRINT ROUND(VELOCITY:ORBIT:MAG,1) + " " AT(22,2).
- }. //IF-ELSE
- PRINT missionClock AT(39,2).
- PRINT activeStage AT(6,3).
- PRINT ROUND((loxRemaining * 100), 1) + "% " AT(22,3).
- IF fairingSep = FALSE { //Prints ATCHD or SPRTD depending on whether the fairings are still on
- PRINT "ATCHD" + " " AT(39,3).
- } ELSE {
- PRINT "SPRTD" + " " AT(39,3).
- }. //IF-ELSE
- WAIT (1 / updateRes). //Update resolution turned into fraction
- }. //UNTIL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement