diff src/parpg/behaviours/moving.py @ 190:a22e92090018

The approach method of MovingAgentBehaviour now accepts a locatior or another instance, and uses the follow method to move to the instance position.
author KarstenBock@gmx.net
date Sat, 12 Nov 2011 20:54:25 +0100
parents ecac92680bef
children
line wrap: on
line diff
--- a/src/parpg/behaviours/moving.py	Sat Nov 12 16:27:39 2011 +0100
+++ b/src/parpg/behaviours/moving.py	Sat Nov 12 20:54:25 2011 +0100
@@ -30,26 +30,34 @@
         self.idle_counter = 1
 
 
-    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"""
+    def approach(self, location_or_agent, action=None):
+        """Approaches a location or another agent and then perform an action 
+        (if set).
+        @type loc: fife.Location
+        @param loc: the location or agent to approach
+        @type action: Action
+        @param action: The action to schedule for execution after the 
+        approach.
+        @return: None"""
+            
         self.state = base._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)        
+        if  isinstance(location_or_agent, fife.Instance):
+            agent = location_or_agent
+            self.agent.follow('run', agent, self.speed + 1)
+        else:
+            location = location_or_agent
+            boxLocation = tuple([int(float(i)) for i in location])
+            l = fife.Location(self.getLocation())
+            l.setLayerCoordinates(fife.ModelCoordinate(*boxLocation))
+            self.agent.move('run', l, self.speed + 1)        
         
     def onInstanceActionFinished(self, instance, action):
         """@type instance: ???
-           @param instance: ???
-           @type action: ???
-           @param action: ???
-           @return: None"""
+        @param instance: ???
+        @type action: ???
+        @param action: ???
+        @return: None"""
         BaseBehaviour.onInstanceActionFinished(self, instance, action)
             
         if(action.getId() != 'stand'):
@@ -64,9 +72,9 @@
         
     def run(self, location):
         """Makes the PC run to a certain location
-           @type location: fife.ScreenPoint
-           @param location: Screen position to run to.
-           @return: None"""
+        @type location: fife.ScreenPoint
+        @param location: Screen position to run to.
+        @return: None"""
         self.state = base._AGENT_STATE_RUN
         self.clear_animations()
         self.nextAction = None
@@ -74,9 +82,9 @@
 
     def walk(self, location):
         """Makes the PC walk to a certain location.
-           @type location: fife.ScreenPoint
-           @param location: Screen position to walk to.
-           @return: None"""
+        @type location: fife.ScreenPoint
+        @param location: Screen position to walk to.
+        @return: None"""
         self.state = base._AGENT_STATE_RUN
         self.clear_animations()
         self.nextAction = None