I'm trying to design how to do this best in Lua.
The best idea I have so far is to use the Publisher/Subscriber type pattern that is implemented in Kikito's beholder.lua. Each time the animal changes state they would announce it. Other animals that have behaviours that are affected by that change would subscribe those keys (and not to others).
To implement limiting message range, animals would include their XY positions with the message. Receivers would compare that to their own position and ignore the messages outside of their range. This means that the greater the number of animals sending messages across the whole world, the greater the slowdown. This is a big flaw.
My questions are:
- Can anyone think of problems that this might create?
- Is there a better solution I haven't thought of? In particular one that avoids the XY filtering problem.