X-Git-Url: https://plomlompom.com/repos/berlin_corona.txt?a=blobdiff_plain;ds=sidebyside;f=roguelike-server;h=0b9af475806fee19e756484cbc064b3bd29ce500;hb=090259ce1d144461c33db6a622919b182dab6888;hp=860cd1ad2a47129df5a8f88ebd45e20bf7e69cc3;hpb=d8143f05add023ec94dec4725c85811b3da22471;p=plomrogue diff --git a/roguelike-server b/roguelike-server index 860cd1a..0b9af47 100755 --- a/roguelike-server +++ b/roguelike-server @@ -414,7 +414,7 @@ def play_game(): obey(read_command(), "in file", do_record=True) -def remake_map(): +def make_map(): """(Re-)make island map. Let "~" represent water, "." land, "X" trees: Build island shape randomly, @@ -475,6 +475,7 @@ def remake_map(): def update_map_memory(t, age_map=True): """Update t's T_MEMMAP with what's in its FOV now,age its T_MEMMEPTHMAP.""" + def age_some_memdepthmap_on_nonfov_cells(): # OUTSOURCED FOR PERFORMANCE REASONS TO libplomrogue.so: # ord_v = ord("v") @@ -490,6 +491,7 @@ def update_map_memory(t, age_map=True): memdepthmap = c_pointer_to_bytearray(t["T_MEMDEPTHMAP"]) fovmap = c_pointer_to_bytearray(t["fovmap"]) libpr.age_some_memdepthmap_on_nonfov_cells(memdepthmap, fovmap) + if not t["T_MEMMAP"]: t["T_MEMMAP"] = bytearray(b' ' * (world_db["MAP_LENGTH"] ** 2)) if not t["T_MEMDEPTHMAP"]: @@ -1200,7 +1202,7 @@ def command_makeworld(seed_string): 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 remake_map() and set + 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 @@ -1251,12 +1253,15 @@ def command_makeworld(seed_string): "No thing action with name 'wait' defined.") return world_db["Things"] = {} - remake_map() + 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()) + 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"]): @@ -1271,6 +1276,7 @@ def command_maplength(maplength_string): val = integer_test(maplength_string, 1, 256) if None != val: world_db["MAP_LENGTH"] = val + world_db["MAP"] = False set_world_inactive() world_db["Things"] = {} libpr.set_maplength(val) @@ -1284,7 +1290,7 @@ def command_worldactive(worldactive_string): map. On activation, rebuild all Things' FOVs, and the player's map memory. """ val = integer_test(worldactive_string, 0, 1) - if val: + if None != val: if 0 != world_db["WORLD_ACTIVE"]: if 0 == val: set_world_inactive() @@ -1301,12 +1307,15 @@ def command_worldactive(worldactive_string): if 0 == Thing: player_exists = True break - if wait_exists and player_exists and "MAP" in world_db: + if wait_exists and player_exists and world_db["MAP"]: for id in world_db["Things"]: if world_db["Things"][id]["T_LIFEPOINTS"]: build_fov_map(world_db["Things"][id]) if 0 == id: update_map_memory(world_db["Things"][id], 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 else: print("Ignoring: Not all conditions for world activation met.") @@ -1425,12 +1434,12 @@ def setter_map(maptype): val = valid_map_line(str_int, mapline) if None != val: length = world_db["MAP_LENGTH"] - if not "MAP" in world_db: + if not world_db["MAP"]: map = bytearray(b' ' * (length ** 2)) else: map = world_db["MAP"] map[val * length:(val * length) + length] = mapline.encode() - if not "MAP" in world_db: + if not world_db["MAP"]: world_db["MAP"] = map @test_Thing_id @@ -1615,6 +1624,7 @@ commands_db = { "use": (1, False, play_commander("use", True)), "ai": (0, False, command_ai) } +# TODO: Unhandled cases: (Un-)killing animates (esp. player!) with T_LIFEPOINTS. """World state database. With sane default values. (Randomness is in rand.)""" @@ -1623,6 +1633,7 @@ world_db = { "MAP_LENGTH": 64, "PLAYER_TYPE": 0, "WORLD_ACTIVE": 0, + "MAP": False, "ThingActions": {}, "ThingTypes": {}, "Things": {}