Mercurial > parpg-core
comparison src/parpg/behaviours/base.py @ 83:9f8faf6e974d
Added BaseBehaviour. Moved methods from MovingAgentBehaviour to BaseBehaviour.
author | KarstenBock@gmx.net |
---|---|
date | Fri, 09 Sep 2011 15:18:17 +0200 |
parents | 62cff91a19cb |
children | d89e88a90c9e |
comparison
equal
deleted
inserted
replaced
82:7cb53edfb95f | 83:9f8faf6e974d |
---|---|
21 """Fife agent listener""" | 21 """Fife agent listener""" |
22 def __init__(self): | 22 def __init__(self): |
23 fife.InstanceActionListener.__init__(self) | 23 fife.InstanceActionListener.__init__(self) |
24 self.agent = None | 24 self.agent = None |
25 self.state = None | 25 self.state = None |
26 self.speed = 0 | |
27 self.idle_counter = 1 | |
28 | 26 |
29 def attachToLayer(self, agent_ID, layer): | 27 def attachToLayer(self, agent_ID, layer): |
30 """Attaches to a certain layer | 28 """Attaches to a certain layer |
31 @type agent_ID: String | 29 @type agent_ID: String |
32 @param agent_ID: ID of the layer to attach to. | 30 @param agent_ID: ID of the layer to attach to. |
55 self.agent.removeActionListener(self) | 53 self.agent.removeActionListener(self) |
56 | 54 |
57 self.agent = layer.getInstance(self.parent.fifeagent.identifier) | 55 self.agent = layer.getInstance(self.parent.fifeagent.identifier) |
58 self.agent.addActionListener(self) | 56 self.agent.addActionListener(self) |
59 self.state = _AGENT_STATE_NONE | 57 self.state = _AGENT_STATE_NONE |
60 self.idle_counter = 1 | |
61 | 58 |
62 def idle(self): | 59 def idle(self): |
63 """@return: None""" | 60 """@return: None""" |
64 self.state = _AGENT_STATE_IDLE | 61 self.state = _AGENT_STATE_IDLE |
65 self.agent.act('stand', self.agent.getFacingLocation()) | 62 self.agent.act('stand', self.agent.getFacingLocation()) |
66 | |
67 def approach(self, location, action=None): | |
68 """Approaches a location and then perform an action (if set). | |
69 @type loc: fife.Location | |
70 @param loc: the location to approach | |
71 @type action: Action | |
72 @param action: The action to schedule for execution after the approach. | |
73 @return: None""" | |
74 self.state = _AGENT_STATE_APPROACH | |
75 self.nextAction = action | |
76 boxLocation = tuple([int(float(i)) for i in location]) | |
77 l = fife.Location(self.agent.getLocation()) | |
78 l.setLayerCoordinates(fife.ModelCoordinate(*boxLocation)) | |
79 self.agent.move('run', l, self.speed + 1) | |
80 | 63 |
81 def onInstanceActionFinished(self, instance, action): | 64 def onInstanceActionFinished(self, instance, action): |
82 """@type instance: ??? | 65 """@type instance: ??? |
83 @param instance: ??? | 66 @param instance: ??? |
84 @type action: ??? | 67 @type action: ??? |
89 self.nextAction = None | 72 self.nextAction = None |
90 self.idle() | 73 self.idle() |
91 | 74 |
92 if act: | 75 if act: |
93 act.execute() | 76 act.execute() |
94 | 77 |
95 if(action.getId() != 'stand'): | |
96 self.idle_counter = 1 | |
97 else: | |
98 self.idle_counter += 1 | |
99 | 78 |
100 def getLocation(self): | 79 def getLocation(self): |
101 """Get the agents position as a fife.Location object. | 80 """Get the agents position as a fife.Location object. |
102 @rtype: fife.Location | 81 @rtype: fife.Location |
103 @return: the location of the agent""" | 82 @return: the location of the agent""" |
109 @return: None""" | 88 @return: None""" |
110 self.state = _AGENT_STATE_TALK | 89 self.state = _AGENT_STATE_TALK |
111 self.pc = pc.behaviour.agent | 90 self.pc = pc.behaviour.agent |
112 self.idle() | 91 self.idle() |
113 | 92 |
114 def run(self, location): | |
115 """Makes the PC run to a certain location | |
116 @type location: fife.ScreenPoint | |
117 @param location: Screen position to run to. | |
118 @return: None""" | |
119 self.state = _AGENT_STATE_RUN | |
120 self.nextAction = None | |
121 self.agent.move('run', location, self.speed + 1) | |
122 | |
123 def walk(self, location): | |
124 """Makes the PC walk to a certain location. | |
125 @type location: fife.ScreenPoint | |
126 @param location: Screen position to walk to. | |
127 @return: None""" | |
128 self.state = _AGENT_STATE_RUN | |
129 self.nextAction = None | |
130 self.agent.move('walk', location, self.speed - 1) | |
131 |