comparison clients/rio_de_hola/scripts/agents/agent.py @ 98:214e3eb81eb2

better structure for techdemo scripts + svn:ignore fixes
author jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 21 Jul 2008 13:46:15 +0000
parents clients/rio_de_hola/scripts/agent.py@4a0efb7baf70
children 9a1529f9625e
comparison
equal deleted inserted replaced
97:346738d09188 98:214e3eb81eb2
1 import fife
2 from scripts.common.common import ProgrammingError
3
4 class Agent(fife.InstanceActionListener):
5 def __init__(self, model, agentName, layer, uniqInMap=True):
6 fife.InstanceActionListener.__init__(self)
7 self.model = model
8 self.agentName = agentName
9 self.layer = layer
10 if uniqInMap:
11 self.agent = layer.getInstance(agentName)
12 self.agent.addActionListener(self)
13
14 def onInstanceActionFinished(self, instance, action):
15 raise ProgrammingError('No OnActionFinished defined for Agent')
16
17 def start(self):
18 raise ProgrammingError('No start defined for Agent')
19
20
21 def create_anonymous_agents(model, objectName, layer, agentClass):
22 agents = []
23 instances = [a for a in layer.getInstances() if a.getObject().getId() == objectName]
24 i = 0
25 for a in instances:
26 agentName = '%s:i:%d' % (objectName, i)
27 i += 1
28 agent = agentClass(model, agentName, layer, False)
29 agent.agent = a
30 a.addActionListener(agent)
31 agents.append(agent)
32 return agents