|
@@ -0,0 +1,79 @@
|
|
1
|
+from synergine.synergy.event.Action import Action
|
|
2
|
+from intelligine.synergy.event.pheromone.PheromoneEvent import PheromoneEvent
|
|
3
|
+from xyzworld.cst import POSITION
|
|
4
|
+from intelligine.cst import PHEROMON_DIRECTION, PHEROMON_DIR_EXPLO, PHEROMON_POSITIONS
|
|
5
|
+from xyzworld.geometry import get_direction_degrees, get_degree_from_north
|
|
6
|
+from intelligine.synergy.event.move.direction import get_direction_for_degrees, get_direction_opposite
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+class ApposeDirection(Action):
|
|
10
|
+
|
|
11
|
+ _listen = PheromoneEvent
|
|
12
|
+
|
|
13
|
+ def prepare(self, context):
|
|
14
|
+ """
|
|
15
|
+ Recupere chaque coordonnees de points qui doivent etre update
|
|
16
|
+ pour ne pas avoir a e calculer dans le run
|
|
17
|
+ :param context:
|
|
18
|
+ :return:
|
|
19
|
+ """
|
|
20
|
+ object_point = context.metas.value.get(POSITION, self._object_id)
|
|
21
|
+ distance = 1 # TODO: Config ?
|
|
22
|
+ self._parameters['concerned_points'] = context.get_arround_points_of(object_point, distance)
|
|
23
|
+
|
|
24
|
+ def run(self, obj, context, synergy_manager):
|
|
25
|
+ """
|
|
26
|
+ On effectue l'incrementation dans le process principal. Beaucoups plus lourd que de le faie dans les
|
|
27
|
+ process. Mais si on le fait dans les process on va rater des infos ...
|
|
28
|
+ met a jour les pts (incremente)
|
|
29
|
+ :param obj:
|
|
30
|
+ :param context:
|
|
31
|
+ :param synergy_manager:
|
|
32
|
+ :return:
|
|
33
|
+ """
|
|
34
|
+ # TODO: Remonter ca dans une objet
|
|
35
|
+
|
|
36
|
+ # a = get_direction_degrees((0, 0, 0), (0, -1, -1)) # 315
|
|
37
|
+ # a = get_direction_degrees((0, 0, 0), (0, 0, -1)) # 0
|
|
38
|
+ # a = get_direction_degrees((0, 0, 0), (0, 1, -1)) # 45
|
|
39
|
+ # a = get_direction_degrees((0, 0, 0), (0, -1, 0)) # 270
|
|
40
|
+ # a = get_direction_degrees((0, 0, 0), (0, 1, 0)) # 90
|
|
41
|
+ # a = get_direction_degrees((0, 0, 0), (0, -1, 1)) # 225
|
|
42
|
+ # a = get_direction_degrees((0, 0, 0), (0, 0, 1)) # 180
|
|
43
|
+ # a = get_direction_degrees((0, 0, 0), (0, 1, 1)) # 135
|
|
44
|
+
|
|
45
|
+ # a = get_degree_from_north((0, 0, 0), (0, -1, -1)) # 315
|
|
46
|
+ # a = get_degree_from_north((0, 0, 0), (0, 0, -1)) # 0
|
|
47
|
+ # a = get_degree_from_north((0, 0, 0), (0, 1, -1)) # 45
|
|
48
|
+ # a = get_degree_from_north((0, 0, 0), (0, -1, 0)) # 270
|
|
49
|
+ # a = get_degree_from_north((0, 0, 0), (0, 1, 0)) # 90
|
|
50
|
+ # a = get_degree_from_north((0, 0, 0), (0, -1, 1)) # 225
|
|
51
|
+ # a = get_degree_from_north((0, 0, 0), (0, 0, 1)) # 180
|
|
52
|
+ # a = get_degree_from_north((0, 0, 0), (0, 1, 1)) # 135
|
|
53
|
+ self._appose_pheromones(obj, context, synergy_manager)
|
|
54
|
+
|
|
55
|
+ def _appose_pheromones(self, obj, context, synergy_manager):
|
|
56
|
+ obj_position = obj.get_position()
|
|
57
|
+ obj_last_pheromon_position = obj.get_last_pheromone_point(PHEROMON_DIRECTION)
|
|
58
|
+ try:
|
|
59
|
+ direction_degrees = get_degree_from_north(obj_last_pheromon_position, obj_position)
|
|
60
|
+ except ZeroDivisionError:
|
|
61
|
+ return
|
|
62
|
+ direction = get_direction_for_degrees(direction_degrees)
|
|
63
|
+ from_direction = get_direction_opposite(direction)
|
|
64
|
+ depose_intensity = 1 # TODO: config
|
|
65
|
+
|
|
66
|
+ for affected_point in self._parameters['concerned_points']:
|
|
67
|
+ self._appose_pheromone(context, affected_point, direction, depose_intensity)
|
|
68
|
+ context.metas.list.add(PHEROMON_POSITIONS, PHEROMON_POSITIONS, affected_point, assert_not_in=False)
|
|
69
|
+
|
|
70
|
+ obj.set_last_pheromone_point(PHEROMON_DIRECTION, obj.get_position())
|
|
71
|
+
|
|
72
|
+ def _appose_pheromone(self, context, affected_point, direction, depose_intensity):
|
|
73
|
+ context.pheromones().increment(affected_point, [PHEROMON_DIRECTION,
|
|
74
|
+ PHEROMON_DIR_EXPLO,
|
|
75
|
+ direction], depose_intensity)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|