home · contact · privacy
Fix buggy healthy_addch().
[plomrogue] / server / thingproliferation.py
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.
4
5
6 def thingproliferation(t, prol_map):
7     """To chance of 1/TT_PROLIFERATE, create t offspring in open neighbor cell.
8
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
11     is selected randomly.
12     """
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):
21         candidates = []
22         for key in sorted(directions_db.keys()):
23             mv_result = mv_yx_in_dir_legal(directions_db[key], t["T_POSY"],
24                                            t["T_POSX"])
25             c = chr(prol_map[mv_result[1] * world_db["MAP_LENGTH"]
26                 + mv_result[2]])
27             if mv_result[0] and thingprol_field_spreadable(c, t):
28                 from server.io import log
29                 candidates.append((mv_result[1], mv_result[2]))
30         if len(candidates):
31             i = rand.next() % len(candidates)
32             tid = id_setter(-1, "Things")
33             newT = new_Thing(t["T_TYPE"], (candidates[i][0], candidates[i][1]))
34             world_db["Things"][tid] = newT
35             thingprol_post_create_hook(t)