From: Christian Heller Date: Sun, 28 Feb 2016 23:18:00 +0000 (+0100) Subject: Server, plugin: Refactor decrement_lifepoint hooking, add missed files. X-Git-Tag: tce~122 X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/index.html?a=commitdiff_plain;h=2fe74dcee473121f423cd37e4b1da5bb0139146e;p=plomrogue Server, plugin: Refactor decrement_lifepoint hooking, add missed files. --- diff --git a/plugins/server/PleaseTheIslandGod.py b/plugins/server/PleaseTheIslandGod.py index 2779847..e989d53 100644 --- a/plugins/server/PleaseTheIslandGod.py +++ b/plugins/server/PleaseTheIslandGod.py @@ -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 diff --git a/server/actions.py b/server/actions.py index f7edb76..7222ad8 100644 --- a/server/actions.py +++ b/server/actions.py @@ -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 index 0000000..c39aa72 --- /dev/null +++ b/server/calc_effort.py @@ -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 index 0000000..bfca4c0 --- /dev/null +++ b/server/config/ai.py @@ -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 diff --git a/server/config/misc.py b/server/config/misc.py index 905041e..299486b 100644 --- a/server/config/misc.py +++ b/server/config/misc.py @@ -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 diff --git a/server/decrement_lifepoints.py b/server/decrement_lifepoints.py index 827a16e..b8cab97 100644 --- a/server/decrement_lifepoints.py +++ b/server/decrement_lifepoints.py @@ -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)) diff --git a/server/world.py b/server/world.py index c00b5f1..90b26de 100644 --- a/server/world.py +++ b/server/world.py @@ -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():