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 thingprol_field_spreadable, thingprol_test_hook, \
15 thingprol_post_create_hook
16 from server.utils import mv_yx_in_dir_legal, rand, id_setter
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_test_hook(t):
22 for key in sorted(directions_db.keys()):
23 mv_result = mv_yx_in_dir_legal(directions_db[key], t["T_POSY"],
25 c = chr(prol_map[mv_result[1] * world_db["MAP_LENGTH"]
27 if mv_result[0] and thingprol_field_spreadable(c, t):
28 from server.io import log
30 candidates.append((mv_result[1], mv_result[2]))
32 i = rand.next() % len(candidates)
33 tid = id_setter(-1, "Things")
34 newT = new_Thing(t["T_TYPE"], (candidates[i][0], candidates[i][1]))
35 world_db["Things"][tid] = newT
36 thingprol_post_create_hook(t)