ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/square_spiral.C
Revision: 1.27
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.26: +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 (©) 2001 Mark Wedel & Crossfire Development Team
7 * Copyright (©) 1992 Frank Tore Johansen
8 *
9 * Deliantra is free software: you can redistribute it and/or modify it under
10 * the terms of the Affero GNU General Public License as published by the
11 * Free Software Foundation, either version 3 of the License, or (at your
12 * option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the Affero GNU General Public License
20 * and the GNU General Public License along with this program. If not, see
21 * <http://www.gnu.org/licenses/>.
22 *
23 * The authors can be reached via e-mail to <support@deliantra.net>
24 */
25
26 /* peterm@langmuir.eecs.berkeley.edu: this function generates a random
27 snake-type maze.
28
29 input: xsize, ysize;
30 output: a char** array with # and . for closed and open respectively.
31
32 a char value of 0 represents a blank space: a '#' is
33 a wall.
34
35 */
36
37 #include <global.h>
38
39 #include <rmg.h>
40 #include "rproto.h"
41
42 /* These are some helper functions which help with
43 manipulating a centered onion and turning it into
44 a square spiral */
45 void
46 make_square_spiral_layout (layout &maze, int options)
47 {
48 /* generate and allocate a doorless, centered onion */
49 map_gen_onion (maze, RMOPT_CENTERED | RMOPT_NO_DOORS, 0);
50
51 int xsize = maze.w;
52 int ysize = maze.h;
53
54 /* find the maze center. */
55 int cx = 0;
56 int cy = 0;
57 for (int i = 0; i < xsize; i++)
58 for (int j = 0; j < ysize; j++)
59 if (maze[i][j] == 'C')
60 {
61 cx = i;
62 cy = j;
63 break;
64 }
65
66 int tx = cx;
67 int ty = cy;
68 for (;;)
69 {
70 /* this starts from within a centered onion layer (or between two layers),
71 and looks up until it finds a wall, and then looks right until it
72 finds a vertical wall, i.e., the corner. It sets tx and ty to that.
73 it also starts from tx and ty. */
74 --ty;
75
76 /* find the top wall. */
77 while (maze[tx][ty] != '#')
78 --ty;
79
80 /* proceed right until a corner is detected */
81 while (maze[tx][ty + 1] != '#')
82 ++tx;
83
84 /* tx and ty should now be the top-right corner of the onion layer */
85 if (ty < 2 || tx < 2 || tx > xsize - 2 || ty > ysize - 2)
86 break;
87
88 make_wall (maze, tx, ty - 1, 1); /* make a vertical wall with a door */
89
90 maze[tx][ty - 1] = '#'; /* convert the door that make_wall puts here to a wall */
91 maze[tx - 1][ty] = 'D'; /* make a doorway out of this layer */
92
93 /* walk left until we find the top-left corner */
94 while (tx > 2 && maze[tx - 1][ty])
95 --tx;
96
97 make_wall (maze, tx - 1, ty, 0); /* make a horizontal wall with a door */
98
99 /* walk down until we find the bottom-left corner */
100 while (ty + 1 < ysize && maze[tx][ty + 1])
101 ++ty;
102
103 make_wall (maze, tx, ty + 1, 1); /* make a vertical wall with a door */
104
105 /* walk rightuntil we find the bottom-right corner */
106 while (tx + 1 < xsize && maze[tx + 1][ty])
107 ++tx;
108
109 make_wall (maze, tx + 1, ty, 0); /* make a horizontal wall with a door */
110 ++tx; /* set up for next layer. */
111 }
112
113 /* place the exits. */
114
115 if (rmg_rndm (2))
116 {
117 maze[cx][cy] = '>';
118 maze[xsize - 2][1] = '<';
119 }
120 else
121 {
122 maze[cx][cy] = '<';
123 maze[xsize - 2][1] = '>';
124 }
125 }
126