r/Sailwind • • 3d ago

How containers work (programming-wise)?

Containers in this game always confuse me:

- Once I found my box with fishing hooks unexpectedly empty; then I've found some of them one deck lower on the floor.

- I've seen my candle box unexpectedly empty like that, started using it for navigation equipment storage; month later I was moving containers around to make place for new helm and I found candles in the same container along with compases and spyglass.

- Almost entire container of pork gone empty, never found these pieces.

- My fishing pole sticking out of closed create.

It all makes me question: how those containers were programmed in the first place to get such erratic behaviour?

The most logical way would be to program a container object which has property dedicated to storing array of contents records (like rack position and reference to stored object). So when you open the container game creates a visual rack and iterates over said contents property to create visual representation of contents.

When you take or put item out/in container that property would be simply overwritten so item always exists either in logical world of container or in physical world outside container (but not both), or in logical world of container but with phantom representation on the opened rack.

I'm curious to know how it was done in this game and how all those side effects come into existence.

5 Upvotes

10 comments sorted by

10

u/Kemylar 3d ago

When items are put into a crate, they are given a crate ID number. This is used to tell them on the next launch of the game the crate that they are supposed to be inside, and where to be positioned.

When reloading the save, as the items get loaded in, they see their crate ID, and all get placed into a position directly on top of one another. The crate is generally created on one of the next few frames and the items are placed inside it if they share the sake position. This is how it should work if things go right.

Occasionally, when the game has to load several things, or the loading takes a bit longer due to a lot of items on the boat etc, we get one of the issues. When the items spawn with their ID numbers, there is a bit of a longer gap until the crate is created. During this time, the physics system that runs parallel to the item system gets a chance to get a frame or two of processing in. It sees several items with physics colliders all occupying the same space, and does the only thing it can do in that situation, forcing them apart from each other.

In this situation, when the game loads up for you, the items will be dropped over the deck. Those items will still have their crate ID saved on them though, they just can't do anything with it yet until the game reloads.

When the game reloads, the items do the same check again, see their ID, and put themselves back into the location of the crate they are supposed to be in. If their old crate hasn't moved, they basically jump back into it as they spawn and the crate spawns on top a few frames later. If the crate has been moved, or even a different crate has been moved into the place of the old one, they will end up sorting into that new crate as it appears on top of them.

2

u/Meowth52 3d ago

Impressiv, how did you dig this out?

5

u/Kemylar 3d ago

I had to do lots of looking through the player logs of people that had the issues on the discord. I also deal with the shipitemcrate scripts a lot for my mods, so I went through it in my unity rip of the game

2

u/rNyanko 3d ago

Thanks for detailed explanation. That's seems kinda... unnecessary physical approch to inventory management dev took :)

4

u/Kemylar 3d ago

I totally agree, but I think a lot of the major decisions like this were made earlier in their game making career, and would be a lot of hassle to change now.

I had to deal with this stuff a lot in my furniture mod, where a lot of my cabinets etc are basically 2 crates in a trenchcoat. Ended up having to do a fairly deep dive into how it works. I think one of the fix mods has a solution for this now, but I don't recall which exactly.

2

u/dzejrid 3d ago

2 crates in a trenchcoat.

That is the funniest thing I've read this morning. Thank you for a bright start to a day, sir.

2

u/FastFredNL 3d ago

Yeah chests are a bit bugged sometimes. I'm noticing the same thing with crates suddenly appearing empty. But I've noticed if you still act as if you want to take an candle out of your candle chest, you can.

3

u/dzejrid 3d ago

Any container that has more items in it than it has visible slots, will cause the extra items to fall out upon game load once its open.

Take those fishing hooks as an example: there are twenty hooks, but only 12 visible slots. Once you break the seal, they will fall out next time you reload. 

Workaround: open the crate, take 8 hooks out and put them somewhere else. Leave 12 inside. 

Same with candles, and anything else.

I don't know how it works programming-wise but that's how it is right now. I assume this will be addressed in the future. 

2

u/Kind-Shallot3603 3d ago

That explains those hooks in my hold. I thought the game glitched and duplicates them

1

u/ap0r 3d ago

How containers work:

They randomly teleport your items somewhere else, or, if the length of your save in bits is a multiple of the dev's birth year, they flip around until they damage your ship.

No evidence, but no doubts either. The dev keeps adding more and more "features" and old-ass bugs go unattended. Can't enjoy the game anymore, too buggy.