def hunger(t): """Decrement t's satiation,dependent on it trigger lifepoint dec chance.""" 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"])): if t == world_db["Things"][0]: if t["T_SATIATION"] < 0: log("You SUFFER from hunger.") else: log("You SUFFER from over-eating.") decrement_lifepoints(t)
def decrement_lifepoints(t): from server.decrement_lifepoints import decrement_lifepoints live_tid = t["T_TYPE"] 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: 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 actor_move(t): """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 from server.utils import mv_yx_in_dir_legal from server.config.world_data import directions_db, symbols_passable passable = False move_result = mv_yx_in_dir_legal(chr(t["T_ARGUMENT"]), t["T_POSY"], t["T_POSX"]) if 1 == move_result[0]: pos = (move_result[1] * world_db["MAP_LENGTH"]) + move_result[2] hitted = [ id for id in world_db["Things"] if world_db["Things"][id] != t if world_db["Things"][id]["T_LIFEPOINTS"] if world_db["Things"][id]["T_POSY"] == move_result[1] if world_db["Things"][id]["T_POSX"] == move_result[2] ] if len(hitted): hit_id = hitted[0] hitted_tid = world_db["Things"][hit_id]["T_TYPE"] if t == world_db["Things"][0]: 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(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_use_attempts_hook(t, ty): if ty == world_db["SLIPPERS"]: if t == world_db["Things"][0]: log("You use the " + world_db["ThingTypes"][ty]["TT_NAME"] + ". " \ "It glows in wondrous colors, and emits a sound as if from a d" "ying cat. The Island God laughs.") t["T_LIFEPOINTS"] = 1 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") or world_db["MAP"][pos] == ord("|")): return for t_id in [ t_id for t_id in world_db["Things"] if not world_db["Things"][t_id] == t if not world_db["Things"][t_id]["carried"] if world_db["Things"][t_id]["T_POSY"] == t["T_POSY"] if world_db["Things"][t_id]["T_POSX"] == t["T_POSX"] ]: return wood_id = None for t_id in t["T_CARRIES"]: type_material = world_db["Things"][t_id]["T_TYPE"] if (world_db["ThingTypes"][type_material]["TT_TOOL"] == "wood"): wood_id = t_id break if wood_id != None: t["T_CARRIES"].remove(wood_id) del world_db["Things"][wood_id] world_db["MAP"][pos] = ord("|") log("With your " + world_db["ThingTypes"][ty]["TT_NAME"] + " you" \ " build a WOODEN BARRIER from your " + world_db["ThingTypes"][type_material]["TT_NAME"] + ".") elif world_db["ThingTypes"][ty]["TT_TOOL"] == "fertilizer": pos = t["T_POSY"] * world_db["MAP_LENGTH"] + t["T_POSX"] if world_db["MAP"][pos] == ord("."): log("You create SOIL.") world_db["MAP"][pos] = ord(":")
def actor_move(t): """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 from server.utils import mv_yx_in_dir_legal from server.config.world_data import directions_db, symbols_passable passable = False move_result = mv_yx_in_dir_legal(chr(t["T_ARGUMENT"]), t["T_POSY"], t["T_POSX"]) if 1 == move_result[0]: pos = (move_result[1] * world_db["MAP_LENGTH"]) + move_result[2] hitted = [id for id in world_db["Things"] if world_db["Things"][id] != t if world_db["Things"][id]["T_LIFEPOINTS"] if world_db["Things"][id]["T_POSY"] == move_result[1] if world_db["Things"][id]["T_POSX"] == move_result[2]] if len(hitted): hit_id = hitted[0] hitted_tid = world_db["Things"][hit_id]["T_TYPE"] if t == world_db["Things"][0]: 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(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_use_attempts_hook(t, ty): if ty == world_db["SLIPPERS"]: if t == world_db["Things"][0]: log("You use the " + world_db["ThingTypes"][ty]["TT_NAME"] + ". " \ "It glows in wondrous colors, and emits a sound as if from a d" "ying cat. The Island God laughs.") t["T_LIFEPOINTS"] = 1 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") or world_db["MAP"][pos] == ord("|")): return for t_id in [t_id for t_id in world_db["Things"] if not world_db["Things"][t_id] == t if not world_db["Things"][t_id]["carried"] if world_db["Things"][t_id]["T_POSY"] == t["T_POSY"] if world_db["Things"][t_id]["T_POSX"] == t["T_POSX"]]: return wood_id = None for t_id in t["T_CARRIES"]: type_material = world_db["Things"][t_id]["T_TYPE"] if (world_db["ThingTypes"][type_material]["TT_TOOL"] == "wood"): wood_id = t_id break if wood_id != None: t["T_CARRIES"].remove(wood_id) del world_db["Things"][wood_id] world_db["MAP"][pos] = ord("|") log("With your " + world_db["ThingTypes"][ty]["TT_NAME"] + " you" \ " build a WOODEN BARRIER from your " + world_db["ThingTypes"][type_material]["TT_NAME"] + ".") elif world_db["ThingTypes"][ty]["TT_TOOL"] == "fertilizer": pos = t["T_POSY"] * world_db["MAP_LENGTH"] + t["T_POSX"] if world_db["MAP"][pos] == ord("."): log("You create SOIL.") world_db["MAP"][pos] = ord(":")
def decrement_lifepoints(t): from server.decrement_lifepoints import decrement_lifepoints live_tid = t["T_TYPE"] 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: 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