home · contact · privacy
TCE: Add map coloring.
[plomrogue] / plugins / server / TheCrawlingEater.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 from server.config.world_data import world_db
7
8
9 def make_map():
10     from server.make_map import new_pos, is_neighbor
11     from server.utils import rand
12     world_db["MAP"] = bytearray(b'X' * (world_db["MAP_LENGTH"] ** 2))
13     length = world_db["MAP_LENGTH"]
14     add_half_width = (not (length % 2)) * int(length / 2)
15     world_db["MAP"][int((length ** 2) / 2) + add_half_width] = ord("#")
16     while (1):
17         y, x, pos = new_pos()
18         if "X" == chr(world_db["MAP"][pos]) and is_neighbor((y, x), "#"):
19             if y == 0 or y == (length - 1) or x == 0 or x == (length - 1):
20                 break
21             world_db["MAP"][pos] = ord("#")
22     n_trees = int((length ** 2) / 16)
23     i_trees = 0
24     while (i_trees <= n_trees):
25         single_allowed = rand.next() % 32
26         y, x, pos = new_pos()
27         if "#" == chr(world_db["MAP"][pos]) \
28                 and ((not single_allowed) or is_neighbor((y, x), ".")):
29             world_db["MAP"][pos] = ord(".")
30             i_trees += 1
31
32
33 def actor_move_attempts_hook(t, move_result, pos):
34     from server.utils import rand
35     if ord("#") == world_db["MAP"][pos] and 0 == int(rand.next() % 5):
36         world_db["MAP"][pos] = ord(".")
37         return True
38     return False
39
40
41 def play_move_attempt_hook(t, direction, pos):
42     if ord("#") == world_db["MAP"][pos]:
43         log("You bite.")
44         world_db["Things"][0]["T_ARGUMENT"] = direction
45         set_command("move")
46         return True
47     return False
48
49
50 import server.config.actions
51 server.config.actions.actor_move_attempts_hook = actor_move_attempts_hook
52 import server.config.commands
53 server.config.commands.play_move_attempt_hook = play_move_attempt_hook
54 import server.config.world_data
55 server.config.world_data.symbols_hide += "#"
56 import server.config.make_world_helpers
57 server.config.make_world_helpers.make_map = make_map
58
59 strong_write(io_db["file_out"], "PLUGIN TheCrawlingEater\n")