home · contact · privacy
Server, plugin: Refactor decrement_lifepoint hooking, add missed files.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 28 Feb 2016 23:18:00 +0000 (00:18 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 28 Feb 2016 23:18:00 +0000 (00:18 +0100)
plugins/server/PleaseTheIslandGod.py
server/actions.py
server/calc_effort.py [new file with mode: 0644]
server/config/ai.py [new file with mode: 0644]
server/config/misc.py
server/decrement_lifepoints.py
server/world.py

index 2779847b831a3fe0e60c44f01e8a921d64265865..e989d539d5f790d392d2e6f3f633d449f03ea9c4 100644 (file)
@@ -103,8 +103,8 @@ def actor_use_attempts_hook(t, ty):
                 "It glows in wondrous colors, and emits a sound as if from a d"
                 "ying cat. The Island God laughs.\n")
         t["T_LIFEPOINTS"] = 1
-        from server.config.misc import decrement_lifepoints_func
-        decrement_lifepoints_func(t)
+        from server.config.misc import decrement_lifepoints
+        decrement_lifepoints(t)
     elif (world_db["ThingTypes"][ty]["TT_TOOL"] == "carpentry"):
         pos = t["T_POSY"] * world_db["MAP_LENGTH"] + t["T_POSX"]
         if (world_db["MAP"][pos] == ord("X")
@@ -300,45 +300,28 @@ def actor_move_attempts_hook(t, move_result, pos):
     return False
 
 def decrement_lifepoints(t):
-    t["T_LIFEPOINTS"] -= 1
+    from server.decrement_lifepoints import decrement_lifepoints
     live_tid = t["T_TYPE"]
-    _id = [_id for _id in world_db["Things"] if world_db["Things"][_id] == t][0]
-    if 0 == t["T_LIFEPOINTS"]:
-        for id in t["T_CARRIES"]:
-            t["T_CARRIES"].remove(id)
-            world_db["Things"][id]["T_POSY"] = t["T_POSY"]
-            world_db["Things"][id]["T_POSX"] = t["T_POSX"]
-            world_db["Things"][id]["carried"] = False
-        t["T_TYPE"] = world_db["ThingTypes"][t["T_TYPE"]]["TT_CORPSE_ID"]
-        if world_db["Things"][0] == t:
-            t["fovmap"] = bytearray(b' ' * (world_db["MAP_LENGTH"] ** 2))
-            log("You die.")
-            log("See README on how to start over.")
-        else:
-            t["fovmap"] = False
-            t["T_MEMMAP"] = False
-            t["T_MEMDEPTHMAP"] = False
-            t["T_MEMTHING"] = []
-            n_species = len([id for id in world_db["Things"]
-                             if world_db["Things"][id]["T_TYPE"] == live_tid])
-            if 0 == n_species:
-                from server.new_thing import new_Thing
-                if world_db["FAVOR_STAGE"] >= 3 and \
+    test = decrement_lifepoints(t)
+    if test > 0 and t != world_db["Things"][0]:
+        n_species = len([tid for tid in world_db["Things"]
+                         if world_db["Things"][tid]["T_TYPE"] == live_tid])
+        if 0 == n_species:
+            from server.new_thing import new_Thing
+            if world_db["FAVOR_STAGE"] >= 3 and \
                     live_tid == world_db["ANIMAL_0"]:
-                    world_db["GOD_FAVOR"] += 3000
-                    log("CONGRATULATIONS! The "
-                        + world_db["ThingTypes"][live_tid]["TT_NAME"]
-                        + " species has died out. The Island God is pleased.")
-                else:
-                    id = id_setter(-1, "Things")
-                    world_db["Things"][id] = new_Thing(live_tid,
-                                                       world_db["altar"])
-                    log("The "
-                        + world_db["ThingTypes"][live_tid]["TT_NAME"]
-                        + " species has temporarily died out. "
-                        + "One new-born is spawned at the altar.")
-        return world_db["ThingTypes"][live_tid]["TT_LIFEPOINTS"]
-    return 0
+                world_db["GOD_FAVOR"] += 3000
+                log("CONGRATULATIONS! The "
+                    + world_db["ThingTypes"][live_tid]["TT_NAME"]
+                    + " species has died out. The Island God is pleased.")
+            else:
+                tid = id_setter(-1, "Things")
+                world_db["Things"][tid] = new_Thing(live_tid,
+                                                    world_db["altar"])
+                log("The " + world_db["ThingTypes"][live_tid]["TT_NAME"] + " s"
+                    "pecies has temporarily died out. One new-born is spawned "
+                    "at the altar.")
+    return test
 
 def command_ttid(id_string):
     id = id_setter(id_string, "ThingTypes", command_ttid)
@@ -638,7 +621,7 @@ commands_db["pickup"] = (0, False, play_pickup)
 
 import server.config.misc
 server.config.misc.make_map_func = make_map
-server.config.misc.decrement_lifepoints_func = decrement_lifepoints
+server.config.misc.decrement_lifepoints = decrement_lifepoints
 server.config.misc.calc_effort_func = calc_effort
 
 import server.config.make_world_helpers
index f7edb76767d60602a705ac02e57980587d90495d..7222ad871cea7c0f3153cf8a61833dff6691d02d 100644 (file)
@@ -20,7 +20,7 @@ def actor_move(t):
     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
@@ -42,7 +42,7 @@ def actor_move(t):
             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
diff --git a/server/calc_effort.py b/server/calc_effort.py
new file mode 100644 (file)
index 0000000..c39aa72
--- /dev/null
@@ -0,0 +1,7 @@
+# This file is part of PlomRogue. PlomRogue is licensed under the GPL version 3
+# or any later version. For details on its copyright, license, and warranties,
+# see the file NOTICE in the root directory of the PlomRogue source package.
+
+
+def calc_effort(thing_action, thing):
+    return thing_action["TA_EFFORT"]
diff --git a/server/config/ai.py b/server/config/ai.py
new file mode 100644 (file)
index 0000000..bfca4c0
--- /dev/null
@@ -0,0 +1,6 @@
+# This file is part of PlomRogue. PlomRogue is licensed under the GPL version 3
+# or any later version. For details on its copyright, license, and warranties,
+# see the file NOTICE in the root directory of the PlomRogue source package.
+
+
+ai_hook_pickup_test = lambda x: True
index 905041efbba5b578127f2ee6b550eeba7b33a505..299486b5b07103824a1d423751970f004fb99f73 100644 (file)
@@ -6,5 +6,5 @@ from server.thingproliferation import thingproliferation
 from server.decrement_lifepoints import decrement_lifepoints
 from server.calc_effort import calc_effort
 
-decrement_lifepoints_func = decrement_lifepoints
+decrement_lifepoints = decrement_lifepoints
 calc_effort_func = calc_effort
index 827a16ea0616da93fe25c13e2ce412a2f315812b..b8cab9740abd995b4e8938c61644b079c06a45ca 100644 (file)
@@ -4,22 +4,22 @@
 
 
 def decrement_lifepoints(t):
-    """Decrement t's lifepoints by 1, and if to zero, corpse it.
+    """Decrement t's lifepoints by 1; if to zero, corpse it, drop its stuff.
 
     If t is the player avatar, only blank its fovmap, so that the client may
     still display memory data. On non-player things, erase fovmap and memory.
-    Dying actors drop all their things.
+    On kill, return dying type's TT_LIFEPOINTS, else 0.
     """
     from server.config.world_data import world_db
     from server.io import log
     t["T_LIFEPOINTS"] -= 1
     if 0 == t["T_LIFEPOINTS"]:
         live_tid = t["T_TYPE"]
-        for id in t["T_CARRIES"]:
-            t["T_CARRIES"].remove(id)
-            world_db["Things"][id]["T_POSY"] = t["T_POSY"]
-            world_db["Things"][id]["T_POSX"] = t["T_POSX"]
-            world_db["Things"][id]["carried"] = False
+        for tid in t["T_CARRIES"]:
+            t["T_CARRIES"].remove(tid)
+            world_db["Things"][tid]["T_POSY"] = t["T_POSY"]
+            world_db["Things"][tid]["T_POSX"] = t["T_POSX"]
+            world_db["Things"][tid]["carried"] = False
         t["T_TYPE"] = world_db["ThingTypes"][t["T_TYPE"]]["TT_CORPSE_ID"]
         if world_db["Things"][0] == t:
             t["fovmap"] = bytearray(b' ' * (world_db["MAP_LENGTH"] ** 2))
index c00b5f14374bfb1fb2ca45c2b3af2e5c76255591..90b26de7db3807a394450f150c7beef6442ccb07 100644 (file)
@@ -30,7 +30,7 @@ def hunger_per_turn(type_id):
 
 def hunger(t):
     """Decrement t's satiation,dependent on it trigger lifepoint dec chance."""
-    from server.config.misc import decrement_lifepoints_func
+    from server.config.misc import decrement_lifepoints
     if t["T_SATIATION"] > -32768:
         t["T_SATIATION"] -= hunger_per_turn(t["T_TYPE"])
     if 0 != t["T_SATIATION"] and 0 == int(rand.next() / abs(t["T_SATIATION"])):
@@ -39,7 +39,7 @@ def hunger(t):
                 log("You SUFFER from hunger.")
             else:
                 log("You SUFFER from over-eating.")
-        decrement_lifepoints_func(t)
+        decrement_lifepoints(t)
 
 
 def set_world_inactive():