Thursday, March 20, 2025

Procedural Warehouses

My last blog post showed the progress I've made on procedural factories. In this post, I'll show how I've generalized factories to industrial buildings and added warehouses as an industrial building sub-type. I have plans to add other building types such as power plants in the future. These buildings share many elements with factories such as overall floorplan, sub-rooms, wall and ceiling beams, sprinkler pipes, HVAC units, ducts, and fans. They also use many of the same textures such as slotted and rusty metals. Reuse of interior elements allows me to create these variants more quickly with less added code complexity.

Warehouses have some significant differences though, most notably the replacement of machines and tanks with rows of shelves. These are similar to shelves found in existing houses, storage rooms, and basements. One main difference is that they're constructed of plywood and metal frames, rather than wood boards mounted to walls. This gives them a sturdier and more industrial look. A second difference is in the types of objects placed on and around these shelves. There are boxes, crates, and pallets everywhere, both on shelves and on the floor. Ladders have been moved against the exterior walls by the entrance door, and the catwalk has been replaced with a forklift 3D model.

Warehouse viewed from the front near the office and entrance, with people and a forklift nearby. The floor has bottles and stains on it.

The placement system supports stacking of pallets on top of each other, stacking of boxes and crates, and placing boxes and crates on pallets. Most of this was done by extending the existing item stacking and player interaction system to be more general. The player can take all of these objects, but only from the top of the stack. Boxes on top can be opened, and the contained items can be removed. The player and building AI people can walk or step over low objects such as individual pallets, which means the placement system doesn't need to worry about them blocking access to areas of the warehouse.

Warehouses have the same office and bathroom sub-rooms as factories. I placed extra rows of high shelves on the roofs of these rooms to make better use of the open space. These shelves aren't against a supporting structure such as other shelves or an exterior wall, so I added a narrow horizontal I-beam connecting them to the exterior side walls. The player can climb ladders to get behind these shelves.

Warehouse showing a stack of pallets on the floor, the front office with entrance door, and additional shelves stacked on top of the sub-rooms.

Warehouse boxes contain a different selection of items compared to boxes found in houses and office buildings. I reworked the shelf and boxes system to allow a different collection of contained objects depending on building and room type. Warehouse boxes contain some of the common items found in earlier boxes such as bottles of water/coke/beer/wine, toilet paper, and cans of spray paint. But they also have new items, including cases of coke and beer cans, boxes of food, and electronic items such as computers, laptops, and microwaves. I even added boxes containing tiny machines which use the same generation and drawing code as machines found in extended basements and factories.

Items are selected based on a combination of randomness and matching the size and shape of the item to the size and shape of the box. For example, tall and narrow boxes may have computer towers, short boxes can contain laptops, and large wide boxes contain microwaves. The goal of the player should be to find the boxes containing more valuable items such as laptops, while avoiding zombies, snakes, spiders, etc.

A stack of boxes and crates next to shelves placed along an exterior wall. Some boxes have been opened, showing items inside.

Warehouses have several entrances. There's a front entrance that opens into the main office, rather than between the office and bathroom as in factories. This means that I had to modify building door and window logic to allow doors to be placed into sub-rooms that already have custom windows that don't match the upper level windows of the main warehouse area. There's a back garage door that would serve as a loading dock, currently using the house garage door texture. I may continue to work on loading docks if I add warehouses to cities in the future or connect the secondary buildings with roads. For now, it only has a connecting driveway, similar to those added to houses. And there's also one or more optional side entrance doors inserted in gaps between rows of shelves.

Warehouse loading door near the back, using the garage door texture.

Warehouses can be quite large. I originally only assigned industrial buildings to smaller brick structures of three to four floors in height. Now I've modified the config file to create some short and wide concrete block buildings that can serve as factories and warehouses. These look more realistic for this type of building. They also make industrial buildings common and easier to find.

I modified overhead map mode to color code buildings based on category/function. This allows the user to select a building and teleport to that location, which definitely helps to accelerate testing of custom types. It's important to visit both large and small buildings to make sure the interior elements scale properly and look reasonable for the interior areas. I spent quite a while fixing problems like this, in particular cases where basement or parking garage stairs were blocked by or intersecting other objects placed at the ground floor.

Large warehouse viewed by standing on top of the upper shelf over the office room. This vantage point is needed to see the size of the space. The forklift is along the back wall on the left.

What's next? I currently have hospitals and schools on my list. I already started working on hospitals, but I decided to go back and add warehouses first because they were a more natural continuation of my work on factories. I've been working a bit on schools as well. It's still early though, so I have no idea how these will turn out.