2016
10.10

Behavior trees sneak peak

I have the first version of behavior trees ready in yendor.ts, just not yet pushed to github.

The result is that monster’s AI is now trivial as it only has to execute the tree tick function:

public update(owner: Actor) {
   super.update(owner);
   // don't update a dead monster
   if (owner.destructible && owner.destructible.isDead()) {
      owner.wait(this.walkTime);
      return;
   }
   if ( this.behaviorTree ) {
      if ( this.__context === undefined ) {
         this.__context = new Yendor.Context();
      }
      this.behaviorTree.tick(this.__context, owner);
   }
}

Now all the creature intelligence (rather dumbness right now) is described in the actor definition JSON :

    ai: {
        type: Actors.AiTypeEnum.MONSTER,
        walkTime: 4,
        tree: new Yendor.BehaviorTree("basic hostile humanoid",
            new Yendor.SequenceNode([
                new Yendor.PriorityNode([
                    new Ai.FindPlayerActionNode(),
                    new Ai.TrackScentActionNode(SCENT_THRESHOLD),
                    new Yendor.InverterNode(new Ai.WaitActionNode()),
                ]),
                new Ai.AttackPlayerActionNode(),
            ])
        ),
    },

The priority node run its children until it finds a successful one : if the player is visible, the creature tries to get to melee range using path finding (FindPlayerActionNode), else it tries to track scent (TrackScentActionNode), else it simply waits (WaitActionNode). This will make much easier to have creatures guarding the chests as planed for 0.8.0.

More info on behavior trees.

No Comment.

Add Your Comment