… | |
… | |
29 | 8 = wall below */ |
29 | 8 = wall below */ |
30 | int surround_index = 0; |
30 | int surround_index = 0; |
31 | |
31 | |
32 | if ((i > 0) && (layout[i - 1][j] != 0 && layout[i - 1][j] != '.')) |
32 | if ((i > 0) && (layout[i - 1][j] != 0 && layout[i - 1][j] != '.')) |
33 | surround_index += 1; |
33 | surround_index += 1; |
|
|
34 | |
34 | if ((i < Xsize - 1) && (layout[i + 1][j] != 0 && layout[i + 1][j] != '.')) |
35 | if ((i < Xsize - 1) && (layout[i + 1][j] != 0 && layout[i + 1][j] != '.')) |
35 | surround_index += 2; |
36 | surround_index += 2; |
|
|
37 | |
36 | if ((j > 0) && (layout[i][j - 1] != 0 && layout[i][j - 1] != '.')) |
38 | if ((j > 0) && (layout[i][j - 1] != 0 && layout[i][j - 1] != '.')) |
37 | surround_index += 4; |
39 | surround_index += 4; |
|
|
40 | |
38 | if ((j < Ysize - 1) && (layout[i][j + 1] != 0 && layout[i][j + 1] != '.')) |
41 | if ((j < Ysize - 1) && (layout[i][j + 1] != 0 && layout[i][j + 1] != '.')) |
39 | surround_index += 8; |
42 | surround_index += 8; |
|
|
43 | |
40 | return surround_index; |
44 | return surround_index; |
41 | } |
45 | } |
42 | |
46 | |
43 | /* actually make the layout: we work by a reduction process: |
47 | /* actually make the layout: we work by a reduction process: |
44 | * first we make everything a wall, then we remove areas to make rooms |
48 | * first we make everything a wall, then we remove areas to make rooms |
45 | */ |
49 | */ |
46 | void |
50 | void |
47 | roguelike_layout_gen (Maze maze, int options) |
51 | roguelike_layout_gen (Layout maze, int options) |
48 | { |
52 | { |
49 | int i, j; |
53 | int i, j; |
50 | Room *walk; |
54 | Room *walk; |
51 | int nrooms = 0; |
55 | int nrooms = 0; |
52 | int tries = 0; |
56 | int tries = 0; |
… | |
… | |
83 | tries++; |
87 | tries++; |
84 | else |
88 | else |
85 | i++; |
89 | i++; |
86 | } |
90 | } |
87 | |
91 | |
88 | if (i == 0) |
92 | if (i == 0) /* no can do! */ |
89 | { /* no can do! */ |
93 | { |
90 | maze->clear (); |
94 | maze->clear (); |
91 | maze->border (); |
95 | maze->border (); |
92 | |
96 | |
93 | maze [(xsize - 1) / 2][(ysize - 1) / 2 ] = '>'; |
97 | maze [(xsize - 1) / 2][(ysize - 1) / 2 ] = '>'; |
94 | maze [(xsize - 1) / 2][(ysize - 1) / 2 + 1] = '<'; |
98 | maze [(xsize - 1) / 2][(ysize - 1) / 2 + 1] = '<'; |
95 | |
99 | |
96 | sfree (rooms, nrooms + 1); |
100 | sfree (rooms, nrooms + 1); |
97 | return; |
101 | return; |
98 | } |
102 | } |
99 | |
|
|
100 | |
103 | |
101 | /* erase the areas occupied by the rooms */ |
104 | /* erase the areas occupied by the rooms */ |
102 | roguelike_make_rooms (rooms, maze, options); |
105 | roguelike_make_rooms (rooms, maze, options); |
103 | |
106 | |
104 | roguelike_link_rooms (rooms, maze, xsize, ysize); |
107 | roguelike_link_rooms (rooms, maze, xsize, ysize); |