- print("World already active.")
- elif 0 == world_db["WORLD_ACTIVE"]:
- wait_exists = False
- for ThingAction in world_db["ThingActions"]:
- if "wait" == world_db["ThingActions"][ThingAction]["TA_NAME"]:
- wait_exists = True
- break
- player_exists = False
- for Thing in world_db["Things"]:
- if 0 == Thing:
- player_exists = True
- break
- altar_found = False
- if world_db["MAP"]:
- 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)
- altar_found = True
- if altar_found and wait_exists and player_exists and \
- world_db["MAP"]:
- for id in world_db["Things"]:
- if world_db["Things"][id]["T_LIFEPOINTS"]:
- build_fov_map(world_db["Things"][id])
- if 0 == id:
- update_map_memory(world_db["Things"][id], False)
- if not world_db["Things"][0]["T_LIFEPOINTS"]:
- empty_fovmap = bytearray(b" " * world_db["MAP_LENGTH"] ** 2)
- world_db["Things"][0]["fovmap"] = empty_fovmap
- world_db["WORLD_ACTIVE"] = 1
+ 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 " + world_db["ThingTypes"][type]["TT_NAME"]
+ + " without some wood in your inventory.")
+ return False
+ elif (tt["TT_TOOL"] == "fertilizer"
+ and not world_db["MAP"][pos] == ord(".")):
+ log("Can only make soil out of NON-SOIL earth.")
+ return False
+ elif tt["TT_TOOL"] == "wood":
+ log("To use wood, you NEED a carpentry tool.")
+ return False
+ elif type == 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 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"]