Book Image

Learning Game AI Programming with Lua

By : David Young
Book Image

Learning Game AI Programming with Lua

By: David Young

Overview of this book

Table of Contents (16 chapters)
Learning Game AI Programming with Lua
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Getting Started with AI Sandbox
Index

Preface

Game AI is a combination of decision making and animation playback. Although classic or academic AI is focused solely on finding the right decision to make, game AI is responsible for acting on numerous decisions over time. Treating game AI independent from animation is a classic mistake that this book avoids by integrating animation and locomotion systems immediately into the AI systems. This subtle difference of decision making and execution changes many of the aspects that game AI programmers have to focus on.

The other large issue with game AI is regarding the specific needs and implementation strategies that are genre-specific. In order to prevent a watered-down approach, this book focuses on one specific genre, which is the first- and third-person action genre. Limiting the AI to this decision allows for an in-depth, tutorial-based approach of creating a full AI system. The overall goal of this book is to create an AI sandbox composed of professional level C and C++ open source libraries exposed to an AI system scripted in Lua.

What this book covers

Chapter 1, Getting Started with AI Sandbox, begins with learning the overview of how projects are set up as well as how the Lua script interacts with C++ code. Here, the beginnings of the AI sandbox are built from open source technologies, starting with a framework that integrates Lua, Ogre3D, OpenSteer, and Bullet Physics.

Chapter 2, Creating and Moving Agents, starts off with examples of the lowest layer of AI interaction with the world, local steering, and movement. Here, agent seeking, avoiding, and group movement are introduced into the sandbox through the use of the OpenSteer library.

Chapter 3, Character Animations, continues with the AI sandbox by exposing Ogre3D's animation playback and resource handling of Lua scripts. Low-level structures for controlling animation clips, animation state machines, and layered animations are integrated into the sandbox.

Chapter 4, Mind Body Control, combines animation handling with local steering and agent movement. Two different approaches toward mind and body interactions will be implemented. The first will focus on the latency between agent decisions and actions, while the second approach will focus on the perceived quality of the agent's actions.

Chapter 5, Navigation, builds up from local movement and moves on to long distance movement and planning. Navigation mesh generation provided by the Recast library will be integrated into the AI sandbox in order to allow A* pathfinding provided by the Detour library.

Chapter 6, Decision Making, adds intelligence to the choices the AI agents make. Different data structures and approaches to creating modular and reusable decision logic are covered through Lua scripts. Decision trees, finite state machines, and behavior trees are integrated into the sandbox.

Chapter 7, Knowledge Representation, adds the ability to store long-term and short-term information for individual agents. A centralized approach to storing and propagating agent knowledge about the world is exposed to Lua.

Chapter 8, Perception, exposes the services that are available to agents for them to query information about the world. Approaches toward visual- and communication-based information is integrated into the sandbox.

Chapter 9, Tactics, exposes a high-level spatial knowledge of the environment to the sandbox. Through a grid-based representation of the world, different knowledge sources are combined in order to give you an accurate tactical view of the environment for decision making.

What you need for this book

The AI sandbox solution and project files are built automatically through Premake, which is the utility program. Visual Studio 2008, 2010, 2012, and 2013 were tested for compatibility with each of the included demos. With the large number of dependencies the sandbox builds from the source, the project setup is only supported from Visual Studio.

The open source Lua IDE, which is Decoda, is used to write and debug Lua scripts within the sandbox. While other Lua script editors can be used, the sandbox natively exposes information that allows seamless Lua debugging within Decoda.

Who this book is for

This book is aimed at programmers who are looking to understand all the facets involved with the creation of the game AI. You should be comfortable with C or C++ and the Lua programming language. While no direct C or C++ knowledge is required, being able to fully debug into the sandbox allows for extending the existing functionality. A combination of both functional and object-oriented Lua will be used by the sandbox, and both approaches will be explained. Additional understanding of modern game engines will be useful but is not required.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The LuaScriptUtilities header defines the metatable name of the vector type."

A block of code is set as follows:

local function CallCallbacks(callbacks, stateName, looping)
    for index = 1, #callbacks do
        callbacks[index].callback(
            stateName, looping, callbacks[index].data);
    end
end

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Open the Settings menu under the Project menu."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from: https://www.packtpub.com/sites/default/files/downloads/1336OS_ColoredImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.