Spawning Loot

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.

Tags: Ostranauts

Comments

matsy's picture
matsy

Sounds like you need another layer of zones so the player can mark rooms and then depending where this loot spawner is it can spawn specific items according to that room type?

It did give me an idea yesterday of an "easy" mission type you could implement. A treasure hunt of sorts where you have to go to a derilict ship and follow the instructions to find a hidden compartment. Ie go five paces from the air lock, turn left five more spaces and look under the floor (obviously more elegantly put) but could then be made procedurally.

dcfedor's picture
dcfedor

Yeah, zone "layers" may end up being a thing. I noticed that Rimworld has one set of zones for resources, but others for movement permissions. And yet another for home, clearing snow, etc.

As for the scavenger hunt, that's an interesting idea! Also, the procedural aspect of it is something I was wondering about this morning: should loot be procedurally placed instead of by-hand? In theory, anyone who authors a ship layout can place the rules, but would it make more sense for the game to figure out what types of loot to place?

E.g. if the room has a food container, spawn food around the room. If it has an airlock, spawn EVA stuff. Etc.

Probably not in the short term, but it's something to consider.

Dan Fedor - Founder, Blue Bottle Games

matsy's picture
matsy

Per the scavenger hunt, my thoughts were more of a treasure hunt in the sense you are looking for a hidden compartment where the captain or crew member has stashed some valuables, obviously the definition of valuable is each to their own. One man's cheesy ouffs is anothers Rolex... Thinking underfloor storage millennium falcon. Per your other blog posts this could be a specific container and assigned as treasure so depending on the loot tables or the generated "scavenger hunt" could assign it.

Procedually placed makes a lot of sense rather than hand. I guess you can attack it on both fronts. Certain items trigger item spawning near it. IE airlock and generator but I foresee issue where the item is slightly generic and the context isn't overly obvious. IE a cupboard, is it in the kitchen? Is it in a bedroom? Hanger?

I think the addition of zoning implents simpler code and more efficient code. As you can set it in the edit mode so items have a static value of their zone they are in, so you can go, look at possible storage locations, apply loot of that location type, kitchen/bedroom etc. Probably have a second method to do the same but not for containers but floor.

Where as if you do it per item you'd have to go for each item, search for storage around item, faffing around for ignoring walls, apply looting rule. And then the context could be incorrect.

dcfedor's picture
dcfedor

Having smuggler's compartments would be cool. And is another way to add to the exploration phase of derelict-diving. One could, as you suggest, employ a sort of "pirate's treasure map" set of instructions to lead to the compartment. Or alternately, certain tools or skills could make finding them easier.

E.g. an "observation" or "smuggling" skill to make them more obvious, or something like an accoustic/EM field detector to notice anomalies in wall/floor density.

Dan Fedor - Founder, Blue Bottle Games