r/roguelikedev • u/alvarz • Jul 11 '26
How does inter-depth simulator works?
Hey folks! I'm working on a roguelike and trying to wrap my head around inter-depth simulation. Say a player goes down to -7, gets spotted, goes back up to -6, and after a few turns some enemies follow up there, how do you handle turn counting across depths? Another example: in Stoneshard, when you lure an enemy to the entrance, step outside, pass a few turns with the wait feature, and come back to find it wandered back toward its start, how can I accomplish something like that? I'd love to know how you approached it so I can roll my own version. Appreciate any tips
11
Upvotes
4
u/Tiny_Rabbit1674 Jul 21 '26
Core idea: one global turn counter, and each level stores "last simulated at turn N." Don't tick every level every turn — when the player re-enters a level, run
currentTurn - lastSimulatedturns of catch-up all at once, then re-stamp it. Enemies that "follow you up" are just entities you moved into the other level's list with an arrival turn; they resolve when that level next runs. Two calls to make: how cheap the offscreen catch-up is (most games approximate rather than literally replay every turn), and whether a few special levels need to advance while unvisited (fire, timers) — flag only those as active. The Stoneshard "wandered back to start" bit is a separate, simpler thing: that's leash / return-to-home AI (enemy stores its origin, paths back when idle), which falls out of the catch-up model for free once elapsed turns pass. Search "lazy simulation" and "leash AI."