1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game for X-windows |
3 | |
3 | * |
|
|
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | |
7 | * |
7 | This program is free software; you can redistribute it and/or modify |
8 | * This program is free software; you can redistribute it and/or modify |
8 | 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 |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. |
11 | * (at your option) any later version. |
11 | |
12 | * |
12 | 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, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
16 | |
17 | * |
17 | 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 |
18 | along with this program; if not, write to the Free Software |
19 | * along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | |
21 | * |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | #include <time.h> |
25 | #include <time.h> |
25 | #include <stdio.h> |
26 | #include <stdio.h> |
26 | #include <global.h> |
27 | #include <global.h> |
27 | #include <maze_gen.h> |
28 | #include <maze_gen.h> |
… | |
… | |
29 | #include <random_map.h> |
30 | #include <random_map.h> |
30 | #include <rproto.h> |
31 | #include <rproto.h> |
31 | #include <sproto.h> |
32 | #include <sproto.h> |
32 | |
33 | |
33 | void |
34 | void |
34 | dump_layout (char **layout, random_map_params * RP) |
35 | dump_layout (char **layout, random_map_params *RP) |
35 | { |
36 | { |
36 | { |
37 | { |
37 | int i, j; |
38 | int i, j; |
38 | |
39 | |
39 | for (i = 0; i < RP->Xsize; i++) |
40 | for (i = 0; i < RP->Xsize; i++) |
… | |
… | |
50 | } |
51 | } |
51 | } |
52 | } |
52 | printf ("\n"); |
53 | printf ("\n"); |
53 | } |
54 | } |
54 | |
55 | |
55 | extern FILE *logfile; |
56 | bool |
56 | |
57 | maptile::generate_random_map (random_map_params *RP) |
57 | maptile * |
|
|
58 | generate_random_map (const char *OutFileName, random_map_params * RP) |
|
|
59 | { |
58 | { |
60 | char **layout, buf[HUGE_BUF]; |
59 | char **layout, buf[16384]; |
61 | maptile *theMap; |
|
|
62 | int i; |
60 | int i; |
63 | |
61 | |
64 | /* pick a random seed, or use the one from the input file */ |
62 | /* pick a random seed, or use the one from the input file */ |
65 | if (RP->random_seed == 0) |
63 | SRANDOM (RP->random_seed ? RP->random_seed + RP->dungeon_level : time (0)); |
66 | RP->random_seed = time (0); |
|
|
67 | |
|
|
68 | SRANDOM (RP->random_seed); |
|
|
69 | |
64 | |
70 | write_map_parameters_to_string (buf, RP); |
65 | write_map_parameters_to_string (buf, RP); |
71 | |
66 | |
72 | if (RP->difficulty == 0) |
67 | if (RP->difficulty == 0) |
73 | { |
68 | { |
… | |
… | |
81 | } |
76 | } |
82 | else |
77 | else |
83 | RP->difficulty_given = 1; |
78 | RP->difficulty_given = 1; |
84 | |
79 | |
85 | if (RP->Xsize < MIN_RANDOM_MAP_SIZE) |
80 | if (RP->Xsize < MIN_RANDOM_MAP_SIZE) |
86 | RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5; |
81 | RP->Xsize = MIN_RANDOM_MAP_SIZE + rndm (25) + 5; |
87 | |
82 | |
88 | if (RP->Ysize < MIN_RANDOM_MAP_SIZE) |
83 | if (RP->Ysize < MIN_RANDOM_MAP_SIZE) |
89 | RP->Ysize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5; |
84 | RP->Ysize = MIN_RANDOM_MAP_SIZE + rndm (25) + 5; |
90 | |
85 | |
91 | if (RP->expand2x > 0) |
86 | if (RP->expand2x > 0) |
92 | { |
87 | { |
93 | RP->Xsize /= 2; |
88 | RP->Xsize /= 2; |
94 | RP->Ysize /= 2; |
89 | RP->Ysize /= 2; |
… | |
… | |
104 | RP->dungeon_level += 1; |
99 | RP->dungeon_level += 1; |
105 | /* allow constant-difficulty maps. */ |
100 | /* allow constant-difficulty maps. */ |
106 | /* difficulty+=1; */ |
101 | /* difficulty+=1; */ |
107 | |
102 | |
108 | /* rotate the layout randomly */ |
103 | /* rotate the layout randomly */ |
109 | layout = rotate_layout (layout, RANDOM () % 4, RP); |
104 | layout = rotate_layout (layout, rndm (4), RP); |
110 | #ifdef RMAP_DEBUG |
105 | #ifdef RMAP_DEBUG |
111 | dump_layout (layout, RP); |
106 | dump_layout (layout, RP); |
112 | #endif |
107 | #endif |
113 | |
108 | |
114 | /* allocate the map and set the floor */ |
109 | /* allocate the map and set the floor */ |
115 | theMap = make_map_floor (layout, RP->floorstyle, RP); |
110 | make_map_floor (layout, RP->floorstyle, RP); |
116 | |
|
|
117 | /* set the name of the map. */ |
|
|
118 | theMap->path = OutFileName; |
|
|
119 | |
111 | |
120 | /* set region */ |
112 | /* set region */ |
121 | theMap->region = RP->region; |
113 | region = RP->region; |
|
|
114 | |
|
|
115 | coroapi::cede (); |
122 | |
116 | |
123 | /* create walls unless the wallstyle is "none" */ |
117 | /* create walls unless the wallstyle is "none" */ |
124 | if (strcmp (RP->wallstyle, "none")) |
118 | if (strcmp (RP->wallstyle, "none")) |
125 | { |
119 | { |
126 | make_map_walls (theMap, layout, RP->wallstyle, RP); |
120 | make_map_walls (this, layout, RP->wallstyle, RP); |
127 | |
121 | |
128 | /* place doors unless doorstyle or wallstyle is "none" */ |
122 | /* place doors unless doorstyle or wallstyle is "none" */ |
129 | if (strcmp (RP->doorstyle, "none")) |
123 | if (strcmp (RP->doorstyle, "none")) |
130 | put_doors (theMap, layout, RP->doorstyle, RP); |
124 | put_doors (this, layout, RP->doorstyle, RP); |
131 | |
125 | |
132 | } |
126 | } |
|
|
127 | |
|
|
128 | coroapi::cede (); |
133 | |
129 | |
134 | /* create exits unless the exitstyle is "none" */ |
130 | /* create exits unless the exitstyle is "none" */ |
135 | if (strcmp (RP->exitstyle, "none")) |
131 | if (strcmp (RP->exitstyle, "none")) |
136 | place_exits (theMap, layout, RP->exitstyle, RP->orientation, RP); |
132 | place_exits (this, layout, RP->exitstyle, RP->orientation, RP); |
137 | |
133 | |
|
|
134 | coroapi::cede (); |
|
|
135 | |
138 | place_specials_in_map (theMap, layout, RP); |
136 | place_specials_in_map (this, layout, RP); |
|
|
137 | |
|
|
138 | coroapi::cede (); |
139 | |
139 | |
140 | /* create monsters unless the monsterstyle is "none" */ |
140 | /* create monsters unless the monsterstyle is "none" */ |
141 | if (strcmp (RP->monsterstyle, "none")) |
141 | if (strcmp (RP->monsterstyle, "none")) |
142 | place_monsters (theMap, RP->monsterstyle, RP->difficulty, RP); |
142 | place_monsters (this, RP->monsterstyle, RP->difficulty, RP); |
|
|
143 | |
|
|
144 | coroapi::cede (); |
143 | |
145 | |
144 | /* treasures needs to have a proper difficulty set for the map. */ |
146 | /* treasures needs to have a proper difficulty set for the map. */ |
145 | theMap->difficulty = theMap->estimate_difficulty (); |
147 | difficulty = estimate_difficulty (); |
|
|
148 | |
|
|
149 | coroapi::cede (); |
146 | |
150 | |
147 | /* create treasure unless the treasurestyle is "none" */ |
151 | /* create treasure unless the treasurestyle is "none" */ |
148 | if (strcmp (RP->treasurestyle, "none")) |
152 | if (strcmp (RP->treasurestyle, "none")) |
149 | place_treasure (theMap, layout, RP->treasurestyle, RP->treasureoptions, RP); |
153 | place_treasure (this, layout, RP->treasurestyle, RP->treasureoptions, RP); |
|
|
154 | |
|
|
155 | coroapi::cede (); |
150 | |
156 | |
151 | /* create decor unless the decorstyle is "none" */ |
157 | /* create decor unless the decorstyle is "none" */ |
152 | if (strcmp (RP->decorstyle, "none")) |
158 | if (strcmp (RP->decorstyle, "none")) |
153 | put_decor (theMap, layout, RP->decorstyle, RP->decoroptions, RP); |
159 | put_decor (this, layout, RP->decorstyle, RP->decoroptions, RP); |
|
|
160 | |
|
|
161 | coroapi::cede (); |
154 | |
162 | |
155 | /* generate treasures, etc. */ |
163 | /* generate treasures, etc. */ |
156 | theMap->fix_auto_apply (); |
164 | fix_auto_apply (); |
157 | |
165 | |
|
|
166 | coroapi::cede (); |
158 | unblock_exits (theMap, layout, RP); |
167 | unblock_exits (this, layout, RP); |
159 | |
168 | |
160 | /* free the layout */ |
169 | /* free the layout */ |
161 | for (i = 0; i < RP->Xsize; i++) |
170 | for (i = 0; i < RP->Xsize; i++) |
162 | free (layout[i]); |
171 | free (layout[i]); |
|
|
172 | |
163 | free (layout); |
173 | free (layout); |
164 | |
174 | |
165 | theMap->msg = strdup (buf); |
175 | msg = strdup (buf); |
|
|
176 | in_memory = MAP_IN_MEMORY; |
166 | |
177 | |
167 | return theMap; |
178 | return 1; |
168 | } |
179 | } |
169 | |
180 | |
170 | /* function selects the layout function and gives it whatever |
181 | /* function selects the layout function and gives it whatever |
171 | arguments it needs. */ |
182 | arguments it needs. */ |
172 | char ** |
183 | char ** |
173 | layoutgen (random_map_params * RP) |
184 | layoutgen (random_map_params *RP) |
174 | { |
185 | { |
175 | char **maze = 0; |
186 | char **maze = 0; |
176 | int oxsize = RP->Xsize, oysize = RP->Ysize; |
187 | int oxsize = RP->Xsize, oysize = RP->Ysize; |
177 | |
188 | |
178 | if (RP->symmetry == SYMMETRY_RANDOM) |
189 | if (RP->symmetry == SYMMETRY_RANDOM) |
… | |
… | |
184 | RP->Ysize = RP->Ysize / 2 + 1; |
195 | RP->Ysize = RP->Ysize / 2 + 1; |
185 | if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY) |
196 | if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY) |
186 | RP->Xsize = RP->Xsize / 2 + 1; |
197 | RP->Xsize = RP->Xsize / 2 + 1; |
187 | |
198 | |
188 | if (RP->Xsize < MIN_RANDOM_MAP_SIZE) |
199 | if (RP->Xsize < MIN_RANDOM_MAP_SIZE) |
189 | RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 5; |
200 | RP->Xsize = MIN_RANDOM_MAP_SIZE + rndm (5); |
190 | if (RP->Ysize < MIN_RANDOM_MAP_SIZE) |
201 | if (RP->Ysize < MIN_RANDOM_MAP_SIZE) |
191 | RP->Ysize = MIN_RANDOM_MAP_SIZE + RANDOM () % 5; |
202 | RP->Ysize = MIN_RANDOM_MAP_SIZE + rndm (5); |
192 | RP->map_layout_style = 0; |
203 | RP->map_layout_style = 0; |
193 | |
204 | |
194 | /* Redo this - there was a lot of redundant code of checking for preset |
205 | /* Redo this - there was a lot of redundant code of checking for preset |
195 | * layout style and then random layout style. Instead, figure out |
206 | * layout style and then random layout style. Instead, figure out |
196 | * the numeric layoutstyle, so there is only one area that actually |
207 | * the numeric layoutstyle, so there is only one area that actually |
… | |
… | |
220 | |
231 | |
221 | switch (RP->map_layout_style) |
232 | switch (RP->map_layout_style) |
222 | { |
233 | { |
223 | case LAYOUT_ONION: |
234 | case LAYOUT_ONION: |
224 | maze = map_gen_onion (RP->Xsize, RP->Ysize, RP->layoutoptions1, RP->layoutoptions2); |
235 | maze = map_gen_onion (RP->Xsize, RP->Ysize, RP->layoutoptions1, RP->layoutoptions2); |
225 | if (!(RANDOM () % 3) && !(RP->layoutoptions1 & RMOPT_WALLS_ONLY)) |
236 | if (!(rndm (3)) && !(RP->layoutoptions1 & RMOPT_WALLS_ONLY)) |
226 | roomify_layout (maze, RP); |
237 | roomify_layout (maze, RP); |
227 | break; |
238 | break; |
228 | |
239 | |
229 | case LAYOUT_MAZE: |
240 | case LAYOUT_MAZE: |
230 | maze = maze_gen (RP->Xsize, RP->Ysize, RANDOM () % 2); |
241 | maze = maze_gen (RP->Xsize, RP->Ysize, rndm (2)); |
231 | if (!(RANDOM () % 2)) |
242 | if (!(rndm (2))) |
232 | doorify_layout (maze, RP); |
243 | doorify_layout (maze, RP); |
233 | break; |
244 | break; |
234 | |
245 | |
235 | case LAYOUT_SPIRAL: |
246 | case LAYOUT_SPIRAL: |
236 | maze = map_gen_spiral (RP->Xsize, RP->Ysize, RP->layoutoptions1); |
247 | maze = map_gen_spiral (RP->Xsize, RP->Ysize, RP->layoutoptions1); |
237 | if (!(RANDOM () % 2)) |
248 | if (!(rndm (2))) |
238 | doorify_layout (maze, RP); |
249 | doorify_layout (maze, RP); |
239 | break; |
250 | break; |
240 | |
251 | |
241 | case LAYOUT_ROGUELIKE: |
252 | case LAYOUT_ROGUELIKE: |
242 | /* Don't put symmetry in rogue maps. There isn't much reason to |
253 | /* Don't put symmetry in rogue maps. There isn't much reason to |
… | |
… | |
253 | /* no doorifying... done already */ |
264 | /* no doorifying... done already */ |
254 | break; |
265 | break; |
255 | |
266 | |
256 | case LAYOUT_SNAKE: |
267 | case LAYOUT_SNAKE: |
257 | maze = make_snake_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); |
268 | maze = make_snake_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); |
258 | if (RANDOM () % 2) |
269 | if (rndm (2)) |
259 | roomify_layout (maze, RP); |
270 | roomify_layout (maze, RP); |
260 | break; |
271 | break; |
261 | |
272 | |
262 | case LAYOUT_SQUARE_SPIRAL: |
273 | case LAYOUT_SQUARE_SPIRAL: |
263 | maze = make_square_spiral_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); |
274 | maze = make_square_spiral_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); |
264 | if (RANDOM () % 2) |
275 | if (rndm (2)) |
265 | roomify_layout (maze, RP); |
276 | roomify_layout (maze, RP); |
266 | break; |
277 | break; |
267 | } |
278 | } |
268 | |
279 | |
269 | maze = symmetrize_layout (maze, RP->symmetry_used, RP); |
280 | maze = symmetrize_layout (maze, RP->symmetry_used, RP); |
… | |
… | |
283 | } |
294 | } |
284 | |
295 | |
285 | /* takes a map and makes it symmetric: adjusts Xsize and |
296 | /* takes a map and makes it symmetric: adjusts Xsize and |
286 | Ysize to produce a symmetric map. */ |
297 | Ysize to produce a symmetric map. */ |
287 | char ** |
298 | char ** |
288 | symmetrize_layout (char **maze, int sym, random_map_params * RP) |
299 | symmetrize_layout (char **maze, int sym, random_map_params *RP) |
289 | { |
300 | { |
290 | int i, j; |
301 | int i, j; |
291 | char **sym_maze; |
302 | char **sym_maze; |
292 | int Xsize_orig, Ysize_orig; |
303 | int Xsize_orig, Ysize_orig; |
293 | |
304 | |
… | |
… | |
351 | onion layouts, making them possibly centered on any wall. |
362 | onion layouts, making them possibly centered on any wall. |
352 | It'll modify Xsize and Ysize if they're swapped. |
363 | It'll modify Xsize and Ysize if they're swapped. |
353 | */ |
364 | */ |
354 | |
365 | |
355 | char ** |
366 | char ** |
356 | rotate_layout (char **maze, int rotation, random_map_params * RP) |
367 | rotate_layout (char **maze, int rotation, random_map_params *RP) |
357 | { |
368 | { |
358 | char **new_maze; |
369 | char **new_maze; |
359 | int i, j; |
370 | int i, j; |
360 | |
371 | |
361 | switch (rotation) |
372 | switch (rotation) |
362 | { |
373 | { |
363 | case 0: |
374 | case 0: |
364 | return maze; |
375 | return maze; |
365 | break; |
376 | break; |
366 | case 2: /* a reflection */ |
377 | case 2: /* a reflection */ |
367 | { |
378 | { |
368 | char *newmaze = (char *) malloc (sizeof (char) * RP->Xsize * RP->Ysize); |
379 | char *newmaze = (char *) malloc (sizeof (char) * RP->Xsize * RP->Ysize); |
369 | |
380 | |
370 | for (i = 0; i < RP->Xsize; i++) |
381 | for (i = 0; i < RP->Xsize; i++) |
371 | { /* make a copy */ |
382 | { /* make a copy */ |
372 | for (j = 0; j < RP->Ysize; j++) |
383 | for (j = 0; j < RP->Ysize; j++) |
373 | { |
384 | { |
374 | newmaze[i * RP->Ysize + j] = maze[i][j]; |
385 | newmaze[i * RP->Ysize + j] = maze[i][j]; |
375 | } |
386 | } |
376 | } |
387 | } |
377 | for (i = 0; i < RP->Xsize; i++) |
388 | for (i = 0; i < RP->Xsize; i++) |
378 | { /* copy a reflection back */ |
389 | { /* copy a reflection back */ |
379 | for (j = 0; j < RP->Ysize; j++) |
390 | for (j = 0; j < RP->Ysize; j++) |
380 | { |
391 | { |
381 | maze[i][j] = newmaze[(RP->Xsize - i - 1) * RP->Ysize + RP->Ysize - j - 1]; |
392 | maze[i][j] = newmaze[(RP->Xsize - i - 1) * RP->Ysize + RP->Ysize - j - 1]; |
382 | } |
393 | } |
383 | } |
394 | } |
… | |
… | |
392 | new_maze = (char **) calloc (sizeof (char *), RP->Ysize); |
403 | new_maze = (char **) calloc (sizeof (char *), RP->Ysize); |
393 | for (i = 0; i < RP->Ysize; i++) |
404 | for (i = 0; i < RP->Ysize; i++) |
394 | { |
405 | { |
395 | new_maze[i] = (char *) calloc (sizeof (char), RP->Xsize); |
406 | new_maze[i] = (char *) calloc (sizeof (char), RP->Xsize); |
396 | } |
407 | } |
397 | if (rotation == 1) /* swap x and y */ |
408 | if (rotation == 1) /* swap x and y */ |
398 | for (i = 0; i < RP->Xsize; i++) |
409 | for (i = 0; i < RP->Xsize; i++) |
399 | for (j = 0; j < RP->Ysize; j++) |
410 | for (j = 0; j < RP->Ysize; j++) |
400 | new_maze[j][i] = maze[i][j]; |
411 | new_maze[j][i] = maze[i][j]; |
401 | |
412 | |
402 | if (rotation == 3) |
413 | if (rotation == 3) |
403 | { /* swap x and y */ |
414 | { /* swap x and y */ |
404 | for (i = 0; i < RP->Xsize; i++) |
415 | for (i = 0; i < RP->Xsize; i++) |
405 | for (j = 0; j < RP->Ysize; j++) |
416 | for (j = 0; j < RP->Ysize; j++) |
406 | new_maze[j][i] = maze[RP->Xsize - i - 1][RP->Ysize - j - 1]; |
417 | new_maze[j][i] = maze[RP->Xsize - i - 1][RP->Ysize - j - 1]; |
407 | } |
418 | } |
408 | |
419 | |
… | |
… | |
422 | } |
433 | } |
423 | |
434 | |
424 | /* take a layout and make some rooms in it. |
435 | /* take a layout and make some rooms in it. |
425 | --works best on onions.*/ |
436 | --works best on onions.*/ |
426 | void |
437 | void |
427 | roomify_layout (char **maze, random_map_params * RP) |
438 | roomify_layout (char **maze, random_map_params *RP) |
428 | { |
439 | { |
429 | int tries = RP->Xsize * RP->Ysize / 30; |
440 | int tries = RP->Xsize * RP->Ysize / 30; |
430 | int ti; |
441 | int ti; |
431 | |
442 | |
432 | for (ti = 0; ti < tries; ti++) |
443 | for (ti = 0; ti < tries; ti++) |
… | |
… | |
459 | /* checks the layout to see if I can stick a horizontal(dir = 0) wall |
470 | /* checks the layout to see if I can stick a horizontal(dir = 0) wall |
460 | (or vertical, dir == 1) |
471 | (or vertical, dir == 1) |
461 | here which ends up on other walls sensibly. */ |
472 | here which ends up on other walls sensibly. */ |
462 | |
473 | |
463 | int |
474 | int |
464 | can_make_wall (char **maze, int dx, int dy, int dir, random_map_params * RP) |
475 | can_make_wall (char **maze, int dx, int dy, int dir, random_map_params *RP) |
465 | { |
476 | { |
466 | int i1; |
477 | int i1; |
467 | int length = 0; |
478 | int length = 0; |
468 | |
479 | |
469 | /* dont make walls if we're on the edge. */ |
480 | /* dont make walls if we're on the edge. */ |
… | |
… | |
544 | make_wall (char **maze, int x, int y, int dir) |
555 | make_wall (char **maze, int x, int y, int dir) |
545 | { |
556 | { |
546 | maze[x][y] = 'D'; /* mark a door */ |
557 | maze[x][y] = 'D'; /* mark a door */ |
547 | switch (dir) |
558 | switch (dir) |
548 | { |
559 | { |
549 | case 0: /* horizontal */ |
560 | case 0: /* horizontal */ |
550 | { |
561 | { |
551 | int i1; |
562 | int i1; |
552 | |
563 | |
553 | for (i1 = x - 1; maze[i1][y] == 0; i1--) |
564 | for (i1 = x - 1; maze[i1][y] == 0; i1--) |
554 | maze[i1][y] = '#'; |
565 | maze[i1][y] = '#'; |
555 | for (i1 = x + 1; maze[i1][y] == 0; i1++) |
566 | for (i1 = x + 1; maze[i1][y] == 0; i1++) |
556 | maze[i1][y] = '#'; |
567 | maze[i1][y] = '#'; |
557 | break; |
568 | break; |
558 | } |
569 | } |
559 | case 1: /* vertical */ |
570 | case 1: /* vertical */ |
560 | { |
571 | { |
561 | int i1; |
572 | int i1; |
562 | |
573 | |
563 | for (i1 = y - 1; maze[x][i1] == 0; i1--) |
574 | for (i1 = y - 1; maze[x][i1] == 0; i1--) |
564 | maze[x][i1] = '#'; |
575 | maze[x][i1] = '#'; |
565 | for (i1 = y + 1; maze[x][i1] == 0; i1++) |
576 | for (i1 = y + 1; maze[x][i1] == 0; i1++) |
566 | maze[x][i1] = '#'; |
577 | maze[x][i1] = '#'; |
567 | break; |
578 | break; |
568 | } |
579 | } |
569 | } |
580 | } |
570 | |
581 | |
571 | return 0; |
582 | return 0; |
572 | } |
583 | } |
573 | |
584 | |
574 | /* puts doors at appropriate locations in a layout. */ |
585 | /* puts doors at appropriate locations in a layout. */ |
575 | |
|
|
576 | void |
586 | void |
577 | doorify_layout (char **maze, random_map_params * RP) |
587 | doorify_layout (char **maze, random_map_params *RP) |
578 | { |
588 | { |
579 | int ndoors = RP->Xsize * RP->Ysize / 60; /* reasonable number of doors. */ |
589 | int ndoors = RP->Xsize * RP->Ysize / 60; /* reasonable number of doors. */ |
580 | char *doorlist_x; |
590 | char *doorlist_x; |
581 | char *doorlist_y; |
591 | char *doorlist_y; |
582 | int doorlocs = 0; /* # of available doorlocations */ |
592 | int doorlocs = 0; /* # of available doorlocations */ |
… | |
… | |
597 | doorlist_x[doorlocs] = i; |
607 | doorlist_x[doorlocs] = i; |
598 | doorlist_y[doorlocs] = j; |
608 | doorlist_y[doorlocs] = j; |
599 | doorlocs++; |
609 | doorlocs++; |
600 | } |
610 | } |
601 | } |
611 | } |
|
|
612 | |
602 | while (ndoors > 0 && doorlocs > 0) |
613 | while (ndoors > 0 && doorlocs > 0) |
603 | { |
614 | { |
604 | int di; |
615 | int di; |
605 | int sindex; |
616 | int sindex; |
606 | |
617 | |
… | |
… | |
616 | /* reduce the size of the list */ |
627 | /* reduce the size of the list */ |
617 | doorlocs--; |
628 | doorlocs--; |
618 | doorlist_x[di] = doorlist_x[doorlocs]; |
629 | doorlist_x[di] = doorlist_x[doorlocs]; |
619 | doorlist_y[di] = doorlist_y[doorlocs]; |
630 | doorlist_y[di] = doorlist_y[doorlocs]; |
620 | } |
631 | } |
|
|
632 | |
621 | free (doorlist_x); |
633 | free (doorlist_x); |
622 | free (doorlist_y); |
634 | free (doorlist_y); |
623 | } |
635 | } |
624 | |
636 | |
625 | |
|
|
626 | void |
637 | void |
627 | write_map_parameters_to_string (char *buf, random_map_params * RP) |
638 | write_map_parameters_to_string (char *buf, random_map_params *RP) |
628 | { |
639 | { |
629 | char small_buf[256]; |
640 | char small_buf[16384]; |
630 | |
641 | |
631 | sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize); |
642 | sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize); |
632 | |
643 | |
633 | if (RP->wallstyle[0]) |
644 | if (RP->wallstyle[0]) |
634 | { |
645 | { |
… | |
… | |
676 | { |
687 | { |
677 | sprintf (small_buf, "exitstyle %s\n", RP->exitstyle); |
688 | sprintf (small_buf, "exitstyle %s\n", RP->exitstyle); |
678 | strcat (buf, small_buf); |
689 | strcat (buf, small_buf); |
679 | } |
690 | } |
680 | |
691 | |
681 | if (RP->final_map[0]) |
692 | if (RP->final_map.length ()) |
682 | { |
693 | { |
683 | sprintf (small_buf, "final_map %s\n", RP->final_map); |
694 | sprintf (small_buf, "final_map %s\n", &RP->final_map); |
684 | strcat (buf, small_buf); |
695 | strcat (buf, small_buf); |
685 | } |
696 | } |
686 | |
697 | |
687 | if (RP->exit_on_final_map[0]) |
698 | if (RP->exit_on_final_map[0]) |
688 | { |
699 | { |
689 | sprintf (small_buf, "exit_on_final_map %s\n", RP->exit_on_final_map); |
700 | sprintf (small_buf, "exit_on_final_map %s\n", RP->exit_on_final_map); |
690 | strcat (buf, small_buf); |
701 | strcat (buf, small_buf); |
691 | } |
702 | } |
692 | |
703 | |
693 | if (RP->this_map[0]) |
704 | if (RP->this_map.length ()) |
694 | { |
705 | { |
695 | sprintf (small_buf, "origin_map %s\n", RP->this_map); |
706 | sprintf (small_buf, "origin_map %s\n", &RP->this_map); |
696 | strcat (buf, small_buf); |
707 | strcat (buf, small_buf); |
697 | } |
708 | } |
698 | |
709 | |
699 | if (RP->expand2x) |
710 | if (RP->expand2x) |
700 | { |
711 | { |
… | |
… | |
706 | { |
717 | { |
707 | sprintf (small_buf, "layoutoptions1 %d\n", RP->layoutoptions1); |
718 | sprintf (small_buf, "layoutoptions1 %d\n", RP->layoutoptions1); |
708 | strcat (buf, small_buf); |
719 | strcat (buf, small_buf); |
709 | } |
720 | } |
710 | |
721 | |
711 | |
|
|
712 | if (RP->layoutoptions2) |
722 | if (RP->layoutoptions2) |
713 | { |
723 | { |
714 | sprintf (small_buf, "layoutoptions2 %d\n", RP->layoutoptions2); |
724 | sprintf (small_buf, "layoutoptions2 %d\n", RP->layoutoptions2); |
715 | strcat (buf, small_buf); |
725 | strcat (buf, small_buf); |
716 | } |
726 | } |
717 | |
727 | |
718 | |
|
|
719 | if (RP->layoutoptions3) |
728 | if (RP->layoutoptions3) |
720 | { |
729 | { |
721 | sprintf (small_buf, "layoutoptions3 %d\n", RP->layoutoptions3); |
730 | sprintf (small_buf, "layoutoptions3 %d\n", RP->layoutoptions3); |
722 | strcat (buf, small_buf); |
731 | strcat (buf, small_buf); |
723 | } |
732 | } |
… | |
… | |
725 | if (RP->symmetry) |
734 | if (RP->symmetry) |
726 | { |
735 | { |
727 | sprintf (small_buf, "symmetry %d\n", RP->symmetry); |
736 | sprintf (small_buf, "symmetry %d\n", RP->symmetry); |
728 | strcat (buf, small_buf); |
737 | strcat (buf, small_buf); |
729 | } |
738 | } |
730 | |
|
|
731 | |
739 | |
732 | if (RP->difficulty && RP->difficulty_given) |
740 | if (RP->difficulty && RP->difficulty_given) |
733 | { |
741 | { |
734 | sprintf (small_buf, "difficulty %d\n", RP->difficulty); |
742 | sprintf (small_buf, "difficulty %d\n", RP->difficulty); |
735 | strcat (buf, small_buf); |
743 | strcat (buf, small_buf); |
… | |
… | |
772 | { |
780 | { |
773 | sprintf (small_buf, "origin_y %d\n", RP->origin_y); |
781 | sprintf (small_buf, "origin_y %d\n", RP->origin_y); |
774 | strcat (buf, small_buf); |
782 | strcat (buf, small_buf); |
775 | } |
783 | } |
776 | |
784 | |
|
|
785 | if (RP->treasureoptions) |
|
|
786 | { |
|
|
787 | sprintf (small_buf, "treasureoptions %d\n", RP->treasureoptions); |
|
|
788 | strcat (buf, small_buf); |
|
|
789 | } |
|
|
790 | |
777 | if (RP->random_seed) |
791 | if (RP->random_seed) |
778 | { |
792 | { |
779 | /* Add one so that the next map is a bit different */ |
|
|
780 | sprintf (small_buf, "random_seed %d\n", RP->random_seed + 1); |
793 | sprintf (small_buf, "random_seed %d\n", RP->random_seed); |
781 | strcat (buf, small_buf); |
794 | strcat (buf, small_buf); |
782 | } |
|
|
783 | |
|
|
784 | if (RP->treasureoptions) |
|
|
785 | { |
795 | } |
786 | sprintf (small_buf, "treasureoptions %d\n", RP->treasureoptions); |
796 | |
|
|
797 | if (RP->custom) |
|
|
798 | { |
|
|
799 | sprintf (small_buf, "custom %s\n", RP->custom); |
787 | strcat (buf, small_buf); |
800 | strcat (buf, small_buf); |
788 | } |
801 | } |
789 | } |
802 | } |
790 | |
803 | |
791 | void |
804 | void |
… | |
… | |
813 | int difficulty_given_n, |
826 | int difficulty_given_n, |
814 | int decoroptions_n, |
827 | int decoroptions_n, |
815 | int orientation_n, |
828 | int orientation_n, |
816 | int origin_x_n, int origin_y_n, int random_seed_n, int treasureoptions_n, float difficulty_increase) |
829 | int origin_x_n, int origin_y_n, int random_seed_n, int treasureoptions_n, float difficulty_increase) |
817 | { |
830 | { |
818 | |
|
|
819 | char small_buf[256]; |
831 | char small_buf[16384]; |
820 | |
832 | |
821 | sprintf (buf, "xsize %d\nysize %d\n", xsize_n, ysize_n); |
833 | sprintf (buf, "xsize %d\nysize %d\n", xsize_n, ysize_n); |
822 | |
834 | |
823 | if (wallstyle_n && wallstyle_n[0]) |
835 | if (wallstyle_n && wallstyle_n[0]) |
824 | { |
836 | { |
… | |
… | |
889 | if (layoutoptions1_n) |
901 | if (layoutoptions1_n) |
890 | { |
902 | { |
891 | sprintf (small_buf, "layoutoptions1 %d\n", layoutoptions1_n); |
903 | sprintf (small_buf, "layoutoptions1 %d\n", layoutoptions1_n); |
892 | strcat (buf, small_buf); |
904 | strcat (buf, small_buf); |
893 | } |
905 | } |
894 | |
|
|
895 | |
906 | |
896 | if (layoutoptions2_n) |
907 | if (layoutoptions2_n) |
897 | { |
908 | { |
898 | sprintf (small_buf, "layoutoptions2 %d\n", layoutoptions2_n); |
909 | sprintf (small_buf, "layoutoptions2 %d\n", layoutoptions2_n); |
899 | strcat (buf, small_buf); |
910 | strcat (buf, small_buf); |
… | |
… | |
968 | if (treasureoptions_n) |
979 | if (treasureoptions_n) |
969 | { |
980 | { |
970 | sprintf (small_buf, "treasureoptions %d\n", treasureoptions_n); |
981 | sprintf (small_buf, "treasureoptions %d\n", treasureoptions_n); |
971 | strcat (buf, small_buf); |
982 | strcat (buf, small_buf); |
972 | } |
983 | } |
973 | |
|
|
974 | |
|
|
975 | } |
984 | } |
976 | |
985 | |
977 | /* copy an object with an inventory... i.e., duplicate the inv too. */ |
986 | /* copy an object with an inventory... i.e., duplicate the inv too. */ |
978 | void |
987 | void |
979 | copy_object_with_inv (object *src_ob, object *dest_ob) |
988 | copy_object_with_inv (object *src_ob, object *dest_ob) |
980 | { |
989 | { |
981 | object *walk, *tmp; |
990 | object *walk, *tmp; |
982 | |
991 | |
983 | src_ob->copy_to (dest_ob); |
992 | src_ob->copy_to (dest_ob); |
984 | |
993 | |
985 | for (walk = src_ob->inv; walk != NULL; walk = walk->below) |
994 | for (walk = src_ob->inv; walk; walk = walk->below) |
986 | { |
995 | { |
987 | tmp = object::create (); |
996 | tmp = object::create (); |
|
|
997 | |
988 | walk->copy_to (tmp); |
998 | walk->copy_to (tmp); |
989 | insert_ob_in_ob (tmp, dest_ob); |
999 | insert_ob_in_ob (tmp, dest_ob); |
990 | } |
1000 | } |
991 | } |
1001 | } |