changeset 75:c3350fc9cd45

Added approach functionality to the BaseBehaviour
author KarstenBock@gmx.net
date Thu, 08 Sep 2011 14:20:31 +0200
parents 47e1345fbac2
children 4934b62e0e48
files src/parpg/behaviours/base.py src/parpg/behaviours/npc.py src/parpg/behaviours/player.py
diffstat 3 files changed, 34 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/parpg/behaviours/base.py	Wed Sep 07 14:48:08 2011 +0200
+++ b/src/parpg/behaviours/base.py	Thu Sep 08 14:20:31 2011 +0200
@@ -64,5 +64,35 @@
         self.state = _AGENT_STATE_IDLE
         self.agent.act('stand', self.agent.getFacingLocation())
 
+    def approach(self, location, action=None):
+        """Approaches a location and then perform an action (if set).
+           @type loc: fife.Location
+           @param loc: the location to approach
+           @type action: Action
+           @param action: The action to schedule for execution after the approach.
+           @return: None"""
+        self.state = _AGENT_STATE_APPROACH
+        self.nextAction = action
+        boxLocation = tuple([int(float(i)) for i in location])
+        l = fife.Location(self.agent.getLocation())
+        l.setLayerCoordinates(fife.ModelCoordinate(*boxLocation))
+        self.agent.move('run', l, self.speed + 1)        
+        
     def onInstanceActionFinished(self, instance, action):
-        pass
\ No newline at end of file
+        """@type instance: ???
+           @param instance: ???
+           @type action: ???
+           @param action: ???
+           @return: None"""
+        # First we reset the next behavior 
+        act = self.nextAction
+        self.nextAction = None 
+        self.idle()
+        
+        if act:
+            act.execute()
+            
+        if(action.getId() != 'stand'):
+            self.idle_counter = 1
+        else:
+            self.idle_counter += 1 
\ No newline at end of file
--- a/src/parpg/behaviours/npc.py	Wed Sep 07 14:48:08 2011 +0200
+++ b/src/parpg/behaviours/npc.py	Thu Sep 08 14:20:31 2011 +0200
@@ -66,14 +66,13 @@
         """What the NPC does when it has finished an action.
            Called by the engine and required for InstanceActionListeners.
            @type instance: fife.Instance
-           @param instance: self.agent (the NPC listener is listening for this
-                                        instance)
+           @param instance: self.agent
            @type action: ???
            @param action: ???
            @return: None"""
         if self.state == base._AGENT_STATE_WANDER:
             self.target_loc = self.getTargetLocation()
-        self.idle()
+        BaseBehaviour.onInstanceActionFinished(self, instance, action)
         
     
     def idle(self):
--- a/src/parpg/behaviours/player.py	Wed Sep 07 14:48:08 2011 +0200
+++ b/src/parpg/behaviours/player.py	Thu Sep 08 14:20:31 2011 +0200
@@ -23,23 +23,4 @@
         self.idle_counter = 1
         self.speed = 0
         self.nextAction = None
-        self.agent = None
-        
-    def onInstanceActionFinished(self, instance, action):
-        """@type instance: ???
-           @param instance: ???
-           @type action: ???
-           @param action: ???
-           @return: None"""
-        # First we reset the next behavior 
-        act = self.nextAction
-        self.nextAction = None 
-        self.idle()
-        
-        if act:
-            act.execute()
-            
-        if(action.getId() != 'stand'):
-            self.idle_counter = 1
-        else:
-            self.idle_counter += 1  
\ No newline at end of file
+        self.agent = None
\ No newline at end of file