kRPC: Control the game using C#, C++, Java, Lua, Python...

kRPC: Control the game using C#, C++, Java, Lua, Python...

7.8k Downloads

Unexpected Returns in resources_in_decouple_stage() Method in Python Client

FlyingFaller opened this issue ยท 0 comments

commented

What happened?

When using the vessel.resources_in_decouple_stage(i, cumulative=False) method the expected output is a resources object for a given stage number i. However, with simple, linearly assembled and staged rockets, resources are incorrectly sorted into stages. A basic description of this behavior from testing using vessel.resources_in_decouple_stage(stage=i, cumulative=False).names to observe where KRPC is placing different resources.

  • Stages are always -1 indexed. The last stage is always -1 and the reason for this is unclear.
  • When a staging event does not immediately consume a resource (solid or liquid propellant), e.g. booster, then separate, then sustainer ignition as opposed to booster then separate and simultaneous sustainer ignition, the separator/decoupler is interpreted as its own stage without any resources (an empty list).
  • When there are any stages above the point of control, e.g. a launch escape system, those resources are lumped into KRPC stage -1 regardless of how you organize the sequence of staging events in-game. However, if the resources placed above the point of control are used before the last stage, empty KRPC resource objects will be inserted into stages before stage -1, but the associated resources will still be lumped into stage -1.
  • Electricity may be consumed/available for use for every stage, but is only ever reported for the stage containing the batteries.

Some of this is certainly buggy behavior, but some may be intended but confusing due to lack of documentation.

How can someone else reproduce it?

Using the latest version of KSP with KRPC 0.5.4 installed on both KSP and your Python client import KRPC and connect to the server:

import krpc
conn = krpc.connect(name='KRPC Test')

Build a simple vessel. I recommend starting with just a probe core and adding stages one by one with different resources to make them easier to identify. Launch the vessel and get the active:

vessel = conn.space_center.active_vessel

Using this simple loop print out the list of resources associated with each stage number i (adjust the bounds of the loop as necessary):

for i in range(-3, 7):
    print(f'Stage {i}: {vessel.resources_in_decouple_stage(stage=i, cumulative=False).names}')

Play around with the organization of staging events and the effect. For example, consider a simple three stage rocket: liquid booster, decoupler, probe core, decoupler, solid stage escape tower. When stages are organized in KSP as:

  1. Launch escape system: decoupler and solid rocket
  2. Booster-probe core decoupler
  3. Liquid booster rocket

the output is:

Stage -2: []
Stage -1: ['ElectricCharge', 'SolidFuel']
Stage 0: []
Stage 1: ['LiquidFuel', 'Oxidizer']
Stage 2: []

When the launch escape system is moved to activate before the probe core and booster separate, so the new sequence is:

  1. Booster-probe core decoupler
  2. Launch escape system: decoupler and solid rocket
  3. Liquid booster rocket

the output is:

Stage -2: []
Stage -1: ['ElectricCharge', 'SolidFuel']
Stage 0: ['LiquidFuel', 'Oxidizer']
Stage 1: []
Stage 2: []

This is the same output generated if the rocket is arranged with the launch escape system activating first (stage 2 in KSP). If you did a nonsensical sequence, like the following, you will get an equally nonsensical output from KRPC.

  1. Liquid booster rocket
  2. Booster-probe core decoupler
  3. Launch escape system: decoupler and solid rocket

with output:

Stage -2: []
Stage -1: ['ElectricCharge', 'SolidFuel']
Stage 0: []
Stage 1: ['LiquidFuel', 'Oxidizer']
Stage 2: []

What is your environment?

I am using the following versions:

  • KSP: 1.12.5.3190
  • KRPC KSP Mod: 0.5.4
  • KRPC Python Client: 0.5.4
  • Python: 3.10.7

I also have many, many visual mods installed, but no physics or parts mods. All other KRPC functions I have used have behaved as expected.

Anything else we need to know?

No response