]> git.mar77i.info Git - elevator/commitdiff
panel_prio lets callers go somewhere befeore next call_queue
authormar77i <mar77i@protonmail.ch>
Tue, 20 Aug 2024 08:21:51 +0000 (10:21 +0200)
committermar77i <mar77i@protonmail.ch>
Tue, 20 Aug 2024 08:21:51 +0000 (10:21 +0200)
elevator.py

index e0c3d59ff02f2f16534185f710e8de0154feee18..44435aa46453ea2c0b80a7d2bcede6756a24eae0 100755 (executable)
@@ -154,6 +154,7 @@ class Door:
         elif self.state >= self.CLOSED:
             self.state = self.CLOSED
             self.direction = 0
+            self.elevator.panel_prio = False
         return True
 
     def draw(self, surf):
@@ -226,6 +227,14 @@ class Elevator:
         self.destination = None
         self.queued_dest = None
         self.call_queue = []
+        self.panel_prio = False
+
+    def pop_destination(self, destination):
+        if destination == self.queued_dest:
+            self.queued_dest = None
+        while destination in self.call_queue:
+            self.call_queue.remove(destination)
+        self.destination = destination
 
     def pick_destination(self):
         """
@@ -236,15 +245,11 @@ class Elevator:
         if not all(door.state == door.CLOSED for door in self.doors):
             return False
         if self.queued_dest is not None:
-            self.destination = self.queued_dest
-            while self.destination in self.call_queue:
-                self.call_queue.remove(self.destination)
-            self.queued_dest = None
+            self.pop_destination(self.queued_dest)
             return True
-        elif len(self.call_queue) > 0:
-            self.destination = self.call_queue.pop(0)
-            if self.destination == self.queued_dest:
-                self.destination = None
+        elif not self.panel_prio and len(self.call_queue) > 0:
+            self.pop_destination(self.call_queue.pop(0))
+            self.panel_prio = True
             return True
         return False