Advertisement
Guest User

Untitled

a guest
Sep 17th, 2022
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.48 KB | Source Code | 0 0
  1. @lazyglobal off.
  2.  
  3. function calc_deltav_vacuum_all
  4. {
  5.     parameter ves is ship.
  6.  
  7.     local deltaV to 0.
  8.     local stageCounter to ves:stagenum.
  9.     // The parts begin from bottom to top, the stageNum begins from top to bottom.
  10.     // "calc_deltav_vacuum_stage" expects the part logic. So we count from 0 up.
  11.     local currentStage to 0.
  12.     local totalWetmass to 0.
  13.     until stageCounter = -1
  14.     {
  15.         local calcDeltaVResult to calc_deltav_vacuum_stage(currentStage, ves, totalWetmass).
  16.         local returnDeltaV to calcDeltaVResult[0].
  17.         set totalWetmass to totalWetmass + calcDeltaVResult[1].
  18.         set deltaV to deltaV + returnDeltaV.
  19.         set stageCounter to stageCounter - 1.
  20.         set currentStage to currentStage + 1.
  21.     }
  22.     print "Total delta v of vessel is " + round(deltaV) + " m/s".
  23.     return deltaV.
  24. }
  25.  
  26. function calc_deltav_vacuum_stage
  27. {
  28.     parameter currentStage.
  29.     parameter ves is ship.
  30.     parameter upperWetMass is 0.
  31.  
  32.     // HACK: Workaround mapping
  33.     set currentStage to currentStage - 1.
  34.  
  35.     local totalIsp to 0.
  36.     local totalWetmass to upperWetMass.
  37.     local totalDrymass to upperWetMass.
  38.     local parts to ves:parts.
  39.     for part in parts
  40.     {
  41.         // HACK: Workaround because engine were always one stage too high
  42.         if (part:typename = "engine" and (part:stage - 1) = currentStage)
  43.         {
  44.             print "Part on stage: " + (currentStage + 1) + " is (engine) " + part:name.
  45.             set totalIsp to totalIsp + part:visp.
  46.             set totalWetmass to totalWetmass + part:mass.
  47.             set totalDrymass to totalDrymass + part:drymass.
  48.         }
  49.         else if (part:stage = currentStage and part:typename <> "engine")
  50.         {
  51.             print "Part on stage: " + (currentStage + 1) + " is " + part:name.
  52.             set totalWetmass to totalWetmass + part:mass.
  53.             set totalDrymass to totalDrymass + part:drymass.
  54.         }
  55.     }
  56.     if (totalIsp = 0 or totalWetmass = 0 or totalDrymass = 0)
  57.     {
  58.         print "DeltaV of stage " + (currentStage + 1) + " is 0 m/s".
  59.         return list(0, 0).
  60.     }
  61.     local deltaV to (totalIsp * constant:g0 * ln(totalWetmass / totalDrymass)).
  62.     print "totalIsp of stage " + (currentStage + 1) + " is " + round(totalIsp).
  63.     print "totalWetmass of stage " + (currentStage + 1) + " is " + round(totalWetmass, 2).
  64.     print "DeltaV of stage " + (currentStage + 1) + " is " + round(deltaV) + " m/s".
  65.     return list(deltaV, totalWetmass).
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement