annotate behaviours/moving.py @ 132:e2ccd64f3a86

Split code off from createInventoryItems to createItemByID and createItemByType. Entities with a containable component will now get the "item_type" field set to the Template, if that field is not present.
author KarstenBock@gmx.net
date Sat, 08 Oct 2011 14:18:16 +0200
parents 57f1cff9a75d
children 04854cf6e1ac
rev   line source
103
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
1 # This file is part of PARPG.
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
2
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
3 # PARPG is free software: you can redistribute it and/or modify
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
4 # it under the terms of the GNU General Public License as published by
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
5 # the Free Software Foundation, either version 3 of the License, or
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
6 # (at your option) any later version.
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
7
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
8 # PARPG is distributed in the hope that it will be useful,
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
11 # GNU General Public License for more details.
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
12
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
13 # You should have received a copy of the GNU General Public License
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
14 # along with PARPG. If not, see <http://www.gnu.org/licenses/>.
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
15
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
16 from fife import fife
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
17 import base
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
18 from base import BaseBehaviour
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
19
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
20 class MovingAgentBehaviour (BaseBehaviour):
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
21 """Fife agent listener"""
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
22 def __init__(self):
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
23 BaseBehaviour.__init__(self)
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
24 self.speed = 0
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
25 self.idle_counter = 1
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
26
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
27 def onNewMap(self, layer):
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
28 """Sets the agent onto the new layer."""
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
29 BaseBehaviour.onNewMap(self, layer)
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
30 self.idle_counter = 1
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
31
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
32
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
33 def approach(self, location, action=None):
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
34 """Approaches a location and then perform an action (if set).
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
35 @type loc: fife.Location
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
36 @param loc: the location to approach
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
37 @type action: Action
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
38 @param action: The action to schedule for execution after the approach.
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
39 @return: None"""
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
40 self.state = base._AGENT_STATE_APPROACH
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
41 self.nextAction = action
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
42 boxLocation = tuple([int(float(i)) for i in location])
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
43 l = fife.Location(self.agent.getLocation())
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
44 l.setLayerCoordinates(fife.ModelCoordinate(*boxLocation))
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
45 self.agent.move('run', l, self.speed + 1)
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
46
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
47 def onInstanceActionFinished(self, instance, action):
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
48 """@type instance: ???
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
49 @param instance: ???
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
50 @type action: ???
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
51 @param action: ???
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
52 @return: None"""
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
53 BaseBehaviour.onInstanceActionFinished(self, instance, action)
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
54
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
55 if(action.getId() != 'stand'):
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
56 self.idle_counter = 1
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
57 else:
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
58 self.idle_counter += 1
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
59
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
60 def idle(self):
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
61 """@return: None"""
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
62 BaseBehaviour.idle(self)
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
63 self.animate('stand')
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
64
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
65 def run(self, location):
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
66 """Makes the PC run to a certain location
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
67 @type location: fife.ScreenPoint
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
68 @param location: Screen position to run to.
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
69 @return: None"""
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
70 self.state = base._AGENT_STATE_RUN
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
71 self.clear_animations()
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
72 self.nextAction = None
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
73 self.agent.move('run', location, self.speed + 1)
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
74
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
75 def walk(self, location):
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
76 """Makes the PC walk to a certain location.
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
77 @type location: fife.ScreenPoint
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
78 @param location: Screen position to walk to.
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
79 @return: None"""
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
80 self.state = base._AGENT_STATE_RUN
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
81 self.clear_animations()
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
82 self.nextAction = None
57f1cff9a75d Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents: 61
diff changeset
83 self.agent.move('walk', location, self.speed - 1)
55
8b1ad2d342d8 Renamed BaseBehaviour to MovingAgentBehaviour
KarstenBock@gmx.net
parents:
diff changeset
84