home · contact · privacy
Server: Performance optimization in init_score_map().
[plomrogue] / server / ai.py
index a243aa4dfc9e49d20c096162089185576fd21e7f..070ecad2258b1e1b3646367e933a38b256af6ebc 100644 (file)
@@ -161,9 +161,16 @@ def get_dir_to_target(t, filter):
              if get_map_score(world_db["Things"][id]["T_POSY"] * maplength
                               + world_db["Things"][id]["T_POSX"])]
         elif "a" != filter:
-            [set_map_score_at_thingpos(id, 65535)
-             for id in world_db["Things"]
-             if animate_in_fov(world_db["Things"][id], maplength)]
+            #[set_map_score_at_thingpos(tid, 65535)
+            # for tid in world_db["Things"]
+            # if animate_in_fov(world_db["Things"][tid], maplength)]
+            # ABOVE INLINED FOR PERFORMANCE REASONS BY BLOCK BELOW
+            for Thing in world_db["Things"].values():
+                if Thing["T_LIFEPOINTS"] and not Thing["carried"] and not \
+                        Thing == t:
+                    pos = Thing["T_POSY"] * maplength + Thing["T_POSX"]
+                    if 118 == t["fovmap"][pos]:
+                        set_map_score(pos, 65535)
 
     def rand_target_dir(neighbors, cmp, dirs):
         candidates = []
@@ -285,12 +292,13 @@ def ai(t):
         if get_dir_to_target(t, "f"):
             return
         sel = get_inventory_slot_to_consume(t)
+        from server.config.ai import ai_hook_pickup_test
         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):
+        elif standing_on_food(t) and ai_hook_pickup_test(t):
                 t["T_COMMAND"] = [id for id in world_db["ThingActions"]
                                   if world_db["ThingActions"][id]["TA_NAME"]
                                   == "pickup"][0]