ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/snake.C
Revision: 1.19
Committed: Sat Nov 17 23:40:02 2018 UTC (5 years, 5 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.18: +1 -0 lines
Log Message:
copyright update 2018

File Contents

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