Goal Oriented Action PlanningPosted on
So I had a problem. I was moving merrily along with a task system based on state machines. And it was becoming an unreadable nightmare. It started out fine. An object is lying loose on the floor of the station. The task dispatcher is aware of the object and wants to store it in a stockpile. So it pulls the object out of its object list and creates a PickupAndStoreObject task. Works fine. Until the what-ifs start. What if the stockpile is de-zoned mid task. What if the entity assigned the task suddenly goes into a starving state and wants to find food instead. What if the item is iron ore and a smelter on the station is looking for iron ore as a raw material.
These are all fine cases. They can all be handled. But now start thinking about inter-dependency between tasks. Between tasks and entities and objects. Initially, I just broke down the task into the smallest possible sub-tasks. PickupObject. MoveToLocation. StoreObject. But each subtask would put the entity into a different state. And the tick loops for my entities were getting insanely long.
Luckily I stumbled on this site https://best.kevin.games
Unwittingly I had been preparing for this. In Goal Oriented Action Planning, a goal (store item in stockpile) is comprised of independent actions. Each subtask would become a self-contained action with all the knowledge of how to execute contained in the action itself. Prerequisites and results would let the actions know how to relate to each other and a Goal planner would be able to find a path tree through multiple actions to achieve its goal. The entity would need to know nothing about execution and would only need a state for working action. The task would tell the entity model what cosmetic states to select. By adding a cost value to every action we can also dictate which actions will be preferred. Prefer taking the iron to a smelter over storing it in a stockpile for instance.
It took me a few days to rework my whole task system but its going to pay dividends. Adding a new action type will be trivial now top gaming chairs. I can even add and remove usable actions to an entity on the fly based on game circumstance. I recommend anyone doing complicated state machine for AI entities take a look at this approach instead.
I’ve got two artists creating assets for the game now so I’m planning for next update to contain concept art and new models to make up for no new pics this post.