It's Interesting and odd to read the comments about GM and compare them to the framework I've evolved for my own use.
(...)
Interesting read. Yeah, it's great when a program can be nicely stratified, and all data stored in simple arrays and trees. The problem with games is that they just
don't want to be nice and stratified. They are messy blobs of various interconnected things, and that is our task to put them together
Yes, different entites need to know about each other and refer to each other in some way. For example, I have regions and units. There can be a number of units at the same region. On the one hand, I want to be able to access all the units from the given region. On the other hand, each unit may need to know its current region to find where are the possible exits to the neighboring regions. Such interconnectedness arises very often. And if you avoid it, the code may degrade to a gigantic god-class or a god-function. So, we really need to connect them somehow.
What I do, is almost identical to what you describe. The game entities that need to know about each other are labeled with an ID, a simple integer. The IDs of the units are generated uniquely, so there is no possible collision. The regions have the IDs defined at the map generation stage. The units and the regions simply know each others' IDs, this is enough to link them. The objects themselves are stored in corresponding data structure, in arrays, hash tables, or maps (an O(log n) access binary tree). With a few intermediate abstraction layers, the game data is quite manageable this way. I thought about generalizing this approach somehow with a generic module, but I'm not there yet.
Actually I do have several semi-god modules that combine different things together, but I was always able to refactor and break such semi-gods apart when they were becoming too unwieldy.