ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/square_spiral.C
(Generate patch)

Comparing deliantra/server/random_maps/square_spiral.C (file contents):
Revision 1.2 by root, Sun Sep 10 16:06:37 2006 UTC vs.
Revision 1.23 by root, Sat Apr 23 04:56:53 2011 UTC

1
2/* 1/*
3 * static char *rcsid_map_c = 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
4 * "$Id: square_spiral.C,v 1.2 2006/09/10 16:06:37 root Exp $"; 3 *
4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992 Frank Tore Johansen
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>
5 */ 23 */
6 24
7/*
8 CrossFire, A Multiplayer game for X-windows
9
10 Copyright (C) 2001 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26
27 The authors can be reached via e-mail at crossfire-devel@real-time.com
28*/
29
30
31/* peterm@langmuir.eecs.berkeley.edu: this function generates a random 25/* peterm@langmuir.eecs.berkeley.edu: this function generates a random
32snake-type layout. 26snake-type maze.
33 27
34input: xsize, ysize; 28input: xsize, ysize;
35output: a char** array with # and . for closed and open respectively. 29output: a char** array with # and . for closed and open respectively.
36 30
37a char value of 0 represents a blank space: a '#' is 31a char value of 0 represents a blank space: a '#' is
38a wall. 32a wall.
39 33
40*/ 34*/
41 35
36#include <global.h>
42 37
43#include <stdio.h>
44#include <global.h>
45#include <time.h>
46
47#include <maze_gen.h>
48#include <room_gen.h> 38#include <rmg.h>
49#include <random_map.h>
50#include <sproto.h>
51#include <rproto.h> 39#include "rproto.h"
52
53
54char **map_gen_onion (int xsize, int ysize, int option, int layers);
55
56 40
57/* These are some helper functions which help with 41/* These are some helper functions which help with
58 manipulating a centered onion and turning it into 42 manipulating a centered onion and turning it into
59 a square spiral */ 43 a square spiral */
44void
45make_square_spiral_layout (layout &maze, int options)
46{
47 /* generate and allocate a doorless, centered onion */
48 map_gen_onion (maze, RMOPT_CENTERED | RMOPT_NO_DOORS, 0);
60 49
61/* this starts from within a centered onion layer (or between two layers), 50 int xsize = maze.w;
62 and looks up until it finds a wall, and then looks right until it 51 int ysize = maze.h;
63 finds a vertical wall, i.e., the corner. It sets cx and cy to that.
64 it also starts from cx and cy. */
65 52
66void 53 /* find the maze center. */
67find_top_left_corner (char **maze, int *cx, int *cy) 54 int cx = 0;
68{ 55 int cy = 0;
56 for (int i = 0; i < xsize; i++)
57 for (int j = 0; j < ysize; j++)
58 if (maze[i][j] == 'C')
59 {
60 cx = i;
61 cy = j;
62 break;
63 }
69 64
70 (*cy)--; 65 int tx = cx;
71 /* find the top wall. */ 66 int ty = cy;
72 while (maze[*cx][*cy] == 0) 67 for (;;)
73 (*cy)--; 68 {
74 /* proceed right until a corner is detected */ 69 /* this starts from within a centered onion layer (or between two layers),
75 while (maze[*cx][*cy + 1] == 0) 70 and looks up until it finds a wall, and then looks right until it
76 (*cx)++; 71 finds a vertical wall, i.e., the corner. It sets tx and ty to that.
72 it also starts from tx and ty. */
73 --ty;
77 74
78 /* cx and cy should now be the top-right corner of the onion layer */ 75 /* find the top wall. */
79} 76 while (maze[tx][ty] != '#')
77 --ty;
80 78
79 /* proceed right until a corner is detected */
80 while (maze[tx][ty + 1] != '#')
81 ++tx;
81 82
82char ** 83 /* tx and ty should now be the top-right corner of the onion layer */
83make_square_spiral_layout (int xsize, int ysize, int options)
84{
85 int i, j;
86 int cx, cy;
87 int tx, ty;
88
89 /* generate and allocate a doorless, centered onion */
90 char **maze = map_gen_onion (xsize, ysize, OPT_CENTERED | OPT_NO_DOORS, 0);
91
92 /* find the layout center. */
93 cx = 0;
94 cy = 0;
95 for (i = 0; i < xsize; i++)
96 for (j = 0; j < ysize; j++)
97 {
98 if (maze[i][j] == 'C')
99 {
100 cx = i;
101 cy = j;
102 }
103 }
104 tx = cx;
105 ty = cy;
106 while (1)
107 {
108 find_top_left_corner (maze, &tx, &ty);
109
110 if (ty < 2 || tx < 2 || tx > xsize - 2 || ty > ysize - 2) 84 if (ty < 2 || tx < 2 || tx > xsize - 2 || ty > ysize - 2)
111 break; 85 break;
86
112 make_wall (maze, tx, ty - 1, 1); /* make a vertical wall with a door */ 87 make_wall (maze, tx, ty - 1, 1); /* make a vertical wall with a door */
113 88
114 maze[tx][ty - 1] = '#'; /* convert the door that make_wall puts here to a wall */ 89 maze[tx][ty - 1] = '#'; /* convert the door that make_wall puts here to a wall */
115 maze[tx - 1][ty] = 'D'; /* make a doorway out of this layer */ 90 maze[tx - 1][ty] = 'D'; /* make a doorway out of this layer */
116 91
117 /* walk left until we find the top-left corner */ 92 /* walk left until we find the top-left corner */
118 while ((tx > 2) && maze[tx - 1][ty]) 93 while (tx > 2 && maze[tx - 1][ty])
119 tx--; 94 --tx;
120 95
121 make_wall (maze, tx - 1, ty, 0); /* make a horizontal wall with a door */ 96 make_wall (maze, tx - 1, ty, 0); /* make a horizontal wall with a door */
122 97
123 /* walk down until we find the bottom-left corner */ 98 /* walk down until we find the bottom-left corner */
124 while (((ty + 1) < ysize) && maze[tx][ty + 1]) 99 while (ty + 1 < ysize && maze[tx][ty + 1])
125 ty++; 100 ++ty;
126 101
127 make_wall (maze, tx, ty + 1, 1); /* make a vertical wall with a door */ 102 make_wall (maze, tx, ty + 1, 1); /* make a vertical wall with a door */
128 103
129 /* walk rightuntil we find the bottom-right corner */ 104 /* walk rightuntil we find the bottom-right corner */
130 while (((tx + 1) < xsize) && maze[tx + 1][ty]) 105 while (tx + 1 < xsize && maze[tx + 1][ty])
131 tx++; 106 ++tx;
132 107
133 make_wall (maze, tx + 1, ty, 0); /* make a horizontal wall with a door */ 108 make_wall (maze, tx + 1, ty, 0); /* make a horizontal wall with a door */
134 tx++; /* set up for next layer. */ 109 ++tx; /* set up for next layer. */
135 } 110 }
136 111
137 /* place the exits. */ 112 /* place the exits. */
138 113
139 if (RANDOM () % 2) 114 if (rmg_rndm (2))
140 { 115 {
141 maze[cx][cy] = '>'; 116 maze[cx][cy] = '>';
142 maze[xsize - 2][1] = '<'; 117 maze[xsize - 2][1] = '<';
143 } 118 }
144 else 119 else
145 { 120 {
146 maze[cx][cy] = '<'; 121 maze[cx][cy] = '<';
147 maze[xsize - 2][1] = '>'; 122 maze[xsize - 2][1] = '>';
148 } 123 }
124}
149 125
150 return maze;
151}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines