Refueling Code, O2 Canisters, pV = nRT

Hey Folks! I've gotta say, this refueling thing sort of side swiped me. I was sort of picturing it as being a really simple, almost throwaway piece of code to bridge the gap until I came back to it later. But it turns out to have quite a few tricky (or at least non-trivial) parts to it.

With the UI mockup done yesterday, I started writing code to handle all of the dynamic data. So far, so good. There's a lot of data in here, but that's not really too challenging.

However, in adding the logic for said data, it was a bit trickier. Some rows use a slider to let the player choose how much to purchase, while other rows are a one-time fee. Still others are just a subtotal without any other data. And finally, we have some blank rows. I had to do a bit of planning to get the same set of code working for each of these, but that saves me having 3-4 different classes with almost identical code to maintain.

Doing the calculations for what we've purchased revealed that I missed one variable, and had to add a new column for it. And the event handler to update the form when a slider changed required a bit of research into C#'s action/func stuff. Doable, but I thought it'd be more straightforward.

Then came the tricky part: I had yet to query the player's ship for any of this data used in the form. How much liquid He3 was on board? Heavy water? Oxygen? It turns out each of these required a bit of special handling, since each was stored slightly differently. Some solid, some liquid, some gas, some electrical, and each in different container types. Plus, that meant I had to make sure I could differentiate these containers in code, so I needed some more "conditions" to label them. (E.g. "IsVesselO2")

So a chunk of my afternoon was writing not only code to inquire about these resources, but converting the resulting data into consistent units for sale. E.g. I have to use liquid/solid density calcs to get the fuel capacity and amounts, while the O2 canisters are 5l a pop, at 20,000 kPa, and internally tracked in moles for easy gas-mixing calcs, so I needed ideal gas law to convert moles to kg. Plus, power capacity was stored in a slightly different way because...well I don't know why anymore. I may have to refactor that someday.

Anyway, it was a bit hairy in there getting all the data I need. But I think I've got that part done now.

Next step will be to get this UI to show up when crew accesses a thing. So that means I need a placeholder thing to access, put it on the sample station layout, and then fire it up and see what breaks!

Tags: Ostranauts