home · contact · privacy
Server: Optimize thing position calculation.
[plomrogue] / server / actions.py
index 22d165a4023c6652cb02706be7b0b01ac3cf79f9..4dc470b69d068ad5173946ae9ec2d62eb114dc53 100644 (file)
@@ -14,9 +14,13 @@ def actor_wait(t):
 
 
 def actor_move(t):
-    """If passable, move/collide(=attack) thing into T_ARGUMENT's direction."""
+    """If passable, move/collide(=attack) thing into T_ARGUMENT's direction.
+
+    On attack, return 0 on non-kill and TT_LIFEPOINTS of killed type on kill,
+    plus type id of attacked Thing. On move, return mv_yx_in_dir_legal result.
+    """
     from server.build_fov_map import build_fov_map
-    from server.config.misc import decrement_lifepoints_func
+    from server.config.misc import decrement_lifepoints
     from server.utils import mv_yx_in_dir_legal
     from server.config.world_data import directions_db, symbols_passable
     passable = False
@@ -31,28 +35,35 @@ def actor_move(t):
                   if world_db["Things"][id]["T_POSX"] == move_result[2]]
         if len(hitted):
             hit_id = hitted[0]
-            hitted_type_id = world_db["Things"][hit_id]["T_TYPE"]
+            hitted_tid = world_db["Things"][hit_id]["T_TYPE"]
             if t == world_db["Things"][0]:
-                hitted_name = world_db["ThingTypes"][hitted_type_id]["TT_NAME"]
+                hitted_name = world_db["ThingTypes"][hitted_tid]["TT_NAME"]
                 log("You WOUND " + hitted_name + ".")
             elif 0 == hit_id:
                 hitter_name = world_db["ThingTypes"][t["T_TYPE"]]["TT_NAME"]
                 log(hitter_name +" WOUNDS you.")
-            decr_test = decrement_lifepoints_func(world_db["Things"][hit_id])
+            decr_test = decrement_lifepoints(world_db["Things"][hit_id])
             if decr_test > 0 and t == world_db["Things"][0]:
                 log(hitted_name + " dies.")
+            return decr_test, hitted_tid
+        from server.config.actions import actor_move_attempts_hook
+        if actor_move_attempts_hook(t, move_result, pos):
+            return
         passable = chr(world_db["MAP"][pos]) in symbols_passable
     dir = [dir for dir in directions_db
            if directions_db[dir] == chr(t["T_ARGUMENT"])][0]
     if passable:
         t["T_POSY"] = move_result[1]
         t["T_POSX"] = move_result[2]
+        t["pos"] = move_result[1] * world_db["MAP_LENGTH"] + move_result[2]
         for id in t["T_CARRIES"]:
             world_db["Things"][id]["T_POSY"] = move_result[1]
             world_db["Things"][id]["T_POSX"] = move_result[2]
+            world_db["Things"][id]["pos"] = t["pos"]
         build_fov_map(t)
         if t == world_db["Things"][0]:
             log("You MOVE " + dir + ".")
+        return move_result
 
 
 def actor_pickup(t):
@@ -62,8 +73,7 @@ def actor_pickup(t):
     """
     ids = [id for id in world_db["Things"] if world_db["Things"][id] != t
            if not world_db["Things"][id]["carried"]
-           if world_db["Things"][id]["T_POSY"] == t["T_POSY"]
-           if world_db["Things"][id]["T_POSX"] == t["T_POSX"]]
+           if world_db["Things"][id]["pos"] == t["pos"]]
     if len(ids):
         lowest_tid = -1
         for iid in ids: