ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/square_spiral.C
Revision: 1.14
Committed: Tue Apr 15 03:00:24 2008 UTC (16 years, 2 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.13: +1 -1 lines
Log Message:
new logging thread, fix bugs in random map generator

File Contents

# Content
1 /*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 *
8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your 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 GNU General Public License
19 * along with this program. If not, see <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 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
37 #include "random_map.h"
38 #include "rproto.h"
39
40 /* These are some helper functions which help with
41 manipulating a centered onion and turning it into
42 a square spiral */
43
44 /* this starts from within a centered onion layer (or between two layers),
45 and looks up until it finds a wall, and then looks right until it
46 finds a vertical wall, i.e., the corner. It sets cx and cy to that.
47 it also starts from cx and cy. */
48
49 void
50 find_top_left_corner (char **maze, int *cx, int *cy)
51 {
52 --(*cy);
53
54 /* find the top wall. */
55 while (maze[*cx][*cy] == 0)
56 --(*cy);
57
58 /* proceed right until a corner is detected */
59 while (maze[*cx][*cy + 1] == 0)
60 ++(*cx);
61
62 /* cx and cy should now be the top-right corner of the onion layer */
63 }
64
65 void
66 make_square_spiral_layout (Layout maze, int options)
67 {
68 int i, j;
69 int cx, cy;
70 int tx, ty;
71
72 /* generate and allocate a doorless, centered onion */
73 map_gen_onion (maze, RMOPT_CENTERED | RMOPT_NO_DOORS, 0);
74
75 int xsize = maze->w;
76 int ysize = maze->h;
77
78 /* find the layout center. */
79 cx = 0;
80 cy = 0;
81 for (i = 0; i < xsize; i++)
82 for (j = 0; j < ysize; j++)
83 if (maze[i][j] == 'C')
84 {
85 cx = i;
86 cy = j;
87 }
88
89 tx = cx;
90 ty = cy;
91 for (;;)
92 {
93 find_top_left_corner (maze, &tx, &ty);
94
95 if (ty < 2 || tx < 2 || tx > xsize - 2 || ty > ysize - 2)
96 break;
97
98 make_wall (maze, tx, ty - 1, 1); /* make a vertical wall with a door */
99
100 maze[tx][ty - 1] = '#'; /* convert the door that make_wall puts here to a wall */
101 maze[tx - 1][ty] = 'D'; /* make a doorway out of this layer */
102
103 /* walk left until we find the top-left corner */
104 while ((tx > 2) && maze[tx - 1, ty])
105 tx--;
106
107 make_wall (maze, tx - 1, ty, 0); /* make a horizontal wall with a door */
108
109 /* walk down until we find the bottom-left corner */
110 while (((ty + 1) < ysize) && maze[tx][ty + 1])
111 ty++;
112
113 make_wall (maze, tx, ty + 1, 1); /* make a vertical wall with a door */
114
115 /* walk rightuntil we find the bottom-right corner */
116 while (((tx + 1) < xsize) && maze[tx + 1][ty])
117 tx++;
118
119 make_wall (maze, tx + 1, ty, 0); /* make a horizontal wall with a door */
120 tx++; /* set up for next layer. */
121 }
122
123 /* place the exits. */
124
125 if (rndm (2))
126 {
127 maze[cx][cy] = '>';
128 maze[xsize - 2][1] = '<';
129 }
130 else
131 {
132 maze[cx][cy] = '<';
133 maze[xsize - 2][1] = '>';
134 }
135 }
136