Showing posts with label abilities. Show all posts
Showing posts with label abilities. Show all posts

Saturday, October 20, 2012

Navigating The Flow

Hey Readers,
 
It's been a busy couple of weeks. My main focus has been on getting in some kind of backend interface to control all of the different commands that are going to be available for the user. I needed something that would be flexible since there are going to be so many different possible commands.

User Contexts

I decided to go with something I call User Contexts. The idea behind the user context is simple, It's basically a state object which contains all the logics to execute commands for that context. So for example

Main User Context =>Has two options, Build Item and Move Item            
*Build Item
    Build User Context =>Choosing Build Item spawns off a new Build User Context from the Main
    *Build Wall
    *Build Floor
*Move Item
    Move Item Context
    *Click on location to move item to

So each user context knows about it's current state and how to construct the next level of user contexts which are based on the available commands. When a new context is created it's returned to the main game state as the current context. In addition each previous user context is linked to the next context so that when the current user context is finished it can easily jump to the last context.

Interfacing with the User

This was all well and good for the back end but I needed a way to convey this to the user. To keep things simple I decided to build a console UI element which could be easily written to. I didn't want to waste a lot of time fooling around with creating new UI's for each User Context so I thought this would be an easy alternative that would still convey what the possible options are to the user. I set up a function in the User Context which takes in a UIConsole so that each context can print whatever information it needs to convey. There's also a number of functions for user input for overriding what the functionality should be when there's mouse or keyboard input.

Status of the Game World

While I was mucking around with setting up this user context console window I thought it would be great to have another console window for displaying information about the currently selected object. I haven't really taken this one too far but my thought is to set up a status component I can give to each of my game objects so they can convey useful state to the user. Some useful info might be how much resources are left in a crate, or what ability a character is currently using, or maybe how much is left to do on an object in construction.


In the coming weeks I'd like to flesh out a few more gameplay features: obtaining resources, the job system, item destruction. We'll see how far I get though. I've posted another video showing the progression I've made. You can see the User Context console is in the top right corner and the object status console is in the bottom right corner.
 


Wednesday, October 3, 2012

Having Fun With Behaviour Trees

Hey Readers,

The last two weeks I've been working on resource management and progressing on the 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.