1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) Crossfire Development Team (restored, original file without copyright notice) |
5 | * Copyright (©) 1994-2004 Crossfire Development Team (restored, original file without copyright notice) |
6 | * |
6 | * |
7 | * Deliantra is free software: you can redistribute it and/or modify it under |
7 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * the terms of the Affero GNU General Public License as published by the |
8 | * the terms of the Affero GNU General Public License as published by the |
9 | * Free Software Foundation, either version 3 of the License, or (at your |
9 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | * option) any later version. |
10 | * option) any later version. |
11 | * |
11 | * |
12 | * This program is distributed in the hope that it will be useful, |
12 | * This program is distributed in the hope that it will be useful, |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * GNU General Public License for more details. |
15 | * GNU General Public License for more details. |
16 | * |
16 | * |
17 | * You should have received a copy of the Affero GNU General Public License |
17 | * You should have received a copy of the Affero GNU General Public License |
18 | * and the GNU General Public License along with this program. If not, see |
18 | * and the GNU General Public License along with this program. If not, see |
19 | * <http://www.gnu.org/licenses/>. |
19 | * <http://www.gnu.org/licenses/>. |
20 | * |
20 | * |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
22 | */ |
23 | |
23 | |
24 | /* generate a rogue/nethack-like maze */ |
24 | /* generate a rogue/nethack-like maze */ |
25 | #include <global.h> |
25 | #include <global.h> |
26 | #include <random_map.h> |
26 | #include <rmg.h> |
27 | #include <rproto.h> |
27 | #include <rproto.h> |
28 | |
28 | |
29 | typedef struct |
29 | typedef struct |
30 | { |
30 | { |
31 | int x; |
31 | int x; |
… | |
… | |
190 | ty = rmg_rndm (ysize); |
190 | ty = rmg_rndm (ysize); |
191 | |
191 | |
192 | /* generate a distribution of sizes centered about basesize */ |
192 | /* generate a distribution of sizes centered about basesize */ |
193 | sx = rmg_rndm (x_basesize) + rmg_rndm (x_basesize) + rmg_rndm (x_basesize); |
193 | sx = rmg_rndm (x_basesize) + rmg_rndm (x_basesize) + rmg_rndm (x_basesize); |
194 | sy = rmg_rndm (y_basesize) + rmg_rndm (y_basesize) + rmg_rndm (y_basesize); |
194 | sy = rmg_rndm (y_basesize) + rmg_rndm (y_basesize) + rmg_rndm (y_basesize); |
195 | sy = (int) (sy * .5); /* renormalize */ |
195 | sy >>= 1; /* renormalize */ |
196 | |
196 | |
197 | /* find the corners */ |
197 | /* find the corners */ |
198 | ax = tx - sx / 2; |
198 | ax = tx - sx / 2; |
199 | zx = tx + sx / 2 + sx % 2; |
199 | zx = tx + sx / 2 + sx % 2; |
200 | |
200 | |
… | |
… | |
220 | } |
220 | } |
221 | |
221 | |
222 | /* if we've got here, presumably the room is OK. */ |
222 | /* if we've got here, presumably the room is OK. */ |
223 | |
223 | |
224 | /* get a pointer to the first free room */ |
224 | /* get a pointer to the first free room */ |
225 | for (walk = rooms; walk->x != 0; walk++) |
225 | for (walk = rooms; walk->x; walk++) |
226 | ; |
226 | ; |
227 | |
227 | |
228 | walk->x = tx; |
228 | walk->x = tx; |
229 | walk->y = ty; |
229 | walk->y = ty; |
230 | walk->sx = sx; |
230 | walk->sx = sx; |
231 | walk->sy = sy; |
231 | walk->sy = sy; |
232 | walk->ax = ax; |
232 | walk->ax = ax; |
233 | walk->ay = ay; |
233 | walk->ay = ay; |
234 | walk->zx = zx; |
234 | walk->zx = zx; |
… | |
… | |
240 | /* write all the rooms into the maze */ |
240 | /* write all the rooms into the maze */ |
241 | static void |
241 | static void |
242 | roguelike_make_rooms (Room *rooms, char **maze, int options) |
242 | roguelike_make_rooms (Room *rooms, char **maze, int options) |
243 | { |
243 | { |
244 | int making_circle = 0; |
244 | int making_circle = 0; |
245 | int i, j; |
|
|
246 | int R; |
245 | int R; |
247 | Room *walk; |
246 | Room *walk; |
248 | |
247 | |
249 | for (walk = rooms; walk->x != 0; walk++) |
248 | for (walk = rooms; walk->x; walk++) |
250 | { |
249 | { |
251 | /* first decide what shape to make */ |
250 | /* first decide what shape to make */ |
252 | switch (options) |
251 | switch (options) |
253 | { |
252 | { |
254 | case 1: |
253 | case 1: |
… | |
… | |
266 | R = walk->sx / 2; |
265 | R = walk->sx / 2; |
267 | else |
266 | else |
268 | R = walk->sy / 2; |
267 | R = walk->sy / 2; |
269 | |
268 | |
270 | /* enscribe a rectangle */ |
269 | /* enscribe a rectangle */ |
271 | for (i = walk->ax; i < walk->zx; i++) |
270 | for (int i = walk->ax; i < walk->zx; i++) |
272 | for (j = walk->ay; j < walk->zy; j++) |
271 | for (int j = walk->ay; j < walk->zy; j++) |
273 | if (!making_circle || ((int) (0.5 + hypot (walk->x - i, walk->y - j))) <= R) |
272 | if (!making_circle || ((int) (0.5 + hypot (walk->x - i, walk->y - j))) <= R) |
274 | maze[i][j] = '.'; |
273 | maze[i][j] = '.'; |
275 | } |
274 | } |
276 | } |
275 | } |
277 | |
276 | |