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

Team communications


So far, team communication has revolved around agent visibility; we can now extend these communications to include behavioral logic selections such as new enemy selection, position updates, and retreat positions.

The EnemySelection event

To coordinate attacks, our agents need to notify their teammates when they've selected a new enemy. Sending out an event when a new enemy is being pursued requires you to add a new EventType string. With a specific EventType, we can create a wrapper function that will message the team about the enemy:

AgentCommunications.lua:

AgentCommunications.EventType.EnemySelection = "EnemySelection";

SoldierActions.lua:

local function SendEnemySelection(sandbox, agent, enemy)
    AgentCommunications_SendTeamMessage(
        sandbox,
        agent,
        AgentCommunications.EventType.EnemySelection,
        { agent = agent });
end

function SoldierActions_PursueInitialize(userData)
    
        ...
        
        userData.controller:QueueCommand...