ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/snake.C
Revision: 1.7
Committed: Fri Apr 11 21:09:53 2008 UTC (16 years, 1 month ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.6: +17 -31 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.4
2 elmex 1.1 /* peterm@langmuir.eecs.berkeley.edu: this function generates a random
3     snake-type layout.
4    
5     input: xsize, ysize;
6     output: a char** array with # and . for closed and open respectively.
7    
8     a char value of 0 represents a blank space: a '#' is
9     a wall.
10    
11     */
12    
13     #include <global.h>
14 root 1.7 #include "random_map.h"
15     #include "rproto.h"
16 elmex 1.1
17 root 1.7 Maze
18 root 1.2 make_snake_layout (int xsize, int ysize, int options)
19     {
20     int i, j;
21 elmex 1.1
22 root 1.7 Maze maze (xsize, ysize);
23 elmex 1.1
24     /* write the outer walls */
25 root 1.7 for (i = 0; i < xsize; i++) maze[i][0] = maze[i][ysize - 1] = '#';
26     for (j = 0; j < ysize; j++) maze[0][j] = maze[xsize - 1][j] = '#';
27 elmex 1.1
28     /* Bail out if the size is too small to make a snake. */
29 root 1.2 if (xsize < 8 || ysize < 8)
30     return maze;
31 elmex 1.1
32     /* decide snake orientation--vertical or horizontal , and
33     make the walls and place the doors. */
34    
35 root 1.5 if (rndm (2))
36 root 1.2 { /* vertical orientation */
37 root 1.6 int n_walls = rndm (xsize - 5) / 3 + 1;
38 root 1.2 int spacing = xsize / (n_walls + 1);
39     int orientation = 1;
40    
41     for (i = spacing; i < xsize - 3; i += spacing)
42     {
43     if (orientation)
44     {
45     for (j = 1; j < ysize - 2; j++)
46 root 1.7 maze[i][j] = '#';
47    
48 root 1.2 maze[i][j] = 'D';
49     }
50     else
51     {
52     for (j = 2; j < ysize; j++)
53 root 1.7 maze[i][j] = '#';
54    
55 root 1.2 maze[i][1] = 'D';
56     }
57 root 1.7
58 root 1.2 orientation ^= 1; /* toggle the value of orientation */
59 elmex 1.1 }
60     }
61 root 1.2 else
62     { /* horizontal orientation */
63 root 1.6 int n_walls = rndm (ysize - 5) / 3 + 1;
64 root 1.2 int spacing = ysize / (n_walls + 1);
65     int orientation = 1;
66    
67     for (i = spacing; i < ysize - 3; i += spacing)
68     {
69     if (orientation)
70     {
71     for (j = 1; j < xsize - 2; j++)
72 root 1.7 maze[j][i] = '#';
73    
74 root 1.2 maze[j][i] = 'D';
75     }
76     else
77     {
78     for (j = 2; j < xsize; j++)
79 root 1.7 maze[j][i] = '#';
80    
81 root 1.2 maze[1][i] = 'D';
82     }
83 root 1.7
84 root 1.2 orientation ^= 1; /* toggle the value of orientation */
85 elmex 1.1 }
86     }
87 root 1.2
88 elmex 1.1 /* place the exit up/down */
89 root 1.5 if (rndm (2))
90 root 1.2 {
91     maze[1][1] = '<';
92     maze[xsize - 2][ysize - 2] = '>';
93     }
94 elmex 1.1 else
95 root 1.2 {
96     maze[1][1] = '>';
97     maze[xsize - 2][ysize - 2] = '<';
98     }
99    
100 elmex 1.1 return maze;
101     }
102 root 1.7