home · contact · privacy
Further server optimization by outsourcing to libplomrogue.
[plomrogue] / roguelike-server
index fd3edbde27f09f9483e6f43772d56b24980272b3..d452efbee6ec250036dd93e2af50077b48f9270a 100755 (executable)
@@ -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)
@@ -325,7 +330,10 @@ def try_worldstate_update():
                 type_id = world_db["Things"][id]["T_TYPE"]
                 name = world_db["ThingTypes"][type_id]["TT_NAME"]
                 inventory = inventory + name + "\n"
-        string = str(world_db["TURN"]) + "\n" + \
+        ## 7DRL additions:  GOD_MOOD, GOD_FAVOR
+        string = str(world_db["GOD_MOOD"]) + "\n" + \
+                 str(world_db["GOD_FAVOR"]) + "\n" + \
+                 str(world_db["TURN"]) + "\n" + \
                  str(world_db["Things"][0]["T_LIFEPOINTS"]) + "\n" + \
                  str(world_db["Things"][0]["T_SATIATION"]) + "\n" + \
                  inventory + "%\n" + \
@@ -822,6 +830,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 +848,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]
@@ -1537,6 +1554,8 @@ commands_db = {
     "SEED_MAP": (1, False, command_seedmap),
     "SEED_RANDOMNESS": (1, False, command_seedrandomness),
     "TURN": (1, False, setter(None, "TURN", 0, 65535)),
+    "GOD_MOOD": (1, False, setter(None, "GOD_MOOD", -32768, 32767)), ##
+    "GOD_FAVOR": (1, False, setter(None, "GOD_FAVOR", -32768, 32767)), ##
     "PLAYER_TYPE": (1, False, setter(None, "PLAYER_TYPE", 0)),
     "MAP_LENGTH": (1, False, command_maplength),
     "WORLD_ACTIVE": (1, False, command_worldactive),
@@ -1583,6 +1602,8 @@ world_db = {
     "SEED_MAP": 0,
     "PLAYER_TYPE": 0,
     "WORLD_ACTIVE": 0,
+    "GOD_MOOD": 0, ##
+    "GOD_FAVOR": 0, ##
     "ThingActions": {},
     "ThingTypes": {},
     "Things": {}