home · contact · privacy
turn_over(): hunger() before Thing action, so no suicide corpses hunger.
[plomrogue] / roguelike-server
index edd0579d4cac9e27778ecff8c7e9806986c34665..e4b23e0b7b02d39e642e6232f534044f6e3b02fd 100755 (executable)
@@ -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"]:
@@ -1046,15 +1048,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,7 +1203,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 +1254,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"]):
@@ -1285,7 +1291,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()
@@ -1308,6 +1314,9 @@ 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
             else:
                 print("Ignoring: Not all conditions for world activation met.")
@@ -1616,6 +1625,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.)"""