Sunday, June 22, 2025

Underground Jails

It's getting close to the 4th of July and summer time in general when I'll be busy with other things and won't have as much time to work on 3DWorld. I may not get a chance to write a blog post in July. I didn't want to start on a big project such as a new building type right now, so instead I added a new room type. I'm not exactly sure what made me think of this, but I decided to add basement jails. I was particularly interested to see how the lighting and shadow code performed on a room full of narrow horizontal and vertical bars. I suppose these fit with the interrogation rooms I added last October.

It's always easiest to place special room types underground as I don't need to worry about windows and other exterior elements. The existing code for extended basements creates a huge network of underground rooms that I can work with. The first step is to choose one that's both long enough and wide enough to create a hallway with rows of jail cells on either side. This isn't as common as you may think since the existing code tends to create rooms on the smaller side or rooms that are long and narrow. (Usually the long narrow rooms are the result of failed hallways that don't have a room to connect to and are converted to "leaf" rooms.) The second test is for a doorway near the center of either one or both of the long ends of the room, and no side doorways. Most rooms meet the door requirements.

Once the jail rooms are selected, they're divided in the short dimension into a central hallway with rows of cells to either side. Bars separating the cells and hallway use a mixture of rusted metal or scratched metal textures. The room doorway connects to this hallway. Cell size is uniform for each room and chosen to be deep enough to fit a bed's length and long enough to fit the bed width, cell door, and sink side-by-side. The cell door is in the center and has a set of bars to either side of it spanning the width of the cell. In addition, I added a toilet to the back wall opposite the door with a toilet paper holder next to it. It's not much privacy, but I suppose it's not much worse than the toilet placement in some of my generated houses.

Each cell is created in a similar way to bedroom closets in houses. I didn't make them sub-rooms because the sub-room logic really only works well for a single nested room, and it wasn't needed in this case. I added a small round light to the ceiling in each cell, in addition to the larger hallway light(s). At first I had the two groups independently controlled, but later added a single light switch next to the door that controls both sets of lights. I reduced the amount of indirect lighting for jails because there are so many lights, few occluders, and I feel it looks better when the jail area is somewhat darker than other rooms.

Jail bars are handled like interior windows used with conference rooms. They're not occluders since the player can see through them, but they do block object interactions. This means you can't take objects through the bars or interact with objects on the other side of the bars such as flushing the toilet. Zombies also can't attack through jail cell bars.

All cell doors swing outward into the hallway. In fact I reused the same logic as interior doors and only changed the graphics to replace white wood with rusty metal bars. I also replaced the wood door open/close sound with a metal door sound. Jail cell doors are narrower than standard building interior doors so that they don't block the narrow central hallway as much. I initially had problems with zombies passing through the openings because their collision bounds were expanded to include their animations and were wider than the doorway. After some experimenting, I went with shrinking the length of the bars to either side of the door when used with AI collisions. This effectively widens the opening slightly for the AI to pass through while following the player.

The first style of jail cell has walls separating adjacent cells. These use a plaster material in houses and a concrete material in office buildings to match the extended basement room walls of these two building types. I replaced the carpet on the floor with concrete in these rooms. The walls, ceilings, and floors pick up the cracks and water damage properties of the building's basement. Here is an example of this style of jail with indirect lighting enabled.

Jail with walls between cells. Some doors have been opened and some others are locked with brown padlocks.

Some of the cell doors are locked with a padlock, with a key to all cell locks hanging on the wall opposite the door. The screenshot above has brown padlocks and a brown key that can be seen in the very back if you click on the image to zoom in. In theory it should be possible to lock a zombie in a cell if I set the doors to be re-lockable, but I don't think this works in practice. They only enter the cell if the player is in there, and they tend to block the exit and corner the player in the cell. The only way I've been able to get by them without being killed is by pausing the AI logic or disabling collision checks. So instead I changed the padlocks to be permanently removed when the cells are unlocked so that it's not possible for the player to lock themself inside. The key remains in the player's inventory after use and can be used from either side of the door just in case. Maybe I'll eventually add a way for the player to place zombie bait in jail cells, and then allow the door to be re-locked.

The second style of jail cell uses another set of bars in the opposite direction to separate cells rather than adding walls. It forms cells surrounded by bars on up to three sides. It didn't look correct to place a sink next to these bars, so I moved the sink to the back wall between the bed and toilet. Only cells that are long enough to fit all three of {bed, sink, toilet} along the back wall can use this style. This produces a more open floorplan and more complex shadows.

Another jail with bars between cells rather than walls.

Jail beds are different from house beds. They have black metal rather than wood frames, and always have white sheets. The theme here is grayscale colors. Some of the cells have a single bed, while others have bunk beds. These are really just two beds stacked vertically with a short ladder added to the side.

Closeup of a jail cell bunk bed. A sink and toilet are also visible.

I actually added bunk beds to house bedrooms earlier, I just haven't shown that in my blog yet. I also added a small random chance of a person sleeping in the bed. This somewhat unintentionally applies to jail cell beds as well, but only for jails in house basements. Let me find someone sleeping ... there she is. That's not a very relaxed position, and her head is a bit too much sunk into the pillow. I didn't have a sleeping animation, so I used the first frame of the idle animation instead.

A jail cell bunk bed with a woman sleeping in it.

She's not wearing an orange or black and white jumpsuit though. And high heels in jail? I guess there's not much I can do about it because I can't find a 3D model of a person with a prison uniform on Mixamo, other than one of the zombie models I already have. Wait, I can make all zombies prisoners. That's appropriate for this post! They're not lying in beds though because I don't have any animation for this zombie model that looks correct when lying in a bed. Both the idle and walking animations have him hunched over with his arms out.

Zombie prisoners have cornered me at the end of the jail hallway. At least he only has one arm to hit me with.

I still feel like these jails are a bit too bright. I can turn off indirect lighting and it looks like the screenshot below. There are more shadows and light vs. dark color contrast. I kind of like this look. It reminds me of a black and white photograph. What do you think?

A jail with concrete rather than plaster walls and many cracks. This screenshot has indirect lighting disabled and has harsher lighting with more shadows.

That was a fun post to write, especially the part at the end with the woman in bed and the zombies. What's next? Now that I have jail cells, it should be possible to add full prisons. I would need to work out the window placement so that cells can be added to above ground rooms. It's likely significant effort to customize the interior enough for a prison, so I'm not sure if and when I'll attempt this.

The project with source code is available on GitHub. Some people have been asking me how they can view these buildings themselves. This requires changing default.txt to enable config_heightmap.txt, which is the base scene I've added cities and buildings to. It helps to download the extra 3D models and textures from my Google Drive link. You can find the instructions in my README file.

2 comments:

  1. I'm unclear how "In theory it should be possible to lock a zombie in a cell" if "Once the padlock has been removed it can't be re-added." Do you mean "Ideally" instead of "In theory?"

    Yes, the cells do look like old underexposed black and white photographs with the indirect lighting disabled.

    Neat little update! Have an enjoyable Fourth, and month of July.

    ReplyDelete
    Replies
    1. It's easy to change the door lock logic to make it re-lockable (with the key) vs. always unlocked. Since it didn't seem practical to lock zombies in cells I left the cells unlocked after removing the padlock. I felt that was safer because there's less chance of the player locking themselves in the cell. (The logic for who has what key gets complex, especially when toggling gameplay mode on and off.) It's written an odd way because after writing the first sentence I went to look at the code and experiment before continuing with the post. I'll go back and reword that part.

      Thanks, you too!

      Delete