1 # This file is part of PlomRogue. PlomRogue is licensed under the GPL version 3
2 # or any later version. For details on its copyright, license, and warranties,
3 # see the file NOTICE in the root directory of the PlomRogue source package.
6 def thingproliferation(t, prol_map):
7 """To chance of 1/TT_PROLIFERATE, create t offspring in open neighbor cell.
9 Naturally only works with TT_PROLIFERATE > 0. The neighbor cell must be be
10 marked passable in prol_map. If there are several map cell candidates, one
13 from server.config.world_data import directions_db, world_db
14 from server.config.thingproliferation import field_spreadable, \
15 thingprol_plugin_conditions, thingprol_plugin_post_create_hook
16 from server.utils import mv_yx_in_dir_legal, rand
17 from server.new_thing import new_Thing
18 prolscore = world_db["ThingTypes"][t["T_TYPE"]]["TT_PROLIFERATE"]
19 if prolscore and (1 == prolscore or 1 == (rand.next() % prolscore)) and \
20 thingprol_plugin_conditions(t):
22 for dir in [directions_db[key] for key in sorted(directions_db.keys())]:
23 mv_result = mv_yx_in_dir_legal(dir, t["T_POSY"], t["T_POSX"])
24 c = str(prol_map[mv_result[1] + world_db["MAP_LENGTH"]
26 if mv_result[0] and field_spreadable(c, t):
27 candidates.append((mv_result[1], mv_result[2]))
29 i = rand.next() % len(candidates)
30 id = id_setter(-1, "Things")
31 newT = new_Thing(t["T_TYPE"], (candidates[i][0], candidates[i][1]))
32 world_db["Things"][id] = newT
33 thingprol_plugin_post_create_hook(t)