Jump to content

Accessing ModuleResourceConverter/Harvester conversion rates


Recommended Posts

I'm looking for a way to access the "current" conversion rate of a ModuleResourceConverter or ModuleResourceHarvester. I've figured out how to get the inputs and outputs, but it's not very clear from staring at the API for a few hours how I might actually scale those inputs/outputs in order to get the current rate of production (or use) of one of the output resources. 

I can get in/out lists and rates with this:

BaseConverter.inputList, BaseConverter.outputList

There's lots of fields with various parameters that would affect the final in/out numbers - I just don't see how I can get the "results" of the conversion at the current timestep. I feel like I must be missing something. 

(and no, I can't do deltas on resource consumption/production to get this ;). 

Link to comment
Share on other sites

1 hour ago, RoverDude said:

@Nertea - what are you looking to do exactly?  There are a lot of dials and hooks on that specific module and I can point you in the right direction.  Ping me here or on IRC.

Thanks - I'm trying to write a thing in a plugin that polls electricity-producing or consuming modules. Converters/harvesters are a big part of that, so I'm looking to figure out, for example, how much an Ec using converter is currently pulling, or perhaps how much a RoverDude reactor is producing.

Link to comment
Share on other sites

Oh!  That's easy then :)  There's a hook for post-processing.  This will give you delta time and a time factor.  You can use this as a multiplier on the recipe's EC use to get actual consumption rate (this way it takes into account all of the calculations including thermal, etc.)

some of my modules use this hook (for example, the life support recycler in USI-LS)

Link to comment
Share on other sites

protected override void PostProcess(ConverterResults result, double deltaTime)
        {
            var diff = Math.Abs(deltaTime - result.TimeFactor);
            RecyclerIsActive = diff < 0.00001f;
        }

I presume this is what you're talking about then? I can then use something like...

EcRate = result.TimeFactor * outputs.ecResource.ratio

Now as that's a protected override, how do I get at it from another class without extending resource converter? This might be more of a general programming Q...

 

edit: @RoverDude, adding a ping.

 

Edited by Nertea
Link to comment
Share on other sites

That's usually how custom stuff like that is done with resources - you inherit from baseconverter (or one of the super classes) and fiddle with the hooks as needed.  So if you needed it in another class (say, something that culled all of the results), just add a public property, set it in post process, and do your thing.

 

Actually.. two more ways.

There's an event (OnEfficiencyChange) that will also kick the most recent TimeFactor to you.  You can also access this directly with lastTimeFactor 

(totally forgot I exposed these in 1.2!)

Link to comment
Share on other sites

4 minutes ago, RoverDude said:

That's usually how custom stuff like that is done with resources - you inherit from baseconverter (or one of the super classes) and fiddle with the hooks as needed.  So if you needed it in another class (say, something that culled all of the results), just add a public property, set it in post process, and do your thing.

 

Actually.. two more ways.

There's an event (OnEfficiencyChange) that will also kick the most recent TimeFactor to you.  You can also access this directly with lastTimeFactor 

(totally forgot I exposed these in 1.2!)

Well that last one is super easy then :P. I'll give it a shot when I have some testing time and report back!

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