home · contact · privacy
Server: Refactor and fix bugs in in thing proliferation.
[plomrogue] / server / thingproliferation.py
index 801ee2943195cbe66d7bd5dc8ab693e7b733660c..fec8eb4ec22ea133788343a00e1aaae3b998d283 100644 (file)
@@ -7,23 +7,30 @@ def thingproliferation(t, prol_map):
     """To chance of 1/TT_PROLIFERATE, create t offspring in open neighbor cell.
 
     Naturally only works with TT_PROLIFERATE > 0. The neighbor cell must be be
-    marked "." in prol_map. If there are several map cell candidates, one is
-    selected randomly.
+    marked passable in prol_map. If there are several map cell candidates, one
+    is selected randomly.
     """
-    from server.config.world_data import directions_db, symbols_passable,\
-             world_db
-    from server.utils import mv_yx_in_dir_legal, rand
+    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, 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)):
+    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 = prol_map[mv_result[1] + world_db["MAP_LENGTH"] + mv_result[2]]
-            if mv_result[0] and str(c) in symbols_passable:
+        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)