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

Scoring dangerous areas


The next influence map we'll create is scoring dangerous areas from a team-specific perspective. Using the events that the agents are currently sending out for communication, we can set influence values on the information the team rightfully knows about without resorting to scoring calculations:

SoldierTactics.lua:

require "AgentSenses"

local eventHandlers = {};
local bulletImpacts = {};
local bulletShots = {};
local deadFriendlies = {};
local seenEnemies = {};

Tapping into agent events

Without modifying the existing event system, we can create simple event handlers to store, process, and prune any number of events the agents are already sending. As events are processed differently for the influence map, we store local copies of each event and manage the lifetime of events separately from how agents process them:

SoldierTactics.lua:

local function HandleBulletImpactEvent(sandbox, eventType, event)
    table.insert(
        bulletImpacts, { position = event.position,...