Friday, April 18, 2025

Procedural Hospitals

The next types of procedural buildings on my list after malls, factories, and warehouses are hospitals and schools. I've been working on both of these together, but hospitals were started first and are further along than schools. I'll discuss hospitals in this post and probably get to schools in the next one.

Hospital Exteriors 

My very first addition to hospitals for this round was to add illuminated red crosses to either side of the lit signs on top of city hospital buildings. These use the existing text rendering system with a single "+" character. This is a good start, though it's a minor change that only works in cities and is only really visible at night time.

Night time hospital with emissive green name sign and red crosses to the sides.

Hospital Interiors

The next step was to add ambulances to hospital parking garages. Technically, this isn't the next task I worked on, but it was one of the earlier additions that was completed by the time I started writing this post. Ambulances don't normally fit inside parking garages because they're too tall and may intersect the pipes that run along the ceiling. I had to cheat and shrink them by 20% (compared to ambulances found above ground) so that they fit. It's not too obvious that this shrink was applied. I wonder if I can get away with using this same approach to squeeze a school bus into a school parking garage? Probably not!

Hospital underground parking garage with some slightly smaller than normal ambulances.

With those two minor changes out of the way, it was time to work on hospital interiors. Non-city hospitals are only assigned to larger cube-based buildings where the ground floor part is large enough to add primary and secondary hallways. This allows the existing secondary and ring hallway floorplan templates to be used, with various rooms placed along the hallways. The resulting rooms have relatively consistent sizes that work well for hospital room types.

The only major difference to the hallways themselves is the addition of a reception desk at one end of the primary hallway on each floor, rather than at both ends of the hallway on the ground floor only. These can serve as nurse desks or similar. All of the normal hallway items still apply: water fountains, fire extinguishers, clocks, and US flags.

The major difference between hospitals and office buildings is the assignment of room types. While hospitals can have some office rooms, the majority of rooms are related to hospital services. So far I've added recovery rooms for one or multiple patients, exam rooms, waiting rooms, operating rooms, and classrooms. Each of these contains a different set of placed object types with some amount of overlap.

Patient Rooms

Most rooms along the building exterior that have windows and a single door are reserved for patients. These have one or more hospital beds selected from one of three new 3D models, which are randomly selected per hospital part. The number of beds is a function of room size to best utilize the available space. Rooms that have multiple beds along a single wall have curtains separating the beds. TVs are placed on the walls opposite beds where there's space, and if their line of sight isn't blocked. I also added a variety of other items to hospital rooms including tables with flowers and telephones on them, chairs, couches, potted plants, and the new wheelchair 3D model. Chairs come in several existing varieties: wooden house chairs, plastic office chairs, and occasional rocking chairs. At this time the beds are all empty because I don't have any models of people with a lying down animation.

Here are some example hospital rooms. I've enabled indirect lighting in all screenshots, so they're quite bright inside.

Hospital patient room with three beds separated by curtains, a table, couch, chairs, and wheelchair.
 

Another hospital room with beds, curtains, table with plant, and rocking chair.

Hospital room with a different style of bed, couch, and TVs on the wall.

Very bright hospital room that's long and thin with a third bed type.

Just for fun, I made hospital beds slightly under the max player carry limit. This means that you can pick one up if your inventory is otherwise empty, but you'll be at max carry capacity and extra slow. It makes more sense to move the beds around by pushing and pulling if they get in the way. Their wheels make them movable by the player.

If the room is large enough, it also includes a private bathroom in the corner to one side of the entrance door. Once again I've reused the nested sub-room system from factories and warehouses. The bathroom has a separate light, toilet, sink, and mirror. The placement system ensures both the main room door and the bathroom door are not blocked by anything. Bathrooms are added at the floorplanning step since they require adding walls, which means that patient rooms are selected before the main room assignment pass. This complicates later placement steps as it requires shuffling room types around if stairs are added later or a bed can't be fit in the room.

Hospital patient room private bathroom, added as a nested sub-room in the corner by the door.

Waiting Rooms 

Waiting rooms were the next to be added, since they contain mostly existing objects. The interior walls of the room are lined with rows of chairs and one or two couches. If the room is large enough, an additional one or two rows of chairs are placed against a short wall in the center. I also put a TV on the wall, and either a bookcase with reading books or a vending machine in a corner of the room. Finally, I added either a digital or analog clock on the wall that dynamically updates to show the true time.

Vending machines are a new type of interactive object. These have been placed in office building and hotel lounges and lobbies as well. There are two types of vending machines with different exterior textures, one serving bottled drinks and the other serving snacks such as chips and candy bars. I got the textures, stats, and item lists for both of these from online vending machine ads. I was surprised at the typical cost: $8000 for refrigerated vending machines and $6000 for non-refrigerated ones! Of course the player could steal these for that value, if only they weren't several times over the player carrying capacity.

Vending machines are interactive. They have a fixed number of random items (0-9) that can be purchased for $2 each. Where does the player get $2 from? You have to steal it from somewhere else in the building. Drink vending machines give random drink consumables that have various effects on the player: water, Coke, beer, and wine. Yes, $2 alcohol from vending machines! In hospitals! The first two drinks heal the player and the second two make the player drunk. And if the player doesn't need a heal, that's $2 wasted. Being slightly drunk is a good thing because it increases damage resistance, but being too drunk causes visual artifacts and can eventually kill the player. Snack machines produce a variety of items that heal a small amount of health. I don't know how practical these vending machines are, but they were a lot of fun to add.

I also changed the set of random items the player can loot by breaking into parked cars so that some of them have effects such as healing. Maybe it's too easy to get healed now? Most of my time playing I'm either at full health or dead though, so it may not matter all that much.

Waiting rooms are more commonly placed on ground floors, but can appear at any floor. Rooms that would normally be assigned to patient rooms are re-assigned to waiting rooms if stairs or elevators are added to them later during the "connect" step. However, these rooms may already have nested bathrooms. That works out fine though because these can be repurposed as waiting room bathrooms. Or maybe they're intended for sample collection for lab work? I do need to check for bathroom intersections when placing other room objects.

Here are some waiting rooms that I've come across in the hospital closest to the starting area. 

Hospital waiting room with gray chairs and couch, a TV on the wall, and a bookcase in the corner by the elevator cutout. (The elevator opens to the hallway outside the room.)

Another waiting room with a drink vending machine and stairs going up on the right side. This one has a private bathroom as well.

A very small waiting room with a single couch, at the top of the stairs shown in the previous screenshot. This one has a snack vending machine and an analog clock.

Exam Rooms 

Exam rooms were next. I felt like I already had enough hospital bed 3D models, so I used a random existing bed model rather than adding yet another exam bed model. I placed a doctor's desk with computer, monitor, and phone in the room. Then I added an optional computer monitor on the wall, an optional first aid kit, an optional wheelchair, a filing cabinet, a chair, and a stool. I added either a simple sink or full bathroom vanity with doors/drawers full of items.

Hospital exam room that's probably too large, with bed, desk, sink (behind the bed), wall monitor, first aid kit, and filing cabinet.
 

Ah, that's right, vanities are new as well. I started by adding these to house bathrooms. They're basically the same as kitchen cabinets + sinks, except they're white rather than brown wood and contain a different set of items. They also have mirrors that open, similar to bathroom medicine cabinets. At the moment exam room vanities have the same items found in house bathroom vanities. That will likely change later.

Vanity model used as a hospital exam room sink and cabinet. Those are definitely not cans of beer inside the open door.

All right, I changed them to contain bottles of medicine rather than other types of cans and bottles. But I'm not going to capture a new screenshot for this post.

Hospitals sure contain a lot of medicine bottles. Right now medicine fully heals the player, including the effects of snake and spider venom. Maybe I should add different types of medicines that have different effects? Some of them can be bad for the player, just to make things interesting. Or I can add a time limit to prevent players from using medicine too frequently. Maybe there's a message "can't take more than one dose of medicine in the same minute" or a negative effect on the player.

I feel like I should add some other equipment such as a blood pressure cuff. The problem is that I don't want to fill hospitals with a large number of unique models as that hurts both load time and framerate. A second problem is that these rooms are too large for exam rooms. This particular hospital with secondary hallways has a main floorplan where all the rooms are the same relatively large size, so I can't do much about the wasted space. Ring hallways have a greater variety of room sizes that produce more interesting room layouts.

Operating Rooms 

Operating rooms were added last, mostly because I had a hard time deciding what to add to them. I started with a hospital bed 3D model (again), but eventually replaced it with an operating table. I changed the ceiling lights to be round, larger, and brighter. I added the 3D model of what is apparently called a "trolley" - the metal wheeled cart that holds the operating instruments. I added one or two machines along the walls or in the corner of the room. These are the same machines I previously added to extended basements and factories. They seem to fit with the strange equipment likely to be seen in operating rooms. I also attempted to place a metal chemical/gas tank along the wall, using the same tank object as factories. I placed a clock on one of the walls. Finally, I added another optional wheelchair. It's a nice looking model, so it may as well go into every hospital room type.

Operating room with large and very bright lights, an operating table, some machines, a trolley, and a wheelchair.
 

Another operating room. This one is larger and has a chemical tank along the far wall.
 

There's a good chance that I'll go back to improve operating rooms in the future. I think there's a lot of potential, especially if I can work them into the gameplay somehow. Maybe the player can strap zombies onto operating tables? Maybe the player can use a scalpel as a weapon?

Classrooms 

Finally, there are classrooms. I actually copied these from schools, so I won't show classrooms until the procedural schools post. I suppose these are for training of student doctors, health related classes for the public, and that sort of thing.

Hospitals occasionally contain conference rooms that are assigned during the floorplan stage. These are left over from the office building logic and seem okay to allow. And of course there are standard bathrooms with stalls. Whatever rooms remain that are too small to fit beds, etc. can be made into offices, storage, or utility rooms.


3 comments:

  1. Hospital Comment Notes

    Seems like you should invest in making generally available variable-height stories so the parking garages can be the right height. IIRC you already did this as a special case for building lobbies? And underground malls?

    A few more ideas for hospital room types: lab spaces with test tubes, centrifuges, autoclaves, etc. Commercial laundry rooms for housekeeping (for hotels as well)? Commercial kitchen (for convention halls, corporate headquarters, and restaraunts as well)?

    I remember Sim Copter handled people by just using one very simple procedural animation for people walking around, and then when they were injured, they changed to a head sticking out of a white cube (maybe a tapered cube?) to represent someone wrapped up for medical helicopter transport. Since you have helicopters, this might be a good way to go. You could probably procedurally mask all the facets in the person model except the head. I checked SketchFab for a low-poly medical patient transport model, but didn't see one, so I'll whip one up soon.

    The hospital patient rooms I've been in all have the windows higher on the walls, usually with a low couch-bed below the window.

    I don't think I've ever seen a hospital with a carpeted floor though. It's always something easy to wash down. You know, for all the fluids and stuff.

    Fish tanks in medical waiting rooms?

    Now that you have all these hospital rooms, how hard would it be to add smaller doctor/dentist/medical offices?

    Love the vending machines. It should be easy to make any-item vending machines, that dispense a random item from the game. All you'd need is the vending machine graphic for the front, right? I'll make one and e-mail it to you.

    Instead of forcing the player to explore to find healing items, or implementing some sort of auto-healing, what about an auto-explore feature that rapidly traverses all the rooms in a building until you encounter a zombie? Once you deal with all the zombies, mark the building as "cleared" and then you have access to all the items in that building. You would probably want to implement some sort of fast-forward in-game time system, but that shouldn't be too difficult.

    The fact that you don't have a debug mode for the game yet baffles me. You're literally using the same starting seed every time and then wandering around trying to find corner-cases and bugs? I would implement this even before variable floor heights. Have it generate an empty world with rows of rooms (no ceilings) in various extreme aspect ratios, buildings with various floor heights, areas with extreme item quantities, etc. Lock the room types to only the kind of room or building that you are working on, so you can rapidly examine, debug, and iterate with confidence.

    "room that's probably too large" I was going to point this out if you didn't. These are the most palatial hospital rooms I've ever seen! This could be a kind of eerie feel though, every building you enter has progressively larger and larger rooms. You end up in a city-sized lobby that you need a motorcycle to effectively traverse!

    "definitely not cans of beer" the size of paper towel rolls!

    Seems like you could use the alcohol overdose system for medicine as well.

    For the operating room machines/equipment, I would at least change the texture from galvanized steel to white plastic (maybe the same as the walls, but with the bump map turned way down?)

    Ooh, the idea of strapping zombies to the operating table suggests curing the zombies somehow. That could be an interesting gameplay arc! Maybe you can gather machine parts from elsewhere in the city to repair the operating room machines, and then some random items from around the city to make some zombie curing medicine? Do you want to do a procedurally generated surgery mini-game? The player is some sort of magical mad scientist? Possibilities abound!

    ReplyDelete
    Replies
    1. Thanks for all of the suggestions!

      Above ground buildings must be the same space between all floors because the exterior and windows are generated before the interior. Except for factories and warehouses, where the whole building is special. Underground rooms don't have that restriction because there's no exterior. But if I was to change the height of parking garages, I would likely need to rework all of the pipe logic, elevators, stairs, connected rooms, etc. It's a lot of effort. Malls can be taller, but they were designed that way from the beginning.

      Lab spaces would be good, but would require many new object types. Commercial laundry rooms is a good idea since I already have washer and dryer models. Commercial kitchens - maybe. Some office buildings already have small kitchens. I don't think any of the current building types would need them, except for maybe school cafeterias.

      I've never played Sim Copter. Maybe I could add something like that if I can find a way to integrate helicopters and medical transport into gameplay. Otherwise it seems like a lot of effort for something the player may never see unless they're looking for it.

      I can move the windows up, but it would have to be for the entire building. I can't change window height per room. I don't think what I have looks too much difference from some of the reference images I've seen.

      Carpeted floors are a good point. Hospitals and schools should have some sort of tile floors like malls. I didn't think about that.

      I have fish tanks in some office building lounges. Maybe I can add them to some hospital waiting rooms. Though I can't say I've ever seen that, except in a children's hospital.

      Doctor/dentist/medical offices would be possible, but I could have to customize each one. It's the same with restaurants, gas stations, convenience stores, police stations, and fire stations. I want to complete all of the larger specialized buildings before working on the smaller ones.

      I'm not sure what you mean by "any item" vending machines. Do you mean they select a random object from my current set of 196 object types? I can't simply create an object by ID and give it to the player. Some are attached and can't be inventory items. Some require special state, flags, or indexing into other parts of the building data structure. Only some object types have their interact logic written. And some would be larger than the vending machine itself. I would have to list the supported objects and have a big if-else tree or switch statement that created them. The current snack vending machine produces a generic object type with no graphic and only a description + weight + value, rather than selecting a real object type.

      Auto explore takes away the fun of exploration. I want this to be an exploration game. It's not only about the zombies. There are rats, snakes, and spiders that can hurt the player. There are locked doors and keys to find. And some of the buildings have a thousand rooms that would take forever to auto explore. There's also no clearing of buildings because the player can't actually kill zombies. They can be contained at best by locking them in a room or blocking them with tape or furniture.

      Delete
    2. Comment was too long; continued:
      Most of the bugs I come across are encountered when testing some unrelated feature. I can pretty quickly fast travel to anywhere in the map. The starting seed does give me 18K buildings total! I usually don't need to look very long to find a problem. There are also a large number of internal checks that buildings are properly formed, areas are reachable by AIs, etc. And I can override most things like building types, sizes, etc. either in the config file or by modifying a line of code. When I was working on factories, I made all office buildings that fit the factory footprint into factories. For hospitals, I changed all rooms to the type I was currently working on. And for objects like machines, I filled the entire room with them. I also have all sorts of debug visualizations for building type, AI paths, collision objects, etc.

      Your debugging method is actually difficult to implement. Things like rooms are generated with rules and constraints, and have graph edges connecting everything together inside a building. I can't simply create an array of completely random rooms or objects and have them work properly. Nor can I fill and empty world with rooms and no ceilings. The nesting is terrain tile => building => part => room and the ceiling is technically part of the room.

      The hospital that many of the screenshots were taken from was originally an office building with rooms full of cubicles. Some of the other buildings have smaller rooms. But it does help to have a larger room because it makes placement easier, allows for more object/item flexibility, and reduces problems with AI path finding. (Keep in mind that AIs must fit for all animation frames - they can't squeeze into a narrow space.)

      Yes, the cans are too large. I started with cans in upper kitchen cabinets and reused the code for vanities. But the can size was scaled by the object size, and vanities are nearly twice the height of upper cabinets. I've already fixed this.

      Yes, I was thinking of adding medicine overdose. The only problem is that there's no status bar for it, so how would the player know how close they are to an OD? (By the way, I have a fun method for testing this. I need to take damage so that I can use medicine, but not enough to die. So I find a hostile rat, let it bite me, then pick it up so that it stops biting me. Then when I want to take more damage I put it back down.)

      I originally had white objects in ORs. But they blended in with the walls and I felt like there was too much white, so I switched to a metal texture. I suppose I can change it back. Maybe I can use off-white colors but no dirt or damage?

      Anything with curing zombies, surgery, or mini games will have to wait until sometime later. My TODO list is so long already, and I added several new items based on this reply.

      Delete