About

I'm a software engineer who works on game development part time. I teach game development (on gamedev.stackexchange.com and lynda.com). I'm always working on something, and I'll post updates here. Let me know if there's a game development topic you want to know more about, I probably know the answer, or at least where to get one.

Sunday, July 31, 2011

Unit Goals


I’ve re-worked how units get things done. I gave them goals.
Up until this weekend units had a few things controlling them. They had the Unit worker, which did things like make sure they had jobs and checked their physics to make sure they weren’t flying. There was also the Job worker, which would move the units around, make them add/remove cubes and modify their inventory. 
Now the new system is much simpler, easier to understand and easier to debug. Basically, the Unit worker does everything. The Job worker still exists, but it’s only there to hand out jobs and make sure that jobs and their tasks are still valid.
The units now have a main goal and a secondary goal. (I’ll talk about goals and tasks from here on out, just remember that as far as the unit is concerned, they’re the same thing) When they need work, they ask the job worker for a job. Then they ask the job for a task. For example, a player selects 20 cubes they want removed. That’s a remove job. Then each one of the cubes that needs to be removed is a remove task. Each job is made up of tasks. So when a unit is assigned to a remove job, it asks the job what it’s main goal should be. The job finds the remove task closest to the unit, then that task becomes the unit’s main goal.
So what’s with the secondary goals? Those are the things that need to get done before the main goal can be completed. Continuing with the remove job example, the secondary goal would be “Move within range of the cube to be removed”. Once the secondary goals are met, the unit can start work on the main goal.
Once the main goal is complete, the unit can just ask the job for the next task.
Well I said it was simpler, so you should have seen the other system! Here it is in graph form:

No comments:

Post a Comment