+ if 0 == id:
+ while 1:
+ id = id + 1
+ if id not in world_db["ThingActions"]:
+ break
+ if id > 255:
+ print("Ignoring: "
+ "No unused ID available to add to ID list.")
+ return
+ world_db["ThingActions"][id] = {
+ "TA_EFFORT": 1,
+ "TA_NAME": "wait"
+ }
+ command_taid.id = id
+
+
+def command_taeffort(str_int):
+ """Set to int(str_int) effort value of ThingAction of command_taid.id."""
+ if hasattr(command_taid, "id"):
+ val = integer_test(str_int, 0, 255)
+ if val:
+ world_db["ThingActions"][command_taid.id]["TA_EFFORT"] = val
+ else:
+ print("Ignoring: No thing action defined to manipulate yet.")
+
+
+def command_taname(name):
+ """Set to name name value of ThingAction of command_taid.id.
+
+ The name must match a valid thing action function. If after the name
+ setting no ThingAction with name "wait" remains, call set_world_inactive().
+ """
+ if hasattr(command_taid, "id"):
+ if name == "wait" or name == "move" or name == "use" \
+ or name == "drop" or name == "pick_up":
+ world_db["ThingActions"][command_taid.id]["TA_NAME"] = name
+ if 1 == world_db["WORLD_ACTIVE"]:
+ wait_defined = False
+ for id in world_db["ThingActions"]:
+ if "wait" == world_db["ThingActions"][id]["TA_NAME"]:
+ wait_defined = True
+ break
+ if not wait_defined:
+ set_world_inactive()
+ else:
+ print("Ignoring: Invalid action name.")
+ else:
+ print("Ignoring: No thing action defined to manipulate yet.")
+ # In contrast to the original,naming won't map a function to a ThingAction.
+
+
+"""Commands database.
+
+Map command start tokens to ([0]) number of expected command arguments, ([1])
+the command's meta-ness (i.e. is it to be written to the record file, is it to
+be ignored in replay mode if read from server input file), and ([2]) a function
+to be called on it.
+"""
+commands_db = {
+ "QUIT": (0, True, command_quit),
+ "PING": (0, True, command_ping),
+ "MAKE_WORLD": (1, False, command_makeworld),
+ "SEED_MAP": (1, False, command_seedmap),
+ "SEED_RANDOMNESS": (1, False, worlddb_value_setter("SEED_RANDOMNESS", 0,
+ 4294967295)),
+ "TURN": (1, False, worlddb_value_setter("TURN", 0, 65535)),
+ "PLAYER_TYPE": (1, False, worlddb_value_setter("PLAYER_TYPE", 0, 255)),
+ "MAP_LENGTH": (1, False, command_maplength),
+ "WORLD_ACTIVE": (1, False, command_worldactive),
+ "TA_ID": (1, False, command_taid),
+ "TA_EFFORT": (1, False, command_taeffort),
+ "TA_NAME": (1, False, command_taname)
+}
+
+
+"""World state database. With sane default values."""
+world_db = {
+ "TURN": 1,
+ "SEED_MAP": 0,
+ "SEED_RANDOMNESS": 0,
+ "PLAYER_TYPE": 0,
+ "MAP_LENGTH": 64,
+ "WORLD_ACTIVE": 0,
+ "ThingActions": {},
+ "ThingTypes": {},
+ "Things": {}
+}
+
+
+"""File IO database."""
+io_db = {
+ "path_save": "save",
+ "path_record": "record",
+ "path_worldconf": "confserver/world",
+ "path_server": "server/",
+ "path_in": "server/in",
+ "path_out": "server/out",
+ "path_worldstate": "server/worldstate",
+ "tmp_suffix": "_tmp",
+ "kicked_by_rival": False
+}
+
+
+try:
+ opts = parse_command_line_arguments()
+ setup_server_io()
+ # print("DUMMY: Run game.")
+ if None != opts.replay:
+ replay_game()
+ else:
+ play_game()