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