Nivekk / KOS

Fully programmable autopilot mod for KSP.
Other
80 stars 30 forks source link

stage fuel values are wrong because they only read the nearest fuel tank in the hose chain. #240

Open Dunbaratu opened 11 years ago

Dunbaratu commented 11 years ago

The values STAGE:LIQUIDFUEL and STAGE:OXIDIZER report incorrect values when the rocket design includes a yellow fuel feed hose linking tanks. It seems that they ignore the tank on the other side of the hose and only list the value of the tank immediately connected to the engine.

Example:

              /\
             /  \
            /    \
            |    |
            |    |
            ******
            |AAAA|
            |AAAA|
            |AAAA|
            |AAAA|
            |AAAA|
            |----|
            | || |
            ******
            |    |
           /|    |\
          / |    | \     <----- yellow hoses attaching B to C and to D
         /  |BB  |  \ 
       ./--.|BBBB|.---.
       |CCC||BBBB||DDD|
       |CCC|`----'|DDD|
       |CCC|      |DDD|
       `---'      `---'
        / \        / \ 
       /___\      /___\

In that example, the ***** lines are the stage separators. In the current stage the "AAA" fuel shouldn't be displayed because it's part of the next stage up, but the "BBB" fuel should be part of stage:liquidfuel and stage:oxidier, and it's not being added in. Only the CCC and DDD fuel is being added in to the stage total. .

a1270 commented 11 years ago

That is because the stage resources are built up from an active engine. Shutting off one engine in your example will half the fuel claimed to be in stage. I'll look into reworking the code @palaslet was working on before he vanished. Though i can't see how you'd go about doing that just yet.

palaslet commented 11 years ago

Sorry for being vanished guys... I've been preoccupied with more than my usual 200% load at work. I'm painfully aware of the limitations of the code, but haven't had time to review it. I even added this line of code in my proposal: " /* Need to support FuelLine here? */"

Dunbaratu commented 11 years ago

Yeah its a bit tricky. Theres lots of weird cases.

  1. You need to ensure tank B doesn't get counted twice (once because feeds to C and once again because it feeds to D.)
  2. You need to recurse over the chain more than one hop if tank B also has a hose feeding into it and so on.
  3. It has to be directional. A hose from B to C adds to the stage but a hose from C to B does not. 4, B and C might not be the same stage if theres a detacher between them.

actually # 4 isn't done right by the main game either so mimicking the game behavior here is fine I guess.