X-Git-Url: https://plomlompom.com/repos/berlin_corona.txt?a=blobdiff_plain;ds=inline;f=roguelike-server;h=4944701fa2ba4630b9ec06112c4239eaa3202871;hb=e82bb6fc98e7fca1856730bbbb22def6f86a40a0;hp=ef3fdbcc5a8491fe71e8f8418f775132b5b1fcbe;hpb=dcdb99eb5863af512f8f079c320216bfeec5d9e2;p=plomrogue diff --git a/roguelike-server b/roguelike-server index ef3fdbc..4944701 100755 --- a/roguelike-server +++ b/roguelike-server @@ -33,13 +33,18 @@ def prep_library(): """Prepare ctypes library at ./libplomrogue.so""" libpath = ("./libplomrogue.so") if not os.access(libpath, os.F_OK): - raise SystemExit("No library " + libpath + - ", run ./compile-server.sh first?") + raise SystemExit("No library " + libpath + ", run ./redo first?") libpr = ctypes.cdll.LoadLibrary(libpath) libpr.seed_rrand.restype = ctypes.c_uint32 return libpr +def c_pointer_to_bytearray(ba): + """Return C char * pointer to ba.""" + type = ctypes.c_char * len(ba) + return type.from_buffer(ba) + + def strong_write(file, string): """Apply write(string), then flush().""" file.write(string) @@ -822,6 +827,17 @@ def get_dir_to_target(t, filter): return True return False + def set_cells_passable_on_memmap_to_65534_on_scoremap(): + # OUTSOURCED TO libplomrogue.so: + # memmap = t["T_MEMMAP"] + # for i in [i for i in range(world_db["MAP_LENGTH"] ** 2) + # if ord_dot == memmap[i]]: + # set_map_score(i, 65534) # i.e. 65535-1 + map = c_pointer_to_bytearray(t["T_MEMMAP"]) + if libpr.set_cells_passable_on_memmap_to_65534_on_scoremap(map): + raise RuntimeError("No score map allocated for " + "set_cells_passable_on_memmap_to_65534_on_scoremap().") + def init_score_map(): test = libpr.init_score_map() if test: @@ -829,9 +845,7 @@ def get_dir_to_target(t, filter): ord_dot = ord(".") ord_v = ord("v") ord_blank = ord(" ") - for i in [i for i in range(world_db["MAP_LENGTH"] ** 2) - if ord_dot == t["T_MEMMAP"][i]]: - set_map_score(i, 65535 - 1) + set_cells_passable_on_memmap_to_65534_on_scoremap() if "a" == filter: for id in world_db["Things"]: Thing = world_db["Things"][id] @@ -1080,7 +1094,6 @@ def id_setter(id, category, id_store=False, start_at_1=False): id = id + 1 if id not in world_db[category]: break - return None if id_store: id_store.id = id return id