Skip to content

Commit

Permalink
Agent info channel
Browse files Browse the repository at this point in the history
New channel to be able to get information from other agents. Currently this is limited to getting tags from other agents.
  • Loading branch information
Peter-Noble committed Jan 29, 2017
1 parent ae88107 commit e5cba46
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
9 changes: 8 additions & 1 deletion cm_bpyNodes.py
Expand Up @@ -166,7 +166,8 @@ class NewInputNode(LogicNode):
("PATH", "Path", "", 6),
("SOUND", "Sound", "", 7),
("STATE", "State", "", 8),
("WORLD", "World", "", 9)])
("WORLD", "World", "", 9),
("AGENTINFO", "AgentInfo", "", 10)])

Constant = FloatProperty(name="Constant")

Expand Down Expand Up @@ -230,6 +231,8 @@ class NewInputNode(LogicNode):
("RX", "rx", "", 2),
("ARRIVED", "Arrived", "", 3)])

GetTagName = StringProperty(name="Get Tag Name")

def draw_buttons(self, context, layout):
layout.prop(self, "InputSource", text="Input")
if self.InputSource == "CONSTANT":
Expand Down Expand Up @@ -265,6 +268,8 @@ def draw_buttons(self, context, layout):
layout.prop_search(self, "TargetObject", context.scene, "objects")
if self.TargetObject != "":
layout.prop(self, "TargetOptions")
elif self.InputSource == "AGENTINFO":
layout.prop(self, "GetTagName")

def getSettings(self, node):
node.settings["InputSource"] = self.InputSource
Expand Down Expand Up @@ -300,6 +305,8 @@ def getSettings(self, node):
node.settings["TargetObject"] = self.TargetObject
if self.TargetObject != "":
node.settings["TargetOptions"] = self.TargetOptions
elif self.InputSource == "AGENTINFO":
node.settings["GetTagName"] = self.GetTagName


def update_properties(self, context):
Expand Down
1 change: 1 addition & 0 deletions cm_channels/__init__.py
Expand Up @@ -25,6 +25,7 @@
from .cm_groundChannels import Ground
from .cm_formationChannels import Formation
from .cm_pathChannels import Path
from .cm_agentInfoChannels import AgentInfo

from .cm_masterChannels import channelTimes, timeChannel

Expand Down
37 changes: 37 additions & 0 deletions cm_channels/cm_agentInfoChannels.py
@@ -0,0 +1,37 @@
# Copyright 2016 CrowdMaster Developer Team
#
# ##### BEGIN GPL LICENSE BLOCK ######
# This file is part of CrowdMaster.
#
# CrowdMaster is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# CrowdMaster is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with CrowdMaster. If not, see <http://www.gnu.org/licenses/>.
# ##### END GPL LICENSE BLOCK #####

from .cm_masterChannels import MasterChannel as Mc
from .cm_masterChannels import timeChannel


class AgentInfo(Mc):
"""Used to get information about other agent in a scene"""

@timeChannel("AgentInfo")
def getTag(self, inputs, tag):
"""For each agent in the input look up their tag"""
result = {}
for into in inputs:
for i in into:
if i in self.sim.agents:
agentTags = self.sim.agents[i].access["tags"]
if tag in agentTags:
result[i] = agentTags[tag]
return result
5 changes: 5 additions & 0 deletions cm_nodeFunctions.py
Expand Up @@ -198,6 +198,11 @@ def core(self, inps, settings):
elif settings["WorldOptions"] == "TIME":
return {"None": channels["World"].time}

elif settings["InputSource"] == "AGENTINFO":
agent = channels["AgentInfo"]
if settings["GetTagName"].strip() != "":
return agent.getTag(inps, settings["GetTagName"].strip())


class LogicGRAPH(Neuron):
"""Return value 0 to 1 mapping from graph"""
Expand Down
4 changes: 3 additions & 1 deletion cm_simulate.py
Expand Up @@ -44,6 +44,7 @@ def __init__(self):
Flock = chan.Flock(self)
Ground = chan.Ground(self)
Formation = chan.Formation(self)
AgentInfo = chan.AgentInfo(self)
Path = chan.Path(self)
self.lvars = {"Noise": Noise,
"Sound": Sound,
Expand All @@ -52,7 +53,8 @@ def __init__(self):
"Flock": Flock,
"Ground": Ground,
"Formation": Formation,
"Path": Path}
"Path": Path,
"AgentInfo": AgentInfo}
if preferences.show_debug_options:
self.totalTime = 0
self.totalFrames = 0
Expand Down

0 comments on commit e5cba46

Please sign in to comment.