home · contact · privacy
Server: Refactor and fix bugs in in thing proliferation.
authorChristian Heller <c.heller@plomlompom.de>
Mon, 29 Feb 2016 02:00:18 +0000 (03:00 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 29 Feb 2016 02:00:18 +0000 (03:00 +0100)
server/config/thingproliferation.py
server/thingproliferation.py
server/thingproliferation_helpers.py [deleted file]
server/world.py

index a8382d683718cf3e00977ff903b3d5bfffa23af3..3e55c8baf254db1d771bec0b04467137a21be7b6 100644 (file)
@@ -3,9 +3,9 @@
 # see the file NOTICE in the root directory of the PlomRogue source package.
 
 
-import server.thingproliferation_helpers
+from server.config.world_data import symbols_passable
 
 
-field_spreadable = server.thingproliferation_helpers.field_spreadable
+field_spreadable = lambda x, y: x in symbols_passable
 thingprol_plugin_conditions = lambda x: True
 thingprol_plugin_post_create_hook = lambda x: None
index ad55b3fc7c3c090691f1b5abef7ae71ccd95c5c3..fec8eb4ec22ea133788343a00e1aaae3b998d283 100644 (file)
@@ -13,21 +13,24 @@ def thingproliferation(t, prol_map):
     from server.config.world_data import directions_db, world_db
     from server.config.thingproliferation import field_spreadable, \
         thingprol_plugin_conditions, thingprol_plugin_post_create_hook
-    from server.utils import mv_yx_in_dir_legal, rand
+    from server.utils import mv_yx_in_dir_legal, rand, id_setter
     from server.new_thing import new_Thing
     prolscore = world_db["ThingTypes"][t["T_TYPE"]]["TT_PROLIFERATE"]
     if prolscore and (1 == prolscore or 1 == (rand.next() % prolscore)) and \
         thingprol_plugin_conditions(t):
         candidates = []
-        for dir in [directions_db[key] for key in sorted(directions_db.keys())]:
-            mv_result = mv_yx_in_dir_legal(dir, t["T_POSY"], t["T_POSX"])
-            c = str(prol_map[mv_result[1] + world_db["MAP_LENGTH"]
-                    + mv_result[2]])
+        for key in sorted(directions_db.keys()):
+            mv_result = mv_yx_in_dir_legal(directions_db[key], t["T_POSY"],
+                                           t["T_POSX"])
+            c = chr(prol_map[mv_result[1] * world_db["MAP_LENGTH"]
+                + mv_result[2]])
             if mv_result[0] and field_spreadable(c, t):
+                from server.io import log
+                log("PROL")
                 candidates.append((mv_result[1], mv_result[2]))
         if len(candidates):
             i = rand.next() % len(candidates)
-            id = id_setter(-1, "Things")
+            tid = id_setter(-1, "Things")
             newT = new_Thing(t["T_TYPE"], (candidates[i][0], candidates[i][1]))
-            world_db["Things"][id] = newT
+            world_db["Things"][tid] = newT
             thingprol_plugin_post_create_hook(t)
diff --git a/server/thingproliferation_helpers.py b/server/thingproliferation_helpers.py
deleted file mode 100644 (file)
index df02313..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-# This file is part of PlomRogue. PlomRogue is licensed under the GPL version 3
-# or any later version. For details on its copyright, license, and warranties,
-# see the file NOTICE in the root directory of the PlomRogue source package.
-
-
-from server.config.world_data import symbols_passable
-
-
-def field_spreadable(field_type, ignore):
-    return field_type in symbols_passable
index cde01988a2fe542e5cb7c95a2b61e3928bd2efb7..a313eae76f916a0b17056a101726bf76dfbbeed8 100644 (file)
@@ -59,10 +59,10 @@ def turn_over():
     id = 0
     while world_db["Things"][0]["T_LIFEPOINTS"]:
         proliferable_map = world_db["MAP"][:]
-        for id in [id for id in world_db["Things"]
-                   if not world_db["Things"][id]["carried"]]:
-            y = world_db["Things"][id]["T_POSY"]
-            x = world_db["Things"][id]["T_POSX"]
+        for tid in [tid for tid in world_db["Things"]
+                   if not world_db["Things"][tid]["carried"]]:
+            y = world_db["Things"][tid]["T_POSY"]
+            x = world_db["Things"][tid]["T_POSX"]
             proliferable_map[y * world_db["MAP_LENGTH"] + x] = ord('X')
         for id in [id for id in world_db["Things"]]:  # Only what's from start!
             if not id in world_db["Things"] or \