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, 1 month 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

# 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    
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 root 1.2 void
50     find_top_left_corner (char **maze, int *cx, int *cy)
51     {
52 root 1.9 --(*cy);
53 elmex 1.1
54     /* find the top wall. */
55 root 1.2 while (maze[*cx][*cy] == 0)
56 root 1.9 --(*cy);
57    
58 elmex 1.1 /* proceed right until a corner is detected */
59 root 1.2 while (maze[*cx][*cy + 1] == 0)
60 root 1.9 ++(*cx);
61 root 1.2
62 elmex 1.1 /* cx and cy should now be the top-right corner of the onion layer */
63     }
64    
65 root 1.13 void
66 root 1.14 make_square_spiral_layout (Layout maze, int options)
67 root 1.2 {
68     int i, j;
69     int cx, cy;
70     int tx, ty;
71 elmex 1.1
72     /* generate and allocate a doorless, centered onion */
73 root 1.13 map_gen_onion (maze, RMOPT_CENTERED | RMOPT_NO_DOORS, 0);
74    
75     int xsize = maze->w;
76     int ysize = maze->h;
77 elmex 1.1
78     /* find the layout center. */
79 root 1.2 cx = 0;
80     cy = 0;
81     for (i = 0; i < xsize; i++)
82     for (j = 0; j < ysize; j++)
83 root 1.9 if (maze[i][j] == 'C')
84     {
85     cx = i;
86     cy = j;
87     }
88    
89 root 1.2 tx = cx;
90     ty = cy;
91 root 1.9 for (;;)
92 root 1.2 {
93     find_top_left_corner (maze, &tx, &ty);
94    
95     if (ty < 2 || tx < 2 || tx > xsize - 2 || ty > ysize - 2)
96     break;
97 root 1.9
98 root 1.2 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 elmex 1.1
103 root 1.2 /* walk left until we find the top-left corner */
104 root 1.12 while ((tx > 2) && maze[tx - 1, ty])
105 root 1.2 tx--;
106 elmex 1.1
107 root 1.2 make_wall (maze, tx - 1, ty, 0); /* make a horizontal wall with a door */
108 elmex 1.1
109 root 1.2 /* walk down until we find the bottom-left corner */
110     while (((ty + 1) < ysize) && maze[tx][ty + 1])
111     ty++;
112 elmex 1.1
113 root 1.2 make_wall (maze, tx, ty + 1, 1); /* make a vertical wall with a door */
114 elmex 1.1
115 root 1.2 /* walk rightuntil we find the bottom-right corner */
116     while (((tx + 1) < xsize) && maze[tx + 1][ty])
117     tx++;
118 elmex 1.1
119 root 1.2 make_wall (maze, tx + 1, ty, 0); /* make a horizontal wall with a door */
120     tx++; /* set up for next layer. */
121     }
122 elmex 1.1
123     /* place the exits. */
124    
125 root 1.8 if (rndm (2))
126 root 1.2 {
127     maze[cx][cy] = '>';
128     maze[xsize - 2][1] = '<';
129     }
130     else
131     {
132     maze[cx][cy] = '<';
133     maze[xsize - 2][1] = '>';
134     }
135 elmex 1.1 }
136 root 1.9