ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/snake.C
Revision: 1.13
Committed: Fri Jul 2 15:03:57 2010 UTC (13 years, 10 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.12: +2 -2 lines
Log Message:
renmae Layout => layout, add (as of now) useless accessors

File Contents

# Content
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 */
23
24 /* peterm@langmuir.eecs.berkeley.edu: this function generates a random
25 snake-type maze.
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 #include "random_map.h"
37 #include "rproto.h"
38
39 void
40 make_snake_layout (layout &maze, int options)
41 {
42 int i, j;
43
44 maze.clear ();
45 maze.border ();
46
47 int xsize = maze.w;
48 int ysize = maze.h;
49
50 /* Bail out if the size is too small to make a snake. */
51 if (xsize < 8 || ysize < 8)
52 return;
53
54 /* decide snake orientation--vertical or horizontal , and
55 make the walls and place the doors. */
56
57 if (rmg_rndm (2))
58 { /* vertical orientation */
59 int n_walls = rmg_rndm (xsize - 5) / 3 + 1;
60 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 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 */
81 }
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)
90 {
91 if (orientation)
92 {
93 for (j = 1; j < xsize - 2; 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 */
107 }
108 }
109
110 /* place the exit up/down */
111 if (rmg_rndm (2))
112 {
113 maze[1][1] = '<';
114 maze[xsize - 2][ysize - 2] = '>';
115 }
116 else
117 {
118 maze[1][1] = '>';
119 maze[xsize - 2][ysize - 2] = '<';
120 }
121 }
122