comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:4a0efb7baf70
1 import common, fife
2
3 class Agent(fife.InstanceActionListener):
4 def __init__(self, model, agentName, layer, uniqInMap=True):
5 fife.InstanceActionListener.__init__(self)
6 self.model = model
7 self.agentName = agentName
8 self.layer = layer
9 if uniqInMap:
10 self.agent = layer.getInstance(agentName)
11 self.agent.addActionListener(self)
12
13 def onInstanceActionFinished(self, instance, action):
14 raise ProgrammingError('No OnActionFinished defined for Agent')
15
16 def start(self):
17 raise ProgrammingError('No start defined for Agent')
18
19
20 def create_anonymous_agents(model, objectName, layer, agentClass):
21 agents = []
22 instances = [a for a in layer.getInstances() if a.getObject().getId() == objectName]
23 i = 0
24 for a in instances:
25 agentName = '%s:i:%d' % (objectName, i)
26 i += 1
27 agent = agentClass(model, agentName, layer, False)
28 agent.agent = a
29 a.addActionListener(agent)
30 agents.append(agent)
31 return agents