This week I’m continuing my work on the sleep system. A first cut of this puppy is more or less done. As you can see from this debug screenshot, we have beds! And people have learned how to sleep in them! Here’s how the system works in its first iteration.

As time goes by throughout the day, your citizens grow more and more sleepy. When their sleepiness hits a threshhold, they figure it’s time to go to sleep and start looking around for an unused bed. If they find one, they will claim it as their own, run to it, and fall to sleep. So citizens know whose bed is whose, and won’t hijack someone else’s bed. This means that each little guy can potentially have his own home if you build your town that way.

Ownership of a bed will eventually expire. So if something…unfortunate…happens to one of your citizens, someone else will eventually claim their bed. Also, if a citizen can’t find a bed for a while, either because there are none available or because he can’t get to any of the beds, he will eventually give up and just collapse on the ground, exhausted. Sleeping on the ground will be much less effective than sleeping in beds, so you’ll have plenty of incentive to make enough beds to go around.

With this basic implementation in place, we’re going to call sleeping “done” for now and move on to other aspects of the game. We’ll see how it works in practice and add richness where necessary. One obvious enhancement is the ability to explicitly assign a bed to a particular citizen, and we will almost certainly add that soon. And obviously we’ll need to implement our facial animation system soon, so everyone doesn’t sleep with their eyes open!