X-Git-Url: https://plomlompom.com/repos/berlin_corona.txt?a=blobdiff_plain;f=roguelike-server;h=c51b65de6a9eeb5f830caef517ffef1efc6027fb;hb=294144fde53ac36b9f5e03fa9557dbb384863e47;hp=41506c0800e22f2e115d4a86c3d5936188ddba3c;hpb=fd9a37455ebccd94d981be866223b2a203a817df;p=plomrogue diff --git a/roguelike-server b/roguelike-server index 41506c0..c51b65d 100755 --- a/roguelike-server +++ b/roguelike-server @@ -903,6 +903,7 @@ def actor_pick_up(t): Define topmostness by how low the thing's type ID is. """ # 7DRL: Non-player picking up player-dropped consumable -> GOD_FAVOR gain. + # 7DRL: Only player picks up non-food. used_slots = len(t["T_CARRIES"]) # # if used_slots < world_db["ThingTypes"][t["T_TYPE"]]["TT_STORAGE"]: # # ids = [id for id in world_db["Things"] if world_db["Things"][id] != t @@ -914,6 +915,9 @@ def actor_pick_up(t): for iid in ids: tid = world_db["Things"][iid]["T_TYPE"] if lowest_tid == -1 or tid < lowest_tid: + if (t != world_db["Things"][0] and # # + world_db["ThingTypes"][tid]["TT_TOOL"] != "food"): + continue id = iid lowest_tid = tid world_db["Things"][id]["carried"] = True @@ -1069,34 +1073,33 @@ def thingproliferation(t, prol_map): def try_healing(t): - """Grow t's HP to a 1/32 chance if < HP max, satiation > 0, and waiting. - - On success, decrease satiation score by 32. - """ + """If t's HP < max, increment them if well-nourished, maybe waiting.""" # 7DRL: Successful heals increment God's mood. - if t["T_SATIATION"] > 0 \ - and t["T_LIFEPOINTS"] < \ - world_db["ThingTypes"][t["T_TYPE"]]["TT_LIFEPOINTS"] \ - and 0 == (rand.next() % 31) \ - and t["T_COMMAND"] == [id for id in world_db["ThingActions"] - if world_db["ThingActions"][id]["TA_NAME"] == - "wait"][0]: - t["T_LIFEPOINTS"] += 1 - world_db["GOD_MOOD"] += 1 # # - t["T_SATIATION"] -= 32 - if t == world_db["Things"][0]: - strong_write(io_db["file_out"], "LOG You heal.\n") + if t["T_LIFEPOINTS"] < \ + world_db["ThingTypes"][t["T_TYPE"]]["TT_LIFEPOINTS"]: + wait_id = [id for id in world_db["ThingActions"] + if world_db["ThingActions"][id]["TA_NAME"] == "wait"][0] + wait_divider = 8 if t["T_COMMAND"] == wait_id else 1 + testval = int(abs(t["T_SATIATION"]) / wait_divider) + if (testval <= 1 or 1 == (rand.next() % testval)): + t["T_LIFEPOINTS"] += 1 + if t != world_db["Things"][0]: # # + world_db["GOD_MOOD"] += 1 # # + if t == world_db["Things"][0]: + strong_write(io_db["file_out"], "LOG You heal.\n") + + +def hunger_per_turn(type_id): + """The amount of satiation score lost per turn for things of given type.""" + return int(math.sqrt(world_db["ThingTypes"][type_id]["TT_LIFEPOINTS"])) def hunger(t): """Decrement t's satiation,dependent on it trigger lifepoint dec chance.""" if t["T_SATIATION"] > -32768: - t["T_SATIATION"] -= 1 - if not world_db["ThingTypes"][t["T_TYPE"]]["TT_LIFEPOINTS"]: - raise RuntimeError("A thing that should not hunger is hungering.") - stomach = int(32767 / world_db["ThingTypes"][t["T_TYPE"]]["TT_LIFEPOINTS"]) - if int(int(abs(t["T_SATIATION"]) / stomach) - / ((rand.next() % stomach) + 1)): + #max_hp = world_db["ThingTypes"][t["T_TYPE"]]["TT_LIFEPOINTS"] + t["T_SATIATION"] -= hunger_per_turn(t["T_TYPE"]) # int(math.sqrt(max_hp)) + if 0 != t["T_SATIATION"] and 0 == int(rand.next() / abs(t["T_SATIATION"])): if t == world_db["Things"][0]: if t["T_SATIATION"] < 0: strong_write(io_db["file_out"], "LOG You suffer from hunger.\n") @@ -1306,6 +1309,7 @@ def get_dir_to_target(t, filter): def standing_on_food(t): """Return True/False whether t is standing on a consumable.""" for id in [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["ThingTypes"][world_db["Things"][id]["T_TYPE"]] @@ -1315,16 +1319,24 @@ def standing_on_food(t): def get_inventory_slot_to_consume(t): - """Return slot Id of strongest consumable in t's inventory, else -1.""" - cmp_food = 0 + """Return invent. slot of healthiest consumable(if any healthy),else -1.""" + cmp_food = -1 selection = -1 i = 0 + hunger_u = hunger_per_turn(t["T_TYPE"]) + type = [id for id in world_db["ThingActions"] + if world_db["ThingActions"][id]["TA_NAME"] == "use"][0] + consume_hungering = world_db["ThingActions"][type]["TA_EFFORT"] * hunger_u for id in t["T_CARRIES"]: type = world_db["Things"][id]["T_TYPE"] if world_db["ThingTypes"][type]["TT_TOOL"] == "food" \ - and world_db["ThingTypes"][type]["TT_TOOLPOWER"] > cmp_food: - cmp_food = world_db["ThingTypes"][type]["TT_TOOLPOWER"] - selection = i + and world_db["ThingTypes"][type]["TT_TOOLPOWER"]: + nutvalue = world_db["ThingTypes"][type]["TT_TOOLPOWER"] + tmp_cmp = abs(t["T_SATIATION"] + nutvalue - consume_hungering) + if (cmp_food < 0 and tmp_cmp < abs(t["T_SATIATION"])) \ + or tmp_cmp < cmp_food: + cmp_food = tmp_cmp + selection = i i += 1 return selection