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, 6 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

# User Rev Content
1 root 1.11 /*
2     * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 root 1.17 *
4 root 1.19 * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
5 root 1.18 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
6 root 1.15 * Copyright (©) 1994-2004 Crossfire Development Team (restored, original file without copyright notice)
7 root 1.17 *
8 root 1.11 * 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 root 1.17 *
13 root 1.11 * 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 root 1.17 *
18 root 1.11 * 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 root 1.17 *
22 root 1.11 * The authors can be reached via e-mail to <support@deliantra.net>
23     */
24 root 1.4
25 elmex 1.1 /* peterm@langmuir.eecs.berkeley.edu: this function generates a random
26 root 1.13 snake-type maze.
27 elmex 1.1
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 root 1.14 #include <rmg.h>
38 root 1.7 #include "rproto.h"
39 elmex 1.1
40 root 1.8 void
41 root 1.13 make_snake_layout (layout &maze, int options)
42 root 1.2 {
43     int i, j;
44 elmex 1.1
45 root 1.12 maze.clear ();
46     maze.border ();
47 elmex 1.1
48 root 1.12 int xsize = maze.w;
49     int ysize = maze.h;
50 elmex 1.1
51     /* Bail out if the size is too small to make a snake. */
52 root 1.2 if (xsize < 8 || ysize < 8)
53 root 1.8 return;
54 elmex 1.1
55     /* decide snake orientation--vertical or horizontal , and
56     make the walls and place the doors. */
57    
58 root 1.10 if (rmg_rndm (2))
59 root 1.2 { /* vertical orientation */
60 root 1.10 int n_walls = rmg_rndm (xsize - 5) / 3 + 1;
61 root 1.2 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 root 1.7 maze[i][j] = '#';
70    
71 root 1.2 maze[i][j] = 'D';
72     }
73     else
74     {
75     for (j = 2; j < ysize; j++)
76 root 1.7 maze[i][j] = '#';
77    
78 root 1.2 maze[i][1] = 'D';
79     }
80 root 1.7
81 root 1.2 orientation ^= 1; /* toggle the value of orientation */
82 elmex 1.1 }
83     }
84 root 1.2 else
85     { /* horizontal orientation */
86 root 1.10 int n_walls = rmg_rndm (ysize - 5) / 3 + 1;
87 root 1.2 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 root 1.7 maze[j][i] = '#';
96    
97 root 1.2 maze[j][i] = 'D';
98     }
99     else
100     {
101     for (j = 2; j < xsize; j++)
102 root 1.7 maze[j][i] = '#';
103    
104 root 1.2 maze[1][i] = 'D';
105     }
106 root 1.7
107 root 1.2 orientation ^= 1; /* toggle the value of orientation */
108 elmex 1.1 }
109     }
110 root 1.2
111 elmex 1.1 /* place the exit up/down */
112 root 1.10 if (rmg_rndm (2))
113 root 1.2 {
114     maze[1][1] = '<';
115     maze[xsize - 2][ysize - 2] = '>';
116     }
117 elmex 1.1 else
118 root 1.2 {
119     maze[1][1] = '>';
120     maze[xsize - 2][ysize - 2] = '<';
121     }
122 elmex 1.1 }
123 root 1.7