home · contact · privacy
6798e9c23f5d022eb47d475a7b54354857c23e69
[plomrogue] / plugins / client / 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 curses.init_pair(77, curses.COLOR_WHITE, curses.COLOR_GREEN)
7 curses.init_pair(78, curses.COLOR_BLACK, curses.COLOR_RED)
8 curses.init_pair(79, curses.COLOR_WHITE, curses.COLOR_BLUE)
9 curses.init_pair(80, curses.COLOR_BLACK, curses.COLOR_YELLOW)
10
11
12 def win_bar_maker(color_number, symbol, title):
13     def win_bar(self):
14         winmap = []
15         for i in range(world_data[title]):
16             winmap += [(symbol, curses.color_pair(color_number))]
17         winmap_size = [1, len(winmap)]
18         offset = [0, 0]
19         return offset, winmap_size, winmap
20     return win_bar
21
22
23 def win_map(self):
24     charmap = {
25         "0": "_",
26         "1": ".",
27         "2": ":",
28         "3": "%",
29         "4": "#",
30         "5": "X",
31         "*": "O",
32         "&": "0",
33     }
34     win_size = self.size
35     offset = [0, 0]
36     for i in range(2):
37         if world_data["map_center"][i] * (i + 1) > win_size[i] / 2 and \
38                 win_size[i] < world_data["map_size"] * (i + 1):
39             if world_data["map_center"][i] * (i + 1) \
40                 < world_data["map_size"] * (i + 1) - win_size[i] / 2:
41                 offset[i] = world_data["map_center"][i] * (i + 1) \
42                     - int(win_size[i] / 2)
43                 if i == 1:
44                     offset[1] = offset[1] + world_data["map_center"][0] % 2
45             else:
46                 offset[i] = world_data["map_size"] * (i + 1) - win_size[i] + i
47     winmap_size = [world_data["map_size"], world_data["map_size"] * 2 + 1]
48     winmap = []
49     curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLACK)
50     #curses.init_pair(2, curses.COLOR_BLUE, curses.COLOR_BLACK)
51     #curses.init_pair(3, curses.COLOR_CYAN, curses.COLOR_BLACK)
52     curses.init_pair(4, curses.COLOR_GREEN, curses.COLOR_BLACK)
53     curses.init_pair(5, curses.COLOR_YELLOW, curses.COLOR_BLACK)
54     curses.init_pair(6, curses.COLOR_RED, curses.COLOR_BLACK)
55     curses.init_pair(7, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
56     curses.init_pair(8, curses.COLOR_BLACK, curses.COLOR_WHITE)
57     curses.init_pair(9, curses.COLOR_BLACK, curses.COLOR_BLUE)
58     curses.init_pair(10, curses.COLOR_BLACK, curses.COLOR_CYAN)
59     curses.init_pair(11, curses.COLOR_BLACK, curses.COLOR_GREEN)
60     curses.init_pair(12, curses.COLOR_BLACK, curses.COLOR_YELLOW)
61     curses.init_pair(13, curses.COLOR_BLACK, curses.COLOR_RED)
62     curses.init_pair(14, curses.COLOR_BLACK, curses.COLOR_MAGENTA)
63     col_unknown = curses.color_pair(1)
64     col_creature = curses.color_pair(13)
65     col_player = curses.color_pair(8)
66     earth_colors = [
67         curses.color_pair(4),
68         curses.color_pair(5),
69         curses.color_pair(5),
70         curses.color_pair(6),
71         curses.color_pair(6),
72         curses.color_pair(7),
73     ]
74     water_colors = [
75         curses.color_pair(9),
76         curses.color_pair(10),
77         curses.color_pair(11),
78         curses.color_pair(12),
79         curses.color_pair(14),
80     ]
81     for y in range(world_data["map_size"]):
82         for x in range(world_data["map_size"]):
83             pos = y * world_data["map_size"] + x
84             char = world_data["fov_map"][pos]
85             if world_data["look_mode"] and y == world_data["map_center"][0] \
86                     and x == world_data["map_center"][1]:
87                 if char == " ":
88                     bonus = "?"
89                 else:
90                     bonus = world_data["wetmap"][pos]
91                 char = world_data["mem_map"][pos]
92                 winmap += [(char, curses.A_REVERSE), (bonus, curses.A_REVERSE)]
93                 continue
94             bonus = " "
95             attribute = col_unknown
96             if char == " ":
97                 if world_data["soundmap"][pos] != "0":
98                     bonus = "?"
99                 char = world_data["mem_map"][pos]
100                 if char in charmap:
101                     char = charmap[char]
102                 winmap += [(char, attribute), bonus]
103             else:
104                 wetval = ord(world_data["wetmap"][pos]) - ord("0")
105                 if char in "012345-+":
106                     mapval = 0
107                     if char not in "-+":
108                         mapval = ord(char) - ord("0")
109                     if 1 <= wetval <= 5:
110                         attribute = water_colors[wetval + (mapval - 1)]
111                     else:
112                         attribute = earth_colors[mapval]
113                 if char == "&":
114                     attribute = col_player
115                 if char in charmap:
116                     char = charmap[char]
117                 elif char == "@":
118                     attribute = col_creature
119                     av_pos = world_data["avatar_position"]
120                     if pos == av_pos[0] * world_data["map_size"] + av_pos[1]:
121                         attribute = col_player
122                 winmap += [(char, attribute), bonus]
123         if y % 2 == 0:
124             winmap += "  "
125     return offset, winmap_size, winmap
126
127
128 from client.config.world_data import world_data
129 world_data["kidney"] = 0
130 world_data["stomach"] = 0
131 world_data["bowel"] = 0
132 world_data["bladder"] = 0
133 world_data["wetmap"] = " " * (world_data["map_size"] ** 2)
134 world_data["soundmap"] = " " * (world_data["map_size"] ** 2)
135 from client.config.io import io
136 io["worldstate_read_order"] += [["stomach", "int"]]
137 io["worldstate_read_order"] += [["kidney", "int"]]
138 io["worldstate_read_order"] += [["bowel", "int"]]
139 io["worldstate_read_order"] += [["bladder", "int"]]
140 io["worldstate_read_order"] += [["wetmap", "map"]]
141 io["worldstate_read_order"] += [["soundmap", "map"]]
142 from client.config.windows import windows_config
143 from client.windows import win_log
144 windows_config[:] = [
145     {"config": [0, -34],
146      "func": win_map,
147      "scroll_hints": False,
148       "title": "THE CRAWLING EATER"},
149     {"config": [1, 33],
150      "func": win_bar_maker(77, "%", "stomach"),
151      "scroll_hints": False,
152      "title": "stomach"},
153     {"config": [1, 33],
154      "func": win_bar_maker(79, "~", "kidney"),
155      "scroll_hints": False,
156       "title": "kidney"},
157     {"config": [1, 33],
158      "func": win_bar_maker(78, "%", "bowel"),
159      "scroll_hints": False,
160      "title": "bowel"},
161     {"config": [1, 33],
162      "func": win_bar_maker(80, "~", "bladder"),
163      "scroll_hints": False,
164       "title": "bladder"},
165     {"config": [-8, 33],
166      "func": win_log,
167      "scroll_hints": False,
168      "title": "log"}
169 ]
170 from client.window_management import set_windows
171 set_windows()
172 from client.commands import command_sender
173 from client.config.commands import commands
174 commands["S"] = (command_sender("drop"),)
175 commands["D"] = (command_sender("drink"),)
176 commands["P"] = (command_sender("pee"),)
177 commands["1"] = (command_sender("HELP 1"),)
178 commands["2"] = (command_sender("HELP 2"),)
179 commands["3"] = (command_sender("HELP 3"),)
180 commands["4"] = (command_sender("HELP 4"),)