sholloway / agents-playground

MIT License
4 stars 0 forks source link

Interconnected Systems #62

Open sholloway opened 1 year ago

sholloway commented 1 year ago

Simulation games are hierarchies of interconnected systems. I need to identify the best practices for how to design and build simulations composed of multiple systems.

Example Systems

What is a system?

System Architecture Needs

In dwarf mode, say. It starts with some announcement checks and considers autosaves, etc. A lot of the rest doesn't happen every tick. Every hundred ticks, for instance, it'll check job assignments and 'strange moods.' Armies are moved on the world map. Every hundred ticks (staggered from the job check), it handles job applications by dwarves, a kind of invisible auction that it uses to manage the various competing priorities. Every ten ticks it advances the seasons, which actually does all kinds of things with the weather and map (both locally and in the world), and it also does a check for certain plot element advances (diplomats, sieges, etc.), and it checks whether your fort is still alive.

Then it hits some things that it does every tick. Fluids and other map tile information is advanced (though there are various optimizations here so that not every tile is necessarily checked every turn, and there are various flags so that entire sections of the map can be skipped if nothing has happened.) Vermin running around are updated. Other 'events' on the map, like active fires, are handled.

If a flag is set, wounded/thirsty/hungry dwarves that can't care for themselves get an update, and every so often, dead dwarves 'think' about their burial arrangements so that jobs can be set. Caged and chained creatures update their thoughts and situation periodically.

Then creatures leave the map if they are set to at the edges.

Every fifty ticks, staggered from other updates, all of the taverns, temples, libraries, etc. get their information updated. Stockpiles, staggered on a different tick, also work this way. Similarly with storage job creation, though that process is complicated with various optimizations and lengthening ping times and so forth, and it's still slow, since at some point, 50000+ boulders will cause trouble.

Every thousand ticks, objects that have been marked for deletion and removed from the game are actually deleted and freed. This happens more often with items, every fifty ticks, along with a building use check (mostly updates for wells and some other flags that often need checking.)

We hit another every tick update at this point. Projectiles are moved. Activities (which range from dances to martial training to storytelling) get updated as needed. Dwarves and other creatures decide on and advance their immediate actions (movement to an adjacent tile, working at a workshop, etc.) -- the bulk of their AI (outside of job selection) is here.

Every hundred ticks, items are rotted. Every tick, vegetation is advanced (though there are various staggers and flags here.) Building states are updated every tick as needed, and minecarts are moved. Hauling routes are advanced. Temperature is updated (there are various optimization flags here, but this is still an unfortunately slow process.)

Finally the camera is updated to follow the creature you are following, if any. "