JPLRepo / AmpYear

A KSP plugin that better manages electricity adds Reserve Power, ION & PPT RCS. See the ReadMe file below for dependencies.
7 stars 6 forks source link

[NEW][BUG 1.1.2.1a] AmpYear doesn't seem to recognize ODFC #90

Open zer0Kerbal opened 4 years ago

zer0Kerbal commented 4 years ago

as reported here.

On Demand Fuel Cells.

Screenshot and Logs here:

JPLRepo commented 4 years ago

Don't think that's a bug. Seeing how AmpYear doesn't support this mod. Be more of a feature request to add support for it.

What is ODFC? I looked at the code.. but I don't have time to sit down and analyze how it works. So if you could supply me with information regarding: How the module works. What fields would AmpYear need to reference in the partmodule to determine - If its active or not. If its generating EC or not. How much EC it currently holds.

Then I can look to include support for it when I have a spare 30mins. Thanks.

zer0Kerbal commented 4 years ago

@JPLRepo This is a pleasant surprise! 🎆 On Demand Fuel Cells is a Part Module that emulates a Fuel Cell with resources in; EC and resources (optional) out.

Originally it was reported as a bug, and yes I would agree that it would be more of a feature request.

Just like it is to add backgroundProcessing to is.

Hopefully this is what you need, if not kindly tell me.

How it Works (summary): has a confignode list of fuels and rates; byproducts and rates; and EC (max) production. If it has a demand (vessel EC <= threshold) it produces EC to cover need (up to maxProduction) consumed fuels at proportional rate and producing byproducts (optional) also at a proportional rate. It is essence a modified resource converter, and is heading toward being one.

Status of ODFC module:

            guiActive = true,
            guiActiveEditor = true,
            guiName = "Enabled:",
            groupName = "ODFC"),
            UI_Toggle(disabledText = "No",
            enabledText = "Yes")]
        public bool fuelCellIsEnabled = true;```

Current/Max EC production ability:
       [KSPField(isPersistant = false,
        guiActive = true,
        guiActiveEditor = false,
        guiName = "EC/s (cur/max)",
        groupName = "ODFC")]
    public string ECs_status = "ERROR!";


```       [KSPField(isPersistant = false,
            guiActive = false,
            guiActiveEditor = true,
            guiName = "Max EC/s",
            groupName = "ODFC")]
        public string maxECs_status = "ERROR!";```

Fuels/Byproducts:
```        [KSPField(isPersistant = false,
            guiActive = true,
            guiActiveEditor = true,
            guiName = "Fuel Used",
            groupName = "ODFC")]
        public string fuel_consumption = "ERROR!";```

```       [KSPField(isPersistant = false,
            guiActive = false,
            guiActiveEditor = false,
            guiName = "Byproducts",
            groupName = "ODFC")]
        public string byproducts = "ERROR!";```
JPLRepo commented 4 years ago

It's a shame it doesn't inherit and use one of the stock part modules. Sounds like it's very similar to moduleresourceconverter. If it did AmpYear would support it out of the box. But anyway, I'll take a look and see if I can write a reflection class to read it and process it in AmpYear for KSP 1.9

JPLRepo commented 4 years ago

I took a look at the code... it is pretty much a resource converter. this could be done with very little effort. Anyway, the problem I see is there is no field in the module I can reference to get the amount of EC it is producing easily... these are calculated in the update methods but in temporary variables.

2020-02-09 16_21_33

it looks like it writes the EC generated to a variable: ECs_status But this is a string and is also used to display other state strings. not just an amount. Would be good if ECAmount was actually a public float (or double) variable that I could read using reflection.

zer0Kerbal commented 4 years ago

I thought as much about the strings. Easy enough to add a public double ECAmount

how's this (in public class ODFC : PartModule) public Double ECAmount = 0f;

I just took the variable declaration (which was done later) and just moved the declaration from the function to the class.

Thank you

zer0Kerbal commented 4 years ago

It's a shame it doesn't inherit and use one of the stock part modules. Sounds like it's very similar to moduleresourceconverter. If it did AmpYear would support it out of the box. But anyway, I'll take a look and see if I can write a reflection class to read it and process it in AmpYear for KSP 1.9

I have thought about having it do so; but I inherited the code and have been updating as I can. It's a mess, but am slowly working on getting it up to speed. Most of the mess is mine, notes everywhere --- but those are going away. (hey, all coders are vain about their code 👍 )

Thank you.

zer0Kerbal commented 4 years ago

I just was able to skim the code and instead of ECAmount kindly use this:

public Double fuelModeMaxECRateLimit = 0f;

it seems to be perfect for what we need

JPLRepo commented 4 years ago

Doesn't look perfect to me... The amount of EC being put into the part is calculated: Double ECAmount = fuelModeMaxECRateLimit * cfTime; part.RequestResource(ElectricChargeID, -ECAmount);

so fuelModeMaxECRateLimit is not the amount of EC being placed into the part resources each FixedUpdate.

zer0Kerbal commented 4 years ago

Doesn't look perfect to me... The amount of EC being put into the part is calculated: Double ECAmount = fuelModeMaxECRateLimit * cfTime; part.RequestResource(ElectricChargeID, -ECAmount);

so fuelModeMaxECRateLimit is not the amount of EC being placed into the part resources each FixedUpdate.

you are correct - had changed it to this (in the TweakScaleSupport branch):

        /// <summary>
        /// Gets the On Demand Fuelcells(ODFC) Electric Charge (EC) Production.
        /// AMPYear / JPRepo / Background?
        /// allows AMPYear and others to see current EC/s production
        /// </summary>
        /// <value>
        /// The On Demand Fuelcells(ODFC) Electric Charge (EC) Production.
        /// </value>
      ###   public double OnDemandFuelCellsEC { get { return this._fuelModeMaxECRateLimit; } }

might not be perfect - but it is the LCD on the outside of the black box. We will adjust it to make sure our end works for next release, which won't happen until the 'doesn't save scaling from editor to flight' bug is fixed - which is 🚧 .

again thank you.