From e5cba468efa2748765f521f25fbc579e49af9150 Mon Sep 17 00:00:00 2001 From: Peter-Noble Date: Fri, 20 Jan 2017 12:44:32 +0000 Subject: [PATCH] Agent info channel New channel to be able to get information from other agents. Currently this is limited to getting tags from other agents. --- cm_bpyNodes.py | 9 ++++++- cm_channels/__init__.py | 1 + cm_channels/cm_agentInfoChannels.py | 37 +++++++++++++++++++++++++++++ cm_nodeFunctions.py | 5 ++++ cm_simulate.py | 4 +++- 5 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 cm_channels/cm_agentInfoChannels.py diff --git a/cm_bpyNodes.py b/cm_bpyNodes.py index 3538877..b7f12da 100644 --- a/cm_bpyNodes.py +++ b/cm_bpyNodes.py @@ -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") @@ -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": @@ -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 @@ -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): diff --git a/cm_channels/__init__.py b/cm_channels/__init__.py index ac507ed..e9e8f72 100644 --- a/cm_channels/__init__.py +++ b/cm_channels/__init__.py @@ -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 diff --git a/cm_channels/cm_agentInfoChannels.py b/cm_channels/cm_agentInfoChannels.py new file mode 100644 index 0000000..98fc8f4 --- /dev/null +++ b/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 . +# ##### 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 diff --git a/cm_nodeFunctions.py b/cm_nodeFunctions.py index e5d6f35..a71dde0 100644 --- a/cm_nodeFunctions.py +++ b/cm_nodeFunctions.py @@ -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""" diff --git a/cm_simulate.py b/cm_simulate.py index 2403d39..61f1470 100644 --- a/cm_simulate.py +++ b/cm_simulate.py @@ -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, @@ -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