… | |
… | |
19 | * <http://www.gnu.org/licenses/>. |
19 | * <http://www.gnu.org/licenses/>. |
20 | * |
20 | * |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
22 | */ |
23 | |
23 | |
24 | /* generate a rogue/nethack-like layout */ |
24 | /* generate a rogue/nethack-like maze */ |
25 | #include <global.h> |
25 | #include <global.h> |
26 | #include <random_map.h> |
26 | #include <random_map.h> |
27 | #include <rproto.h> |
27 | #include <rproto.h> |
28 | |
28 | |
29 | typedef struct |
29 | typedef struct |
… | |
… | |
41 | static int roguelike_place_room (Room *rooms, int xsize, int ysize, int nrooms); |
41 | static int roguelike_place_room (Room *rooms, int xsize, int ysize, int nrooms); |
42 | static void roguelike_make_rooms (Room *rooms, char **maze, int options); |
42 | static void roguelike_make_rooms (Room *rooms, char **maze, int options); |
43 | static void roguelike_link_rooms (Room *rooms, char **maze, int xsize, int ysize); |
43 | static void roguelike_link_rooms (Room *rooms, char **maze, int xsize, int ysize); |
44 | |
44 | |
45 | int |
45 | int |
46 | surround_check (char **layout, int i, int j, int Xsize, int Ysize) |
46 | surround_check (char **maze, int i, int j, int Xsize, int Ysize) |
47 | { |
47 | { |
48 | /* 1 = wall to left, |
48 | /* 1 = wall to left, |
49 | 2 = wall to right, |
49 | 2 = wall to right, |
50 | 4 = wall above |
50 | 4 = wall above |
51 | 8 = wall below */ |
51 | 8 = wall below */ |
52 | int surround_index = 0; |
52 | int surround_index = 0; |
53 | |
53 | |
54 | if ((i > 0) && (layout[i - 1][j] != 0 && layout[i - 1][j] != '.')) surround_index |= 1; |
54 | if ((i > 0) && (maze[i - 1][j] != 0 && maze[i - 1][j] != '.')) surround_index |= 1; |
55 | if ((i < Xsize - 1) && (layout[i + 1][j] != 0 && layout[i + 1][j] != '.')) surround_index |= 2; |
55 | if ((i < Xsize - 1) && (maze[i + 1][j] != 0 && maze[i + 1][j] != '.')) surround_index |= 2; |
56 | if ((j > 0) && (layout[i][j - 1] != 0 && layout[i][j - 1] != '.')) surround_index |= 4; |
56 | if ((j > 0) && (maze[i][j - 1] != 0 && maze[i][j - 1] != '.')) surround_index |= 4; |
57 | if ((j < Ysize - 1) && (layout[i][j + 1] != 0 && layout[i][j + 1] != '.')) surround_index |= 8; |
57 | if ((j < Ysize - 1) && (maze[i][j + 1] != 0 && maze[i][j + 1] != '.')) surround_index |= 8; |
58 | |
58 | |
59 | return surround_index; |
59 | return surround_index; |
60 | } |
60 | } |
61 | |
61 | |
62 | /* actually make the layout: we work by a reduction process: |
62 | /* actually make the maze: we work by a reduction process: |
63 | * first we make everything a wall, then we remove areas to make rooms |
63 | * first we make everything a wall, then we remove areas to make rooms |
64 | */ |
64 | */ |
65 | void |
65 | void |
66 | roguelike_layout_gen (Layout &maze, int options) |
66 | roguelike_layout_gen (layout &maze, int options) |
67 | { |
67 | { |
68 | int i, j; |
68 | int i, j; |
69 | Room *walk; |
69 | Room *walk; |
70 | int nrooms = 0; |
70 | int nrooms = 0; |
71 | int tries = 0; |
71 | int tries = 0; |