Partial Pressure Partially Working

Hey Folks! Today I dug deeper into the system I spoke about the other day. The one where the AI can interact with gases in the room to simulate breathing, asphyxiation, and gaseous poisoning.

The theory was that I would have my AIs execute a condition periodically that checked the current room for gas levels in O2, N2, CO2, etc. If those levels were normal, the AI would be fine. If they were wrong, the AI's bodily O2 stat would deteriorate until they became hypoxic and eventually died of asphyxiation. This stat stuff is pretty easy to setup once reasonable values are figured out (through research).

The trick, however, is that mixed gases are a whole new ball of wax. My old code did a good job approximating gas exchange between rooms when that was just a single gas type. But if you have one room with CO2 and the other with an N2/O2 mixture (typical spaceship atmo), that's a slightly more complex problem.

Though, not too complex. At least in theory. Basically, the thermodynamics of gas mixing can be pretty easily treated as if the individual gases from each room's mixtures were expanding into the new combined rooms' volume. The aforementioned CO2 and N2/O2 rooms would just need to do three calculations each: one for each gas.

Okay, not too bad. I just have to change my single-gas calculations to instead use a list of gases. An hour or so of work took care of that.

Now, however, I think the room gas exchanges seem wrong. They still mix, and the overall pressure between them equalizes. But not totally. They seem to reach a point where one room has a slightly higher pressure than a connected room. So I need to figure out why.

I'm also thinking that the room will need to calculate some sort of per-gas partial pressure stat so the AI can correctly track how much O2 (and other gases) it is getting each interaction. If a huge room and a tiny room both have 50 moles of O2, that means very different things. One room has a high pressure, and is breathable, while the huge room would likely be near vacuum. And even though I have overall pressure tracked per room, this doesn't tell me what fraction of the atmosphere is O2 vs. other gases. It can be calculated, though, and perhaps the code I have to calculate overall pressure needs to be split into per-gas calcs just as the gas transfer code did.

I'll look into that tomorrow.