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.5 by root, Thu Jan 18 19:42:10 2007 UTC vs.
Revision 1.8 by root, Mon Apr 14 22:41:17 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines