|  | @@ -1,10 +1,8 @@
 | 
	
		
			
			| 1 | 1 |  from synergine.synergy.event.Action import Action
 | 
	
		
			
			| 2 | 2 |  from intelligine.synergy.event.move.MoveEvent import MoveEvent
 | 
	
		
			
			| 3 |  | -from random import randint, choice, randrange
 | 
	
		
			
			| 4 | 3 |  from synergine.synergy.event.exception.ActionAborted import ActionAborted
 | 
	
		
			
			| 5 | 4 |  from xyzworld.cst import POSITION
 | 
	
		
			
			| 6 |  | -from intelligine.cst import PREVIOUS_DIRECTION, BLOCKED_SINCE
 | 
	
		
			
			| 7 |  | -from intelligine.synergy.event.move.direction import directions_same_level, directions_slighty
 | 
	
		
			
			|  | 5 | +from intelligine.cst import PREVIOUS_DIRECTION, BLOCKED_SINCE, BRAIN_PART_MOVE, BRAIN_SCHEMA
 | 
	
		
			
			| 8 | 6 |  from intelligine.synergy.event.move.direction import get_position_with_direction_decal
 | 
	
		
			
			| 9 | 7 |  
 | 
	
		
			
			| 10 | 8 |  
 | 
	
	
		
			
			|  | @@ -19,11 +17,13 @@ class MoveAction(Action):
 | 
	
		
			
			| 19 | 17 |  
 | 
	
		
			
			| 20 | 18 |      def prepare(self, context):
 | 
	
		
			
			| 21 | 19 |          object_point = context.metas.value.get(POSITION, self._object_id)
 | 
	
		
			
			| 22 |  | -        direction = self._get_prepared_direction(context, object_point)
 | 
	
		
			
			|  | 20 | +        direction = self._get_prepared_direction(context)
 | 
	
		
			
			| 23 | 21 |          self._set_prepared_direction(context, object_point, direction)
 | 
	
		
			
			| 24 | 22 |  
 | 
	
		
			
			| 25 |  | -    def _get_prepared_direction(self, context, object_point):
 | 
	
		
			
			| 26 |  | -        return self._get_random_direction(context)
 | 
	
		
			
			|  | 23 | +    def _get_prepared_direction(self, context):
 | 
	
		
			
			|  | 24 | +        object_brain_schema = context.metas.value.get(BRAIN_SCHEMA, self._object_id)
 | 
	
		
			
			|  | 25 | +        object_move_brain_part = object_brain_schema[BRAIN_PART_MOVE]
 | 
	
		
			
			|  | 26 | +        return object_move_brain_part.get_direction(context, self._object_id)
 | 
	
		
			
			| 27 | 27 |  
 | 
	
		
			
			| 28 | 28 |      def _set_prepared_direction(self, context, object_point, direction):
 | 
	
		
			
			| 29 | 29 |          move_to_point = get_position_with_direction_decal(direction, object_point)
 | 
	
	
		
			
			|  | @@ -34,32 +34,6 @@ class MoveAction(Action):
 | 
	
		
			
			| 34 | 34 |              # TODO: mettre self._dont_move = True ?
 | 
	
		
			
			| 35 | 35 |              pass
 | 
	
		
			
			| 36 | 36 |  
 | 
	
		
			
			| 37 |  | -    def _get_random_direction(self, context):
 | 
	
		
			
			| 38 |  | -        try:
 | 
	
		
			
			| 39 |  | -            blocked_since = context.metas.value.get(BLOCKED_SINCE, self._object_id)
 | 
	
		
			
			| 40 |  | -        except KeyError:
 | 
	
		
			
			| 41 |  | -            blocked_since = 0
 | 
	
		
			
			| 42 |  | -        direction_name = None
 | 
	
		
			
			| 43 |  | -        if blocked_since <= 3:  #TODO: config
 | 
	
		
			
			| 44 |  | -            try:
 | 
	
		
			
			| 45 |  | -                previous_direction = context.metas.value.get(PREVIOUS_DIRECTION, self._object_id)
 | 
	
		
			
			| 46 |  | -                # TODO: Faut mettre ca en plus propre (proba d'aller tou droit, config, etc)
 | 
	
		
			
			| 47 |  | -                if randrange(100) < 75:  # 75% de change d'aller tout droit
 | 
	
		
			
			| 48 |  | -                    # Dans le futur: les fourmis vont moins tout droit quand elle se croient et se touche
 | 
	
		
			
			| 49 |  | -                    return previous_direction
 | 
	
		
			
			| 50 |  | -
 | 
	
		
			
			| 51 |  | -                directions_list = directions_slighty[previous_direction]
 | 
	
		
			
			| 52 |  | -                # TODO: TMP tant que 1 niveau (z)
 | 
	
		
			
			| 53 |  | -                directions_list = [direction for direction in directions_list if direction > 9 and direction < 19]
 | 
	
		
			
			| 54 |  | -                direction_name = choice(directions_list)
 | 
	
		
			
			| 55 |  | -            except KeyError:
 | 
	
		
			
			| 56 |  | -                pass
 | 
	
		
			
			| 57 |  | -
 | 
	
		
			
			| 58 |  | -        if not direction_name:
 | 
	
		
			
			| 59 |  | -            direction_name = randint(directions_same_level[0], directions_same_level[1])
 | 
	
		
			
			| 60 |  | -
 | 
	
		
			
			| 61 |  | -        return direction_name
 | 
	
		
			
			| 62 |  | -
 | 
	
		
			
			| 63 | 37 |      @staticmethod
 | 
	
		
			
			| 64 | 38 |      def _direction_point_is_possible(context, direction_point):
 | 
	
		
			
			| 65 | 39 |          return context.position_is_penetrable(direction_point)
 | 
	
	
		
			
			|  | @@ -77,5 +51,8 @@ class MoveAction(Action):
 | 
	
		
			
			| 77 | 51 |              raise ActionAborted()
 | 
	
		
			
			| 78 | 52 |  
 | 
	
		
			
			| 79 | 53 |          obj.set_position(self._move_to_point)
 | 
	
		
			
			|  | 54 | +        obj.get_brain().get_part(BRAIN_PART_MOVE).done(obj, context)
 | 
	
		
			
			|  | 55 | +
 | 
	
		
			
			|  | 56 | +        # TODO: Ces metas update dans ant ?
 | 
	
		
			
			| 80 | 57 |          context.metas.value.set(PREVIOUS_DIRECTION, self._object_id, self._move_to_direction)
 | 
	
		
			
			| 81 |  | -        context.metas.value.set(BLOCKED_SINCE, self._object_id, 0)
 | 
	
		
			
			|  | 58 | +        context.metas.value.set(BLOCKED_SINCE, self._object_id, 0)
 |