Problem:
There's no way to control who goes through a given passageway and who doesn't. This makes it hard to reduce the effect of villains, but in general it would be nice to limit your tavern or library to civs you're actually at peace with...
My suggestion is to solve this by allowing military units to guard doors, hatches, bridges and floodgates. This is different from stationing, because the units involved should be able to check who goes in and out of a passageway, and hold back those that aren't allowed somewhere. Attempts to breach should be reported to the sheriff.
Guards should be able to grant and dissallow passage based on:
- Citizenship
- Residency
- Membership of a particular entity (such as, 'carpenter guild members only')
- membership of entities that have a certain diplomatic state with yours (such as, only folk we're at peace with, or only folk we have trade agreements with)
- Positions or titles (example: only the king, bookkeeper and high lilac of the diamond order are allowed to enter this chamber)
- profession.
- ownership of a certain kind of item (only people with red cloaks are allowed to enter this area)
- ownership of the room that the door leads into (only the king or queen are allowed to enter their own rooms)
- state of life (baby/child, prevent baby from crawling to the magma chambers)
To ensure it isn't foolproof there's the following considerations:
- It takes time to setup and you'd need to use the military scheduling system.
- Histfigs are already able to lie about their identity, which in the event it is about membership to groups possible to claim to be part of them. Being the king himself might be much harder to pull off.
- Histfigs should be able to flip guards, this is already in the game.
- guards should be supplied with food and drink, or otherwise just leave their post to get some.
This will also improve the intrigue game when villains do manage to penetrate the chamber: Was it the guards who were responsible for the breach, or, in fact, was it the king himself!?
As a last note: citizens in general should be treated more gently by the guards, but children especially should not trigger anything but being disallowed, even if the child is doing his hardest best to prove the guards that they are totally an adult.
Edit: I just realized this has the same problem as keys and locks, in that it means the pathfinding map is not homogenous among all units.