Mercurial > fife-parpg
annotate demos/rio_de_hola/scripts/agents/agent.py @ 499:3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
All demos and tools now use the new settings extension.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Fri, 14 May 2010 17:37:42 +0000 |
parents | 70697641fca3 |
children |
rev | line source |
---|---|
395
70697641fca3
Adding the correct FIFE header to rio_de_hola and pychan_demo files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
1 # -*- coding: utf-8 -*- |
70697641fca3
Adding the correct FIFE header to rio_de_hola and pychan_demo files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
2 |
70697641fca3
Adding the correct FIFE header to rio_de_hola and pychan_demo files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
3 # #################################################################### |
70697641fca3
Adding the correct FIFE header to rio_de_hola and pychan_demo files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
4 # Copyright (C) 2005-2009 by the FIFE team |
70697641fca3
Adding the correct FIFE header to rio_de_hola and pychan_demo files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
5 # http://www.fifengine.de |
70697641fca3
Adding the correct FIFE header to rio_de_hola and pychan_demo files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
6 # This file is part of FIFE. |
70697641fca3
Adding the correct FIFE header to rio_de_hola and pychan_demo files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
7 # |
70697641fca3
Adding the correct FIFE header to rio_de_hola and pychan_demo files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
8 # FIFE is free software; you can redistribute it and/or |
70697641fca3
Adding the correct FIFE header to rio_de_hola and pychan_demo files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
9 # modify it under the terms of the GNU Lesser General Public |
70697641fca3
Adding the correct FIFE header to rio_de_hola and pychan_demo files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
10 # License as published by the Free Software Foundation; either |
70697641fca3
Adding the correct FIFE header to rio_de_hola and pychan_demo files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
11 # version 2.1 of the License, or (at your option) any later version. |
70697641fca3
Adding the correct FIFE header to rio_de_hola and pychan_demo files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
12 # |
70697641fca3
Adding the correct FIFE header to rio_de_hola and pychan_demo files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
13 # This library is distributed in the hope that it will be useful, |
70697641fca3
Adding the correct FIFE header to rio_de_hola and pychan_demo files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
70697641fca3
Adding the correct FIFE header to rio_de_hola and pychan_demo files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
70697641fca3
Adding the correct FIFE header to rio_de_hola and pychan_demo files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
16 # Lesser General Public License for more details. |
70697641fca3
Adding the correct FIFE header to rio_de_hola and pychan_demo files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
17 # |
70697641fca3
Adding the correct FIFE header to rio_de_hola and pychan_demo files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
18 # You should have received a copy of the GNU Lesser General Public |
70697641fca3
Adding the correct FIFE header to rio_de_hola and pychan_demo files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
19 # License along with this library; if not, write to the |
70697641fca3
Adding the correct FIFE header to rio_de_hola and pychan_demo files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
20 # Free Software Foundation, Inc., |
70697641fca3
Adding the correct FIFE header to rio_de_hola and pychan_demo files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
70697641fca3
Adding the correct FIFE header to rio_de_hola and pychan_demo files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
22 # #################################################################### |
70697641fca3
Adding the correct FIFE header to rio_de_hola and pychan_demo files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
23 |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
24 from fife import fife |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
25 from scripts.common.common import ProgrammingError |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
26 |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
27 class Agent(fife.InstanceActionListener): |
499
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
395
diff
changeset
|
28 def __init__(self, settings, model, agentName, layer, uniqInMap=True): |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
29 fife.InstanceActionListener.__init__(self) |
499
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
395
diff
changeset
|
30 self.settings = settings |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
31 self.model = model |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
32 self.agentName = agentName |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
33 self.layer = layer |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
34 if uniqInMap: |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
35 self.agent = layer.getInstance(agentName) |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
36 self.agent.addActionListener(self) |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
37 |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
38 def onInstanceActionFinished(self, instance, action): |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
39 raise ProgrammingError('No OnActionFinished defined for Agent') |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
40 |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
41 def start(self): |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
42 raise ProgrammingError('No start defined for Agent') |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
43 |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
44 |
499
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
395
diff
changeset
|
45 def create_anonymous_agents(settings, model, objectName, layer, agentClass): |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
46 agents = [] |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
47 instances = [a for a in layer.getInstances() if a.getObject().getId() == objectName] |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
48 i = 0 |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
49 for a in instances: |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
50 agentName = '%s:i:%d' % (objectName, i) |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
51 i += 1 |
499
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
395
diff
changeset
|
52 agent = agentClass(settings, model, agentName, layer, False) |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
53 agent.agent = a |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
54 a.addActionListener(agent) |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
55 agents.append(agent) |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
56 return agents |