… | |
… | |
21 | * |
21 | * |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | #include <global.h> |
25 | #include <global.h> |
|
|
26 | #include <util.h> |
26 | #include <random_map.h> |
27 | #include <random_map.h> |
27 | #include <rproto.h> |
28 | #include <rproto.h> |
28 | |
29 | |
29 | /* Put in the walls and autojoin them. */ |
30 | /* Put in the walls and autojoin them. */ |
30 | |
31 | |
… | |
… | |
37 | 2 = wall to right, |
38 | 2 = wall to right, |
38 | 4 = wall above |
39 | 4 = wall above |
39 | 8 = wall below */ |
40 | 8 = wall below */ |
40 | int surround_index = 0; |
41 | int surround_index = 0; |
41 | |
42 | |
42 | if (i > 0 && maze[i - 1][j] != 0) surround_index |= 1; |
43 | if (i > 0 && maze[i - 1][j] != 0) surround_index |= 1; |
43 | if (i < maze.w - 1 && maze[i + 1][j] != 0) surround_index |= 2; |
44 | if (i < maze.w - 1 && maze[i + 1][j] != 0) surround_index |= 2; |
44 | if (j > 0 && maze[i][j - 1] != 0) surround_index |= 4; |
45 | if (j > 0 && maze[i][j - 1] != 0) surround_index |= 4; |
45 | if (j < maze.h - 1 && maze[i][j + 1] != 0) surround_index |= 8; |
46 | if (j < maze.h - 1 && maze[i][j + 1] != 0) surround_index |= 8; |
46 | |
47 | |
47 | return surround_index; |
48 | return surround_index; |
48 | } |
49 | } |
49 | |
50 | |
… | |
… | |
55 | 2 = wall to right, |
56 | 2 = wall to right, |
56 | 4 = wall above |
57 | 4 = wall above |
57 | 8 = wall below */ |
58 | 8 = wall below */ |
58 | int surround_index = 0; |
59 | int surround_index = 0; |
59 | |
60 | |
60 | if (i > 0 && maze[i - 1][j] == '#') surround_index |= 1; |
61 | if (i > 0 && maze[i - 1][j] == '#') surround_index |= 1; |
61 | if (i < maze.w - 1 && maze[i + 1][j] == '#') surround_index |= 2; |
62 | if (i < maze.w - 1 && maze[i + 1][j] == '#') surround_index |= 2; |
62 | if (j > 0 && maze[i][j - 1] == '#') surround_index |= 4; |
63 | if (j > 0 && maze[i][j - 1] == '#') surround_index |= 4; |
63 | if (j < maze.h - 1 && maze[i][j + 1] == '#') surround_index |= 8; |
64 | if (j < maze.h - 1 && maze[i][j + 1] == '#') surround_index |= 8; |
64 | |
65 | |
65 | return surround_index; |
66 | return surround_index; |
66 | } |
67 | } |
67 | |
68 | |
… | |
… | |
143 | wall_name[l] = 0; |
144 | wall_name[l] = 0; |
144 | break; |
145 | break; |
145 | } |
146 | } |
146 | } |
147 | } |
147 | |
148 | |
148 | surround_index = surround_flag2 (maze, i, j); |
|
|
149 | |
|
|
150 | switch (surround_index) |
|
|
151 | { |
|
|
152 | case 0: |
|
|
153 | strcat (wall_name, "_0"); |
149 | strcat (wall_name, "_"); |
154 | break; |
150 | strcat (wall_name, wall_suffix [surround_flag2 (maze, i, j)]); |
155 | case 1: |
151 | |
156 | strcat (wall_name, "_1_3"); |
|
|
157 | break; |
|
|
158 | case 2: |
|
|
159 | strcat (wall_name, "_1_4"); |
|
|
160 | break; |
|
|
161 | case 3: |
|
|
162 | strcat (wall_name, "_2_1_2"); |
|
|
163 | break; |
|
|
164 | case 4: |
|
|
165 | strcat (wall_name, "_1_2"); |
|
|
166 | break; |
|
|
167 | case 5: |
|
|
168 | strcat (wall_name, "_2_2_4"); |
|
|
169 | break; |
|
|
170 | case 6: |
|
|
171 | strcat (wall_name, "_2_2_1"); |
|
|
172 | break; |
|
|
173 | case 7: |
|
|
174 | strcat (wall_name, "_3_1"); |
|
|
175 | break; |
|
|
176 | case 8: |
|
|
177 | strcat (wall_name, "_1_1"); |
|
|
178 | break; |
|
|
179 | case 9: |
|
|
180 | strcat (wall_name, "_2_2_3"); |
|
|
181 | break; |
|
|
182 | case 10: |
|
|
183 | strcat (wall_name, "_2_2_2"); |
|
|
184 | break; |
|
|
185 | case 11: |
|
|
186 | strcat (wall_name, "_3_3"); |
|
|
187 | break; |
|
|
188 | case 12: |
|
|
189 | strcat (wall_name, "_2_1_1"); |
|
|
190 | break; |
|
|
191 | case 13: |
|
|
192 | strcat (wall_name, "_3_4"); |
|
|
193 | break; |
|
|
194 | case 14: |
|
|
195 | strcat (wall_name, "_3_2"); |
|
|
196 | break; |
|
|
197 | case 15: |
|
|
198 | strcat (wall_name, "_4"); |
|
|
199 | break; |
|
|
200 | } |
|
|
201 | wall_arch = archetype::find (wall_name); |
152 | wall_arch = archetype::find (wall_name); |
202 | |
153 | |
203 | return wall_arch ? wall_arch->instance () : the_wall->arch->instance (); |
154 | return wall_arch ? wall_arch->instance () : the_wall->arch->instance (); |
|
|
155 | } |
|
|
156 | |
|
|
157 | // checks whether the layout has a "reachable" space at a given point, i.e. |
|
|
158 | // not a wall that is completely surrounded by walls. |
|
|
159 | static bool inline |
|
|
160 | is_visible (layout &maze, int i, int j) |
|
|
161 | { |
|
|
162 | for (int dx = -1; dx <= 1; ++dx) |
|
|
163 | for (int dy = -1; dy <= 1; ++dy) |
|
|
164 | { |
|
|
165 | int x = i + dx; |
|
|
166 | int y = j + dy; |
|
|
167 | |
|
|
168 | if (IN_RANGE_EXC (x, 0, maze.w) |
|
|
169 | && IN_RANGE_EXC (y, 0, maze.h) |
|
|
170 | && maze [x][y] != '#') |
|
|
171 | return true; |
|
|
172 | } |
|
|
173 | |
|
|
174 | return false; |
204 | } |
175 | } |
205 | |
176 | |
206 | /* takes a map and a maze, and puts walls in the map (picked from |
177 | /* takes a map and a maze, and puts walls in the map (picked from |
207 | w_style) at '#' marks. */ |
178 | w_style) at '#' marks. */ |
208 | void |
179 | void |
… | |
… | |
222 | ? find_style ("/styles/miningstyles", m_style, RP->difficulty) |
193 | ? find_style ("/styles/miningstyles", m_style, RP->difficulty) |
223 | : 0; |
194 | : 0; |
224 | |
195 | |
225 | if ((the_wall = style_map->pick_random_object (rmg_rndm))) |
196 | if ((the_wall = style_map->pick_random_object (rmg_rndm))) |
226 | { |
197 | { |
227 | int i, j; |
198 | // first pass, remove all "unreachable" (in-rock) walls |
228 | char *cp; |
199 | // and replace them by "blocked" spaces. |
|
|
200 | |
|
|
201 | layout clean_maze (maze); |
|
|
202 | |
|
|
203 | if (archetype *blocked = archetype::find ("blocked")) |
|
|
204 | for (int x = 0; x < maze.w; ++x) |
|
|
205 | for (int y = 0; y < maze.h; ++y) |
|
|
206 | if (maze [x][y] == '#' && !is_visible (maze, x, y)) |
|
|
207 | { |
|
|
208 | clean_maze [x][y] = 'X'; |
|
|
209 | |
|
|
210 | // erase everything on this space ad replace it by blocked |
|
|
211 | mapspace &ms = map->at (x, y); |
|
|
212 | |
|
|
213 | while (ms.top) |
|
|
214 | ms.top->destroy (); |
|
|
215 | |
|
|
216 | map->insert (blocked->instance (), x, y, 0, INS_NO_MERGE | INS_NO_WALK_ON); |
|
|
217 | } |
|
|
218 | |
|
|
219 | // second pass, add in walls |
|
|
220 | |
229 | int joinedwalls = 0; |
221 | int joinedwalls = 0; |
230 | object *thiswall; |
|
|
231 | |
222 | |
232 | sprintf (RP->wall_name, "%s", &the_wall->arch->archname); |
223 | assign (RP->wall_name, the_wall->arch->archname); |
233 | if ((cp = strchr (RP->wall_name, '_')) != NULL) |
224 | if (char *cp = strchr (RP->wall_name, '_')) |
234 | { |
225 | { |
235 | *cp = 0; |
226 | *cp = 0; |
236 | joinedwalls = 1; |
227 | joinedwalls = 1; |
237 | } |
228 | } |
238 | |
229 | |
239 | for (i = 0; i < RP->Xsize; i++) |
230 | for (int i = 0; i < RP->Xsize; i++) |
240 | for (j = 0; j < RP->Ysize; j++) |
231 | for (int j = 0; j < RP->Ysize; j++) |
241 | { |
|
|
242 | if (maze[i][j] == '#') |
232 | if (clean_maze [i][j] == '#') |
243 | { |
233 | { |
244 | if (joinedwalls) |
|
|
245 | thiswall = pick_joined_wall (the_wall, maze, i, j, RP); |
234 | object *thiswall = joinedwalls ? pick_joined_wall (the_wall, clean_maze, i, j, RP) |
246 | else |
235 | : the_wall->arch->instance (); |
247 | thiswall = the_wall->arch->instance (); |
|
|
248 | |
236 | |
249 | thiswall->move_block = MOVE_ALL; |
237 | thiswall->move_block = MOVE_ALL; |
250 | map->insert (thiswall, i, j, thiswall, INS_NO_MERGE | INS_NO_WALK_ON); |
238 | map->insert (thiswall, i, j, thiswall, INS_NO_MERGE | INS_NO_WALK_ON); |
251 | |
239 | |
252 | if (mining_map) |
240 | if (mining_map) |
253 | if (object *vein = mining_map->at (rmg_rndm (mining_map->width), rmg_rndm (mining_map->height)).bot) |
241 | if (object *vein = mining_map->at (rmg_rndm (mining_map->width), rmg_rndm (mining_map->height)).bot) |
254 | map->insert (vein->clone (), i, j, thiswall, INS_NO_MERGE | INS_NO_WALK_ON); |
242 | map->insert (vein->clone (), i, j, thiswall, INS_NO_MERGE | INS_NO_WALK_ON); |
255 | } |
243 | } |
256 | } |
|
|
257 | } |
244 | } |
258 | } |
245 | } |
259 | |
246 | |
260 | /* this takes a map, and changes an existing wall to match what's blocked |
247 | /* this takes a map, and changes an existing wall to match what's blocked |
261 | * around it, counting only doors and walls as blocked. If insert_flag is |
248 | * around it, counting only doors and walls as blocked. If insert_flag is |
… | |
… | |
277 | object *the_wall = 0; |
264 | object *the_wall = 0; |
278 | object *new_wall = 0; |
265 | object *new_wall = 0; |
279 | archetype *wall_arch = 0; |
266 | archetype *wall_arch = 0; |
280 | |
267 | |
281 | /* first find the wall */ |
268 | /* first find the wall */ |
282 | for (the_wall = GET_MAP_OB (the_map, i, j); the_wall != NULL; the_wall = the_wall->above) |
269 | for (the_wall = GET_MAP_OB (the_map, i, j); the_wall; the_wall = the_wall->above) |
283 | if ((the_wall->move_type & MOVE_WALK) && the_wall->type != EXIT && the_wall->type != TELEPORTER) |
270 | if ((the_wall->move_type & MOVE_WALK) && the_wall->type != EXIT && the_wall->type != TELEPORTER) |
284 | break; |
271 | break; |
285 | |
|
|
286 | |
272 | |
287 | /* if what we found is a door, don't remove it, set the_wall to NULL to |
273 | /* if what we found is a door, don't remove it, set the_wall to NULL to |
288 | * signal that later. |
274 | * signal that later. |
289 | */ |
275 | */ |
290 | if (the_wall && (the_wall->type == DOOR || the_wall->type == LOCKED_DOOR)) |
276 | if (the_wall && (the_wall->type == DOOR || the_wall->type == LOCKED_DOOR)) |
… | |
… | |
307 | RP->wall_name[l] = 0; |
293 | RP->wall_name[l] = 0; |
308 | break; |
294 | break; |
309 | } |
295 | } |
310 | } |
296 | } |
311 | |
297 | |
312 | surround_index = surround_flag4 (the_map, i, j); |
|
|
313 | /* This would be a lot cleaner to just us a lookup table, |
|
|
314 | * eg, wall_suffix[surround_index] |
|
|
315 | */ |
|
|
316 | switch (surround_index) |
|
|
317 | { |
|
|
318 | case 0: |
|
|
319 | strcat (RP->wall_name, "_0"); |
298 | strcat (RP->wall_name, "_"); |
320 | break; |
299 | strcat (RP->wall_name, wall_suffix [surround_flag4 (the_map, i, j)]); |
321 | case 1: |
|
|
322 | strcat (RP->wall_name, "_1_3"); |
|
|
323 | break; |
|
|
324 | case 2: |
|
|
325 | strcat (RP->wall_name, "_1_4"); |
|
|
326 | break; |
|
|
327 | case 3: |
|
|
328 | strcat (RP->wall_name, "_2_1_2"); |
|
|
329 | break; |
|
|
330 | case 4: |
|
|
331 | strcat (RP->wall_name, "_1_2"); |
|
|
332 | break; |
|
|
333 | case 5: |
|
|
334 | strcat (RP->wall_name, "_2_2_4"); |
|
|
335 | break; |
|
|
336 | case 6: |
|
|
337 | strcat (RP->wall_name, "_2_2_1"); |
|
|
338 | break; |
|
|
339 | case 7: |
|
|
340 | strcat (RP->wall_name, "_3_1"); |
|
|
341 | break; |
|
|
342 | case 8: |
|
|
343 | strcat (RP->wall_name, "_1_1"); |
|
|
344 | break; |
|
|
345 | case 9: |
|
|
346 | strcat (RP->wall_name, "_2_2_3"); |
|
|
347 | break; |
|
|
348 | case 10: |
|
|
349 | strcat (RP->wall_name, "_2_2_2"); |
|
|
350 | break; |
|
|
351 | case 11: |
|
|
352 | strcat (RP->wall_name, "_3_3"); |
|
|
353 | break; |
|
|
354 | case 12: |
|
|
355 | strcat (RP->wall_name, "_2_1_1"); |
|
|
356 | break; |
|
|
357 | case 13: |
|
|
358 | strcat (RP->wall_name, "_3_4"); |
|
|
359 | break; |
|
|
360 | case 14: |
|
|
361 | strcat (RP->wall_name, "_3_2"); |
|
|
362 | break; |
|
|
363 | case 15: |
|
|
364 | strcat (RP->wall_name, "_4"); |
|
|
365 | break; |
|
|
366 | } |
|
|
367 | |
300 | |
368 | wall_arch = archetype::find (RP->wall_name); |
301 | wall_arch = archetype::find (RP->wall_name); |
369 | |
302 | |
370 | if (!wall_arch) |
303 | if (!wall_arch) |
371 | { |
304 | { |