|
@@ -1,9 +1,10 @@
|
1
|
1
|
from synergine.synergy.event.Action import Action
|
2
|
2
|
from intelligine.synergy.event.pheromone.PheromoneEvent import PheromoneEvent
|
3
|
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
|
|
4
|
+from intelligine.cst import PHEROMON_DIRECTION, PHEROMON_DIR_EXPLO, PHEROMON_POSITIONS, MOVE_MODE_EXPLO
|
|
5
|
+from xyzworld.geometry import get_degree_from_north
|
6
|
6
|
from intelligine.synergy.event.move.direction import get_direction_for_degrees, get_direction_opposite
|
|
7
|
+from intelligine.core.exceptions import SamePosition
|
7
|
8
|
|
8
|
9
|
|
9
|
10
|
class ApposeDirection(Action):
|
|
@@ -26,54 +27,35 @@ class ApposeDirection(Action):
|
26
|
27
|
On effectue l'incrementation dans le process principal. Beaucoups plus lourd que de le faie dans les
|
27
|
28
|
process. Mais si on le fait dans les process on va rater des infos ...
|
28
|
29
|
met a jour les pts (incremente)
|
29
|
|
- :param obj:
|
30
|
|
- :param context:
|
31
|
|
- :param synergy_manager:
|
32
|
|
- :return:
|
33
|
30
|
"""
|
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
|
31
|
self._appose_pheromones(obj, context, synergy_manager)
|
54
|
32
|
|
55
|
33
|
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
|
34
|
try:
|
59
|
|
- direction_degrees = get_degree_from_north(obj_last_pheromon_position, obj_position)
|
60
|
|
- except ZeroDivisionError:
|
|
35
|
+ from_direction = self._get_from_direction(obj)
|
|
36
|
+ except SamePosition:
|
61
|
37
|
return
|
62
|
|
- direction = get_direction_for_degrees(direction_degrees)
|
63
|
|
- from_direction = get_direction_opposite(direction)
|
64
|
|
- depose_intensity = 1 # TODO: config
|
65
|
38
|
|
|
39
|
+ depose_intensity = 1 # TODO: config
|
|
40
|
+ pheromone_direction_type = self._get_pheromone_direction_type(obj)
|
66
|
41
|
for affected_point in self._parameters['concerned_points']:
|
67
|
|
- self._appose_pheromone(context, affected_point, direction, depose_intensity)
|
|
42
|
+ context.pheromones().increment(affected_point, [PHEROMON_DIRECTION,
|
|
43
|
+ pheromone_direction_type,
|
|
44
|
+ from_direction], depose_intensity)
|
68
|
45
|
context.metas.list.add(PHEROMON_POSITIONS, PHEROMON_POSITIONS, affected_point, assert_not_in=False)
|
69
|
46
|
|
70
|
47
|
obj.set_last_pheromone_point(PHEROMON_DIRECTION, obj.get_position())
|
71
|
48
|
|
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
|
|
-
|
|
49
|
+ def _get_from_direction(self, obj):
|
|
50
|
+ obj_position = obj.get_position()
|
|
51
|
+ obj_last_pheromon_position = obj.get_last_pheromone_point(PHEROMON_DIRECTION)
|
|
52
|
+ try:
|
|
53
|
+ direction_degrees = get_degree_from_north(obj_last_pheromon_position, obj_position)
|
|
54
|
+ except ZeroDivisionError:
|
|
55
|
+ raise SamePosition()
|
|
56
|
+ direction = get_direction_for_degrees(direction_degrees)
|
|
57
|
+ return get_direction_opposite(direction)
|
79
|
58
|
|
|
59
|
+ def _get_pheromone_direction_type(self, obj):
|
|
60
|
+ if obj.get_movement_mode() == MOVE_MODE_EXPLO:
|
|
61
|
+ return PHEROMON_DIR_EXPLO
|