Mercurial > parpg-core
annotate src/parpg/behaviours/base.py @ 116:9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
Added General Entity.
author | KarstenBock@gmx.net |
---|---|
date | Sat, 24 Sep 2011 15:48:24 +0200 |
parents | d89e88a90c9e |
children | ecac92680bef |
rev | line source |
---|---|
116
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
1 # This file is part of PARPG. |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
2 |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
3 # PARPG is free software: you can redistribute it and/or modify |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
4 # it under the terms of the GNU General Public License as published by |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
5 # the Free Software Foundation, either version 3 of the License, or |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
6 # (at your option) any later version. |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
7 |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
8 # PARPG is distributed in the hope that it will be useful, |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
11 # GNU General Public License for more details. |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
12 |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
13 # You should have received a copy of the GNU General Public License |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
14 # along with PARPG. If not, see <http://www.gnu.org/licenses/>. |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
15 |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
16 from fife import fife |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
17 |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
18 _AGENT_STATE_NONE, _AGENT_STATE_IDLE, _AGENT_STATE_APPROACH, _AGENT_STATE_RUN, _AGENT_STATE_WANDER, _AGENT_STATE_TALK = xrange(6) |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
19 |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
20 class BaseBehaviour (fife.InstanceActionListener): |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
21 """Fife agent listener""" |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
22 def __init__(self): |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
23 fife.InstanceActionListener.__init__(self) |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
24 self.agent = None |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
25 self.state = None |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
26 |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
27 def attachToLayer(self, agent_ID, layer): |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
28 """Attaches to a certain layer |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
29 @type agent_ID: String |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
30 @param agent_ID: ID of the layer to attach to. |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
31 @type layer: Fife layer |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
32 @param layer: Layer of the agent to attach the behaviour to |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
33 @return: None""" |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
34 self.agent = layer.getInstance(agent_ID) |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
35 self.agent.addActionListener(self) |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
36 self.state = _AGENT_STATE_NONE |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
37 |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
38 def getX(self): |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
39 """Get the NPC's x position on the map. |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
40 @rtype: integer" |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
41 @return: the x coordinate of the NPC's location""" |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
42 return self.agent.getLocation().getLayerCoordinates().x |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
43 |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
44 def getY(self): |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
45 """Get the NPC's y position on the map. |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
46 @rtype: integer |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
47 @return: the y coordinate of the NPC's location""" |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
48 return self.agent.getLocation().getLayerCoordinates().y |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
49 |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
50 def onNewMap(self, layer): |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
51 """Sets the agent onto the new layer.""" |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
52 if self.agent is not None: |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
53 self.agent.removeActionListener(self) |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
54 |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
55 self.agent = layer.getInstance(self.parent.general.identifier) |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
56 self.agent.addActionListener(self) |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
57 self.state = _AGENT_STATE_NONE |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
58 |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
59 def idle(self): |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
60 """@return: None""" |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
61 self.state = _AGENT_STATE_IDLE |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
62 |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
63 def onInstanceActionFinished(self, instance, action): |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
64 """@type instance: ??? |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
65 @param instance: ??? |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
66 @type action: ??? |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
67 @param action: ??? |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
68 @return: None""" |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
69 # First we reset the next behavior |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
70 act = self.nextAction |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
71 self.nextAction = None |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
72 self.idle() |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
73 |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
74 if act: |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
75 act.execute() |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
76 |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
77 |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
78 def getLocation(self): |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
79 """Get the agents position as a fife.Location object. |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
80 @rtype: fife.Location |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
81 @return: the location of the agent""" |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
82 return self.agent.getLocation() |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
83 |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
84 |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
85 def talk(self, pc): |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
86 """Makes the agent ready to talk to the PC |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
87 @return: None""" |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
88 self.state = _AGENT_STATE_TALK |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
89 self.pc = pc.behaviour.agent |
9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
88
diff
changeset
|
90 self.idle() |
79
62cff91a19cb
Modifications to make the player agent move around by clicking with the mouse.
KarstenBock@gmx.net
parents:
77
diff
changeset
|
91 |