Update 3

I continued working on staff AI, mainly making sure to handle situations where tasks can’t be completed.

For example, imagine there’s an employee, tasked with transporting a delivery crate containing resources from storage to a shop.
Let’s see what could possibly go wrong!

  • the employee is at the other end of the park. The task should ideally be assigned to someone who is close instead. But it can’t just be assigned to “the closest employee”, because what if they are all far away? There’s probably something else they can work on closer to where they are, it’s not very efficient to call one of them all the way over. This should only be done if no available employee has been found in close range for some time (the range can gradually expand over time).
  • the employee might not be able to reach the storage because there’s no path. Calculating paths requires relatively much time and the employee most likely won’t be able to reach the storage within the next few seconds or so either, so instead of trying to reassign the task to the same employee over and over again it should be given to another one instead without retrying (for a while).
  • eventually, some employee managed to pick up the crate and is on his way to the shop. But what if the player is doing some rebuilding and removed some paths, so the employee now can’t reach his goal anymore? He should bring the crate back to the storage. The task most likely can’t be completed for some time, so it should receive some cooldown time before trying to complete it again (performance!).
  • but what if now he can’t reach the storage anymore either? Maybe there’s another stroage he can reach and take it there? But if there’s no reachable stroage? There’s really nothing he can do, so he should probably just drop the crate, carry on with some other task and have someone else pick it up later. Here’s where the Behaviour Trees from last weeks post come in handy, as they allow to quite easily define a range of different strategies.
  • what if the shop doesn’t exist anymore? The task for delivering the resources has to be cancelled and they wait in storage until they are needed elsewhere.

So that’s mostly what I did this week - ensuring we have systems in place to handle cases like these.