So it seems that project zomboid does the key thing. I thought they were able to do that because the map is not random and then I realised that in CDDA the map is not really random either, most of the map chunks are defined in json.
So (if we want to have keys) what about :
-
All the keys that are not around the locked thing are lost and we don’t generate those
-
A small fraction of key remain that are close to the thing they open, we probably need an arbitrary number here that should be based on game balance.
If we take the easy exemple of the closed front door of a house, where can the key be ?
- Under the rug
- In a nearby flower pot
- In the mailbox
- Inside the house : on a desk near the door for exemple
- Or lastly on a nearby Z
So we could either have furniture with a Flag CAN_HAVE_KEY or (i’m not sure how json map works) have coordinate in a map designated as key spawn point.
And then things could go as follow :
- Is the door closed ?
- Is the key around ?
- Lets choose a spawn point and put a key here.