ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/square_spiral.C
Revision: 1.15
Committed: Tue Apr 15 18:43:11 2008 UTC (16 years, 1 month ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-2_5, rel-2_52
Changes since 1.14: +28 -40 lines
Log Message:
fix.bug.

File Contents

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