ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/snake.c
Revision: 1.2
Committed: Sun Aug 13 17:16:03 2006 UTC (17 years, 9 months ago) by elmex
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
State: FILE REMOVED
Log Message:
Made server compile with C++.
Removed cfanim plugin and crossedit.
C++ here we come.

File Contents

# Content
1
2
3 /* peterm@langmuir.eecs.berkeley.edu: this function generates a random
4 snake-type layout.
5
6 input: xsize, ysize;
7 output: a char** array with # and . for closed and open respectively.
8
9 a char value of 0 represents a blank space: a '#' is
10 a wall.
11
12 */
13
14
15 #include <stdio.h>
16 #include <global.h>
17 #include <time.h>
18
19
20
21
22 char **make_snake_layout(int xsize, int ysize,int options) {
23 int i,j;
24
25 /* allocate that array, set it up */
26 char **maze = (char **)calloc(sizeof(char*),xsize);
27 for(i=0;i<xsize;i++) {
28 maze[i] = (char *) calloc(sizeof(char),ysize);
29 }
30
31 /* write the outer walls */
32 for(i=0;i<xsize;i++)
33 maze[i][0] = maze[i][ysize-1] = '#';
34 for(j=0;j<ysize;j++)
35 maze[0][j] = maze[xsize-1][j] = '#';
36
37 /* Bail out if the size is too small to make a snake. */
38 if(xsize < 8 || ysize < 8) return maze;
39
40 /* decide snake orientation--vertical or horizontal , and
41 make the walls and place the doors. */
42
43 if(RANDOM()%2) { /* vertical orientation */
44 int n_walls = RANDOM() % ((xsize - 5)/3) +1;
45 int spacing = xsize / (n_walls+1);
46 int orientation=1;
47 for(i=spacing;i<xsize-3;i+=spacing) {
48 if(orientation) {
49 for(j=1;j<ysize-2;j++) {
50 maze[i][j] = '#';
51 }
52 maze[i][j] = 'D';
53 }
54 else {
55 for(j=2;j<ysize;j++) {
56 maze[i][j] = '#';
57 }
58 maze[i][1] = 'D';
59 }
60 orientation ^= 1; /* toggle the value of orientation */
61 }
62 }
63 else { /* horizontal orientation */
64 int n_walls = RANDOM() % ((ysize - 5)/3) +1;
65 int spacing = ysize / (n_walls+1);
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';
79 }
80 orientation ^= 1; /* toggle the value of orientation */
81 }
82 }
83
84 /* place the exit up/down */
85 if(RANDOM() %2)
86 { maze[1][1] = '<'; maze[xsize-2][ysize-2]='>'; }
87 else
88 { maze[1][1] = '>'; maze[xsize-2][ysize-2]='<'; }
89
90
91 return maze;
92 }
93
94
95