1 | |
1 | /* |
|
|
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
|
|
3 | * |
|
|
4 | * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
|
|
5 | * Copyright (©) Crossfire Development Team (restored, original file without copyright notice) |
|
|
6 | * |
|
|
7 | * Deliantra is free software: you can redistribute it and/or modify it under |
|
|
8 | * the terms of the Affero GNU General Public License as published by the |
|
|
9 | * Free Software Foundation, either version 3 of the License, or (at your |
|
|
10 | * option) any later version. |
|
|
11 | * |
|
|
12 | * This program is distributed in the hope that it will be useful, |
|
|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
15 | * GNU General Public License for more details. |
|
|
16 | * |
|
|
17 | * You should have received a copy of the Affero GNU General Public License |
|
|
18 | * and the GNU General Public License along with this program. If not, see |
|
|
19 | * <http://www.gnu.org/licenses/>. |
|
|
20 | * |
|
|
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
|
|
22 | */ |
2 | |
23 | |
3 | /* peterm@langmuir.eecs.berkeley.edu: this function generates a random |
24 | /* peterm@langmuir.eecs.berkeley.edu: this function generates a random |
4 | snake-type layout. |
25 | snake-type layout. |
5 | |
26 | |
6 | input: xsize, ysize; |
27 | input: xsize, ysize; |
… | |
… | |
9 | a char value of 0 represents a blank space: a '#' is |
30 | a char value of 0 represents a blank space: a '#' is |
10 | a wall. |
31 | a wall. |
11 | |
32 | |
12 | */ |
33 | */ |
13 | |
34 | |
|
|
35 | #include <global.h> |
|
|
36 | #include "random_map.h" |
|
|
37 | #include "rproto.h" |
14 | |
38 | |
15 | #include <stdio.h> |
39 | void |
16 | #include <global.h> |
40 | make_snake_layout (Layout maze, int options) |
17 | #include <time.h> |
41 | { |
|
|
42 | int i, j; |
18 | |
43 | |
|
|
44 | maze->clear (); |
|
|
45 | maze->border (); |
19 | |
46 | |
20 | |
47 | int xsize = maze->w; |
21 | |
48 | int ysize = maze->h; |
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 | |
49 | |
37 | /* Bail out if the size is too small to make a snake. */ |
50 | /* Bail out if the size is too small to make a snake. */ |
38 | if(xsize < 8 || ysize < 8) return maze; |
51 | if (xsize < 8 || ysize < 8) |
|
|
52 | return; |
39 | |
53 | |
40 | /* decide snake orientation--vertical or horizontal , and |
54 | /* decide snake orientation--vertical or horizontal , and |
41 | make the walls and place the doors. */ |
55 | make the walls and place the doors. */ |
42 | |
56 | |
43 | if(RANDOM()%2) { /* vertical orientation */ |
57 | if (rmg_rndm (2)) |
44 | int n_walls = RANDOM() % ((xsize - 5)/3) +1; |
58 | { /* vertical orientation */ |
|
|
59 | int n_walls = rmg_rndm (xsize - 5) / 3 + 1; |
45 | int spacing = xsize / (n_walls+1); |
60 | int spacing = xsize / (n_walls + 1); |
46 | int orientation=1; |
61 | int orientation = 1; |
|
|
62 | |
47 | for(i=spacing;i<xsize-3;i+=spacing) { |
63 | for (i = spacing; i < xsize - 3; i += spacing) |
|
|
64 | { |
48 | if(orientation) { |
65 | if (orientation) |
|
|
66 | { |
49 | for(j=1;j<ysize-2;j++) { |
67 | for (j = 1; j < ysize - 2; j++) |
50 | maze[i][j] = '#'; |
68 | maze[i][j] = '#'; |
|
|
69 | |
|
|
70 | maze[i][j] = 'D'; |
|
|
71 | } |
|
|
72 | else |
|
|
73 | { |
|
|
74 | for (j = 2; j < ysize; j++) |
|
|
75 | maze[i][j] = '#'; |
|
|
76 | |
|
|
77 | maze[i][1] = 'D'; |
|
|
78 | } |
|
|
79 | |
|
|
80 | orientation ^= 1; /* toggle the value of orientation */ |
51 | } |
81 | } |
52 | maze[i][j] = 'D'; |
|
|
53 | } |
82 | } |
|
|
83 | else |
|
|
84 | { /* horizontal orientation */ |
|
|
85 | int n_walls = rmg_rndm (ysize - 5) / 3 + 1; |
|
|
86 | int spacing = ysize / (n_walls + 1); |
|
|
87 | int orientation = 1; |
|
|
88 | |
|
|
89 | for (i = spacing; i < ysize - 3; i += spacing) |
54 | else { |
90 | { |
55 | for(j=2;j<ysize;j++) { |
91 | if (orientation) |
|
|
92 | { |
|
|
93 | for (j = 1; j < xsize - 2; j++) |
56 | maze[i][j] = '#'; |
94 | maze[j][i] = '#'; |
|
|
95 | |
|
|
96 | maze[j][i] = 'D'; |
|
|
97 | } |
|
|
98 | else |
|
|
99 | { |
|
|
100 | for (j = 2; j < xsize; j++) |
|
|
101 | maze[j][i] = '#'; |
|
|
102 | |
|
|
103 | maze[1][i] = 'D'; |
|
|
104 | } |
|
|
105 | |
|
|
106 | orientation ^= 1; /* toggle the value of orientation */ |
57 | } |
107 | } |
58 | maze[i][1] = 'D'; |
|
|
59 | } |
|
|
60 | orientation ^= 1; /* toggle the value of orientation */ |
|
|
61 | } |
108 | } |
62 | } |
109 | |
63 | else { /* horizontal orientation */ |
110 | /* place the exit up/down */ |
64 | int n_walls = RANDOM() % ((ysize - 5)/3) +1; |
111 | if (rmg_rndm (2)) |
65 | int spacing = ysize / (n_walls+1); |
112 | { |
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'; |
113 | maze[1][1] = '<'; |
79 | } |
114 | maze[xsize - 2][ysize - 2] = '>'; |
80 | orientation ^= 1; /* toggle the value of orientation */ |
|
|
81 | } |
115 | } |
82 | } |
|
|
83 | |
|
|
84 | /* place the exit up/down */ |
|
|
85 | if(RANDOM() %2) |
|
|
86 | { maze[1][1] = '<'; maze[xsize-2][ysize-2]='>'; } |
|
|
87 | else |
116 | else |
88 | { maze[1][1] = '>'; maze[xsize-2][ysize-2]='<'; } |
|
|
89 | |
117 | { |
90 | |
118 | maze[1][1] = '>'; |
91 | return maze; |
119 | maze[xsize - 2][ysize - 2] = '<'; |
|
|
120 | } |
92 | } |
121 | } |
93 | |
122 | |
94 | |
|
|
95 | |
|
|