Example #1
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)
Example #2
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)
Example #3
0
def command_taname(name):
    """Set TA_NAME of selected ThingAction.

    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 name == "wait" or name == "move" or name == "use" or name == "drop" \
       or name == "pickup":
        world_db["ThingActions"][command_taid.id]["TA_NAME"] = name
        if 1 == world_db["WORLD_ACTIVE"]:
            for id in world_db["ThingActions"]:
                if "wait" == world_db["ThingActions"][id]["TA_NAME"]:
                    break
            else:
                set_world_inactive()
    else:
        print("Ignoring: Invalid action name.")
Example #4
0
def command_taname(name):
    """Set TA_NAME of selected ThingAction.

    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 name == "wait" or name == "move" or name == "use" or name == "drop" \
       or name == "pickup":
        world_db["ThingActions"][command_taid.id]["TA_NAME"] = name
        if 1 == world_db["WORLD_ACTIVE"]:
            for id in world_db["ThingActions"]:
                if "wait" == world_db["ThingActions"][id]["TA_NAME"]:
                    break
            else:
                set_world_inactive()
    else:
        print("Ignoring: Invalid action name.")
Example #5
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
Example #6
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