1 |
root |
1.11 |
/* |
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 |
|
|
*/ |
23 |
root |
1.4 |
|
24 |
elmex |
1.1 |
/* peterm@langmuir.eecs.berkeley.edu: this function generates a random |
25 |
|
|
snake-type layout. |
26 |
|
|
|
27 |
|
|
input: xsize, ysize; |
28 |
|
|
output: a char** array with # and . for closed and open respectively. |
29 |
|
|
|
30 |
|
|
a char value of 0 represents a blank space: a '#' is |
31 |
|
|
a wall. |
32 |
|
|
|
33 |
|
|
*/ |
34 |
|
|
|
35 |
|
|
#include <global.h> |
36 |
root |
1.7 |
#include "random_map.h" |
37 |
|
|
#include "rproto.h" |
38 |
elmex |
1.1 |
|
39 |
root |
1.8 |
void |
40 |
root |
1.9 |
make_snake_layout (Layout maze, int options) |
41 |
root |
1.2 |
{ |
42 |
|
|
int i, j; |
43 |
elmex |
1.1 |
|
44 |
root |
1.8 |
maze->clear (); |
45 |
|
|
maze->border (); |
46 |
elmex |
1.1 |
|
47 |
root |
1.8 |
int xsize = maze->w; |
48 |
|
|
int ysize = maze->h; |
49 |
elmex |
1.1 |
|
50 |
|
|
/* Bail out if the size is too small to make a snake. */ |
51 |
root |
1.2 |
if (xsize < 8 || ysize < 8) |
52 |
root |
1.8 |
return; |
53 |
elmex |
1.1 |
|
54 |
|
|
/* decide snake orientation--vertical or horizontal , and |
55 |
|
|
make the walls and place the doors. */ |
56 |
|
|
|
57 |
root |
1.10 |
if (rmg_rndm (2)) |
58 |
root |
1.2 |
{ /* vertical orientation */ |
59 |
root |
1.10 |
int n_walls = rmg_rndm (xsize - 5) / 3 + 1; |
60 |
root |
1.2 |
int spacing = xsize / (n_walls + 1); |
61 |
|
|
int orientation = 1; |
62 |
|
|
|
63 |
|
|
for (i = spacing; i < xsize - 3; i += spacing) |
64 |
|
|
{ |
65 |
|
|
if (orientation) |
66 |
|
|
{ |
67 |
|
|
for (j = 1; j < ysize - 2; j++) |
68 |
root |
1.7 |
maze[i][j] = '#'; |
69 |
|
|
|
70 |
root |
1.2 |
maze[i][j] = 'D'; |
71 |
|
|
} |
72 |
|
|
else |
73 |
|
|
{ |
74 |
|
|
for (j = 2; j < ysize; j++) |
75 |
root |
1.7 |
maze[i][j] = '#'; |
76 |
|
|
|
77 |
root |
1.2 |
maze[i][1] = 'D'; |
78 |
|
|
} |
79 |
root |
1.7 |
|
80 |
root |
1.2 |
orientation ^= 1; /* toggle the value of orientation */ |
81 |
elmex |
1.1 |
} |
82 |
|
|
} |
83 |
root |
1.2 |
else |
84 |
|
|
{ /* horizontal orientation */ |
85 |
root |
1.10 |
int n_walls = rmg_rndm (ysize - 5) / 3 + 1; |
86 |
root |
1.2 |
int spacing = ysize / (n_walls + 1); |
87 |
|
|
int orientation = 1; |
88 |
|
|
|
89 |
|
|
for (i = spacing; i < ysize - 3; i += spacing) |
90 |
|
|
{ |
91 |
|
|
if (orientation) |
92 |
|
|
{ |
93 |
|
|
for (j = 1; j < xsize - 2; j++) |
94 |
root |
1.7 |
maze[j][i] = '#'; |
95 |
|
|
|
96 |
root |
1.2 |
maze[j][i] = 'D'; |
97 |
|
|
} |
98 |
|
|
else |
99 |
|
|
{ |
100 |
|
|
for (j = 2; j < xsize; j++) |
101 |
root |
1.7 |
maze[j][i] = '#'; |
102 |
|
|
|
103 |
root |
1.2 |
maze[1][i] = 'D'; |
104 |
|
|
} |
105 |
root |
1.7 |
|
106 |
root |
1.2 |
orientation ^= 1; /* toggle the value of orientation */ |
107 |
elmex |
1.1 |
} |
108 |
|
|
} |
109 |
root |
1.2 |
|
110 |
elmex |
1.1 |
/* place the exit up/down */ |
111 |
root |
1.10 |
if (rmg_rndm (2)) |
112 |
root |
1.2 |
{ |
113 |
|
|
maze[1][1] = '<'; |
114 |
|
|
maze[xsize - 2][ysize - 2] = '>'; |
115 |
|
|
} |
116 |
elmex |
1.1 |
else |
117 |
root |
1.2 |
{ |
118 |
|
|
maze[1][1] = '>'; |
119 |
|
|
maze[xsize - 2][ysize - 2] = '<'; |
120 |
|
|
} |
121 |
elmex |
1.1 |
} |
122 |
root |
1.7 |
|