Jump to content

Resource Flow Mechanics Overhaul


Majiir

Recommended Posts

Redundant resource definitions is something that can only be handled by those modders getting together and settling on a compromise; as they likely use those resources differently, some third party bit of code coming in and making them the same would break one or both of them, and almost certain create a situation of massive unbalance. The mods in question will have to become balanced together.

Also it's not really the responsibility of the resource manager to do that even if it wouldn't be a horrible idea.

Link to comment
Share on other sites

The ORS is completely unrelated to this; it's an open resource spawning and collection system similar to Kethane

That's not exactly true Greys, ORS is only parly about custom resource definitions, the other part is exactly the topic of this thread. Notably it includes the resource manager that I wrote for Interstellar, which is designed to provide a managed alternative to part.RequestResource for resources featuring long term ongoing supply and demand. This is mainly advantageous for resources that behave like ElectricCharge and have a large and consistent turnover.

The upcoming version will provide a "fixed" RequestResource function which behaves like part.RequestResource for STACK_PRIORITY_SEARCH and NO_FLOW resources but implement custom behaviour for ALL_VESSEL flow resources, this is to avoid the unusual stock behaviour of part.RequestResource returning 0 when the resource draw is 1e-5 or less.

Link to comment
Share on other sites

Redundant resource definitions is something that can only be handled by those modders getting together and settling on a compromise; as they likely use those resources differently, some third party bit of code coming in and making them the same would break one or both of them, and almost certain create a situation of massive unbalance.

Also, resource definitions may vary even if the nomenclature is the same. For example, KSP Interstellar treats a Megajoule as equal to 1,000 Electrical charge - but if you view the Mk. 1 pod as analogous to the Mercury capsule, and the Mk. 1-2 as analogous to the Apollo CM, 1 Megajoule would equal about 1 Electrical charge. (the Mk. 1 has 50 electric charge, and the Mercury capsule had batteries with 13-16.5 kWh of charge, which works out to 46-59MJ)(amounts grew over the course of the program) So if another mod author presumes that KSP scales to RL, then there is a difference in how the mod will perform when KSPI is installed - one or the other isn't going to work correctly.

Link to comment
Share on other sites

  • 1 month later...

Consider the following use case of a life support mod, which should be supported IMHO:

- Per-Crewmember consumption: oxygen, food; production: waste

- Crewmember dies (and consumption ceases) if either oxygen or food can not be provided for a short period of time

- Regenerator module, consumes electricity and waste, produces oxygen

Now assume that the oxygen storage capacity is very small, so basically the regenerator must provide oxygen for two kerbals at all times.

Assume that the vessel has two crew members, but during a few days before and after Kerbol apoapsis, the oxygen production is insufficient for two kerbals due to low solar panel electricity output.

The correct behaviour would be to let one Kerbal die at apoapsis, and cease his food consumption.

This needs to work even if the vessel is not loaded during its apoapsis pass. An incorrect implementation might

- not even notice that the vessel had insufficient power

- continue the Kerbal's food consumption/waste production until the vessel is loaded again

Link to comment
Share on other sites

  • 3 years later...

Note: I understand the thread is old, I'm posting this anyway not to discuss with the previous posters (probably most gone by now), but to leave a link to source code that may be useful to those that ends up in this thread because interested in these issues.

 

On 12/18/2013 at 9:03 AM, Majiir said:

A few items to get us started:

  • Batch resource requests. Producing or consuming multiple resources in proportion is non-trivial, and the rest of the library may necessitate this feature.
  • Storage-independent request resolution. In other words, how much (or little) resource storage a vessel has should not influence how resources flow in that vessel. This applies to high-timewarp situations but also comes up when a vessel has zero storage for some resource but produces and consumes it simultaneously.
  • Offline resource flow. This might be implemented by allowing modules to declare a constant resource flow rate and resolving storage deltas when the vessel is loaded again.

3 years later, all 3 of these features have been implemented in the resource cache system of this mod. The relevant source code is here, and is in the public domain.

  • 'Batch resource requests': the OP clearly understood the issue here. When inputs and outputs are inter-dependent, the problem is essentially of an information-loss nature: the inter-dependency information need to be preserved and taken into account when executing the 'requests'. This is solved in the code linked, by preserving information in recipes.
  • 'Storage-independent resolution': another great insight by the OP. This is solved in the code linked by allowing pure-inputs and pure-outputs recipes to overflow/underflow the resource capacity, while the inter-dependent recipes are instead executed using an iterative algorithm, that is very simple and fundamentally agnostic of the orders in which recipes are executed.
  • 'Offline resource flow': This is also accomplished in the code linked. Producers and consumers in unloaded vessels are simulated, resulting in a set of recipes that is then feed into the resource cache system. The state of all resources is then synchronized back into the vessel proto structures. The process is atomic, and performed at an arbitrary frequency.
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...