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

Managing events


As the sandbox broadcasts events to every sandbox object that registers a callback function, we'll create an agent communication system that provides commonly used functionalities such as event type registration and event filtering.

Assigning agent teams

So far, our agents fend for themselves in a free-for-all style; now, we'll assign teams to utilize team-based communication as well as the beginnings of cooperative strategy. By changing the initialization of the agent, we can assign the agent to either team1 or team2 and assign a different character model accordingly:

IndirectSoldierAgent.lua:

function Agent_Initialize(agent)
    Soldier_InitializeAgent(agent);
    agent:SetTeam("team" .. (agent:GetId() % 2 + 1));

    soldierUserData = {};

    if (agent:GetTeam() == "team1") then
        soldierUserData.soldier = Soldier_CreateSoldier(agent);
    else
        soldierUserData.soldier = 
            Soldier_CreateLightSoldier(agent);
    end
    
    ...
    
end

Even with a...