Your archers are engaging enemy cavalry from a distance using their ranged attack. The opposing forces harass you, the archers get a bit too complacent and move away from the protection of your infantry. Seeing the opportunity, the enemy cavalry charges suddenly! How do you make sure your archers or crossbowmen switch to their hand weapon to try to limit the damage?
Such problems come up very frequently in game AI. What do you need to do to make sure the AI can deal with changing its mind, for instance to switch between an attack that makes sense in one situation (e.g. ranged attack) vs. another attack mode that needs to be used otherwise (e.g. close combat)? How should you structure your behaviors to support such situations? This masterclass using examples from the indie game Mount & Blade to explain the solutions.