def make_world(seed): """(Re-)build game world, i.e. map, things, to a new turn 1 from seed. Seed rand with seed. Do more only with a "wait" ThingAction and world["PLAYER_TYPE"] matching ThingType of TT_START_NUMBER > 0. Then, world_db["Things"] emptied, call make_map() and set world_db["WORLD_ACTIVE"], world_db["TURN"] to 1. Build new Things according to ThingTypes' TT_START_NUMBERS, with Thing of ID 0 to ThingType of ID = world["PLAYER_TYPE"]. Place Things randomly, and actors not on each other. Init player's memory map. Write "NEW_WORLD" line to out file. """ def free_pos(type): i = 0 while 1: err = "Space to put thing on too hard to find. Map too small?" while 1: y = rand.next() % world_db["MAP_LENGTH"] x = rand.next() % world_db["MAP_LENGTH"] if chr(world_db["MAP"][y * world_db["MAP_LENGTH"] + x]) in \ symbols_passable and pos_test(type, y, x): break i += 1 if i == 65535: raise SystemExit(err) # Replica of C code, wrongly ignores animatedness of new Thing. pos_clear = (0 == len([id for id in world_db["Things"] if world_db["Things"][id]["T_LIFEPOINTS"] if world_db["Things"][id]["T_POSY"] == y if world_db["Things"][id]["T_POSX"] == x])) if pos_clear: break return (y, x) playertype = world_makable() if playertype < 0: return rand.seed = seed libpr.set_maplength(world_db["MAP_LENGTH"]) world_db["Things"] = {} make_map() world_db["WORLD_ACTIVE"] = 1 world_db["TURN"] = 1 for i in range(world_db["ThingTypes"][playertype]["TT_START_NUMBER"]): id = id_setter(-1, "Things") world_db["Things"][id] = new_Thing(playertype, free_pos(playertype)) if not world_db["Things"][0]["fovmap"]: empty_fovmap = bytearray(b" " * world_db["MAP_LENGTH"] ** 2) world_db["Things"][0]["fovmap"] = empty_fovmap update_map_memory(world_db["Things"][0]) for type in world_db["ThingTypes"]: for i in range(world_db["ThingTypes"][type]["TT_START_NUMBER"]): if type != playertype: id = id_setter(-1, "Things") world_db["Things"][id] = new_Thing(type, free_pos(type)) strong_write(io_db["file_out"], "NEW_WORLD\n")
def enter_altar(): from server.new_thing import new_Thing if world_db["FAVOR_STAGE"] > 9000: log("You step on a soul-less slab of stone.") return log("YOU ENTER SACRED GROUND.") if world_db["FAVOR_STAGE"] == 0: world_db["FAVOR_STAGE"] = 1 log(altar_msg_0) elif world_db["FAVOR_STAGE"] == 1 and world_db["GOD_FAVOR"] < 100: altar_msg_wait(100) elif world_db["FAVOR_STAGE"] == 1 and world_db["GOD_FAVOR"] >= 100: world_db["FAVOR_STAGE"] = 2 log(altar_msg_1) id = id_setter(-1, "Things") world_db["Things"][id] = new_Thing(world_db["PLANT_1"], world_db["altar"]) id = id_setter(-1, "Things") world_db["Things"][id] = new_Thing(world_db["TOOL_0"], world_db["altar"]) elif world_db["FAVOR_STAGE"] == 2 and \ 0 == len([id for id in world_db["Things"] if world_db["Things"][id]["T_TYPE"] == world_db["PLANT_1"]]): log(altar_msg_2) id = id_setter(-1, "Things") world_db["Things"][id] = new_Thing(world_db["PLANT_1"], world_db["altar"]) world_db["GOD_FAVOR"] -= 250 elif world_db["FAVOR_STAGE"] == 2 and world_db["GOD_FAVOR"] < 500: altar_msg_wait(500) elif world_db["FAVOR_STAGE"] == 2 and world_db["GOD_FAVOR"] >= 500: world_db["FAVOR_STAGE"] = 3 log(altar_msg_3) log(altar_msg_4) world_db["EMPATHY"] = 1 elif world_db["FAVOR_STAGE"] == 3 and world_db["GOD_FAVOR"] < 5000: altar_msg_wait(5000) elif world_db["FAVOR_STAGE"] == 3 and world_db["GOD_FAVOR"] >= 5000: world_db["FAVOR_STAGE"] = 4 log(altar_msg_5) id = id_setter(-1, "Things") world_db["Things"][id] = new_Thing(world_db["TOOL_1"], world_db["altar"]) elif world_db["GOD_FAVOR"] < 20000: altar_msg_wait(20000) elif world_db["GOD_FAVOR"] > 20000: world_db["FAVOR_STAGE"] = 9001 log(altar_msg_6) id = id_setter(-1, "Things") world_db["Things"][id] = new_Thing(world_db["SLIPPERS"], world_db["altar"])
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_attempts_hook(t, move_result, pos): if (ord("X") == world_db["MAP"][pos] or ord("|") == world_db["MAP"][pos]): for tid in t["T_CARRIES"]: ty = world_db["Things"][tid]["T_TYPE"] if world_db["ThingTypes"][ty]["TT_TOOL"] == "axe": axe_name = world_db["ThingTypes"][ty]["TT_NAME"] if t == world_db["Things"][0]: log("With your " + axe_name + ", you chop!") if ord("X") == world_db["MAP"][pos]: world_db["GOD_FAVOR"] -= 1 chop_power = world_db["ThingTypes"][ty]["TT_TOOLPOWER"] case_X = world_db["MAP"][pos] == ord("X") if (chop_power > 0 and ((case_X and 0 == int(rand.next() / chop_power)) or (not case_X and 0 == int(rand.next() / (3 * chop_power))))): if t == world_db["Things"][0]: log("You chop it DOWN.") if ord("X") == world_db["MAP"][pos]: world_db["GOD_FAVOR"] -= 10 world_db["MAP"][pos] = ord(".") i = 3 if case_X else 1 from server.new_thing import new_Thing for i in range(i): tid = id_setter(-1, "Things") world_db["Things"][tid] = new_Thing( world_db["LUMBER"], (move_result[1], move_result[2])) build_fov_map(t) return True return False
def actor_move_attempts_hook(t, move_result, pos): if (ord("X") == world_db["MAP"][pos] or ord("|") == world_db["MAP"][pos]): for tid in t["T_CARRIES"]: ty = world_db["Things"][tid]["T_TYPE"] if world_db["ThingTypes"][ty]["TT_TOOL"] == "axe": axe_name = world_db["ThingTypes"][ty]["TT_NAME"] if t == world_db["Things"][0]: log("With your " + axe_name + ", you chop!") if ord("X") == world_db["MAP"][pos]: world_db["GOD_FAVOR"] -= 1 chop_power = world_db["ThingTypes"][ty]["TT_TOOLPOWER"] case_X = world_db["MAP"][pos] == ord("X") if (chop_power > 0 and ((case_X and 0 == int(rand.next() / chop_power)) or (not case_X and 0 == int(rand.next() / (3 * chop_power))))): if t == world_db["Things"][0]: log("You chop it DOWN.") if ord("X") == world_db["MAP"][pos]: world_db["GOD_FAVOR"] -= 10 world_db["MAP"][pos] = ord(".") i = 3 if case_X else 1 from server.new_thing import new_Thing for i in range(i): tid = id_setter(-1, "Things") world_db["Things"][tid] = new_Thing(world_db["LUMBER"], (move_result[1], move_result[2])) build_fov_map(t) return True return False
def thingproliferation(t, prol_map): """To chance of 1/TT_PROLIFERATE, create t offspring in open neighbor cell. Naturally only works with TT_PROLIFERATE > 0. The neighbor cell must be be marked passable in prol_map. If there are several map cell candidates, one is selected randomly. """ from server.config.world_data import directions_db, world_db, \ thingprol_field_spreadable, thingprol_test_hook, \ thingprol_post_create_hook from server.utils import mv_yx_in_dir_legal, rand, id_setter from server.new_thing import new_Thing prolscore = world_db["ThingTypes"][t["T_TYPE"]]["TT_PROLIFERATE"] if prolscore and (1 == prolscore or 1 == (rand.next() % prolscore)) and \ thingprol_test_hook(t): candidates = [] for key in sorted(directions_db.keys()): mv_result = mv_yx_in_dir_legal(directions_db[key], t["T_POSY"], t["T_POSX"]) c = chr(prol_map[mv_result[1] * world_db["MAP_LENGTH"] + mv_result[2]]) if mv_result[0] and thingprol_field_spreadable(c, t): from server.io import log candidates.append((mv_result[1], mv_result[2])) if len(candidates): i = rand.next() % len(candidates) tid = id_setter(-1, "Things") newT = new_Thing(t["T_TYPE"], (candidates[i][0], candidates[i][1])) world_db["Things"][tid] = newT thingprol_post_create_hook(t)
def command_tid(id_string): """Set ID of Thing to manipulate. ID unused? Create new one. Default new Thing's type to the first available ThingType, others: zero. """ tid = id_setter(id_string, "Things", command_tid) if None != tid: if world_db["ThingTypes"] == {}: print("Ignoring: No ThingType to settle new Thing in.") return ty = list(world_db["ThingTypes"].keys())[0] from server.new_thing import new_Thing world_db["Things"][tid] = new_Thing(ty)
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