X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=roguelike-server;h=27ede4e882f2265750a4a6c24c259c3f9206412c;hb=b1c36ca1d6f9bc4f88f616733dfbc751cb63b465;hp=edd0579d4cac9e27778ecff8c7e9806986c34665;hpb=ef81977d5ecb68dd362b290268a921e4236850ff;p=plomrogue diff --git a/roguelike-server b/roguelike-server index edd0579..27ede4e 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"]: @@ -576,6 +578,11 @@ def build_fov_map(t): raise RuntimeError("Malloc error in build_fov_Map().") +def log_help(): + """Send quick usage info to log.""" + strong_write(io_db["file_out"], "LOG See README file for help.\n") + + def decrement_lifepoints(t): """Decrement t's lifepoints by 1, and if to zero, corpse it. @@ -594,6 +601,8 @@ def decrement_lifepoints(t): if world_db["Things"][0] == t: t["fovmap"] = bytearray(b' ' * (world_db["MAP_LENGTH"] ** 2)) strong_write(io_db["file_out"], "LOG You die.\n") + strong_write(io_db["file_out"], + "LOG See README on how to start over.\n") else: t["fovmap"] = False t["T_MEMMAP"] = False @@ -1046,15 +1055,16 @@ def turn_over(): break ai(Thing) try_healing(Thing) - Thing["T_PROGRESS"] += 1 - taid = [a for a in world_db["ThingActions"] - if a == Thing["T_COMMAND"]][0] - ThingAction = world_db["ThingActions"][taid] - if Thing["T_PROGRESS"] == ThingAction["TA_EFFORT"]: - eval("actor_" + ThingAction["TA_NAME"])(Thing) - Thing["T_COMMAND"] = 0 - Thing["T_PROGRESS"] = 0 hunger(Thing) + if Thing["T_LIFEPOINTS"]: + Thing["T_PROGRESS"] += 1 + taid = [a for a in world_db["ThingActions"] + if a == Thing["T_COMMAND"]][0] + ThingAction = world_db["ThingActions"][taid] + if Thing["T_PROGRESS"] == ThingAction["TA_EFFORT"]: + eval("actor_" + ThingAction["TA_NAME"])(Thing) + Thing["T_COMMAND"] = 0 + Thing["T_PROGRESS"] = 0 thingproliferation(Thing, proliferable_map) if whilebreaker: break @@ -1200,11 +1210,12 @@ 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 other. Init player's memory map. Write "NEW_WORLD" line to out file. + Call log_help(). """ def free_pos(): @@ -1251,12 +1262,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"]): @@ -1264,6 +1278,7 @@ def command_makeworld(seed_string): id = id_setter(-1, "Things") world_db["Things"][id] = new_Thing(type, free_pos()) strong_write(io_db["file_out"], "NEW_WORLD\n") + log_help() def command_maplength(maplength_string): @@ -1283,9 +1298,10 @@ def command_worldactive(worldactive_string): 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. + Also call log_help(). """ val = integer_test(worldactive_string, 0, 1) - if val: + if None != val: if 0 != world_db["WORLD_ACTIVE"]: if 0 == val: set_world_inactive() @@ -1308,7 +1324,11 @@ def command_worldactive(worldactive_string): 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 + log_help() else: print("Ignoring: Not all conditions for world activation met.") @@ -1594,7 +1614,7 @@ commands_db = { "TT_START_NUMBER": (1, False, setter("ThingType", "TT_START_NUMBER", 0, 255)), "TT_PROLIFERATE": (1, False, setter("ThingType", "TT_PROLIFERATE", - 0, 255)), + 0, 65535)), "TT_LIFEPOINTS": (1, False, setter("ThingType", "TT_LIFEPOINTS", 0, 255)), "T_ID": (1, False, command_tid), "T_ARGUMENT": (1, False, setter("Thing", "T_ARGUMENT", 0, 255)), @@ -1616,6 +1636,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.)"""