Mercurial > fife-parpg
comparison demos/rio_de_hola/scripts/agents/agent.py @ 378:64738befdf3b
bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
author | vtchill@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 11 Jan 2010 23:34:52 +0000 |
parents | |
children | 70697641fca3 |
comparison
equal
deleted
inserted
replaced
377:fe6fb0e0ed23 | 378:64738befdf3b |
---|---|
1 from fife 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 |