Hey Folks! I decided to try tackling loot spawning today. Since converting an installed part into loot for carrying would require spawning portable items anyway, that seemed like a logical stepping stone.
First, I had to figure out how to define the rules for spawning loot. It seemed like the easiest approach would be to choose the loot data to spawn, and designate an area in which to spawn its loot. And initially, I thought zones might work.
However, zones have one major limitation: any given tile can only be a single zone type. And since we're blanketing the ship already in crew spawning zones, barter zones, and forbid zones, it seemed like that would cut out a lot of available space for spawning loot. What if we wanted loot to appear in a spawn zone? Or a barter zone? Or the entire ship?
So the next best thing I could think of is to place a loot spawner on the ship, and use it to spawn loot when the ship is initialized. This way, we could control which loot appears and where, without interfering with zones. (It's quite possible I need to rethink zones at some point, but not before we prove this approach works.)
So there's a new object type now: LootSpawner. It's that present icon you see in today's image. You place it like any other item on a ship, and it's a 1x1 grid. Then, if you open its UI, you can change the loot it spawns, and the radius, and the item expands/shrinks accordingly.
Later, when the ship is being loaded, one of three things happens.
1 - If we are in ship editing mode, this item gets loaded with the ship normally.
2 - If we are spawning a new ship, these objects get replaced with their loot in the occupied footprint.
3 - If we are loading a save file, these won't be in the data due to #2.
This required a bit of plumbing to setup, including code to try and place any spawned loot in empty space, special rendering for the scaled/unshaded icon, ship loading code branches, and even a new way to assign behaviors to items as they're being loaded.
Over the course of this project, it's clear I had a lot to learn about how Unity, and entity component systems in general, worked. So I'm constantly realizing I could be doing things more safely/reliably/elegantly, and my old ways wither on the vine. Ideally, I would've just known this all in advance and saved the time of stumbling through, but oh well.
Hopefully, tomorrow I should have this working. And I can setup some loot spawns on the derelicts to optionally put EVA suits near the airlock, tools in the hold, maybe scattered food packets and hull patches, etc. And if that all works, hopefully I can reuse some of the loot spawning work to make ship parts breakable into parts on the floor that can be carried.