Programming Blog 09 – A Big, Brown Deck

Greetings, dear followers of the programming side of Junkfish. I have been tasked once again with providing you all with an update on the codey side of our developmental process; in particular, the procedural generation (I’m told that people enjoy that kind of thing, as far as coding nonsense goes).

So it has been a while since I last had the privilege of writing to you all, I daresay some of you missed my wonderful words, and, as a result, there are some new sections and systems that I can present to you. My last entry was about stairs, multiple ship levels, and what the other programmers had been up to, so this post shall follow on with the section I proceeded to work on after that previous post: the outer deck of the ship.

Now, before you get too excited, I have to confess that it isn’t the entire outer deck of the ship; only the upper levels and areas required to help the player elude our majestic beast. However, that isn’t to say that what exists isn’t a lovely change of scenery compared to the confines of the ship shell. So, without further ado, allow me to cover the basic methodology regarding the procedural generation of the outer decks.

The big, brown deck itself

The deck is covered in both rooms and small sections that are 1 cuboid in size. The general idea behind creating it is: spawn as many rooms as possible, then fill the remaining holes with the appropriate 1×1 segments. Take a moment, and see if you can identify where the rooms are from the picture. A hint is that there are 4 main rooms shown on the immediate deck. If you guessed that the mast is in one of the rooms, you are correct! The room it is in is 7×6 in size, and spawns all of the junk and such that surrounds the mast. Room #2 is the area with a deflated life raft, the large crane machination, and enclosing railings. So well done if you clocked that! The last 2 may be a bit trickier to locate, but they surround the edges of the deck area, and spawn items than line along the railings.

Currently, the number of rooms that can spawn on the deck is limited, which results in a similar looking deck each playthrough. However, extra rooms would not be hard to add, and varying up the deck through the use of these is definitely the intention.

Holier than the Pope

Now, if we just left these rooms as the base deck, we would end up with holes across the area, as shown above. Hence the 1×1 segments. These are spawned in by detecting what kind of room is attached to each side of the node in which the segment is looking to spawn. If a deck or walkway is detected, a connection is permitted. The appropriate model is chosen based on connections, rotated and moved into place, then voilà! A fully kitted-out deck.

You may be wondering “Why not just generate the whole deck out of 1×1 pieces?”. Sure, it would probably have made life a lot easier, and that was the intended approach at the beginning, however it lead to a rather serious issue: spawning of deck objects. Some deck objects where larger than 1×1 cuboids, making it difficult to detect where they would be allowed to spawn in the context of the deck. Also, if every single piece had a chance of spawning a barrel, it would quickly lead to a deck covered completely in barrels. The larger, pre-made tile sections allow greater freedom, flexibility, and creativity with regards to the placement of both preset and random items. For example, the mast is intended to always be at the centre of this piece of deck. It would be hard to guarantee that when only spawning single segment pieces.

And that was a brief, pretty high level run-through on how the deck is created. Not an overly complicated process, but setting up the 1×1 segments and making sure they are correctly orientated can get a bit fiddley.

Now that Jaime has us writing these again, chances are I’ll be talking more about the other bits I’ve been working on. Perhaps I’ll follow up with more information about the rooms and region stuff, I don’t believe I covered it all fully before.

So, talk soon, my lovelies,