示例#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.")
示例#2
0
def make_world(seed):
    """(Re-)build game world, i.e. map, things, to a new turn 1 from seed.

    Seed rand with seed. Do more only with a "wait" ThingAction and
    world["PLAYER_TYPE"] matching ThingType of TT_START_NUMBER > 0. Then,
    world_db["Things"] emptied, call make_map() and set
    world_db["WORLD_ACTIVE"], world_db["TURN"] to 1. Build new Things
    according to ThingTypes' TT_START_NUMBERS, with Thing of ID 0 to ThingType
    of ID = world["PLAYER_TYPE"]. Place Things randomly, and actors not on each
    other. Init player's memory map. Write "NEW_WORLD" line to out file.
    """
    def free_pos(type):
        i = 0
        while 1:
            err = "Space to put thing on too hard to find. Map too small?"
            while 1:
                y = rand.next() % world_db["MAP_LENGTH"]
                x = rand.next() % world_db["MAP_LENGTH"]
                if chr(world_db["MAP"][y * world_db["MAP_LENGTH"] + x]) in \
                    symbols_passable and pos_test(type, y, x):
                    break
                i += 1
                if i == 65535:
                    raise SystemExit(err)
            # Replica of C code, wrongly ignores animatedness of new Thing.
            pos_clear = (0 == len([id for id in world_db["Things"]
                                   if world_db["Things"][id]["T_LIFEPOINTS"]
                                   if world_db["Things"][id]["T_POSY"] == y
                                   if world_db["Things"][id]["T_POSX"] == x]))
            if pos_clear:
                break
        return (y, x)

    playertype = world_makable()
    if playertype < 0:
        return
    rand.seed = seed
    libpr.set_maplength(world_db["MAP_LENGTH"])
    world_db["Things"] = {}
    make_map()
    world_db["WORLD_ACTIVE"] = 1
    world_db["TURN"] = 1
    for i in range(world_db["ThingTypes"][playertype]["TT_START_NUMBER"]):
        id = id_setter(-1, "Things")
        world_db["Things"][id] = new_Thing(playertype, free_pos(playertype))
    if not world_db["Things"][0]["fovmap"]:
        empty_fovmap = bytearray(b" " * world_db["MAP_LENGTH"] ** 2)
        world_db["Things"][0]["fovmap"] = empty_fovmap
    update_map_memory(world_db["Things"][0])
    for type in world_db["ThingTypes"]:
        for i in range(world_db["ThingTypes"][type]["TT_START_NUMBER"]):
            if type != playertype:
                id = id_setter(-1, "Things")
                world_db["Things"][id] = new_Thing(type, free_pos(type))
    strong_write(io_db["file_out"], "NEW_WORLD\n")
示例#3
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.")
            metamapB[pos] = ord(name[0])
    return write_map(metamapB, length)


def calc_effort(thing_action, thing):
    from math import sqrt
    effort = thing_action["TA_EFFORT"]
    if thing_action["TA_NAME"] == "move":
        typ = thing["T_TYPE"]
        max_hp = (world_db["ThingTypes"][typ]["TT_LIFEPOINTS"])
        effort = int(effort / sqrt(max_hp))
        effort = 1 if effort == 0 else effort
    return effort


strong_write(io_db["file_out"], "PLUGIN PleaseTheIslandGod\n")


def set_zero_if_undefined(key):
    if not key in world_db:
        world_db[key] = 0


set_zero_if_undefined("GOD_FAVOR")
set_zero_if_undefined("FAVOR_STAGE")
set_zero_if_undefined("EMPATHY")
world_db["specials"] = [
    "SLIPPERS", "PLANT_0", "PLANT_1", "TOOL_0", "TOOL_1", "LUMBER", "ANIMAL_0",
    "ANIMAL_1"
]
for key in world_db["specials"]:
            else:
                name = " "
            metamapB[pos] = ord(name[0])
    return write_map(metamapB, length)

def calc_effort(thing_action, thing):
    from math import sqrt
    effort = thing_action["TA_EFFORT"]
    if thing_action["TA_NAME"] == "move":
        typ = thing["T_TYPE"]
        max_hp = (world_db["ThingTypes"][typ]["TT_LIFEPOINTS"])
        effort = int(effort / sqrt(max_hp))
        effort = 1 if effort == 0 else effort
    return effort

strong_write(io_db["file_out"], "PLUGIN PleaseTheIslandGod\n")

def set_zero_if_undefined(key):
    if not key in world_db:
        world_db[key] = 0

set_zero_if_undefined("GOD_FAVOR")
set_zero_if_undefined("FAVOR_STAGE")
set_zero_if_undefined("EMPATHY")
world_db["specials"] = ["SLIPPERS", "PLANT_0", "PLANT_1", "TOOL_0", "TOOL_1",
    "LUMBER", "ANIMAL_0", "ANIMAL_1"]
for key in world_db["specials"]:
    set_zero_if_undefined(key)

world_db["terrain_names"][":"] = "SOIL"
world_db["terrain_names"]["|"] = "WALL"
示例#6
0
def command_ping():
    """Send PONG line to server output file."""
    strong_write(io_db["file_out"], "PONG\n")
示例#7
0
def command_ping():
    """Send PONG line to server output file."""
    strong_write(io_db["file_out"], "PONG\n")