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