1 | /* |
1 | /* |
2 | * CrossFire, A Multiplayer game for X-windows |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (C) 1994 Mark Wedel |
5 | * Copyright (©) 1994,2007 Mark Wedel |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
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 |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program; if not, write to the Free Software |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
|
21 | * |
20 | * |
22 | * The author can be reached via e-mail to mark@pyramid.com |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
22 | */ |
24 | |
|
|
25 | |
23 | |
26 | /* The onion room generator: |
24 | /* The onion room generator: |
27 | Onion rooms are like this: |
25 | Onion rooms are like this: |
28 | |
26 | |
29 | char **map_gen_spiral(int xsize, int ysize, int option); |
27 | char **map_gen_spiral(int xsize, int ysize, int option); |
… | |
… | |
51 | |
49 | |
52 | #define MAX_FINE .454545 |
50 | #define MAX_FINE .454545 |
53 | |
51 | |
54 | extern int surround_check (char **maze, int i, int j, int xsize, int ysize); |
52 | extern int surround_check (char **maze, int i, int j, int xsize, int ysize); |
55 | |
53 | |
56 | char ** |
54 | Maze |
57 | map_gen_spiral (int xsize, int ysize, int option) |
55 | map_gen_spiral (int xsize, int ysize, int option) |
58 | { |
56 | { |
59 | int i, j; |
57 | int i, j; |
60 | float parm = 0; |
58 | float parm = 0; |
61 | float x = 0, y = 0; |
59 | float x = 0, y = 0; |
62 | int ic, jc; |
60 | int ic, jc; |
63 | float SizeX, SizeY; |
61 | float SizeX, SizeY; |
64 | float xscale, yscale; |
62 | float xscale, yscale; |
65 | |
63 | |
66 | /* allocate that array, set it up */ |
64 | Maze maze (xsize, ysize); |
67 | char **maze = (char **) calloc (sizeof (char *), xsize); |
|
|
68 | |
|
|
69 | for (i = 0; i < xsize; i++) |
|
|
70 | { |
|
|
71 | maze[i] = (char *) calloc (sizeof (char), ysize); |
|
|
72 | } |
|
|
73 | |
65 | |
74 | /* slightly easier to fill and then cut */ |
66 | /* slightly easier to fill and then cut */ |
75 | for (i = 0; i < xsize; i++) |
67 | for (i = 0; i < xsize; i++) |
76 | for (j = 0; j < ysize; j++) |
68 | for (j = 0; j < ysize; j++) |
77 | maze[i][j] = '#'; |
69 | maze[i][j] = '#'; |
… | |
… | |
81 | SizeX = xsize / 2 - 2; |
73 | SizeX = xsize / 2 - 2; |
82 | SizeY = ysize / 2 - 2; |
74 | SizeY = ysize / 2 - 2; |
83 | |
75 | |
84 | /* select random options if necessary */ |
76 | /* select random options if necessary */ |
85 | if (option == 0) |
77 | if (option == 0) |
86 | { |
|
|
87 | option = RANDOM () % MAX_SPIRAL_OPT; |
78 | option = rndm (MAX_SPIRAL_OPT); |
88 | } |
|
|
89 | |
79 | |
90 | /* the order in which these are evaluated matters */ |
80 | /* the order in which these are evaluated matters */ |
91 | |
81 | |
92 | /* the following two are mutually exclusive. |
82 | /* the following two are mutually exclusive. |
93 | pick one if they're both set. */ |
83 | pick one if they're both set. */ |
… | |
… | |
128 | /* cut out the spiral */ |
118 | /* cut out the spiral */ |
129 | while ((fabs (x) < SizeX) && (fabs (y) < SizeY)) |
119 | while ((fabs (x) < SizeX) && (fabs (y) < SizeY)) |
130 | { |
120 | { |
131 | x = parm * cos (parm) * xscale; |
121 | x = parm * cos (parm) * xscale; |
132 | y = parm * sin (parm) * yscale; |
122 | y = parm * sin (parm) * yscale; |
133 | maze[(int) (ic + x)][(int) (jc + y)] = '\0'; |
123 | maze[int (ic + x)][int (jc + y)] = '\0'; |
134 | parm += 0.01; |
124 | parm += 0.01; |
135 | }; |
125 | }; |
136 | |
126 | |
137 | maze[(int) (ic + x + 0.5)][(int) (jc + y + 0.5)] = '<'; |
127 | maze[int (ic + x + 0.5)][int (jc + y + 0.5)] = '<'; |
138 | |
|
|
139 | |
128 | |
140 | /* cut out the center in a 2x2 and place the center and downexit */ |
129 | /* cut out the center in a 2x2 and place the center and downexit */ |
141 | maze[ic][jc + 1] = '>'; |
130 | maze[ic][jc + 1] = '>'; |
142 | maze[ic][jc] = 'C'; |
131 | maze[ic][jc] = 'C'; |
143 | |
|
|
144 | |
132 | |
145 | return maze; |
133 | return maze; |
146 | } |
134 | } |
147 | |
135 | |
148 | /* the following function connects disjoint spirals which may |
136 | /* the following function connects disjoint spirals which may |
… | |
… | |
224 | i = 0; |
212 | i = 0; |
225 | j = 0; |
213 | j = 0; |
226 | } |
214 | } |
227 | } |
215 | } |
228 | } |
216 | } |
229 | |
|
|
230 | |
|
|
231 | |
|
|
232 | } |
217 | } |