diff --git a/lib/node.ks b/lib/node.ks index 55a0416..f9cf43b 100644 --- a/lib/node.ks +++ b/lib/node.ks @@ -39,10 +39,11 @@ function ExecNode { print "Node execution complete.". } +// currently only works for testing against *current* stage. function WillStage { parameter dV. if not HASNODE { return false. } - return dV > NEXTNODE:DELTAV:MAG. + return dV > SHIP:StageDeltaV(SHIP:STAGENUM):VACUUM. } // Calculate the time required to burn a given dV. @@ -54,19 +55,18 @@ function BurnTime { local lastStage is false. // We allow a small tolerance to deal with potential floating point errors. until totaldV <= 0.001 { - local F is stageThrust(). - local Isp is stageISP(). + local F is stageThrust(s). + local Isp is stageISP(s). local m is stageMass(s). // TODO: handle node execution in atmosphere? local dV is min(totaldV, SHIP:StageDeltaV(s):VACUUM). local t is calcBurnTime(dV, m, Isp, F). - print "DEBUG: " + dV + " m/s^2 in stage " + s + ", in " + t + " seconds.". + set totaldV to totaldV - dV. set s to s - 1. set totalT to totalT + t. } - print "DEBUG: Total Burn Time: " + totalT + " s.". return totalT. } @@ -74,8 +74,10 @@ function BurnTime { function calcBurnTime { parameter dV, m, Isp, F. - if F = 0 { - print "WARNING: Tried to calculate burn time with a thrust of 0. Returning 0. Your calculations are probably wrong.". + if F = 0 or Isp = 0 { + print "WARNING: Tried to calculate burn time with a denominator value of 0. Returning 0. Your calculations are probably wrong.". + print "F: " + F . + print "Isp: " + Isp. return 0. } @@ -96,7 +98,7 @@ function stageISP { local eCount is 0. for e in en { if e:STAGE >= s and e:DECOUPLEDIN < s { - set ispSum to ispSum + e:ISP. + set ispSum to ispSum + e:VACUUMISP. set eCount to eCount + 1. } } @@ -139,11 +141,14 @@ function stageMass { local ps is List(). list PARTS in ps. for part in ps { - if part:DECOUPLEDIN <= s { + if part:DECOUPLEDIN >= s { set m to m - part:MASS. - } else if part:HasSuffix("AVAILABLETHRUST") and part:AVAILABLETHRUST > 0 { - // This is an engine and it is currently active. Subtract the fuel - // it will burn before the next stage. + } + } + + list ENGINES in ps. + for part in ps { + if part:DECOUPLEDIN < s and part:AVAILABLETHRUST > 0 { set m to m - (part:MAXMASSFLOW * SHIP:StageDeltaV(SHIP:STAGENUM):DURATION). } }