Wall Salvage, Room Recalculating

Hey Folks! Finally got the wall salvage interactions done, and made a few bug fixes before starting work on a missing room feature.

I figured out that placement bug from yesterday. It turns out that the loot generated by salvaging starts at tile 0,0, floating in space (i.e. not part of a ship), and as the game tries to place loot on existing stacks, it picked up those floating pieces and stacked there. I just changed the code to ignore pieces that were not part of a ship when placing loot, and it behaved correctly.

The wall salvage wasn't too hard to setup once I figured out that placement bug. You can now right click on a wall and choose "Scrap," and the AI will fetch a laser torch and go to work on it. The wall becomes damaged in the process, yielding some scrap. And the AI can "Scrap" it a second time to totally remove the wall and get more scrap. Today's image shows Mark scrapping an interior wall, the loot it produces, and the message log along the way.

While testing this, I ran into a situation where the AI wouldn't "scrap" when I told it to, and I couldn't figure out why. It turned out to be a pathfinding failure caused by an obstacle I didn't see, so I added code to alert the player via message log if that happens again. E.g. "Michael cannot reach blah blah..."

I also noticed two bugs with walls as they pertain to room gas flow.

First, my damaged walls only had left/right gas flow on them, so rooms above and below the wall weren't exchanging gas if separated by a damaged wall.

Second, the complete absence of a wall halts gas flow between rooms. This is a bit more problematic, since all of my gas flow currently works via an item grabbing gas from A and putting it into B. Obviously, an empty space can't do that, since it doesn't exist :)

So I started looking into ways to fix this, since walls (and floors, and doors, etc.) are inevitably going to disappear from a ship. Whether through damage, salvage, or ship editing/reconstruction, the room config of a ship could change.

One approach would be to replace any disappearing wall/floor/door with an invisible gas exchanger. It'd probably be the easiest thing to do, but would also likely create record-keeping headaches down the line, not to mention performance issues as their number increased.

Another approach is to check all of the adjoining spaces of an item as it's being added or removed to see if they are rooms, and then adjust those rooms. This works pretty well in cases where an item is removed. Either the rooms around it are separate, and now should be joined, or they are already joined.

However, adding an item is more complex. Regardless of the status of rooms around the added item, I'd pretty much have to scan every tile of each adjoining room to see if this was the last "hole" between them, and if that should split the rooms. Basically, run the room generation code again, but make a bunch of edits so that it only affects the nearby rooms.

Or, as I'm leaning towards doing, maybe I just run the room generation code again on the entire ship. And as I do so, check to see if the room at any point is different than before, and record that info. And when done getting new rooms, give each new room appropriate stats based on which old rooms it used to be.

E.g. if new room A is composed of old rooms B and C, make A have an average of B and C's stats. Or if new rooms A and B used to be one bigger room, C, A and B proportionally split C's old stats, based on volume.

Theoretically, both of those last two approaches are going to require similar code, so I might be able to skip redoing the whole ship and just do adjoining rooms. We'll have to see how hard that is.

In any case, this covers one of the outstanding issues I've had with rooms and gases: missing floors, walls, and doors. Whenever I did a derelict "pre-cooking" pass, items removed from the ship would be ignored by the gas system. And if I can get this working, that'll be solved.

Tags: Ostranauts