From: Christian Heller Date: Mon, 29 Feb 2016 02:00:18 +0000 (+0100) Subject: Server: Refactor and fix bugs in in thing proliferation. X-Git-Tag: tce~115 X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/conditions?a=commitdiff_plain;h=6e4d41846d1bf07db5c91724bdb559285c6ad096;p=plomrogue Server: Refactor and fix bugs in in thing proliferation. --- diff --git a/server/config/thingproliferation.py b/server/config/thingproliferation.py index a8382d6..3e55c8b 100644 --- a/server/config/thingproliferation.py +++ b/server/config/thingproliferation.py @@ -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 diff --git a/server/thingproliferation.py b/server/thingproliferation.py index ad55b3f..fec8eb4 100644 --- a/server/thingproliferation.py +++ b/server/thingproliferation.py @@ -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 index df02313..0000000 --- a/server/thingproliferation_helpers.py +++ /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 diff --git a/server/world.py b/server/world.py index cde0198..a313eae 100644 --- a/server/world.py +++ b/server/world.py @@ -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 \