diff entities/action.py @ 158:04854cf6e1ac

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 79d6b17b80a3
children ee2d6835d87a
line wrap: on
line diff
--- a/entities/action.py	Sat Nov 12 16:27:39 2011 +0100
+++ b/entities/action.py	Sat Nov 12 20:54:25 2011 +0100
@@ -324,50 +324,30 @@
            @return: None"""
         player_char = self.model.game_state.\
                     getObjectById("PlayerCharacter").fifeagent
-        npc_coordinates = self.npc.fifeagent.behaviour.getLocation().\
-                        getLayerCoordinates()
-        pc_coordinates = player_char.behaviour.agent.\
-                            getLocation().getLayerCoordinates()
-        
-        distance_squared = (npc_coordinates.x - pc_coordinates.x) *\
-                           (npc_coordinates.x - pc_coordinates.x) +\
-                           (npc_coordinates.y - pc_coordinates.y) *\
-                           (npc_coordinates.y - pc_coordinates.y)
-        
-        # If we are too far away, we approach the NPC again
-        if distance_squared > 2:
-            player_char.behaviour.approach(
-                [npc_coordinates.x, npc_coordinates.y],
-                        TalkAction(self.controller, 
-                                   self.npc, 
-                                   self.commands
-                                   )
-            )        
+        player_char.behaviour.animate(
+            'stand', 
+            self.npc.fifeagent.behaviour.getLocation()
+        )
+
+        if self.npc.dialogue.dialogue is not None:
+            dialogue_controller = DialogueController(
+                self.controller.engine,
+                self.view,
+                self.model,
+                self.controller.application
+            )
+            self.controller.application.manager.push_mode(
+                dialogue_controller
+            )
+            dialogue_controller.startTalk(self.npc)
         else:
-            player_char.behaviour.agent.act(
-                'stand', 
-                self.npc.fifeagent.behaviour.getLocation()
-            )
-    
-            if self.npc.dialogue.dialogue is not None:
-                dialogue_controller = DialogueController(
-                    self.controller.engine,
-                    self.view,
-                    self.model,
-                    self.controller.application
-                )
-                self.controller.application.manager.push_mode(
-                    dialogue_controller
-                )
-                dialogue_controller.startTalk(self.npc)
-            else:
-                self.npc.fifeagent.behaviour.agent.say("Leave me alone!", 1000)
-                
-            self.model.game_state.getObjectById("PlayerCharacter").\
-                fifeagent.behaviour.idle()
-            self.model.game_state.getObjectById("PlayerCharacter").\
-                fifeagent.behaviour.nextAction = None
-            super(TalkAction, self).execute()
+            self.npc.fifeagent.behaviour.agent.say("Leave me alone!", 1000)
+            
+        self.model.game_state.getObjectById("PlayerCharacter").\
+            fifeagent.behaviour.idle()
+        self.model.game_state.getObjectById("PlayerCharacter").\
+            fifeagent.behaviour.nextAction = None
+        super(TalkAction, self).execute()
 
 class UseAction(Action):
     """Action for carryable items. It executes special commands that can be only