• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
  • entries
    8
  • comments
    5
  • views
    12392

Fun With Behaviour Trees

Sign in to follow this  
Followers 0
Dancin_Fool

1306 views

This is a repost from my external blog http://codingintransit.blogspot.ca

Hey readers, the last two weeks I've been working on game resource management and progressing on my job system.

Job System

My initial plan for the job system is essentially that every job has a set of abilities. These abilities can be learned by having that job assigned. The user can issue requests which need to be executed but not directly use the abilities. I iterate over all the character looking for a character that has an ability which can execute the request. Initially I implemented the abilities as a chain of actions. This worked good for my basic needs, my first ability being a build item ability, which consisted of an action chain with a move action and a build item action. This worked but then I started looking at resource management( like using resources to build something, not like in game assets ) and quickly realized that my simple chain of actions was not going to get the job done.

Behaviour Trees

What I decided to do was to make each ability it's own Behaviour Tree. This way I can define very detailed behaviour for how each ability will work. For example my initial flow for the build ability is:

  • Check to see if character is holding construction resource
  • If they are
  • .....Check to see if character is in range of the item to build
  • .....If they are
  • .........Start using resources to build item
  • ....If they aren't
  • ........Move towards build area
  • If they aren't
  • ....Check to see if resources available on map
  • ....If there is
  • ........Check to see if character is in range of resource
  • ........If they are
  • ............Pick up as much resources as character can carry
  • ........If they aren't
  • ............Move towards closest resource pile
  • ....If there isn't
  • ........Fail out job can't be completed right now.


    If the job can't be completed it's unbound from the character ability and returned to the bottom of the command queue.

    Actions and Decisions

    The way I've gone about implementing this is to set up two templated classes, Action and Decision. They both take a templated type which has the implementation for that type of action or decision. Decisions are designed to be the logic which decides which path to take in the tree. Actions are designed to be small pieces of logic which are at the end of a chain of decisions. This is all then linked together with fast delegates. Every decision has a pass, and a fail delegate. Decisions and actions then have a function for get a delegate instance which can be hooked into the pass or the fail.

    Abilities

    These behaviour trees are then assigned to an ability. Currently the only implemented ability is the build ability. The idea is that every job has a number of abilities that can be used by the character that has that job equipped. For example the build ability is a part of the Handyman job. The user doesn't actually control these abilities. What they do is generate a request, so

    • The user chooses a tile they want to build.
    • They generate a build request. This request goes into a global request queue that the characters have access to.
    • On the character update if they aren't already fulfilling a request they will check the request queue and see if any of their abilities can be used to perform a request.
    • If an ability can be used, that ability is bound to the request and the character can start performing the request.
    • When the request is completed or can no longer be executed the ability is unbound and the request is deleted.


      I have a video demoing the evaluation of the build ability. The blue tiles are spots where I've laid down a build request and the crate in the corner is a resource crate that contains some construction resources.

      Apologies for the frame rate. I recorded it on my mobile dev machine, a Toshiba Netbook, so the recording software taxed the system a bit.


      ?

1
Sign in to follow this  
Followers 0


4 Comments


Just a note, try to put everything a npc does into a single bht. Once you start to use different bht to control a single npc, you might run into trouble. To handle different jobs or tasks in my bht I use a special kind of node, call it dispatcher/selector whatever. It selects a sub-tree depending on a given attribute, ie. the job_id. Then each sub-tree contains the neccessary logic for your ability/job, but still in the context of the whole bht.

Something like this:

[CODE]
=root (priority)
== flee ?
== fight ?
== job (selects subtree depending on job_id)
=== build
=== clean
=== patrol
== idle

[/CODE]
0

Share this comment


Link to comment
Thanks for the tip, I was definitely planning on doing something like that when I get to that point. I guess saying that each ability is it's own tree isn't quite true. My plan is to evaluate a set of needs prior to trying to execute any requests which will work quite similar to what you laid out.

My background is in rendering so it's been interesting reading up on all the AI stuff.
0

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now