1 | |
|
|
2 | /* generate a rogue/nethack-like layout */ |
1 | /* generate a rogue/nethack-like layout */ |
3 | #include <global.h> |
2 | #include <global.h> |
4 | #include <random_map.h> |
3 | #include <random_map.h> |
5 | #include <math.h> |
4 | #include <rproto.h> |
6 | |
5 | |
7 | typedef struct |
6 | typedef struct |
8 | { |
7 | { |
9 | int x; |
8 | int x; |
10 | int y; /* coordinates of room centers */ |
9 | int y; /* coordinates of room centers */ |
… | |
… | |
301 | maze[i - 1][j] = 'D'; |
300 | maze[i - 1][j] = 'D'; |
302 | } |
301 | } |
303 | else if (maze[i][j] != 'D' && maze[i][j] != '.') |
302 | else if (maze[i][j] != 'D' && maze[i][j] != '.') |
304 | maze[i][j] = 0; |
303 | maze[i][j] = 0; |
305 | } |
304 | } |
|
|
305 | |
306 | j = MIN (y1, y2); |
306 | j = min (y1, y2); |
|
|
307 | |
307 | if (maze[i][j] == '.') |
308 | if (maze[i][j] == '.') |
308 | in_wall = 0; |
309 | in_wall = 0; |
|
|
310 | |
309 | if (maze[i][j] == 0 || maze[i][j] == '#') |
311 | if (maze[i][j] == 0 || maze[i][j] == '#') |
310 | in_wall = 1; |
312 | in_wall = 1; |
|
|
313 | |
311 | for ( /* j set already */ ; j < MAX (y1, y2); j++) |
314 | for ( /* j set already */ ; j < max (y1, y2); j++) |
312 | { |
315 | { |
313 | if (in_wall == 0 && maze[i][j] == '#') |
316 | if (in_wall == 0 && maze[i][j] == '#') |
314 | { |
317 | { |
315 | in_wall = 1; |
318 | in_wall = 1; |
316 | maze[i][j] = 'D'; |
319 | maze[i][j] = 'D'; |
… | |
… | |
354 | } |
357 | } |
355 | else if (maze[i][j] != 'D' && maze[i][j] != '.') |
358 | else if (maze[i][j] != 'D' && maze[i][j] != '.') |
356 | maze[i][j] = 0; |
359 | maze[i][j] = 0; |
357 | } |
360 | } |
358 | |
361 | |
359 | i = MIN (x1, x2); |
362 | i = min (x1, x2); |
|
|
363 | |
360 | if (maze[i][j] == '.') |
364 | if (maze[i][j] == '.') |
361 | in_wall = 0; |
365 | in_wall = 0; |
|
|
366 | |
362 | if (maze[i][j] == 0 || maze[i][j] == '#') |
367 | if (maze[i][j] == 0 || maze[i][j] == '#') |
363 | in_wall = 1; |
368 | in_wall = 1; |
|
|
369 | |
364 | for ( /* i set already */ ; i < MAX (x1, x2); i++) |
370 | for ( /* i set already */ ; i < max (x1, x2); i++) |
365 | { |
371 | { |
366 | if (in_wall == 0 && maze[i][j] == '#') |
372 | if (in_wall == 0 && maze[i][j] == '#') |
367 | { |
373 | { |
368 | in_wall = 1; |
374 | in_wall = 1; |
369 | maze[i][j] = 'D'; |
375 | maze[i][j] = 'D'; |