ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/snake.C
(Generate patch)

Comparing deliantra/server/random_maps/snake.C (file contents):
Revision 1.1 by elmex, Sun Aug 13 17:16:03 2006 UTC vs.
Revision 1.2 by root, Sun Sep 10 16:06:37 2006 UTC

17#include <time.h> 17#include <time.h>
18 18
19 19
20 20
21 21
22char **
22char **make_snake_layout(int xsize, int ysize,int options) { 23make_snake_layout (int xsize, int ysize, int options)
24{
23 int i,j; 25 int i, j;
24 26
25 /* allocate that array, set it up */ 27 /* allocate that array, set it up */
26 char **maze = (char **)calloc(sizeof(char*),xsize); 28 char **maze = (char **) calloc (sizeof (char *), xsize);
29
27 for(i=0;i<xsize;i++) { 30 for (i = 0; i < xsize; i++)
31 {
28 maze[i] = (char *) calloc(sizeof(char),ysize); 32 maze[i] = (char *) calloc (sizeof (char), ysize);
29 } 33 }
30 34
31 /* write the outer walls */ 35 /* write the outer walls */
32 for(i=0;i<xsize;i++) 36 for (i = 0; i < xsize; i++)
33 maze[i][0] = maze[i][ysize-1] = '#'; 37 maze[i][0] = maze[i][ysize - 1] = '#';
34 for(j=0;j<ysize;j++) 38 for (j = 0; j < ysize; j++)
35 maze[0][j] = maze[xsize-1][j] = '#'; 39 maze[0][j] = maze[xsize - 1][j] = '#';
36 40
37 /* Bail out if the size is too small to make a snake. */ 41 /* Bail out if the size is too small to make a snake. */
38 if(xsize < 8 || ysize < 8) return maze; 42 if (xsize < 8 || ysize < 8)
43 return maze;
39 44
40 /* decide snake orientation--vertical or horizontal , and 45 /* decide snake orientation--vertical or horizontal , and
41 make the walls and place the doors. */ 46 make the walls and place the doors. */
42 47
43 if(RANDOM()%2) { /* vertical orientation */ 48 if (RANDOM () % 2)
49 { /* vertical orientation */
44 int n_walls = RANDOM() % ((xsize - 5)/3) +1; 50 int n_walls = RANDOM () % ((xsize - 5) / 3) + 1;
45 int spacing = xsize / (n_walls+1); 51 int spacing = xsize / (n_walls + 1);
46 int orientation=1; 52 int orientation = 1;
53
47 for(i=spacing;i<xsize-3;i+=spacing) { 54 for (i = spacing; i < xsize - 3; i += spacing)
55 {
48 if(orientation) { 56 if (orientation)
57 {
49 for(j=1;j<ysize-2;j++) { 58 for (j = 1; j < ysize - 2; j++)
59 {
60 maze[i][j] = '#';
61 }
50 maze[i][j] = '#'; 62 maze[i][j] = 'D';
63 }
64 else
65 {
66 for (j = 2; j < ysize; j++)
67 {
68 maze[i][j] = '#';
69 }
70 maze[i][1] = 'D';
71 }
72 orientation ^= 1; /* toggle the value of orientation */
51 } 73 }
52 maze[i][j] = 'D';
53 } 74 }
75 else
76 { /* horizontal orientation */
77 int n_walls = RANDOM () % ((ysize - 5) / 3) + 1;
78 int spacing = ysize / (n_walls + 1);
79 int orientation = 1;
80
81 for (i = spacing; i < ysize - 3; i += spacing)
54 else { 82 {
55 for(j=2;j<ysize;j++) { 83 if (orientation)
84 {
85 for (j = 1; j < xsize - 2; j++)
86 {
87 maze[j][i] = '#';
88 }
56 maze[i][j] = '#'; 89 maze[j][i] = 'D';
90 }
91 else
92 {
93 for (j = 2; j < xsize; j++)
94 {
95 maze[j][i] = '#';
96 }
97 maze[1][i] = 'D';
98 }
99 orientation ^= 1; /* toggle the value of orientation */
57 } 100 }
58 maze[i][1] = 'D';
59 }
60 orientation ^= 1; /* toggle the value of orientation */
61 } 101 }
62 } 102
63 else { /* horizontal orientation */ 103 /* place the exit up/down */
64 int n_walls = RANDOM() % ((ysize - 5)/3) +1; 104 if (RANDOM () % 2)
65 int spacing = ysize / (n_walls+1); 105 {
66 int orientation=1;
67 for(i=spacing;i<ysize-3;i+=spacing) {
68 if(orientation) {
69 for(j=1;j<xsize-2;j++) {
70 maze[j][i] = '#';
71 }
72 maze[j][i] = 'D';
73 }
74 else {
75 for(j=2;j<xsize;j++) {
76 maze[j][i] = '#';
77 }
78 maze[1][i] = 'D'; 106 maze[1][1] = '<';
79 } 107 maze[xsize - 2][ysize - 2] = '>';
80 orientation ^= 1; /* toggle the value of orientation */
81 } 108 }
82 }
83
84 /* place the exit up/down */
85 if(RANDOM() %2)
86 { maze[1][1] = '<'; maze[xsize-2][ysize-2]='>'; }
87 else 109 else
88 { maze[1][1] = '>'; maze[xsize-2][ysize-2]='<'; }
89 110 {
90 111 maze[1][1] = '>';
112 maze[xsize - 2][ysize - 2] = '<';
113 }
114
115
91 return maze; 116 return maze;
92} 117}
93
94
95

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines