Mercurial > fife-parpg
diff clients/rio_de_hola/scripts/agent.py @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/clients/rio_de_hola/scripts/agent.py Sun Jun 29 18:44:17 2008 +0000 @@ -0,0 +1,31 @@ +import common, fife + +class Agent(fife.InstanceActionListener): + def __init__(self, model, agentName, layer, uniqInMap=True): + fife.InstanceActionListener.__init__(self) + self.model = model + self.agentName = agentName + self.layer = layer + if uniqInMap: + self.agent = layer.getInstance(agentName) + self.agent.addActionListener(self) + + def onInstanceActionFinished(self, instance, action): + raise ProgrammingError('No OnActionFinished defined for Agent') + + def start(self): + raise ProgrammingError('No start defined for Agent') + + +def create_anonymous_agents(model, objectName, layer, agentClass): + agents = [] + instances = [a for a in layer.getInstances() if a.getObject().getId() == objectName] + i = 0 + for a in instances: + agentName = '%s:i:%d' % (objectName, i) + i += 1 + agent = agentClass(model, agentName, layer, False) + agent.agent = a + a.addActionListener(agent) + agents.append(agent) + return agents