I was tackling on implementing the checking of victory/defeat conditions to check if the player won already or not, and I realized, “Why not use behaviour trees for this?” Is this really going to help, or is it a case of “when you have a shiny new hammer, everything looks like a nail”?
What I have are these so far:
Types of Victory Conditions:
- All enemies defeated
- Kill certain units
- Survive for N turns
- Default: Only player left who is not defeated
Types of Defeat Conditions:
- All my units defeated
- Certain units of mine are dead
- N number of turns passed
- A (non-ally) player is victorious
(There’s a lot of redundancy there, like “all enemies defeated” would also trigger “all my units defeated” for the opposing player, but for cases where there are more than two players, defeat of one player won’t automatically mean victory because there would be at least two players left.)
Usually there’d be a list of victory conditions and another list for defeat conditions, for each player.
The question is, does triggering at least only one condition in the list constitute an automatic victory (for that player), or do you need all conditions in the list to trigger true to mean victory? Basically, are the conditions in the list strung together in an AND operation or an OR operation?
And the answer is, it depends on each mission the designer creates. So why not allow the designer the flexibility to specify how he wants it? And with my goal of allowing mods, this does need to be flexible.
So I was thinking, why not structure it as a behaviour tree? One behaviour tree for checking victory, and another for checking defeat. And each player will have one of those pairs (there shouldn’t be only one meant for all players since the AI can have different victory conditions than the human player, for example).
So there it is. Right now it’s just a simple message saying “YOU WON” or “YOU LOST”.