Game Development Reference
In-Depth Information
Creating event handlers
Now that agents on the same team are sending out sight events, we need to start processing
them so that agents will share the same information. When a new enemy is sighted, we can
update the blackboard and overwrite any stale information we already have about known
enemies:
AgentSenses.lua
:
local function HandleEnemySightedEvent(
userData, eventType, event)
local blackboard = userData.blackboard;
local knownAgents =
userData.blackboard:Get("visibleAgents") or {};
knownAgents[event.agent:GetId()] = event;
userData.blackboard:Set("visibleAgents", knownAgents);
end
If a dead body is found, we'll erase the current information from the
visibleAgents
blackboard entry so that
visibleAgents
will only contain known living enemies, and
any known dead enemies are added to the
deadEnemies
blackboard entry:
AgentSenses.lua
:
local function HandleDeadEnemySightedEvent(
userData, eventType, event)
local blackboard = userData.blackboard;
local knownAgents =
userData.blackboard:Get("visibleAgents") or {};
local knownBodies =
userData.blackboard:Get("deadEnemies") or {};
knownAgents[event.agent:GetId()] = nil;
knownBodies[event.agent:GetId()] = event;
userData.blackboard:Set("visibleAgents", knownAgents);