From 2d670448b25dc4c3118b36a497858a5f5bf9dce1 Mon Sep 17 00:00:00 2001 From: Shadow15510 Date: Tue, 12 Jul 2022 12:58:21 +0200 Subject: [PATCH 1/3] Fix deadlock with 'follow' --- asci.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/asci.py b/asci.py index 8fde004..d1990bf 100644 --- a/asci.py +++ b/asci.py @@ -1,4 +1,4 @@ -# Asci (1.9.0) +# Asci (1.9.1) from math import floor, ceil @@ -405,7 +405,8 @@ def follow(entity, data, stat, screen, walkable): if entity.args: walkable += entity.args[0] cases = ((data[2] + 1, data[3]), (data[2], data[3] - 1), (data[2] - 1, data[3]), 0, (data[2], data[3] + 1))[data[4] - 1] if not (0 <= cases[0] < screen.map_width and 0 <= cases[1] < screen.map_height): entity.pos_x, entity.pos_y = data[2], data[3] - elif screen.get_cell(cases[0], cases[1]) in walkable: entity.pos_x, entity.pos_y = cases + elif not screen.get_cell(cases[0], cases[1]) in walkable: (entity.pos_x, entity.pos_y), (data[2], data[3]) = (data[2], data[3]), (entity.pos_x, entity.pos_y) + else: entity.pos_x, entity.pos_y = cases def walk_between(entity, data, stat, screen, walkable): From bf7bad73b7b0dd0a99cbcd1315e98312043404cd Mon Sep 17 00:00:00 2001 From: Shadow15510 Date: Wed, 13 Jul 2022 10:30:16 +0200 Subject: [PATCH 2/3] Revision of 'follow' behavior --- asci.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/asci.py b/asci.py index d1990bf..eb3df21 100644 --- a/asci.py +++ b/asci.py @@ -402,11 +402,26 @@ def follow(entity, data, stat, screen, walkable): entity.pos_x, entity.pos_y = data[2], data[3] elif data[4] in (1, 2, 3, 5): + direction = (data[4] - 1) if data[4] != 5 else 3 + if entity.args: walkable += entity.args[0] - cases = ((data[2] + 1, data[3]), (data[2], data[3] - 1), (data[2] - 1, data[3]), 0, (data[2], data[3] + 1))[data[4] - 1] - if not (0 <= cases[0] < screen.map_width and 0 <= cases[1] < screen.map_height): entity.pos_x, entity.pos_y = data[2], data[3] - elif not screen.get_cell(cases[0], cases[1]) in walkable: (entity.pos_x, entity.pos_y), (data[2], data[3]) = (data[2], data[3]), (entity.pos_x, entity.pos_y) - else: entity.pos_x, entity.pos_y = cases + + cases = [(data[2] + 1, data[3]), (data[2], data[3] - 1), (data[2] - 1, data[3]), (data[2], data[3] + 1)] + pos = cases[direction] + + if not (0 <= pos[0] < screen.map_width and 0 <= pos[1] < screen.map_height) or (not screen.get_cell(pos[0], pos[1]) in walkable): + find = False + cases.remove(cases[(direction + 2) % 4]) + for pos in cases: + if (0 <= pos[0] < screen.map_width and 0 <= pos[1] < screen.map_height) and (screen.get_cell(pos[0], pos[1]) in walkable): + find = True + entity.pos_x, entity.pos_y = pos + break + if not find: + entity.pos_x, entity.pos_y = data[2], data[3] + + else: + entity.pos_x, entity.pos_y = pos def walk_between(entity, data, stat, screen, walkable): From af27d031be18f8a7708108766b6b0ca5b9c4acc0 Mon Sep 17 00:00:00 2001 From: Shadow15510 Date: Fri, 15 Jul 2022 22:33:57 +0200 Subject: [PATCH 3/3] Enhance behavior gestion --- asci.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/asci.py b/asci.py index eb3df21..a21e5b3 100644 --- a/asci.py +++ b/asci.py @@ -309,11 +309,13 @@ class Entity: self.behavior = behavior self.args = list(args) - def change_behavior(self, new_behavior): - if self.behavior != "permanent": self.behavior = new_behavior + def change_behavior(self, new_behavior, *args): + if self.behavior != "permanent": + self.behavior = new_behavior + self.args = list(args) def teleport(self, map_id, x, y): - if self.behavio != "permanent": self.map_id, self.pos_x, self.pos_y = map_id, x, y + if self.behavior != "permanent": self.map_id, self.pos_x, self.pos_y = map_id, x, y # Functions used by Asci @@ -429,11 +431,12 @@ def walk_between(entity, data, stat, screen, walkable): new_x, new_y = _walk_engine(entity, frame) if screen.get_cell(new_x, new_y) in walkable: entity.pos_x, entity.pos_y = new_x, new_y - entity.args[0] = frame + if (entity.pos_x, entity.pos_y) == entity.args[1][frame]: entity.args[0] = frame def walk_to(entity, data, stat, screen, walkable): frame = entity.args[0] + print(frame, len(entity.args[1]), entity.args) if len(entity.args[1]) == frame: entity.behavior = "stand by" entity.args = [] @@ -443,7 +446,7 @@ def walk_to(entity, data, stat, screen, walkable): if screen.get_cell(new_x, new_y) in walkable: entity.pos_x, entity.pos_y = new_x, new_y - entity.args[0] += 1 + if (entity.pos_x, entity.pos_y) == entity.args[1][frame]: entity.args[0] += 1 def follow_by_player(entity, data, stat, screen, walkable):