Jump to content

Mod to make batteries drain on ships outside physics range.


Mulbin

Recommended Posts

So at the moment batteries don't drain on probes and ships if they are not the currently active vessel, or within 2km of the active vessel.

I know asmi's life support mod fixed this but I'd really like a mod that just fixes the batteries without adding O2, food etc (I already use IFLS).

Any takers? Hoping its a small mod to fix a huge hole in gameplay... currently probes without solar panels have infinite power.

Link to comment
Share on other sites

The problem is not the batteries themselves but all the parts that drain power. You'd have to change every part that consumes power, such as the probe cores.

BackgroundProcessing is the closest thing I've seen to a general-purpose solution.

Is that how asmi's mod does it? It's not actually very many parts for a mod to effect... particularly if its a module. It takes minutes to write a module manager file for all pods and antennas.

no coders out there fancy tackling the module itself? Seems like a major flaw with ksp than can definitely be fixed (as mentioned its already part of asmis life support so is possible).

I'm happy to type out the MM file to add it to stock parts once the module exists!

Link to comment
Share on other sites

...no coders out there fancy tackling the module itself?...

The main problem here is that PartModules don't actually exist in unloaded vessels. The vessel itself only exists as a set of data, not much code is run. At a part and partmodule level, no code at all is run.

So for unloaded vessels you need a separate bit of code to run in the backbround and calculate changes in values such as electricCharge in batteries based on values of +/- electric charge per second in probe cores, RTGs and solar panels. This is exactly what BackgroundProcessing does.

This means that you don't need to add any modules to probe cores, RTGs and solar panels (in fact, doing so would get you nothing, since those modules would be destroyed the moment the vessel is unloaded). The plugin continuously runs in the background and takes over the power drain / generation functionality of those parts when they are unloaded.

Of course you could also do it with a small plugin that remembers each vessel and how long it has been unloaded and then simply calculates the net value for electricCharge whenever a vessel gets loaded in pseudocode


for each probe core:
netPowerDrain = probe core power consumption per second * time since unload

for each RTG/solar panel
netPowerGenerated = RTG/solar panel power production * time since unload

netPowerChange = netPowerDrain + netPowerGenerated

VesselTotalCharge = VesselTotalCharge + netPowerChange

This however has a few drawbacks. For example if you switch to your vessel while it is in the dark, behind a planet/moon, this method would assume that it was without sunlight the entire time and wouldn't calculate any power generated from the solar panels.

Another advantage of the way BackgroundProcessing does it, is that other mods can act on changes in unloaded vessels while they are unloaded. For example, if RemoteTech ever where to implement BackgroundProcessing, unloaded satellites could go out of power and the mod would actually know about it as it happened and remove that satellite from the relay network.

Hmm. That might be a good idea actually. I think I'll go implement BackgroundProcessing in RT :D

Link to comment
Share on other sites

I might just pipe in with a couple of the limitations of BackgroundProcessing as it stands at the moment:

- It only handles electric charge for ModuleSolarPanels, ModuleCommands, and ModuleGenerators that have no input resources.

AFAIK the only things that generates/uses electric charge and doesn't follow those rules in stock are consume-on-use like antennas, or are liquid fuel engines generating electric charge (and you can't have them on when you offload a vessel).

But this does mean that any mod you're using that adds something that generates or consumes electric charge and doesn't fit into those rules won't work. For example, a hydrogen fuel cell that consumes a hydrogen resource to produce electric charge. A scanner module that consumes charge over time to scan and doesn't do it using a ModuleGenerator that produces negative electric charge. They can be made to work, but it requires people to specifically take into account background processing, and as far as I'm aware nobody does that yet.

- It doesn't work for vessels that are prelaunch. This usually isn't a big deal. The reason is that vessels sometimes exist in a weird transient state when going from VAB to launchpad, and the easiest way to detect that state was to rule out all prelaunch vessels.

- I've had to essentially reimplement the resource generation code, as JDP notes above. I wouldn't be very confident it's an exact match to what Squad is doing. You may notice some differing resource consumption/generation rates backgrounded in some situations. I don't know of any off the top of my head, but I'd be very surprised if they weren't there. I guess one big example is that solar panel tracking speed is ignored - I assume they've tracked to perfect position every 'tick'. A ship that was spinning fast enough that they couldn't do that would be an example then, I guess. Solar panels that don't have tracking don't have that behaviour, of course.

- Keeping track of what partmodules are on a vessel when its been unloaded and is essentially just a ProtoVessel is a goddamn nightmare. If you've changed your mods around with a vessel in the background, expect some stuff to not quite work right. I think I've written defensively enough that nothing should explode, but you might, for example, end up with only some of the resource producers/consumers on the vessel being active.

- I think the way I allocate resources to resource containers doesn't match what KSP does. Also I assume all resources can flow to all resource containers. That's true of electric charge, but if another mod decided to use background processing for something where that's not the case, there's a realism hole. That one is fixable, I guess, but it'd be a lot of work.

- BackgroundProcessing is very new, and I'm quite new to KSP modding. There are almost certainly bugs I don't know about in it. JDP found one today that made background resource consumption/processing rates wrong.

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...