home · contact · privacy
Merge branch 'master' into 7drl2016
[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(76, curses.COLOR_BLACK, curses.COLOR_WHITE)
7 curses.init_pair(77, curses.COLOR_WHITE, curses.COLOR_GREEN)
8 curses.init_pair(78, curses.COLOR_BLACK, curses.COLOR_RED)
9 curses.init_pair(79, curses.COLOR_WHITE, curses.COLOR_BLUE)
10 curses.init_pair(80, curses.COLOR_BLACK, curses.COLOR_YELLOW)
11
12
13 def win_bar_maker(color_number, symbol, title):
14     def win_bar(self):
15         winmap = []
16         for i in range(world_data[title]):
17             if i == 32:
18                 break
19             winmap += [(symbol, curses.color_pair(color_number))]
20         winmap_size = [1, len(winmap)]
21         offset = [0, 0]
22         return offset, winmap_size, winmap
23     return win_bar
24
25
26 def win_map(self):
27     charmap = {
28         "0": "_",
29         "1": ".",
30         "2": ":",
31         "3": "%",
32         "4": "#",
33         "5": "X",
34         "*": "O",
35         "&": "0",
36     }
37     win_size = self.size
38     offset = [0, 0]
39     for i in range(2):
40         if world_data["map_center"][i] * (i + 1) > win_size[i] / 2 and \
41                 win_size[i] < world_data["map_size"] * (i + 1):
42             if world_data["map_center"][i] * (i + 1) \
43                 < world_data["map_size"] * (i + 1) - win_size[i] / 2:
44                 offset[i] = world_data["map_center"][i] * (i + 1) \
45                     - int(win_size[i] / 2)
46                 if i == 1:
47                     offset[1] = offset[1] + world_data["map_center"][0] % 2
48             else:
49                 offset[i] = world_data["map_size"] * (i + 1) - win_size[i] + i
50     winmap_size = [world_data["map_size"], world_data["map_size"] * 2 + 1]
51     winmap = []
52     curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLACK)
53     #curses.init_pair(2, curses.COLOR_BLUE, curses.COLOR_BLACK)
54     curses.init_pair(3, curses.COLOR_CYAN, curses.COLOR_BLACK)
55     curses.init_pair(4, curses.COLOR_GREEN, curses.COLOR_BLACK)
56     curses.init_pair(5, curses.COLOR_YELLOW, curses.COLOR_BLACK)
57     curses.init_pair(6, curses.COLOR_RED, curses.COLOR_BLACK)
58     curses.init_pair(7, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
59     curses.init_pair(8, curses.COLOR_BLACK, curses.COLOR_WHITE)
60     curses.init_pair(9, curses.COLOR_BLACK, curses.COLOR_BLUE)
61     curses.init_pair(10, curses.COLOR_BLACK, curses.COLOR_CYAN)
62     curses.init_pair(11, curses.COLOR_BLACK, curses.COLOR_GREEN)
63     curses.init_pair(12, curses.COLOR_BLACK, curses.COLOR_YELLOW)
64     curses.init_pair(13, curses.COLOR_BLACK, curses.COLOR_RED)
65     curses.init_pair(14, curses.COLOR_BLACK, curses.COLOR_MAGENTA)
66     col_unknown = curses.color_pair(1)
67     col_creature = curses.color_pair(13)
68     col_player = curses.color_pair(8)
69     col_altar = curses.color_pair(3)
70     earth_colors = [
71         curses.color_pair(4),
72         curses.color_pair(5),
73         curses.color_pair(5),
74         curses.color_pair(6),
75         curses.color_pair(6),
76         curses.color_pair(7),
77     ]
78     water_colors = [
79         curses.color_pair(9),
80         curses.color_pair(10),
81         curses.color_pair(11),
82         curses.color_pair(12),
83         curses.color_pair(14),
84     ]
85     for y in range(world_data["map_size"]):
86         for x in range(world_data["map_size"]):
87             pos = y * world_data["map_size"] + x
88             char = world_data["fov_map"][pos]
89             if world_data["look_mode"] and y == world_data["map_center"][0] \
90                     and x == world_data["map_center"][1]:
91                 if char == " ":
92                     bonus = "?"
93                 else:
94                     bonus = world_data["wetmap"][pos]
95                 char = world_data["mem_map"][pos]
96                 winmap += [(char, curses.A_REVERSE), (bonus, curses.A_REVERSE)]
97                 continue
98             bonus = " "
99             attribute = col_unknown
100             if char == " ":
101                 if world_data["soundmap"][pos] != "0":
102                     bonus = "?"
103                 char = world_data["mem_map"][pos]
104                 if char in charmap:
105                     char = charmap[char]
106                 winmap += [(char, attribute), bonus]
107             else:
108                 wetval = ord(world_data["wetmap"][pos]) - ord("0")
109                 if char in "012345-+":
110                     mapval = 0
111                     if char not in "-+":
112                         mapval = ord(char) - ord("0")
113                     if 1 <= wetval <= 5:
114                         attribute = water_colors[wetval + (mapval - 1)]
115                     else:
116                         attribute = earth_colors[mapval]
117                 if char == "&":
118                     attribute = col_player
119                 elif char == "$":
120                     attribute = col_altar
121                 if char in charmap:
122                     char = charmap[char]
123                 elif char == "@":
124                     attribute = col_creature
125                     av_pos = world_data["avatar_position"]
126                     if pos == av_pos[0] * world_data["map_size"] + av_pos[1]:
127                         attribute = col_player
128                 winmap += [(char, attribute), bonus]
129         if y % 2 == 0:
130             winmap += "  "
131     return offset, winmap_size, winmap
132
133
134 from client.config.world_data import world_data
135 world_data["grace"] = 0
136 world_data["kidney"] = 0
137 world_data["stomach"] = 0
138 world_data["bowel"] = 0
139 world_data["bladder"] = 0
140 world_data["wetmap"] = " " * (world_data["map_size"] ** 2)
141 world_data["soundmap"] = " " * (world_data["map_size"] ** 2)
142 world_data["log"] = [
143 "This is not the environment you are used to. This is not the body you are use"
144 "d to. Surely this is a dream. But you have a feeling you might not wake up. U"
145 "nless you find a way out of here. Until then, you must survive. Explore, keep"
146 " fed, and hydrated. And avoid things that move by themselves.",
147 "",
148 "[hit '0' for help]"
149 ]
150 from client.config.io import io
151 io["worldstate_read_order"] += [["stomach", "int"]]
152 io["worldstate_read_order"] += [["kidney", "int"]]
153 io["worldstate_read_order"] += [["bowel", "int"]]
154 io["worldstate_read_order"] += [["bladder", "int"]]
155 io["worldstate_read_order"] += [["wetmap", "map"]]
156 io["worldstate_read_order"] += [["soundmap", "map"]]
157 io["worldstate_read_order"] += [["grace", "int"]]
158 from client.config.windows import windows_config
159 from client.windows import win_log
160 windows_config[:] = [
161     {"config": [0, -33],
162      "func": win_map,
163      "scroll_hints": False,
164       "title": "THE CRAWLING EATER"},
165     {"config": [1, 32],
166      "func": win_bar_maker(76, "+", "grace"),
167      "scroll_hints": False,
168       "title": "grace"},
169     {"config": [1, 32],
170      "func": win_bar_maker(77, "%", "stomach"),
171      "scroll_hints": False,
172      "title": "calories"},
173     {"config": [1, 32],
174      "func": win_bar_maker(79, "~", "kidney"),
175      "scroll_hints": False,
176       "title": "hydration"},
177     {"config": [1, 32],
178      "func": win_bar_maker(78, "%", "bowel"),
179      "scroll_hints": False,
180      "title": "bowel"},
181     {"config": [1, 32],
182      "func": win_bar_maker(80, "~", "bladder"),
183      "scroll_hints": False,
184       "title": "bladder"},
185     {"config": [-10, 32],
186      "func": win_log,
187      "scroll_hints": False,
188      "title": "log"}
189 ]
190 from client.window_management import set_windows
191 set_windows()
192 from client.commands import command_sender
193 from client.config.commands import commands
194 commands["o"] = (command_sender("drop"),)
195 commands["i"] = (command_sender("drink"),)
196 commands["p"] = (command_sender("pee"),)
197 commands["."] = (command_sender("wait"),)
198 commands["0"] = (command_sender("HELP 0"),)
199 commands["1"] = (command_sender("HELP 1"),)
200 commands["2"] = (command_sender("HELP 2"),)
201 commands["3"] = (command_sender("HELP 3"),)
202 commands["4"] = (command_sender("HELP 4"),)
203 commands["5"] = (command_sender("HELP 5"),)
204 commands["6"] = (command_sender("HELP 6"),)
205 commands["7"] = (command_sender("HELP 7"),)
206 commands["8"] = (command_sender("HELP 8"),)
207 commands["9"] = (command_sender("HELP 9"),)
208 commands["D"] = (lambda: None,)
209 commands["J"] = (lambda: None,)
210 commands["K"] = (lambda: None,)
211 commands["P"] = (lambda: None,)
212 commands["U"] = (lambda: None,)
213 commands["j"] = (lambda: None,)
214 commands["k"] = (lambda: None,)
215 commands["W"] = (lambda: None,)