+ elif 3 == len(test):
+ if (t == world_db["Things"][0] and
+ test[1] == world_db["altar"][0] and
+ test[2] == world_db["altar"][1]):
+ enter_altar()
+
+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 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 command_worldactive_test_hook():
+ pos = world_db["MAP"].find(b'_')
+ if pos > 0:
+ y = int(pos / world_db["MAP_LENGTH"])
+ x = pos % world_db["MAP_LENGTH"]
+ world_db["altar"] = (y, x)
+ else:
+ print("Ignored: No altar defined for world to activate.")
+ return False
+ for name in world_db["specials"]:
+ if world_db[name] not in world_db["ThingTypes"]:
+ print("Ignored: Not all specials set for world to activate.")
+ return False
+ return True
+
+def play_move_attempt_hook(t, direction, pos):
+ if (ord("X") == world_db["MAP"][pos] or ord("|") == world_db["MAP"][pos]):
+ carries_axe = False
+ for tid in t["T_CARRIES"]:
+ ty = world_db["Things"][tid]["T_TYPE"]
+ if world_db["ThingTypes"][ty]["TT_TOOL"] == "axe":
+ world_db["Things"][0]["T_ARGUMENT"] = direction
+ set_command("move")
+ return True
+ return False
+
+def play_use_attempt_hook(t, tt):
+ pos = t["T_POSY"] * world_db["MAP_LENGTH"] + t["T_POSX"]
+ if tt["TT_TOOL"] == "axe":
+ log("To use this item for chopping, MOVE towards a tree while carrying"
+ " it in your inventory.")
+ return False
+ elif tt["TT_TOOL"] == "carpentry":
+ if (world_db["MAP"][pos] == ord("X")
+ or world_db["MAP"][pos] == ord("|")):
+ log("CAN'T build when standing on barrier.")
+ return False
+ for tid in [tid for tid in world_db["Things"]
+ if not world_db["Things"][tid] == t
+ if not world_db["Things"][tid]["carried"]
+ if world_db["Things"][tid]["T_POSY"] == t["T_POSY"]
+ if world_db["Things"][tid]["T_POSX"] == t["T_POSX"]]:
+ log("CAN'T build when standing objects.")
+ return False
+ wood_id = None
+ for tid in t["T_CARRIES"]:
+ type_material = world_db["Things"][tid]["T_TYPE"]
+ if world_db["ThingTypes"][type_material]["TT_TOOL"] == "wood":
+ wood_id = tid
+ break
+ if wood_id == None:
+ log("You CAN'T use a " + tt["TT_NAME"]
+ + " without some wood in your inventory.")
+ return False
+ return True
+ elif tt["TT_TOOL"] == "fertilizer":
+ if not world_db["MAP"][pos] == ord("."):
+ log("Can only make soil out of NON-SOIL earth.")
+ return False
+ return True
+ elif tt["TT_TOOL"] == "wood":
+ log("To use wood, you NEED a carpentry tool.")
+ return False
+ elif tt == world_db["ThingTypes"][world_db["SLIPPERS"]]:
+ return True
+
+def play_pickup_attempt_hook(t):
+ if len(t["T_CARRIES"]) >= world_db["ThingTypes"][t["T_TYPE"]]["TT_STORAGE"]:
+ log("CAN'T pick up: No storage room to carry anything more.")
+ return False
+ return True
+
+def specialtypesetter(name):
+ def helper(str_int):
+ val = integer_test(str_int, 0)
+ if None != val:
+ world_db[name] = val
+ if world_db["WORLD_ACTIVE"] \
+ and world_db[name] not in world_db["ThingTypes"]:
+ world_db["WORLD_ACTIVE"] = 0
+ print(name + " fits no known ThingType, deactivating world.")
+ return helper
+
+def write_metamap_A():
+ from server.worldstate_write_helpers import write_map
+ ord_v = ord("v")
+ length = world_db["MAP_LENGTH"]
+ metamapA = bytearray(b'0' * (length ** 2))
+ for tid in [tid for tid in world_db["Things"]
+ if not world_db["Things"][tid]["carried"]
+ if world_db["Things"][tid]["T_LIFEPOINTS"]
+ if world_db["Things"][0]["fovmap"][
+ world_db["Things"][tid]["pos"]] == ord_v]:
+ pos = (world_db["Things"][tid]["pos"])
+ if tid == 0 or world_db["EMPATHY"]:
+ ttid = world_db["Things"][tid]["T_TYPE"]
+ max_hp = world_db["ThingTypes"][ttid]["TT_LIFEPOINTS"]
+ third_of_hp = max_hp / 3
+ hp = world_db["Things"][tid]["T_LIFEPOINTS"]
+ add = 0
+ if hp > 2 * third_of_hp:
+ add = 2
+ elif hp > third_of_hp:
+ add = 1
+ metamapA[pos] = ord('a') + add
+ else:
+ metamapA[pos] = ord('X')
+ for mt in world_db["Things"][0]["T_MEMTHING"]:
+ pos = mt[1] * length + mt[2]
+ if metamapA[pos] < ord('2'):
+ metamapA[pos] += 1
+ return write_map(metamapA, length)
+
+def write_metamap_B():
+ from server.worldstate_write_helpers import write_map
+ ord_v = ord("v")
+ length = world_db["MAP_LENGTH"]
+ metamapB = bytearray(b' ' * (length ** 2))
+ for tid in [tid for tid in world_db["Things"]
+ if not world_db["Things"][tid]["carried"]
+ if world_db["Things"][tid]["T_LIFEPOINTS"]
+ if world_db["Things"][0]["fovmap"][
+ world_db["Things"][tid]["pos"]] == ord_v]:
+ pos = (world_db["Things"][tid]["pos"])
+ if tid == 0 or world_db["EMPATHY"]:
+ action = world_db["Things"][tid]["T_COMMAND"]
+ if 0 != action:
+ name = world_db["ThingActions"][action]["TA_NAME"]
+ else:
+ name = " "
+ metamapB[pos] = ord(name[0])
+ return write_map(metamapB, length)
+
+def calc_effort(thing_action, thing):
+ from math import sqrt
+ effort = thing_action["TA_EFFORT"]
+ if thing_action["TA_NAME"] == "move":
+ typ = thing["T_TYPE"]
+ max_hp = (world_db["ThingTypes"][typ]["TT_LIFEPOINTS"])
+ effort = int(effort / sqrt(max_hp))
+ effort = 1 if effort == 0 else effort
+ return effort
+