Assume I have a behaviour tree like the following:
[A]
/ | \
[B] [C] [D]
- A = Selector (Priority node)
- B = Perception task
- C = Idle task
- D = Walk to point task
The reason the tree looks like this is because B has priority over C and D since it should trigger alert procedures. In short, what I'm trying to model here is that the Agent sensors must have priority over behaviours.
Assume now the agent is in D and this node will continue returning running
until the destination point is reached.
While D is running, something might happen (for instance, the NPC see or hear something) that should break the current operation as soon as possible but, D will go on regardless until it's done.
I know I could paste the sensors code on top of each tree leaf, like for example:
// kinda javaish pseudo code
void run() {
// The node running method
if (this.sensors.alert()) {
return this.fail();
}
// Else, keep going.
if (! this.reachedGoal()) {
// do the walking
return this.running();
}
return this.success();
}
But with that solution the "alert" behaviour is hard coded and out of the tree logic.
What solution do you suggest?