From e347eb6fa6520eb373e556555a39fe87ebf4d635 Mon Sep 17 00:00:00 2001 From: shiva404 Date: Sat, 7 Mar 2026 01:25:48 +0300 Subject: [PATCH] Fixed leaky abstraction Map - calc_step - Object. --- eb_engine.py | 7 ++++++- eb_objects.py | 19 ++----------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/eb_engine.py b/eb_engine.py index 5e4bb6d..03b6e8a 100644 --- a/eb_engine.py +++ b/eb_engine.py @@ -138,7 +138,12 @@ class Map: for j in range(len(self.cells)): for cell in self.cells[j]: if cell.creature_obj: - cell.creature_obj.update(time_delta, self.cell_size, self) + cell.creature_obj.walkable_matrix = self.walkable_matrix + cell.creature_obj.rocks_matrix = self.rocks_matrix + if cell.creature_obj.final_goal is not None: + cell.creature_obj.calc_step(time_delta, self.cell_size, self) + continue + cell.creature_obj.update(time_delta) def compute_walkable_rocks(self): """Вычисляет матрицы walkable и rocks_only БЕЗ учета стартовой позиции""" diff --git a/eb_objects.py b/eb_objects.py index 46bb09a..db90a8c 100644 --- a/eb_objects.py +++ b/eb_objects.py @@ -163,29 +163,16 @@ class Creature(Object): # action/task_counter = 0 #clear goal/wp - def update(self, time_delta, cell_size, map_obj): - self.walkable_matrix = map_obj.walkable_matrix - self.rocks_matrix = map_obj.rocks_matrix - + def update(self, time_delta): #quick_actions? here? #print(self.waypoints, self.final_goal, self.action_counter, self.task_counter) - if self.final_goal is not None: - #print(2) - self.calc_step(time_delta, cell_size, map_obj) - return if self.interrupt_task and self.interrupt_action_status == "completed": - #print(3) self.action_time = 0.0 self.action = self.interrupt_task.pop(0) self.interrupt_action_status = "active" - #print(f" DEBUG: tasks={len(self.tasks)}, " - # f"task_len={len(self.tasks[self.task_counter]) if self.tasks else 0}, " - # f"action={self.action is not None}") - if self.action: - #print(self.action_counter, self.task_counter) self.action_time += time_delta self.action.progress = min(1.0, self.action_time / self.action.duration) @@ -197,9 +184,7 @@ class Creature(Object): self.action = None self.action_time = 0.0 - elif self.tasks: - #print(6) if self.action_counter < len(self.tasks[self.task_counter]): self.action = self.tasks[self.task_counter][self.action_counter] self.action_counter += 1 @@ -213,7 +198,7 @@ class Creature(Object): self.action_counter += 1 self.action_time = 0.0 - + # possibly shorther version of a code above, need to test #elif self.tasks: # if self.action_counter >= len(self.tasks[self.task_counter]): # self.task_counter += 1