Hey guys, wanted a question on how good/terrible the approaching is that I'm planning for a roguelike I'm designing to handle time and actions and pretty much everything that happens in game. Do note that I've got no idea how existing roguelikes normally handle this, but here's my intended approach.
First, we'll have three game objects - a player, a zombie, and a piece of food (for reference).
I've also got an Action Controller, which is actually going to be (basically) a linked list, and a bit of logic for inserting and removing stuff, as well as a variable to hold the current time (the time of the last action handed off) to create new actions relative too. Any object that has stuff that it will do at some point gets an entry for that stuff added to this list. To start with, then, we'd have something like:
object | Action | Time |
Player | Turn | 430 |
Zombie | Turn | 480 |
Food | Rot | 1970 |
The Action Controller will actually handle the entire flow of the game - things only "happen" when the controller resolves an action (though there may be things that happen other than the action, such as updating the screen, changing weather or day/night conditions, or side effects of action). So whatever happens now finishes resolving, and control is handed back the AC.
It looks at the first item in the list, and send a "turn" action request to the player object after removing it. In this case, lets say the player choose to activate a grenade, at the cost of 80 time units. Each object also keeps track of its upcoming actions - it removes this action from it's internal list, processes the game effects of the activation by passing a "trigger" request to the grenade (which sends a new add action request to the AC for "explode" for itself, with 200 time units), and then the player sends a new add action request for "turn" to the AC, in 80 time units. When the player finishes processing, control is passed back to the AC, which now looks like this:
object | Action | Time |
Zombie | Turn | 480 |
Player | Turn | 510 |
Grenade | Explode | 630 |
Food | Rot | 1970 |
Now, do the same thing except with the zombie - assume he hit the player with a strong attack and ends up stunning him. A stun request is sent to the player - it uses that reference I mentioned earlier to get its next turn action, and tell the AC to delete it from the list. It adds the calculated stun time (let's call it 150 time units), and then sends a new add new turn action request to the AC, which does so, inserting the action at time=660... right after the explode action. The zombie then adds his own new turn action at time=200 (they move pretty slow), and passes control back to the AC, which looks like so:
object | Action | Time |
Grenade | Explode | 630 |
Player | Turn | 660 |
Zombie | Turn | 680 |
Food | Rot | 1970 |
The AC hands off the action to the grenade... which promptly explodes, killing both the player and zombie. Upon being destroyed, each object does a few things. First, it deletes all the actions it was tracking, removing them from the AC. Second, it creates a corpse objects. Upon creation, corpse objects will add their own action to the AC, and you'll end up with something like this:
object | Action | Time |
Food | Rot | 1970 |
Zombie Corpse | Regenerate | 2130 |
Player Corpse | Zombify | 2130 |
If the game would actually end at this point, we could add
Would something like this work? Are there significant flaws I'm missing here somewhere that will trip me up? Things I'm not considering?