45 int surround_index = 0;
47 if ((i > 0) && (layout[i-1][j] != 0 && layout[i-1][j] !=
'.'))
49 if ((i < Xsize-1) && (layout[i+1][j] != 0 && layout[i+1][j] !=
'.'))
51 if ((j > 0) && (layout[i][j-1] != 0 && layout[i][j-1] !=
'.'))
53 if ((j < Ysize-1) && (layout[i][j+1] != 0 && layout[i][j+1] !=
'.'))
55 return surround_index;
77 char **maze = (
char **)malloc(
sizeof(
char *)*xsize);
78 for (i = 0; i < xsize; i++) {
79 maze[i] = (
char *)malloc(
sizeof(
char)*ysize);
80 for (j = 0; j < ysize; j++)
88 if (xsize < 11 || ysize < 11) {
89 for (i = 1; i < xsize-1; i++)
90 for (j = 1; j < ysize-1; j++)
92 maze[(xsize-1)/2][(ysize-1)/2] =
'>';
93 maze[(xsize-1)/2][(ysize-1)/2+1] =
'<';
98 nrooms = RANDOM()%10+6;
99 Rooms = (
Room *)calloc(nrooms+1,
sizeof(
Room));
103 while (tries < 450 && i < nrooms) {
112 for (i = 1; i < xsize-1; i++)
113 for (j = 1; j < ysize-1; j++)
115 maze[(xsize-1)/2][(ysize-1)/2] =
'>';
116 maze[(xsize-1)/2][(ysize-1)/2+1] =
'<';
128 maze[Rooms->
x][Rooms->
y] =
'<';
130 for (walk = Rooms; walk->
x != 0; walk++)
140 if (maze[walk->
x][walk->
y+1] ==
'.')
141 maze[walk->
x][walk->
y+1] =
'>';
143 maze[walk->
x][walk->
y-1] =
'>';
145 maze[walk->
x][walk->
y] =
'>';
148 for (i = 0; i < xsize; i++)
149 for (j = 0; j < ysize; j++) {
150 if (maze[i][j] ==
'.')
152 if (maze[i][j] ==
'D') {
155 if (si != 3 && si != 12) {
191 x_basesize = xsize/
isqrt(nrooms);
192 y_basesize = ysize/
isqrt(nrooms);
199 sx = (RANDOM()%x_basesize)+(RANDOM()%x_basesize)+(RANDOM()%x_basesize);
200 sy = (RANDOM()%y_basesize)+(RANDOM()%y_basesize)+(RANDOM()%y_basesize);
211 if (zx > xsize-1 || ax < 1)
213 if (zy > ysize-1 || ay < 1)
217 if (sx < 3 || sy < 3)
221 for (walk = Rooms; walk->
x != 0; walk++) {
222 int dx = abs(tx-walk->
x);
223 int dy = abs(ty-walk->
y);
225 if ((dx < (walk->
sx+sx)/2+2) && (dy < (walk->
sy+sy)/2+2))
232 for (walk = Rooms; walk->
x != 0; walk++)
255 int making_circle = 0;
260 for (walk = Rooms; walk->
x != 0; walk++) {
272 making_circle = ((RANDOM()%3 == 0) ? 1 : 0);
276 if (walk->
sx < walk->
sy)
282 for (i = walk->
ax; i < walk->zx; i++)
283 for (j = walk->
ay; j < walk->zy; j++) {
284 if (!making_circle || ((
int)(0.5+hypot(walk->
x-i, walk->
y-j))) <= R)
308 for (walk = Rooms+1; walk->
x != 0; walk++) {
311 int x2 = (walk-1)->x;
312 int y2 = (walk-1)->y;
320 int tx = x2, ty = y2;
328 for (i = x1; i < x2; i++) {
329 if (in_wall == 0 && maze[i][j] ==
'#') {
332 }
else if (in_wall && maze[i][j] ==
'.') {
335 }
else if (maze[i][j] !=
'D' && maze[i][j] !=
'.')
339 if (maze[i][j] ==
'.')
341 if (maze[i][j] == 0 || maze[i][j] ==
'#')
343 for (; j <
MAX(y1, y2); j++) {
344 if (in_wall == 0 && maze[i][j] ==
'#') {
347 }
else if (in_wall && maze[i][j] ==
'.') {
350 }
else if (maze[i][j] !=
'D' && maze[i][j] !=
'.')
357 int tx = x2, ty = y2;
365 for (j = y1; j < y2; j++) {
366 if (in_wall == 0 && maze[i][j] ==
'#') {
369 }
else if (in_wall && maze[i][j] ==
'.') {
372 }
else if (maze[i][j] !=
'D' && maze[i][j] !=
'.')
377 if (maze[i][j] ==
'.')
379 if (maze[i][j] == 0 || maze[i][j] ==
'#')
381 for (; i <
MAX(x1, x2); i++) {
382 if (in_wall == 0 && maze[i][j] ==
'#') {
385 }
else if (in_wall && maze[i][j] ==
'.') {
389 if (maze[i][j] !=
'D' && maze[i][j] !=
'.')
char ** roguelike_layout_gen(int xsize, int ysize, int options)
static void roguelike_link_rooms(Room *Rooms, char **maze, int xsize, int ysize)
static struct Command_Line_Options options[]
static int roguelike_place_room(Room *Rooms, int xsize, int ysize, int nrooms)
static void roguelike_make_rooms(Room *Rooms, char **maze, int options)
int surround_check(char **layout, int i, int j, int Xsize, int Ysize)