+def play_move(str_arg):
+ if action_exists("move"):
+ from server.config.world_data import directions_db, symbols_passable
+ t = world_db["Things"][0]
+ if not str_arg in directions_db:
+ print("Illegal move direction string.")
+ return
+ dir = ord(directions_db[str_arg])
+ from server.utils import mv_yx_in_dir_legal
+ move_result = mv_yx_in_dir_legal(chr(dir), t["T_POSY"], t["T_POSX"])
+ if 1 == move_result[0]:
+ pos = (move_result[1] * world_db["MAP_LENGTH"]) + move_result[2]
+ if ord("~") == world_db["MAP"][pos]:
+ log("You can't SWIM.")
+ return
+ if (ord("X") == world_db["MAP"][pos]
+ or ord("|") == world_db["MAP"][pos]):
+ carries_axe = False
+ for id in t["T_CARRIES"]:
+ type = world_db["Things"][id]["T_TYPE"]
+ if world_db["ThingTypes"][type]["TT_TOOL"] == "axe":
+ world_db["Things"][0]["T_ARGUMENT"] = dir
+ set_command("move")
+ return
+ if chr(world_db["MAP"][pos]) in symbols_passable:
+ world_db["Things"][0]["T_ARGUMENT"] = dir
+ set_command("move")
+ return
+ log("You CAN'T move there.")
+
+def play_use(str_arg):
+ if action_exists("use"):
+ t = world_db["Things"][0]
+ if 0 == len(t["T_CARRIES"]):
+ log("You have NOTHING to use in your inventory.")
+ else:
+ val = integer_test(str_arg, 0, 255)
+ if None != val and val < len(t["T_CARRIES"]):
+ id = t["T_CARRIES"][val]
+ type = world_db["Things"][id]["T_TYPE"]
+ if (world_db["ThingTypes"][type]["TT_TOOL"] == "axe"
+ and t == world_db["Things"][0]):
+ log("To use this item for chopping, move towards a tree "
+ "while carrying it in your inventory.")
+ return
+ elif (world_db["ThingTypes"][type]["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("|")):
+ log("CAN'T build when standing on barrier.")
+ return
+ for id in [id for id in world_db["Things"]
+ if not 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"]]:
+ log("CAN'T build when standing objects.")
+ return
+ wood_id = None
+ for id in t["T_CARRIES"]:
+ type_material = world_db["Things"][id]["T_TYPE"]
+ if (world_db["ThingTypes"][type_material]["TT_TOOL"]
+ == "wood"):
+ wood_id = id
+ break
+ if wood_id == None:
+ log("You CAN'T use a "
+ + world_db["ThingTypes"][type]["TT_NAME"]
+ + " without some wood in your inventory.")
+ return
+ elif world_db["ThingTypes"][type]["TT_TOOL"] == "fertilizer":
+ pos = t["T_POSY"] * world_db["MAP_LENGTH"] + t["T_POSX"]
+ if not world_db["MAP"][pos] == ord("."):
+ log("Can only make soil out of NON-SOIL earth.")
+ return
+ elif world_db["ThingTypes"][type]["TT_TOOL"] == "wood":
+ log("To use wood, you NEED a carpentry tool.")
+ return
+ elif type != world_db["SLIPPERS"] and not \
+ world_db["ThingTypes"][type]["TT_TOOL"] == "food":
+ log("You CAN'T consume this thing.")
+ return
+ world_db["Things"][0]["T_ARGUMENT"] = val
+ set_command("use")
+ else:
+ print("Illegal inventory index.")
+
+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 id in [id for id in world_db["Things"]
+ if not world_db["Things"][id]["carried"]
+ if world_db["Things"][id]["T_LIFEPOINTS"]
+ if world_db["Things"][0]["fovmap"][
+ world_db["Things"][id]["T_POSY"] * length
+ + world_db["Things"][id]["T_POSX"]] == ord_v]:
+ pos = (world_db["Things"][id]["T_POSY"] * length
+ + world_db["Things"][id]["T_POSX"])
+ if id == 0 or world_db["EMPATHY"]:
+ type = world_db["Things"][id]["T_TYPE"]
+ max_hp = world_db["ThingTypes"][type]["TT_LIFEPOINTS"]
+ third_of_hp = max_hp / 3
+ hp = world_db["Things"][id]["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 id in [id for id in world_db["Things"]
+ if not world_db["Things"][id]["carried"]
+ if world_db["Things"][id]["T_LIFEPOINTS"]
+ if world_db["Things"][0]["fovmap"][
+ world_db["Things"][id]["T_POSY"] * length
+ + world_db["Things"][id]["T_POSX"]] == ord_v]:
+ pos = (world_db["Things"][id]["T_POSY"] * length
+ + world_db["Things"][id]["T_POSX"])
+ if id == 0 or world_db["EMPATHY"]:
+ action = world_db["Things"][id]["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
+
+def play_pickup():
+ """Try "pickup" as player's T_COMMAND"."""
+ if action_exists("pickup"):
+ t = world_db["Things"][0]
+ ids = [id for id in world_db["Things"] if id
+ 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 not len(ids):
+ log("NOTHING to pick up.")
+ elif len(t["T_CARRIES"]) >= world_db["ThingTypes"][t["T_TYPE"]] \
+ ["TT_STORAGE"]:
+ log("CAN'T pick up: No storage room to carry anything more.")
+ else:
+ set_command("pickup")