示例#1
0
def actor_move(t):
    """If passable, move/collide(=attack) thing into T_ARGUMENT's direction.

    On attack, return 0 on non-kill and TT_LIFEPOINTS of killed type on kill,
    plus type id of attacked Thing. On move, return mv_yx_in_dir_legal result.
    """
    from server.build_fov_map import build_fov_map
    from server.config.misc import decrement_lifepoints
    from server.utils import mv_yx_in_dir_legal
    from server.config.world_data import directions_db, symbols_passable
    passable = False
    move_result = mv_yx_in_dir_legal(chr(t["T_ARGUMENT"]), t["T_POSY"],
                                     t["T_POSX"])
    if 1 == move_result[0]:
        pos = (move_result[1] * world_db["MAP_LENGTH"]) + move_result[2]
        hitted = [
            id for id in world_db["Things"] if world_db["Things"][id] != t
            if world_db["Things"][id]["T_LIFEPOINTS"]
            if world_db["Things"][id]["T_POSY"] == move_result[1]
            if world_db["Things"][id]["T_POSX"] == move_result[2]
        ]
        if len(hitted):
            hit_id = hitted[0]
            hitted_tid = world_db["Things"][hit_id]["T_TYPE"]
            if t == world_db["Things"][0]:
                hitted_name = world_db["ThingTypes"][hitted_tid]["TT_NAME"]
                log("You WOUND " + hitted_name + ".")
            elif 0 == hit_id:
                hitter_name = world_db["ThingTypes"][t["T_TYPE"]]["TT_NAME"]
                log(hitter_name + " WOUNDS you.")
            decr_test = decrement_lifepoints(world_db["Things"][hit_id])
            if decr_test > 0 and t == world_db["Things"][0]:
                log(hitted_name + " dies.")
            return decr_test, hitted_tid
        from server.config.actions import actor_move_attempts_hook
        if actor_move_attempts_hook(t, move_result, pos):
            return
        passable = chr(world_db["MAP"][pos]) in symbols_passable
    dir = [
        dir for dir in directions_db
        if directions_db[dir] == chr(t["T_ARGUMENT"])
    ][0]
    if passable:
        t["T_POSY"] = move_result[1]
        t["T_POSX"] = move_result[2]
        t["pos"] = move_result[1] * world_db["MAP_LENGTH"] + move_result[2]
        for id in t["T_CARRIES"]:
            world_db["Things"][id]["T_POSY"] = move_result[1]
            world_db["Things"][id]["T_POSX"] = move_result[2]
            world_db["Things"][id]["pos"] = t["pos"]
        build_fov_map(t)
        if t == world_db["Things"][0]:
            log("You MOVE " + dir + ".")
        return move_result
示例#2
0
def actor_move(t):
    """If passable, move/collide(=attack) thing into T_ARGUMENT's direction.

    On attack, return 0 on non-kill and TT_LIFEPOINTS of killed type on kill,
    plus type id of attacked Thing. On move, return mv_yx_in_dir_legal result.
    """
    from server.build_fov_map import build_fov_map
    from server.config.misc import decrement_lifepoints
    from server.utils import mv_yx_in_dir_legal
    from server.config.world_data import directions_db, symbols_passable
    passable = False
    move_result = mv_yx_in_dir_legal(chr(t["T_ARGUMENT"]),
                                     t["T_POSY"], t["T_POSX"])
    if 1 == move_result[0]:
        pos = (move_result[1] * world_db["MAP_LENGTH"]) + move_result[2]
        hitted = [id for id in world_db["Things"]
                  if world_db["Things"][id] != t
                  if world_db["Things"][id]["T_LIFEPOINTS"]
                  if world_db["Things"][id]["T_POSY"] == move_result[1]
                  if world_db["Things"][id]["T_POSX"] == move_result[2]]
        if len(hitted):
            hit_id = hitted[0]
            hitted_tid = world_db["Things"][hit_id]["T_TYPE"]
            if t == world_db["Things"][0]:
                hitted_name = world_db["ThingTypes"][hitted_tid]["TT_NAME"]
                log("You WOUND " + hitted_name + ".")
            elif 0 == hit_id:
                hitter_name = world_db["ThingTypes"][t["T_TYPE"]]["TT_NAME"]
                log(hitter_name +" WOUNDS you.")
            decr_test = decrement_lifepoints(world_db["Things"][hit_id])
            if decr_test > 0 and t == world_db["Things"][0]:
                log(hitted_name + " dies.")
            return decr_test, hitted_tid
        from server.config.actions import actor_move_attempts_hook
        if actor_move_attempts_hook(t, move_result, pos):
            return
        passable = chr(world_db["MAP"][pos]) in symbols_passable
    dir = [dir for dir in directions_db
           if directions_db[dir] == chr(t["T_ARGUMENT"])][0]
    if passable:
        t["T_POSY"] = move_result[1]
        t["T_POSX"] = move_result[2]
        t["pos"] = move_result[1] * world_db["MAP_LENGTH"] + move_result[2]
        for id in t["T_CARRIES"]:
            world_db["Things"][id]["T_POSY"] = move_result[1]
            world_db["Things"][id]["T_POSX"] = move_result[2]
            world_db["Things"][id]["pos"] = t["pos"]
        build_fov_map(t)
        if t == world_db["Things"][0]:
            log("You MOVE " + dir + ".")
        return move_result
示例#3
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.")
示例#4
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.")
示例#5
0
def new_Thing(_type, pos=(0, 0)):
    """Return Thing of type T_TYPE, with fovmap if alive and world active."""
    from server.config.world_data import thing_defaults, world_db
    from server.build_fov_map import build_fov_map
    thing = {}
    for key in thing_defaults:
        thing[key] = thing_defaults[key]
        if type(thing[key]) == list:
            thing[key] = thing[key][:]
    thing["T_LIFEPOINTS"] = world_db["ThingTypes"][_type]["TT_LIFEPOINTS"]
    thing["T_TYPE"] = _type
    thing["T_POSY"] = pos[0]
    thing["T_POSX"] = pos[1]
    thing["pos"] = thing["T_POSY"] * world_db["MAP_LENGTH"] + thing["T_POSX"]
    if world_db["WORLD_ACTIVE"] and thing["T_LIFEPOINTS"]:
        build_fov_map(thing)
    return thing
示例#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
示例#7
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