00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00036
00037
00038
00039
00040 #include <stdlib.h>
00041 #include <stdio.h>
00042 #include <global.h>
00043 #include <time.h>
00044
00045 #include <maze_gen.h>
00046 #include <room_gen.h>
00047 #include <random_map.h>
00048 #include <sproto.h>
00049 #include <rproto.h>
00050
00051 char **map_gen_onion(int xsize, int ysize, int option, int layers);
00052
00053
00054
00055
00056
00068 void find_top_left_corner(char **maze, int *cx, int *cy) {
00069 (*cy)--;
00070
00071 while (maze[*cx][*cy] == 0)
00072 (*cy)--;
00073
00074 while (maze[*cx][*cy+1] == 0)
00075 (*cx)++;
00076
00077
00078 }
00079
00090 char **make_square_spiral_layout(int xsize, int ysize) {
00091 int i, j;
00092 int cx, cy;
00093 int tx, ty;
00094
00095
00096 char **maze = map_gen_onion(xsize, ysize, OPT_CENTERED|OPT_NO_DOORS, 0);
00097
00098
00099 cx = 0;
00100 cy = 0;
00101 for (i = 0; i < xsize; i++)
00102 for (j = 0; j < ysize; j++) {
00103 if (maze[i][j] == 'C') {
00104 cx = i;
00105 cy = j;
00106 }
00107 }
00108 tx = cx;
00109 ty = cy;
00110 while (1) {
00111 find_top_left_corner(maze, &tx, &ty);
00112
00113 if (ty < 2 || tx < 2 || tx > xsize-2 || ty > ysize-2)
00114 break;
00115 make_wall(maze, tx, ty-1, 1);
00116
00117 maze[tx][ty-1] = '#';
00118 maze[tx-1][ty] = 'D';
00119
00120
00121 while ((tx > 2) && maze[tx-1][ty])
00122 tx--;
00123
00124 make_wall(maze, tx-1, ty, 0);
00125
00126
00127 while (((ty+1) < ysize) && maze[tx][ty+1])
00128 ty++;
00129
00130 make_wall(maze, tx, ty+1, 1);
00131
00132
00133 while (((tx+1) < xsize) && maze[tx+1][ty])
00134 tx++;
00135
00136 make_wall(maze, tx+1, ty, 0);
00137 tx++;
00138 }
00139
00140
00141 if (RANDOM()%2) {
00142 maze[cx][cy] = '>';
00143 maze[xsize-2][1] = '<';
00144 } else {
00145 maze[cx][cy] = '<';
00146 maze[xsize-2][1] = '>';
00147 }
00148
00149 return maze;
00150 }