I believe the most ergonomic way is to pass the event affecting the entity via continue, in addition to the remaining sleep time or None
if nothing interrupted the sleep. We then also need an event effect that resumes another entity immediately i.e.
effect Sleep : int -> (event * int) option
effect Event : (cell * event) -> unit
If, for example, the elephant is sleeping for 20 turns but is hit after 15, it would be resumed immediately with (HitBy Spider, 5)
which it could then handle by:
- Ignoring if irrelevant
- Handling and going back to sleep
That would also allow chain reactions (if intended). For example a knockback event could result in:
Elephant acts and knocks Camel back. Camel wakes up, attempts to move in intended direction but is blocked by a spider. It would then perform a knockback event on the spider (returning to the scheduler which continues the spider with the appropriate event). The spider then moves out of the way and sleeps again. Camel has succeeded with its event and moves too etc.
We could also discontinue the Sleep continuation with an exception. The result is basically identical to the Reset_decision_tree
exception.