From 508cea8a91de7ddf2411153c9b734f3b0cb8adda Mon Sep 17 00:00:00 2001
From: fheinrich <fheinrich@techfak.uni-bielefeld.de>
Date: Thu, 18 Jan 2024 12:58:51 +0100
Subject: [PATCH] Salad viz, unlimited orders possible

---
 .../gui_2d_vis/overcooked_gui.py              | 21 +++++++++++--------
 .../gui_2d_vis/visualization.yaml             |  6 ++++++
 overcooked_simulator/order.py                 | 19 +++++++++++------
 3 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/overcooked_simulator/gui_2d_vis/overcooked_gui.py b/overcooked_simulator/gui_2d_vis/overcooked_gui.py
index d7375be7..db5c8188 100644
--- a/overcooked_simulator/gui_2d_vis/overcooked_gui.py
+++ b/overcooked_simulator/gui_2d_vis/overcooked_gui.py
@@ -549,15 +549,18 @@ class PyGameGUI:
         self.timer_label.set_text(f"Time remaining: {display_time}")
 
     def draw_orders(self, state):
-        orders = [
-            "Burger",
-            "TomatoSoupPlate",
-            "OnionSoupPlate",
-            "OnionSoupPlate",
-            "OnionSoupPlate",
-            "OnionSoupPlate",
-        ]
-
+        # print(state["orders"])
+        # for o in state["orders"]:
+        #     print(o.meal.name)
+        # orders = [
+        #     "Burger",
+        #     "TomatoSoupPlate",
+        #     "OnionSoupPlate",
+        #     "OnionSoupPlate",
+        #     "OnionSoupPlate",
+        #     "OnionSoupPlate",
+        # ]
+        orders = [o.meal.name for o in state["orders"]]
         orders_width = self.game_width - 100
         orders_height = self.screen_margin
         self.orders_screen = pygame.Surface(
diff --git a/overcooked_simulator/gui_2d_vis/visualization.yaml b/overcooked_simulator/gui_2d_vis/visualization.yaml
index bef233b6..35ce1d92 100644
--- a/overcooked_simulator/gui_2d_vis/visualization.yaml
+++ b/overcooked_simulator/gui_2d_vis/visualization.yaml
@@ -193,6 +193,12 @@ Burger:
       path: images/burger.png
       size: 0.8
 
+Salad:
+  parts:
+    - type: image
+      path: images/salad.png
+      size: 0.8
+
 TomatoSoup:
   parts:
     - type: image
diff --git a/overcooked_simulator/order.py b/overcooked_simulator/order.py
index 589e588e..fc10a405 100644
--- a/overcooked_simulator/order.py
+++ b/overcooked_simulator/order.py
@@ -88,6 +88,7 @@ class RandomOrderGeneration(OrderGeneration):
         return self.create_orders_for_meals(
             random.choices(self.available_meals, k=self.kwargs.num_start_meals),
             now,
+            self.kwargs.sample_on_serving,
         )
 
     def get_orders(
@@ -100,6 +101,7 @@ class RandomOrderGeneration(OrderGeneration):
                 return self.create_orders_for_meals(
                     random.choices(self.available_meals, k=len(new_finished_orders)),
                     now,
+                    True,
                 )
         if self.kwargs.sample_on_dur:
             if self.needed_orders:
@@ -122,16 +124,21 @@ class RandomOrderGeneration(OrderGeneration):
                     )
         return []
 
-    def create_orders_for_meals(self, meals: list[Item], now: datetime) -> list[Order]:
+    def create_orders_for_meals(
+        self, meals: list[Item], now: datetime, no_time_limit: bool = False
+    ) -> list[Order]:
         orders = []
         for meal in meals:
-            duration = timedelta(
-                seconds=int(
-                    getattr(random, self.kwargs.duration_sample["func"])(
-                        **self.kwargs.duration_sample["kwargs"]
+            if no_time_limit:
+                duration = datetime.max - now
+            else:
+                duration = timedelta(
+                    seconds=int(
+                        getattr(random, self.kwargs.duration_sample["func"])(
+                            **self.kwargs.duration_sample["kwargs"]
+                        )
                     )
                 )
-            )
             log.info(f"Create order for meal {meal} with duration {duration}")
             orders.append(
                 Order(
-- 
GitLab