Stacking Items

Hey Folks! Hope everyone had a good weekend. It was pretty much wall-to-wall for us, between household maintenance and a trip to the zoo with the little one. Hardly feels like we relaxed at all!

And in keeping with that momentum, I decided to tackle stacking items today :)

I'm pretty sure I'm going to need stacking at some point, so I dug into the code. And as predicted, it's pretty hairy. There's a lot of record-keeping and juggling of references, hiding and revealing of objects, and a lot of conditional placement.

If we remove an item from a container, are we removing its entire stack? Or just one from the stack? What if we place a stack onto a stack that doesn't have room? What if we place an item onto a full stack? What if we need to drop an item nearby, which now requires we check if it has a stack, if the destination tile has a stack, and how that fits?

Lots of permutations and edge cases. And NEO Scavenger ran into a lot of them. I was able to use a bit of the old NS code to review some of the harder-to-predict edge cases. But I still have to rewrite a lot of the code, owing to differences in things like NS's "ground" slot, barter hex, and the fact that I don't have things like charges/item-shutdown yet.

The good news is that a lot of the overall architecture is pretty similar between NS and the space prototype. At least as far as items are concerned. I still have to concepts of containers, adding and removing items, and can hang code off of a lot of the same places.

But I'm only about halfway done writing the code after a day, and I suspect I'll have at least a day of testing and fixing once it compiles.

The good news is that, when finished, I can use a laser torch on a wall to get 5-25 pieces of scrap aluminum, 10-50 garbage pieces, and not have to use every floor tile to store them all :)

Tags: Ostranauts


matsy's picture

This is pretty cool. I imagine similar implementation could be used for mining asteroids in order to get raw materials.

dcfedor's picture

I think you're right. Applying a tool to some natural surface like an asteroid isn't all that different than applying it to a ship's wall, in game terms.

Dan Fedor - Founder, Blue Bottle Games

Rovlad's picture

By the way, RimWorld used a neat trick to avoid visual noise from those "x[number]" stack labels: namely, they're only visible when camera is zoomed-in enough. Not sure how useful it'll be in this game, but it's probably something to consider further down the line.

ra1's picture

You could also make the stack have a longer shadow the "taller" it is.

dcfedor's picture

@Rovlad, that's true. I had forgotten about that. We'll have to see how cluttered these appear in practice. I also don't know how close the typical player is going to want to zoom yet. I have a feeling fairly close, as it's a slightly more intimate/contained space than a Rimworld colony. But one never knows!

@ra1, that's also possible. Though that would require I fix the rendering system to make shadows run smoothly again :)

Dan Fedor - Founder, Blue Bottle Games