X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bdeck_id%7D%7D/cards/%7B%7Bcard_id%7D%7D/static/gitweb.css?a=blobdiff_plain;ds=sidebyside;f=roguelike-server;h=29fe11994b79c15bca1ac95536f788cb16345e21;hb=49679df70be008106ba63448b5ea66297c134bea;hp=b72b9f530b950dd8200a5f870c4c0c2f2a901cb9;hpb=fc7f9132eeb72243ecea80f6eb98bdbd86562f4c;p=plomrogue diff --git a/roguelike-server b/roguelike-server index b72b9f5..29fe119 100755 --- a/roguelike-server +++ b/roguelike-server @@ -1300,6 +1300,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"]] @@ -1309,16 +1310,20 @@ 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 slot Id of healthiest consumable in t's inventory, else -1.""" + cmp_food = -1 selection = -1 i = 0 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) + 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