home · contact · privacy
Server: Fix dependences on possibly undefined actions.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 21 Feb 2016 20:26:25 +0000 (21:26 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 21 Feb 2016 20:26:25 +0000 (21:26 +0100)
server/ai.py

index 21241fcd5b900502e6441d6ad3cbbed4ecceebd7..3212be0c09020816370aba309d1b7404b9df3c0b 100644 (file)
@@ -274,21 +274,26 @@ def ai(t):
     """Determine next command/argment for actor t via AI algorithms."""
     t["T_COMMAND"] = [id for id in world_db["ThingActions"]
                       if world_db["ThingActions"][id]["TA_NAME"] == "wait"][0]
-    if get_dir_to_target(t, "f"):
-        return
-    sel = get_inventory_slot_to_consume(t)
-    if -1 != sel:
-        t["T_COMMAND"] = [id for id in world_db["ThingActions"]
-                          if world_db["ThingActions"][id]["TA_NAME"]
-                             == "use"][0]
-        t["T_ARGUMENT"] = sel
-    elif standing_on_food(t):
+    eating = len([id for id in world_db["ThingActions"]
+                  if world_db["ThingActions"][id]["TA_NAME"] == "use"]) > 0
+    picking = len([id for id in world_db["ThingActions"]
+                   if world_db["ThingActions"][id]["TA_NAME"] == "pickup"]) > 0
+    if eating and picking:
+        if get_dir_to_target(t, "f"):
+            return
+        sel = get_inventory_slot_to_consume(t)
+        if -1 != sel:
             t["T_COMMAND"] = [id for id in world_db["ThingActions"]
                               if world_db["ThingActions"][id]["TA_NAME"]
-                              == "pickup"][0]
-    else:
-        going_to_known_food_spot = get_dir_to_target(t, "c")
-        if not going_to_known_food_spot:
-            aiming_for_walking_food = get_dir_to_target(t, "a")
-            if not aiming_for_walking_food:
-                get_dir_to_target(t, "s")
+                                 == "use"][0]
+            t["T_ARGUMENT"] = sel
+        elif standing_on_food(t):
+                t["T_COMMAND"] = [id for id in world_db["ThingActions"]
+                                  if world_db["ThingActions"][id]["TA_NAME"]
+                                  == "pickup"][0]
+        else:
+            going_to_known_food_spot = get_dir_to_target(t, "c")
+            if not going_to_known_food_spot:
+                aiming_for_walking_food = get_dir_to_target(t, "a")
+                if not aiming_for_walking_food:
+                    get_dir_to_target(t, "s")