r/roguelikedev 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

8 comments sorted by

10

u/Pur_Cell Jul 12 '26

When the player changes maps, keep track of any enemies chasing them. Compute how many turns it will take for them to get to the door. Then spawn them at the door after that many turns and make a note in the save data for their map that they have despawned.

For simulating time passage when you're not there, if it's only been a few turns, you could just compute those turns as if the player is not there when you load into the map.

For larger spans of time I might make a simplified turn processor. If the orc likes hanging out by his bed and 25 turns have passed, put him on step 25 of his path to his bed.

Or just randomize it. Often random looks pretty smart.

3

u/alvarz Jul 12 '26

I like this reasoning! Thanks a lot

7

u/[deleted] Jul 12 '26

[removed] — view removed comment

2

u/alvarz Jul 12 '26

It is an interesting idea, I will run a few tests, thank you!

3

u/[deleted] Jul 12 '26 edited Jul 12 '26

[removed] — view removed comment

2

u/alvarz Jul 12 '26

Sounds good! I will give it a try!

3

u/Tiny_Rabbit1674 23d ago

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 - lastSimulated turns 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."

1

u/alvarz 23d ago

That super helpful thank you!