// functions for calculating steering values. @lazyglobal off. function GetPitch { parameter v is SHIP:FACING:FOREVECTOR. return 90 - vectorangle(SHIP:UP:FOREVECTOR, v). } function GetAscentVector { parameter minPitch. // face prograde, but hold a solid eastern heading and don't // rotate the ship local newHeading is lookdirup(SHIP:SRFPROGRADE:FOREVECTOR, heading(90, 0, 270):TOPVECTOR). if GetPitch(newHeading:FOREVECTOR) < minPitch { set newHeading to heading(90, minPitch, 270). } return newHeading. } function AddCircularizationNode { parameter usePeriapsis is false. local target is SHIP:ORBIT:APOAPSIS. local t is TIME + SHIP:ORBIT:ETA:APOAPSIS. if usePeriapsis { set target to SHIP:ORBIT:PERIAPSIS. set t to SHIP:ORBIT:ETA:PERIAPSIS. } local n is Node(t, 0, 0, 0). add(n). local delta is 1. local diff is n:ORBIT:APOAPSIS - n:ORBIT:PERIAPSIS. until (diff < 1000) { set n:PROGRADE to n:PROGRADE + delta. local newDiff is n:ORBIT:APOAPSIS - n:ORBIT:PERIAPSIS. if newDiff > diff { set delta to (delta * -1) / 10. } set diff to newDiff. } }