changeset 48:1bdadb768bcf

Added approach functionality to the BaseBehaviour
author KarstenBock@gmx.net
date Thu, 08 Sep 2011 14:20:31 +0200
parents dd9bd93ec81c
children 4f9747116061
files behaviours/base.py behaviours/npc.py behaviours/player.py
diffstat 3 files changed, 34 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/behaviours/base.py	Wed Sep 07 14:48:08 2011 +0200
+++ b/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/behaviours/npc.py	Wed Sep 07 14:48:08 2011 +0200
+++ b/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/behaviours/player.py	Wed Sep 07 14:48:08 2011 +0200
+++ b/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