
Welcome, ladies and gentlement, to a tutorial series explaining how to use our new asset store tool, named the Simple Option Stacker!
What are Option Stacks?
An Option Stack is a system often used for the AI in most AAA games. Most commonly used in coherence with the classical Finite State Machine architecture, and the more advanced planner architecture, but also with most other architectures. As you probably know by now, most AIs are built up using states or behaviours. Each state defines how the AI should react to the current situation, and depending on the arcitecture, what conditions lead to other behaviours.
An Option Stack keeps a list of states that the AI is currently in. On top of the stack is the most recently called state. (Normally you would only execute the state that is ontop of the stack.)
This means all other states would temporarily suspend while the top state is being executed.
Let’s look at this example:
An RTS AI unit is ordered to attack player 2’s base. This will push the state “AttackBuilding()” to the top of the stack. However the unit is not whitin range, so it will also push “GoToLocation()” ontop of that. This means that once GoToLocation has finished, it will be removed from the stack, and the unit will proceed to AttackBuilding(). This can easily be hardcoded into an FSM, but things get exponentially more difficult when things get more complex.
Since while the unit is in the GoToLocation state, it walks into an ambush set up by player 3! Now the unit will push something like “ReactToAttack”. The first thing ReactToAttack requires is to take cover, so lets have that as a seperate state. That means “TakeCover” will be pushed ontop of the stack. But on its way to cover, the unit notices a live grenade thrown at its feet! Now it will push “ReactToGrenade” ontop of that. A state where the AIs only goal is to survive the grenade attack. The stack now looks like this:
“AttackBuilding < GoToLocation < ReactToAttack < TakeCover < ReactToGrenade”
The units ultimate goal is to complete the task on the very left, but to do so it must first complete every task in order from the right to the left!
Option Stack principles.
Every Option Stack system MUST contain 3 simple methods:
1. PushState - This will put the specified state ontop of the stack.
2. PopState - This will remove the top state from the stack.
3. GetTop - This will return the top state of the stack.
Every behaviour MUST pop itself after it has completed or is no longer relevant. This is easy, as any state can only pop itself using PopState, because only the top state can be exectued.
Note that at the moment our Simple Option Stacker natively supports states as methods and coroutines, also known as voids and IEnumerators, but the system can easily be modified to work with classes!
Tutorial post list:
Basic
1.1 How to start using Simple Option Stacker Basic
1.2 Features included in the basic edition
Remember that the newest version of Simple Option Stacker always will be available at lustrousgames.com/downloads before the asset store!
If you have found any problems with the pack, found an insignificant spelling error in a thread, or you want to make a suggestion/request for the next patch, feel free to post them on this, or preferrably this other thread, or send me a private message!
If you do not own Simple Option Stacker, feel free to purchase the package at either our website or on the asset store!