Jump to content

change active state based on fuel level


Recommended Posts

I have made a simple generator module part to covert Karbonite to my new resource. However the problem with the generator module is that it as long as it is active it will continue to generate long after the tanks are full, wasting precious resources. I want some way to return the amount of free space left in type x tanks on this.vessel and deactivate the generator when the tanks are full or near full. I checked the API (http://wiki.kerbalspaceprogram.com/wiki/API:Vessel) but did not find what I was looking for. Any suggestions?

Link to comment
Share on other sites

This documentation is more complete. But that's not saying very much. Often there is no documentation and you have to look through the Object Browser for likely-looking class names.

In this case the relevant things are in fact documented and you can probably you can do something like

int resourceID = PartResourceLibrary.GetDefinition("LiquidFuel").id;
double freeSpace = 0;
for(Part p in vessel.parts) {
for(PartResource r in p.Resources) {
if(r.info.id == resourceID) freeSpace += r.maxAmount - r.amount;
}
}

Link to comment
Share on other sites

I recommend using my TacGenericConverter as a replacement for the stock generator module. Or use the modified version of my class created by RoverDude for Karbonite, MKS/OKS, etc. You should really talk to him since it sounds like your effort is overlapping with what he is doing. And I will be folding his changes into my class eventually (he hasn't shared them with me yet).

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...