ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/snake.C
Revision: 1.9
Committed: Tue Apr 15 03:00:24 2008 UTC (16 years, 1 month ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-2_5, rel-2_52
Changes since 1.8: +1 -1 lines
Log Message:
new logging thread, fix bugs in random map generator

File Contents

# Content
1
2 /* 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 #include "random_map.h"
15 #include "rproto.h"
16
17 void
18 make_snake_layout (Layout maze, int options)
19 {
20 int i, j;
21
22 maze->clear ();
23 maze->border ();
24
25 int xsize = maze->w;
26 int ysize = maze->h;
27
28 /* Bail out if the size is too small to make a snake. */
29 if (xsize < 8 || ysize < 8)
30 return;
31
32 /* decide snake orientation--vertical or horizontal , and
33 make the walls and place the doors. */
34
35 if (rndm (2))
36 { /* vertical orientation */
37 int n_walls = rndm (xsize - 5) / 3 + 1;
38 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 maze[i][j] = '#';
47
48 maze[i][j] = 'D';
49 }
50 else
51 {
52 for (j = 2; j < ysize; j++)
53 maze[i][j] = '#';
54
55 maze[i][1] = 'D';
56 }
57
58 orientation ^= 1; /* toggle the value of orientation */
59 }
60 }
61 else
62 { /* horizontal orientation */
63 int n_walls = rndm (ysize - 5) / 3 + 1;
64 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 maze[j][i] = '#';
73
74 maze[j][i] = 'D';
75 }
76 else
77 {
78 for (j = 2; j < xsize; j++)
79 maze[j][i] = '#';
80
81 maze[1][i] = 'D';
82 }
83
84 orientation ^= 1; /* toggle the value of orientation */
85 }
86 }
87
88 /* place the exit up/down */
89 if (rndm (2))
90 {
91 maze[1][1] = '<';
92 maze[xsize - 2][ysize - 2] = '>';
93 }
94 else
95 {
96 maze[1][1] = '>';
97 maze[xsize - 2][ysize - 2] = '<';
98 }
99 }
100