Game Development Reference
In-Depth Information
Handling new agent sightings
As visibility can be updated very often, we only want to send out events for new agent
sightings. We can create a helper function that will take a list of known agents indexed by
their agent ID numbers and a list of currently visible agents. By storing the lastSeen
time of a sighting, we can determine whether an event should be sent out.
Throttling events in this fashion prevents an abundance of redundant events from being
propagated. As events are sent to every registered object, this can have an impact on per-
formance when massive amounts of events are being sent:
AgentSenses.lua :
local function HandleNewAgentSightings(
userData, knownAgents, spottedAgents)
local newAgentSightings = {};
for key, value in pairs(spottedAgents) do
local agentId = value.agent:GetId();
local lastSeen =
value.lastSeen - knownAgents[agentId].lastSeen;
if (knownAgents[agentId] == nil or lastSeen > 500)
then
newAgentSightings[agentId] = value;
end
end
local sandbox = userData.agent:GetSandbox();
for key, value in pairs(newAgentSightings) do
if (userData.agent:GetTeam() ~=
value.agent:GetTeam()) then
if (value.agent:GetHealth() > 0) then
SendNewEnemyEvent(
sandbox, userData.agent,
Search WWH ::




Custom Search