Exemplo n.º 1
0
def command_thingshere(str_y, str_x):
    """Write to out file list of Things known to player at coordinate y, x."""
    if world_db["WORLD_ACTIVE"]:
        y = integer_test(str_y, 0, 255)
        x = integer_test(str_x, 0, 255)
        length = world_db["MAP_LENGTH"]
        if None != y and None != x and y < length and x < length:
            pos = (y * world_db["MAP_LENGTH"]) + x
            strong_write(io_db["file_out"], "THINGS_HERE START\n")
            terrain = chr(world_db["Things"][0]["T_MEMMAP"][pos])
            terrain_name = world_db["terrain_names"][terrain]
            strong_write(io_db["file_out"], "terrain: " + terrain_name + "\n")
            if "v" == chr(world_db["Things"][0]["fovmap"][pos]):
                for id in [id for tid in sorted(list(world_db["ThingTypes"]))
                              for id in world_db["Things"]
                              if not world_db["Things"][id]["carried"]
                              if world_db["Things"][id]["T_TYPE"] == tid
                              if pos == world_db["Things"][id]["pos"]]:
                    type = world_db["Things"][id]["T_TYPE"]
                    name = world_db["ThingTypes"][type]["TT_NAME"]
                    strong_write(io_db["file_out"], name + "\n")
            else:
                for mt in [mt for tid in sorted(list(world_db["ThingTypes"]))
                              for mt in world_db["Things"][0]["T_MEMTHING"]
                              if mt[0] == tid if y == mt[1] if x == mt[2]]:
                    name = world_db["ThingTypes"][mt[0]]["TT_NAME"]
                    strong_write(io_db["file_out"], name + "\n")
            strong_write(io_db["file_out"], "THINGS_HERE END\n")
        else:
            print("Ignoring: Invalid map coordinates.")
    else:
        print("Ignoring: Command only works on existing worlds.")
Exemplo n.º 2
0
def command_tmemthing(str_t, str_y, str_x):
    """Add (int(str_t), int(str_y), int(str_x)) to selected Thing's T_MEMTHING.

    The type must fit to an existing ThingType, and the position into the map.
    """
    type = integer_test(str_t, 0)
    posy = integer_test(str_y, 0, 255)
    posx = integer_test(str_x, 0, 255)
    if None != type and None != posy and None != posx:
        if type not in world_db["ThingTypes"] \
           or posy >= world_db["MAP_LENGTH"] or posx >= world_db["MAP_LENGTH"]:
            print("Ignoring: Illegal value for thing type or position.")
        else:
            memthing = (type, posy, posx)
            world_db["Things"][command_tid.id]["T_MEMTHING"].append(memthing)
Exemplo n.º 3
0
def command_tmemthing(str_t, str_y, str_x):
    """Add (int(str_t), int(str_y), int(str_x)) to selected Thing's T_MEMTHING.

    The type must fit to an existing ThingType, and the position into the map.
    """
    type = integer_test(str_t, 0)
    posy = integer_test(str_y, 0, 255)
    posx = integer_test(str_x, 0, 255)
    if None != type and None != posy and None != posx:
        if type not in world_db["ThingTypes"] \
           or posy >= world_db["MAP_LENGTH"] or posx >= world_db["MAP_LENGTH"]:
            print("Ignoring: Illegal value for thing type or position.")
        else:
            memthing = (type, posy, posx)
            world_db["Things"][command_tid.id]["T_MEMTHING"].append(memthing)
Exemplo n.º 4
0
def command_tcommand(str_int):
    """Set T_COMMAND of selected Thing."""
    val = integer_test(str_int, 0)
    if None != val:
        if 0 == val or val in world_db["ThingActions"]:
            world_db["Things"][command_tid.id]["T_COMMAND"] = val
        else:
            print("Ignoring: ThingAction ID belongs to no known ThingAction.")
Exemplo n.º 5
0
def command_ttcorpseid(str_int):
    """Set TT_CORPSE_ID of selected ThingType."""
    val = integer_test(str_int, 0)
    if None != val:
        if val in world_db["ThingTypes"]:
            world_db["ThingTypes"][command_ttid.id]["TT_CORPSE_ID"] = val
        else:
            print("Ignoring: Corpse ID belongs to no known ThignType.")
Exemplo n.º 6
0
def command_ttcorpseid(str_int):
    """Set TT_CORPSE_ID of selected ThingType."""
    val = integer_test(str_int, 0)
    if None != val:
        if val in world_db["ThingTypes"]:
            world_db["ThingTypes"][command_ttid.id]["TT_CORPSE_ID"] = val
        else:
            print("Ignoring: Corpse ID belongs to no known ThignType.")
Exemplo n.º 7
0
def command_ttype(str_int):
    """Set T_TYPE of selected Thing."""
    val = integer_test(str_int, 0)
    if None != val:
        if val in world_db["ThingTypes"]:
            world_db["Things"][command_tid.id]["T_TYPE"] = val
        else:
            print("Ignoring: ThingType ID belongs to no known ThingType.")
Exemplo n.º 8
0
def command_ttype(str_int):
    """Set T_TYPE of selected Thing."""
    val = integer_test(str_int, 0)
    if None != val:
        if val in world_db["ThingTypes"]:
            world_db["Things"][command_tid.id]["T_TYPE"] = val
        else:
            print("Ignoring: ThingType ID belongs to no known ThingType.")
Exemplo n.º 9
0
def command_tcommand(str_int):
    """Set T_COMMAND of selected Thing."""
    val = integer_test(str_int, 0)
    if None != val:
        if 0 == val or val in world_db["ThingActions"]:
            world_db["Things"][command_tid.id]["T_COMMAND"] = val
        else:
            print("Ignoring: ThingAction ID belongs to no known ThingAction.")
Exemplo n.º 10
0
 def valid_map_line(str_int, mapline):
     val = integer_test(str_int, 0, 255)
     if None != val:
         if val >= world_db["MAP_LENGTH"]:
             print("Illegal value for map line number.")
         elif len(mapline) != world_db["MAP_LENGTH"]:
             print("Map line length is unequal map width.")
         else:
             return val
     return None
Exemplo n.º 11
0
def command_maplength(maplength_string):
    """Redefine map length. Invalidate map, therefore lose all things on it."""
    val = integer_test(maplength_string, 1, 256)
    if None != val:
        from server.utils import libpr
        world_db["MAP_LENGTH"] = val
        world_db["MAP"] = False
        set_world_inactive()
        world_db["Things"] = {}
        libpr.set_maplength(val)
Exemplo n.º 12
0
def command_maplength(maplength_string):
    """Redefine map length. Invalidate map, therefore lose all things on it."""
    val = integer_test(maplength_string, 1, 256)
    if None != val:
        from server.utils import libpr
        world_db["MAP_LENGTH"] = val
        world_db["MAP"] = False
        set_world_inactive()
        world_db["Things"] = {}
        libpr.set_maplength(val)
Exemplo n.º 13
0
 def valid_map_line(str_int, mapline):
     val = integer_test(str_int, 0, 255)
     if None != val:
         if val >= world_db["MAP_LENGTH"]:
             print("Illegal value for map line number.")
         elif len(mapline) != world_db["MAP_LENGTH"]:
             print("Map line length is unequal map width.")
         else:
             return val
     return None
Exemplo n.º 14
0
def play_drop(str_arg):
    """Try "drop" as player's T_COMMAND, int(str_arg) as T_ARGUMENT / slot."""
    if action_exists("drop") and world_db["WORLD_ACTIVE"]:
        t = world_db["Things"][0]
        if 0 == len(t["T_CARRIES"]):
            log("You have NOTHING to drop in your inventory.")
        else:
            val = integer_test(str_arg, 0, 255)
            if None != val and val < len(t["T_CARRIES"]):
                world_db["Things"][0]["T_ARGUMENT"] = val
                set_command("drop")
            else:
                print("Illegal inventory index.")
Exemplo n.º 15
0
def play_drop(str_arg):
    """Try "drop" as player's T_COMMAND, int(str_arg) as T_ARGUMENT / slot."""
    if action_exists("drop") and world_db["WORLD_ACTIVE"]:
        t = world_db["Things"][0]
        if 0 == len(t["T_CARRIES"]):
            log("You have NOTHING to drop in your inventory.")
        else:
            val = integer_test(str_arg, 0, 255)
            if None != val and val < len(t["T_CARRIES"]):
                world_db["Things"][0]["T_ARGUMENT"] = val
                set_command("drop")
            else:
                print("Illegal inventory index.")
Exemplo n.º 16
0
 def helper(str_int):
     val = integer_test(str_int, 0, 255)
     if None != val:
         if val < world_db["MAP_LENGTH"]:
             t = world_db["Things"][command_tid.id]
             t["T_POS" + axis] = val
             t["pos"] = t["T_POSY"] * world_db["MAP_LENGTH"] + t["T_POSX"]
             if world_db["WORLD_ACTIVE"] \
                and world_db["Things"][command_tid.id]["T_LIFEPOINTS"]:
                 build_fov_map(world_db["Things"][command_tid.id])
                 if 0 == command_tid.id:
                     update_map_memory(world_db["Things"][command_tid.id])
         else:
             print("Ignoring: Position is outside of map.")
Exemplo n.º 17
0
 def helper(str_int):
     val = integer_test(str_int, 0, 255)
     if None != val:
         if val < world_db["MAP_LENGTH"]:
             t = world_db["Things"][command_tid.id]
             t["T_POS" + axis] = val
             t["pos"] = t["T_POSY"] * world_db["MAP_LENGTH"] + t["T_POSX"]
             if world_db["WORLD_ACTIVE"] \
                and world_db["Things"][command_tid.id]["T_LIFEPOINTS"]:
                 build_fov_map(world_db["Things"][command_tid.id])
                 if 0 == command_tid.id:
                     update_map_memory(world_db["Things"][command_tid.id])
         else:
             print("Ignoring: Position is outside of map.")
Exemplo n.º 18
0
def command_thingshere(str_y, str_x):
    """Write to out file list of Things known to player at coordinate y, x."""
    if world_db["WORLD_ACTIVE"]:
        y = integer_test(str_y, 0, 255)
        x = integer_test(str_x, 0, 255)
        length = world_db["MAP_LENGTH"]
        if None != y and None != x and y < length and x < length:
            pos = (y * world_db["MAP_LENGTH"]) + x
            strong_write(io_db["file_out"], "THINGS_HERE START\n")
            terrain = chr(world_db["Things"][0]["T_MEMMAP"][pos])
            terrain_name = world_db["terrain_names"][terrain]
            strong_write(io_db["file_out"], "terrain: " + terrain_name + "\n")
            if "v" == chr(world_db["Things"][0]["fovmap"][pos]):
                for id in [
                        id for tid in sorted(list(world_db["ThingTypes"]))
                        for id in world_db["Things"]
                        if not world_db["Things"][id]["carried"]
                        if world_db["Things"][id]["T_TYPE"] == tid
                        if pos == world_db["Things"][id]["pos"]
                ]:
                    type = world_db["Things"][id]["T_TYPE"]
                    name = world_db["ThingTypes"][type]["TT_NAME"]
                    strong_write(io_db["file_out"], name + "\n")
            else:
                for mt in [
                        mt for tid in sorted(list(world_db["ThingTypes"]))
                        for mt in world_db["Things"][0]["T_MEMTHING"]
                        if mt[0] == tid if y == mt[1] if x == mt[2]
                ]:
                    name = world_db["ThingTypes"][mt[0]]["TT_NAME"]
                    strong_write(io_db["file_out"], name + "\n")
            strong_write(io_db["file_out"], "THINGS_HERE END\n")
        else:
            print("Ignoring: Invalid map coordinates.")
    else:
        print("Ignoring: Command only works on existing worlds.")
Exemplo n.º 19
0
def command_tcarries(str_int):
    """Append int(str_int) to T_CARRIES of selected Thing.

    The ID int(str_int) must not be of the selected Thing, and must belong to a
    Thing with unset "carried" flag. Its "carried" flag will be set on owning.
    """
    val = integer_test(str_int, 0)
    if None != val:
        if val == command_tid.id:
            print("Ignoring: Thing cannot carry itself.")
        elif val in world_db["Things"] \
                and not world_db["Things"][val]["carried"]:
            world_db["Things"][command_tid.id]["T_CARRIES"].append(val)
            world_db["Things"][val]["carried"] = True
        else:
            print("Ignoring: Thing not available for carrying.")
Exemplo n.º 20
0
def command_tcarries(str_int):
    """Append int(str_int) to T_CARRIES of selected Thing.

    The ID int(str_int) must not be of the selected Thing, and must belong to a
    Thing with unset "carried" flag. Its "carried" flag will be set on owning.
    """
    val = integer_test(str_int, 0)
    if None != val:
        if val == command_tid.id:
            print("Ignoring: Thing cannot carry itself.")
        elif val in world_db["Things"] \
                and not world_db["Things"][val]["carried"]:
            world_db["Things"][command_tid.id]["T_CARRIES"].append(val)
            world_db["Things"][val]["carried"] = True
        else:
            print("Ignoring: Thing not available for carrying.")
Exemplo n.º 21
0
def command_worldactive(worldactive_string):
    """Toggle world_db["WORLD_ACTIVE"] if possible.

    An active world can always be set inactive. An inactive world can only be
    set active with a "wait" ThingAction, and a player Thing (of ID 0), and a
    map. On activation, rebuild all Things' FOVs, and the player's map memory.
    """
    val = integer_test(worldactive_string, 0, 1)
    if None != val:
        if 0 != world_db["WORLD_ACTIVE"]:
            if 0 == val:
                set_world_inactive()
            else:
                print("World already active.")
        elif 0 == world_db["WORLD_ACTIVE"]:
            for ThingAction in world_db["ThingActions"]:
                if "wait" == world_db["ThingActions"][ThingAction]["TA_NAME"]:
                    break
            else:
                print("Ignored: No wait action defined for world to activate.")
                return
            for Thing in world_db["Things"]:
                if 0 == Thing:
                    break
            else:
                print("Ignored: No player defined for world to activate.")
                return
            if not world_db["MAP"]:
                print("Ignoring: No map defined for world to activate.")
                return
            from server.config.commands import command_worldactive_test_hook
            if not command_worldactive_test_hook():
                return
            for tid in world_db["Things"]:
                if world_db["Things"][tid]["T_LIFEPOINTS"]:
                    build_fov_map(world_db["Things"][tid])
                    if 0 == tid:
                        update_map_memory(world_db["Things"][tid], 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
Exemplo n.º 22
0
def command_worldactive(worldactive_string):
    """Toggle world_db["WORLD_ACTIVE"] if possible.

    An active world can always be set inactive. An inactive world can only be
    set active with a "wait" ThingAction, and a player Thing (of ID 0), and a
    map. On activation, rebuild all Things' FOVs, and the player's map memory.
    """
    val = integer_test(worldactive_string, 0, 1)
    if None != val:
        if 0 != world_db["WORLD_ACTIVE"]:
            if 0 == val:
                set_world_inactive()
            else:
                print("World already active.")
        elif 0 == world_db["WORLD_ACTIVE"]:
            for ThingAction in world_db["ThingActions"]:
                if "wait" == world_db["ThingActions"][ThingAction]["TA_NAME"]:
                    break
            else:
                print("Ignored: No wait action defined for world to activate.")
                return
            for Thing in world_db["Things"]:
                if 0 == Thing:
                    break
            else:
                print("Ignored: No player defined for world to activate.")
                return
            if not world_db["MAP"]:
                print("Ignoring: No map defined for world to activate.")
                return
            from server.config.commands import command_worldactive_test_hook
            if not command_worldactive_test_hook():
                return
            for tid in world_db["Things"]:
                if world_db["Things"][tid]["T_LIFEPOINTS"]:
                    build_fov_map(world_db["Things"][tid])
                    if 0 == tid:
                        update_map_memory(world_db["Things"][tid], 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
Exemplo n.º 23
0
def play_use(str_arg):
    """Try "use" as player's T_COMMAND, int(str_arg) as T_ARGUMENT / slot."""
    if action_exists("use") and world_db["WORLD_ACTIVE"]:
        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"]):
                tid = t["T_CARRIES"][val]
                tt = world_db["ThingTypes"][world_db["Things"][tid]["T_TYPE"]]
                from server.config.commands import play_use_attempt_hook
                hook_test = play_use_attempt_hook(t, tt)
                if not (tt["TT_TOOL"] == "food" or hook_test):
                    if hook_test != False:
                        log("You CAN'T use this thing.")
                    return
                world_db["Things"][0]["T_ARGUMENT"] = val
                set_command("use")
            else:
                print("Illegal inventory index.")
Exemplo n.º 24
0
def play_use(str_arg):
    """Try "use" as player's T_COMMAND, int(str_arg) as T_ARGUMENT / slot."""
    if action_exists("use") and world_db["WORLD_ACTIVE"]:
        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"]):
                tid = t["T_CARRIES"][val]
                tt = world_db["ThingTypes"][world_db["Things"][tid]["T_TYPE"]]
                from server.config.commands import play_use_attempt_hook
                hook_test = play_use_attempt_hook(t, tt)
                if not (tt["TT_TOOL"] == "food" or hook_test):
                    if hook_test != False:
                        log("You CAN'T use this thing.")
                    return
                world_db["Things"][0]["T_ARGUMENT"] = val
                set_command("use")
            else:
                print("Illegal inventory index.")
Exemplo n.º 25
0
def command_makeworld(seed_string):
    """Call make_world()."""
    val = integer_test(seed_string, 0, 4294967295)
    if None != val:
        from server.make_world import make_world
        make_world(val)
Exemplo n.º 26
0
def command_seedrandomness(seed_string):
    """Set rand seed to int(seed_string)."""
    from server.utils import rand
    val = integer_test(seed_string, 0, 4294967295)
    if None != val:
        rand.seed = val
Exemplo n.º 27
0
 def f(val_string):
     val = integer_test(val_string, min, max)
     if None != val:
         world_db[key] = val
Exemplo n.º 28
0
 def f(val_string):
     val = integer_test(val_string, min, max)
     if None != val:
         world_db[category + "s"][id_store.id][key] = val
Exemplo n.º 29
0
def command_seedrandomness(seed_string):
    """Set rand seed to int(seed_string)."""
    from server.utils import rand
    val = integer_test(seed_string, 0, 4294967295)
    if None != val:
        rand.seed = val
Exemplo n.º 30
0
 def f(val_string):
     val = integer_test(val_string, min, max)
     if None != val:
         world_db[category + "s"][id_store.id][key] = val
Exemplo n.º 31
0
 def f(val_string):
     val = integer_test(val_string, min, max)
     if None != val:
         world_db[key] = val
Exemplo n.º 32
0
def command_makeworld(seed_string):
    """Call make_world()."""
    val = integer_test(seed_string, 0, 4294967295)
    if None != val:
        from server.make_world import make_world
        make_world(val)