Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // !runscript mMcreu59
- function transferFuelAmount {
- parameter srcEl to 0.
- parameter destEl to 1.
- parameter resType to "liquidfuel".
- parameter amount to 1.
- set srcTanks to list().
- for elRes in ship:elements[srcEl]:resources
- if elRes:name = resType
- for p in elRes:parts
- for res in p:resources
- if res:Name = resType and res:amount > 0 and res:enabled {
- srcTanks:add(p).
- }
- set destTanks to list().
- for elRes in ship:elements[destEl]:resources
- if elRes:name = resType
- for p in elRes:parts
- for res in p:resources
- if res:Name = resType and res:amount + 1 < res:capacity and res:enabled = 1 {
- destTanks:add(p).
- }
- if srcTanks:length < 1 print "No Source Tanks with " + resType.
- if destTanks:length < 1 print "No destination tanks with room for " + resType.
- if srcTanks:length > 0 and destTanks:length > 0 {
- local trans is transfer(resType, srcTanks, destTanks, amount).
- set trans:active to true.
- on trans:status {print restype + " transfer is " + trans:status.}
- return trans.
- }
- }
- function transferfuel {
- parameter srcEl to 0.
- parameter destEl to 1.
- parameter resType to "liquidfuel".
- set srcTanks to list().
- for elRes in ship:elements[srcEl]:resources
- if elRes:name = resType
- for p in elRes:parts
- for res in p:resources
- if res:Name = resType and res:amount > 0 and res:enabled = 1{
- srcTanks:add(p).
- }
- set destTanks to list().
- for elRes in ship:elements[destEl]:resources
- if elRes:name = resType
- for p in elRes:parts
- for res in p:resources
- if res:Name = resType and res:amount + 1 < res:capacity and res:enabled = 1 {
- destTanks:add(p).
- }
- if srcTanks:length < 1 print "No unlocked Source Tanks with " + resType.
- if destTanks:length < 1 print "No unlocked destination tanks with room for " + resType.
- if srcTanks:length > 0 and destTanks:length > 0 {
- local trans is transferAll(resType, srcTanks, destTanks).
- set trans:active to true.
- on trans:status {print restype + " transfer is " + trans:status. }
- return trans.
- }
- }
- function FillMeUpScotty {
- parameter srcEl to 1.
- parameter destEl to 0.
- parameter resourceList to List("liquidfuel","oxidizer").
- set transfers to list().
- for res in resourceList {
- set trans to transferfuel(srcEl, destEl, res).
- transfers:add(trans).
- }
- }
- function ShowResources {
- set elcount to 0.
- for el in ship:elements {
- print "[" + elcount + "] " + el:name.
- set elcount to elcount + 1.
- set rescount to 0.
- for res in el:resources {
- print (" [" + rescount + "] " + res:name):padright(21)
- + round(res:amount / res:capacity * 100):tostring():padright(4)
- + round(res:amount,1):tostring():padright(8)
- + "/ "
- + round(res:capacity,1):tostring().
- set rescount to rescount + 1.
- }
- print "-".
- }
- }
- function balanceResource {
- parameter resourceName is "liquidfuel".
- for res in ship:resources
- if res:name = resourceName
- set shipResource to res.
- set targetPercent to shipResource:amount / shipResource:capacity.
- print "Targeting " + round(targetPercent*100, 2):tostring() + "% in each tank".
- set remainingTanks to shipResource:parts.
- set transfer to list().
- until remainingTanks:length = 1 {
- print remainingTanks:length + " remaining tanks".
- set activeTank to remainingTanks[0].
- remainingTanks:remove(0).
- for tankRes in activeTank:resources
- if tankRes:name = resourceName
- set activeTankResource to tankRes.
- set targetAmount to targetPercent * activeTankResource:capacity.
- set transferAmount to targetAmount - activeTankResource:amount.
- // if positive transfer in
- if(transferAmount > 0)
- set resTransfer to transfer(resourceName, remainingTanks, list(activeTank), transferAmount).
- // if negative transfer out
- if(transferamount < 0)
- set resTransfer to transfer(resourceName, list(activeTank), remainingTanks, -transferAmount).
- set resTransfer:active to true.
- wait until resTransfer:status <> "Transferring" or abs(targetAmount - activeTankResource:amount) < 0.1.
- set resTransfer:active to false.
- if resTransfer:status <> "Finished" and resTransfer:status <> "Inactive" print resTransfer:status.
- }
- list engines in es. set totalTorque to v(0,0,0). for e in es set totalTorque to totalTorque + vcrs(e:position, e:facing:vector) * e:availablethrust.
- print "Complete. Torque at " + round(totalTorque:mag,4).
- }
- function transferDv {
- parameter srcEl.
- parameter destEl.
- parameter isp.
- parameter targetdv.
- set elementdrymass to 0.
- for p in ship:elements[destEl]:parts
- set elementdrymass to elementdrymass + p:drymass.
- //add non fuel mass back into drymass
- set fuellist to list("liquidfuel","oxidizer"). //todo:switch for different engine fuel requirements
- for elres in ship:elements[destEl]:resources {
- if not fuellist:contains(elres:name)
- set elementdrymass to elementdrymass + elres:amount * elres:density.
- if elres:name = "liquidfuel"
- set currLiquid to elres:amount.
- if elres:name = "oxidizer"
- set currOx to elres:amount.
- }
- set finalmass to elementdrymass * constant:e^(targetdv / isp / constant:g0).
- set liquidtarget to 9 / 20 * (finalmass - elementdrymass).
- set oxtarget to 11 / 20 * (finalmass - elementdrymass).
- set liquidunits to liquidtarget / 0.005.
- set oxunits to oxtarget / 0.005.
- //remove existing fuel amounts
- set liquidunits to liquidunits - currLiquid.
- set oxunits to oxunits - currOx.
- set lox to transferFuelAmount (srcEl, destEl, "liquidfuel", liquidunits).
- set ox to transferFuelAmount (srcEl, destEl, "oxidizer", oxunits).
- }
- function getsubtree {
- parameter p.
- parameter parts is list().
- for x in p:children {
- parts:add(x).
- getsubtree(x, parts).
- }
- return parts.
- }
- showresources().
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement