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 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
11 | * option) any later version. |
… | |
… | |
50 | */ |
50 | */ |
51 | |
51 | |
52 | |
52 | |
53 | #include <global.h> |
53 | #include <global.h> |
54 | #include <random_map.h> |
54 | #include <random_map.h> |
|
|
55 | #include <rproto.h> |
55 | |
56 | |
56 | #ifndef MIN |
|
|
57 | # define MIN(x,y) (((x)<(y))? (x):(y)) |
|
|
58 | #endif |
|
|
59 | void centered_onion (char **maze, int xsize, int ysize, int option, int layers); |
57 | static void centered_onion (char **maze, int xsize, int ysize, int option, int layers); |
60 | void bottom_centered_onion (char **maze, int xsize, int ysize, int option, int layers); |
58 | static void bottom_centered_onion (char **maze, int xsize, int ysize, int option, int layers); |
61 | void bottom_right_centered_onion (char **maze, int xsize, int ysize, int option, int layers); |
59 | static void bottom_right_centered_onion (char **maze, int xsize, int ysize, int option, int layers); |
62 | |
60 | |
63 | void draw_onion (char **maze, float *xlocations, float *ylocations, int layers); |
61 | static void draw_onion (char **maze, float *xlocations, float *ylocations, int layers); |
64 | void make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options); |
62 | static void make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options); |
65 | |
63 | |
66 | void |
64 | void |
67 | map_gen_onion (Layout maze, int option, int layers) |
65 | map_gen_onion (Layout maze, int option, int layers) |
68 | { |
66 | { |
69 | int i, j; |
67 | int i, j; |
… | |
… | |
107 | bottom_centered_onion (maze, xsize, ysize, option, layers); |
105 | bottom_centered_onion (maze, xsize, ysize, option, layers); |
108 | else if (option & RMOPT_CENTERED) |
106 | else if (option & RMOPT_CENTERED) |
109 | centered_onion (maze, xsize, ysize, option, layers); |
107 | centered_onion (maze, xsize, ysize, option, layers); |
110 | } |
108 | } |
111 | |
109 | |
112 | void |
110 | static void |
113 | centered_onion (char **maze, int xsize, int ysize, int option, int layers) |
111 | centered_onion (char **maze, int xsize, int ysize, int option, int layers) |
114 | { |
112 | { |
115 | int i, maxlayers; |
113 | int i, maxlayers; |
116 | |
114 | |
117 | maxlayers = (MIN (xsize, ysize) - 2) / 5; |
115 | maxlayers = (min (xsize, ysize) - 2) / 5; |
118 | |
116 | |
119 | if (!maxlayers) |
117 | if (!maxlayers) |
120 | return; /* map too small to onionize */ |
118 | return; /* map too small to onionize */ |
121 | |
119 | |
122 | if (layers > maxlayers) |
120 | if (layers > maxlayers) |
… | |
… | |
179 | |
177 | |
180 | sfree (xlocations, 2 * layers); |
178 | sfree (xlocations, 2 * layers); |
181 | sfree (ylocations, 2 * layers); |
179 | sfree (ylocations, 2 * layers); |
182 | } |
180 | } |
183 | |
181 | |
184 | void |
182 | static void |
185 | bottom_centered_onion (char **maze, int xsize, int ysize, int option, int layers) |
183 | bottom_centered_onion (char **maze, int xsize, int ysize, int option, int layers) |
186 | { |
184 | { |
187 | int i, maxlayers; |
185 | int i, maxlayers; |
188 | |
186 | |
189 | maxlayers = (MIN (xsize, ysize) - 2) / 5; |
187 | maxlayers = (min (xsize, ysize) - 2) / 5; |
190 | |
188 | |
191 | if (!maxlayers) |
189 | if (!maxlayers) |
192 | return; /* map too small to onionize */ |
190 | return; /* map too small to onionize */ |
193 | |
191 | |
194 | if (layers > maxlayers) |
192 | if (layers > maxlayers) |
… | |
… | |
260 | |
258 | |
261 | sfree (xlocations, 2 * layers); |
259 | sfree (xlocations, 2 * layers); |
262 | sfree (ylocations, 2 * layers); |
260 | sfree (ylocations, 2 * layers); |
263 | } |
261 | } |
264 | |
262 | |
265 | /* draw_boxes: draws the lines in the maze defining the onion layers */ |
263 | /* draw_boxes: draws the lines in the maze defining the onion layers */ |
266 | void |
264 | static void |
267 | draw_onion (char **maze, float *xlocations, float *ylocations, int layers) |
265 | draw_onion (char **maze, float *xlocations, float *ylocations, int layers) |
268 | { |
266 | { |
269 | int i, j, l; |
267 | int i, j, l; |
270 | |
268 | |
271 | for (l = 0; l < layers; l++) |
269 | for (l = 0; l < layers; l++) |
… | |
… | |
291 | } |
289 | } |
292 | |
290 | |
293 | } |
291 | } |
294 | } |
292 | } |
295 | |
293 | |
296 | void |
294 | static void |
297 | make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options) |
295 | make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options) |
298 | { |
296 | { |
299 | int freedoms; /* number of different walls on which we could place a door */ |
297 | int freedoms; /* number of different walls on which we could place a door */ |
300 | int which_wall; /* left, 1, top, 2, right, 3, bottom 4 */ |
298 | int which_wall; /* left, 1, top, 2, right, 3, bottom 4 */ |
301 | int l, x1 = 0, x2, y1 = 0, y2; |
299 | int l, x1 = 0, x2, y1 = 0, y2; |
… | |
… | |
407 | y1 = (int) (ylocations[l] + ylocations[2 * layers - l - 1]) / 2; |
405 | y1 = (int) (ylocations[l] + ylocations[2 * layers - l - 1]) / 2; |
408 | |
406 | |
409 | maze[x1][y1] = 'C'; |
407 | maze[x1][y1] = 'C'; |
410 | } |
408 | } |
411 | |
409 | |
412 | void |
410 | static void |
413 | bottom_right_centered_onion (char **maze, int xsize, int ysize, int option, int layers) |
411 | bottom_right_centered_onion (char **maze, int xsize, int ysize, int option, int layers) |
414 | { |
412 | { |
415 | int i, maxlayers; |
413 | int i, maxlayers; |
416 | |
414 | |
417 | maxlayers = (MIN (xsize, ysize) - 2) / 5; |
415 | maxlayers = (min (xsize, ysize) - 2) / 5; |
418 | |
416 | |
419 | if (!maxlayers) |
417 | if (!maxlayers) |
420 | return; /* map too small to onionize */ |
418 | return; /* map too small to onionize */ |
421 | |
419 | |
422 | if (layers > maxlayers) |
420 | if (layers > maxlayers) |