1 |
|
2 |
/* |
3 |
CrossFire, A Multiplayer game for X-windows |
4 |
|
5 |
Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
6 |
Copyright (C) 1992 Frank Tore Johansen |
7 |
|
8 |
This program is free software; you can redistribute it and/or modify |
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 |
11 |
(at your option) any later version. |
12 |
|
13 |
This program is distributed in the hope that it will be useful, |
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
GNU General Public License for more details. |
17 |
|
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 |
20 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
21 |
|
22 |
The authors can be reached via e-mail at <crossfire@schmorp.de> |
23 |
*/ |
24 |
|
25 |
#include <time.h> |
26 |
#include <stdio.h> |
27 |
#include <global.h> |
28 |
#include <maze_gen.h> |
29 |
#include <room_gen.h> |
30 |
#include <random_map.h> |
31 |
#include <rproto.h> |
32 |
#include <sproto.h> |
33 |
|
34 |
void |
35 |
dump_layout (char **layout, random_map_params *RP) |
36 |
{ |
37 |
{ |
38 |
int i, j; |
39 |
|
40 |
for (i = 0; i < RP->Xsize; i++) |
41 |
{ |
42 |
for (j = 0; j < RP->Ysize; j++) |
43 |
{ |
44 |
if (layout[i][j] == 0) |
45 |
layout[i][j] = ' '; |
46 |
printf ("%c", layout[i][j]); |
47 |
if (layout[i][j] == ' ') |
48 |
layout[i][j] = 0; |
49 |
} |
50 |
printf ("\n"); |
51 |
} |
52 |
} |
53 |
printf ("\n"); |
54 |
} |
55 |
|
56 |
extern FILE *logfile; |
57 |
|
58 |
maptile * |
59 |
generate_random_map (const char *OutFileName, random_map_params *RP) |
60 |
{ |
61 |
char **layout, buf[HUGE_BUF]; |
62 |
maptile *theMap; |
63 |
int i; |
64 |
|
65 |
/* pick a random seed, or use the one from the input file */ |
66 |
if (RP->random_seed == 0) |
67 |
RP->random_seed = time (0); |
68 |
|
69 |
SRANDOM (RP->random_seed); |
70 |
|
71 |
write_map_parameters_to_string (buf, RP); |
72 |
|
73 |
if (RP->difficulty == 0) |
74 |
{ |
75 |
RP->difficulty = RP->dungeon_level; /* use this instead of a map difficulty */ |
76 |
|
77 |
if (RP->difficulty_increase > 0.001) |
78 |
RP->difficulty = (int) ((float) RP->dungeon_level * RP->difficulty_increase); |
79 |
|
80 |
if (RP->difficulty < 1) |
81 |
RP->difficulty = 1; |
82 |
} |
83 |
else |
84 |
RP->difficulty_given = 1; |
85 |
|
86 |
if (RP->Xsize < MIN_RANDOM_MAP_SIZE) |
87 |
RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5; |
88 |
|
89 |
if (RP->Ysize < MIN_RANDOM_MAP_SIZE) |
90 |
RP->Ysize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5; |
91 |
|
92 |
if (RP->expand2x > 0) |
93 |
{ |
94 |
RP->Xsize /= 2; |
95 |
RP->Ysize /= 2; |
96 |
} |
97 |
|
98 |
layout = layoutgen (RP); |
99 |
|
100 |
#ifdef RMAP_DEBUG |
101 |
dump_layout (layout, RP); |
102 |
#endif |
103 |
|
104 |
/* increment these for the current map */ |
105 |
RP->dungeon_level += 1; |
106 |
/* allow constant-difficulty maps. */ |
107 |
/* difficulty+=1; */ |
108 |
|
109 |
/* rotate the layout randomly */ |
110 |
layout = rotate_layout (layout, RANDOM () % 4, RP); |
111 |
#ifdef RMAP_DEBUG |
112 |
dump_layout (layout, RP); |
113 |
#endif |
114 |
|
115 |
/* allocate the map and set the floor */ |
116 |
theMap = make_map_floor (layout, RP->floorstyle, RP); |
117 |
|
118 |
/* set the name of the map. */ |
119 |
theMap->path = OutFileName; |
120 |
|
121 |
/* set region */ |
122 |
theMap->region = RP->region; |
123 |
|
124 |
/* create walls unless the wallstyle is "none" */ |
125 |
if (strcmp (RP->wallstyle, "none")) |
126 |
{ |
127 |
make_map_walls (theMap, layout, RP->wallstyle, RP); |
128 |
|
129 |
/* place doors unless doorstyle or wallstyle is "none" */ |
130 |
if (strcmp (RP->doorstyle, "none")) |
131 |
put_doors (theMap, layout, RP->doorstyle, RP); |
132 |
|
133 |
} |
134 |
|
135 |
/* create exits unless the exitstyle is "none" */ |
136 |
if (strcmp (RP->exitstyle, "none")) |
137 |
place_exits (theMap, layout, RP->exitstyle, RP->orientation, RP); |
138 |
|
139 |
place_specials_in_map (theMap, layout, RP); |
140 |
|
141 |
/* create monsters unless the monsterstyle is "none" */ |
142 |
if (strcmp (RP->monsterstyle, "none")) |
143 |
place_monsters (theMap, RP->monsterstyle, RP->difficulty, RP); |
144 |
|
145 |
/* treasures needs to have a proper difficulty set for the map. */ |
146 |
theMap->difficulty = theMap->estimate_difficulty (); |
147 |
|
148 |
/* create treasure unless the treasurestyle is "none" */ |
149 |
if (strcmp (RP->treasurestyle, "none")) |
150 |
place_treasure (theMap, layout, RP->treasurestyle, RP->treasureoptions, RP); |
151 |
|
152 |
/* create decor unless the decorstyle is "none" */ |
153 |
if (strcmp (RP->decorstyle, "none")) |
154 |
put_decor (theMap, layout, RP->decorstyle, RP->decoroptions, RP); |
155 |
|
156 |
/* generate treasures, etc. */ |
157 |
theMap->fix_auto_apply (); |
158 |
|
159 |
unblock_exits (theMap, layout, RP); |
160 |
|
161 |
/* free the layout */ |
162 |
for (i = 0; i < RP->Xsize; i++) |
163 |
free (layout[i]); |
164 |
|
165 |
free (layout); |
166 |
|
167 |
theMap->msg = strdup (buf); |
168 |
theMap->in_memory = MAP_IN_MEMORY; |
169 |
|
170 |
return theMap; |
171 |
} |
172 |
|
173 |
/* function selects the layout function and gives it whatever |
174 |
arguments it needs. */ |
175 |
char ** |
176 |
layoutgen (random_map_params *RP) |
177 |
{ |
178 |
char **maze = 0; |
179 |
int oxsize = RP->Xsize, oysize = RP->Ysize; |
180 |
|
181 |
if (RP->symmetry == SYMMETRY_RANDOM) |
182 |
RP->symmetry_used = (RANDOM () % (SYMMETRY_XY)) + 1; |
183 |
else |
184 |
RP->symmetry_used = RP->symmetry; |
185 |
|
186 |
if (RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY) |
187 |
RP->Ysize = RP->Ysize / 2 + 1; |
188 |
if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY) |
189 |
RP->Xsize = RP->Xsize / 2 + 1; |
190 |
|
191 |
if (RP->Xsize < MIN_RANDOM_MAP_SIZE) |
192 |
RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 5; |
193 |
if (RP->Ysize < MIN_RANDOM_MAP_SIZE) |
194 |
RP->Ysize = MIN_RANDOM_MAP_SIZE + RANDOM () % 5; |
195 |
RP->map_layout_style = 0; |
196 |
|
197 |
/* Redo this - there was a lot of redundant code of checking for preset |
198 |
* layout style and then random layout style. Instead, figure out |
199 |
* the numeric layoutstyle, so there is only one area that actually |
200 |
* calls the code to make the maps. |
201 |
*/ |
202 |
if (strstr (RP->layoutstyle, "onion")) |
203 |
RP->map_layout_style = LAYOUT_ONION; |
204 |
|
205 |
if (strstr (RP->layoutstyle, "maze")) |
206 |
RP->map_layout_style = LAYOUT_MAZE; |
207 |
|
208 |
if (strstr (RP->layoutstyle, "spiral")) |
209 |
RP->map_layout_style = LAYOUT_SPIRAL; |
210 |
|
211 |
if (strstr (RP->layoutstyle, "rogue")) |
212 |
RP->map_layout_style = LAYOUT_ROGUELIKE; |
213 |
|
214 |
if (strstr (RP->layoutstyle, "snake")) |
215 |
RP->map_layout_style = LAYOUT_SNAKE; |
216 |
|
217 |
if (strstr (RP->layoutstyle, "squarespiral")) |
218 |
RP->map_layout_style = LAYOUT_SQUARE_SPIRAL; |
219 |
|
220 |
/* No style found - choose one ranomdly */ |
221 |
if (RP->map_layout_style == LAYOUT_NONE) |
222 |
RP->map_layout_style = (RANDOM () % (NROFLAYOUTS - 1)) + 1; |
223 |
|
224 |
switch (RP->map_layout_style) |
225 |
{ |
226 |
case LAYOUT_ONION: |
227 |
maze = map_gen_onion (RP->Xsize, RP->Ysize, RP->layoutoptions1, RP->layoutoptions2); |
228 |
if (!(RANDOM () % 3) && !(RP->layoutoptions1 & RMOPT_WALLS_ONLY)) |
229 |
roomify_layout (maze, RP); |
230 |
break; |
231 |
|
232 |
case LAYOUT_MAZE: |
233 |
maze = maze_gen (RP->Xsize, RP->Ysize, RANDOM () % 2); |
234 |
if (!(RANDOM () % 2)) |
235 |
doorify_layout (maze, RP); |
236 |
break; |
237 |
|
238 |
case LAYOUT_SPIRAL: |
239 |
maze = map_gen_spiral (RP->Xsize, RP->Ysize, RP->layoutoptions1); |
240 |
if (!(RANDOM () % 2)) |
241 |
doorify_layout (maze, RP); |
242 |
break; |
243 |
|
244 |
case LAYOUT_ROGUELIKE: |
245 |
/* Don't put symmetry in rogue maps. There isn't much reason to |
246 |
* do so in the first place (doesn't make it any more interesting), |
247 |
* but more importantly, the symmetry code presumes we are symmetrizing |
248 |
* spirals, or maps with lots of passages - making a symmetric rogue |
249 |
* map fails because its likely that the passages the symmetry process |
250 |
* creates may not connect the rooms. |
251 |
*/ |
252 |
RP->symmetry_used = SYMMETRY_NONE; |
253 |
RP->Ysize = oysize; |
254 |
RP->Xsize = oxsize; |
255 |
maze = roguelike_layout_gen (RP->Xsize, RP->Ysize, RP->layoutoptions1); |
256 |
/* no doorifying... done already */ |
257 |
break; |
258 |
|
259 |
case LAYOUT_SNAKE: |
260 |
maze = make_snake_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); |
261 |
if (RANDOM () % 2) |
262 |
roomify_layout (maze, RP); |
263 |
break; |
264 |
|
265 |
case LAYOUT_SQUARE_SPIRAL: |
266 |
maze = make_square_spiral_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); |
267 |
if (RANDOM () % 2) |
268 |
roomify_layout (maze, RP); |
269 |
break; |
270 |
} |
271 |
|
272 |
maze = symmetrize_layout (maze, RP->symmetry_used, RP); |
273 |
|
274 |
#ifdef RMAP_DEBUG |
275 |
dump_layout (maze, RP); |
276 |
#endif |
277 |
|
278 |
if (RP->expand2x) |
279 |
{ |
280 |
maze = expand2x (maze, RP->Xsize, RP->Ysize); |
281 |
RP->Xsize = RP->Xsize * 2 - 1; |
282 |
RP->Ysize = RP->Ysize * 2 - 1; |
283 |
} |
284 |
|
285 |
return maze; |
286 |
} |
287 |
|
288 |
/* takes a map and makes it symmetric: adjusts Xsize and |
289 |
Ysize to produce a symmetric map. */ |
290 |
char ** |
291 |
symmetrize_layout (char **maze, int sym, random_map_params *RP) |
292 |
{ |
293 |
int i, j; |
294 |
char **sym_maze; |
295 |
int Xsize_orig, Ysize_orig; |
296 |
|
297 |
Xsize_orig = RP->Xsize; |
298 |
Ysize_orig = RP->Ysize; |
299 |
RP->symmetry_used = sym; /* tell everyone else what sort of symmetry is used. */ |
300 |
if (sym == SYMMETRY_NONE) |
301 |
{ |
302 |
RP->Xsize = Xsize_orig; |
303 |
RP->Ysize = Ysize_orig; |
304 |
return maze; |
305 |
} |
306 |
/* pick new sizes */ |
307 |
RP->Xsize = ((sym == SYMMETRY_X || sym == SYMMETRY_XY) ? RP->Xsize * 2 - 3 : RP->Xsize); |
308 |
RP->Ysize = ((sym == SYMMETRY_Y || sym == SYMMETRY_XY) ? RP->Ysize * 2 - 3 : RP->Ysize); |
309 |
|
310 |
sym_maze = (char **) calloc (sizeof (char *), RP->Xsize); |
311 |
for (i = 0; i < RP->Xsize; i++) |
312 |
sym_maze[i] = (char *) calloc (sizeof (char), RP->Ysize); |
313 |
|
314 |
if (sym == SYMMETRY_X) |
315 |
for (i = 0; i < RP->Xsize / 2 + 1; i++) |
316 |
for (j = 0; j < RP->Ysize; j++) |
317 |
{ |
318 |
sym_maze[i][j] = maze[i][j]; |
319 |
sym_maze[RP->Xsize - i - 1][j] = maze[i][j]; |
320 |
}; |
321 |
if (sym == SYMMETRY_Y) |
322 |
for (i = 0; i < RP->Xsize; i++) |
323 |
for (j = 0; j < RP->Ysize / 2 + 1; j++) |
324 |
{ |
325 |
sym_maze[i][j] = maze[i][j]; |
326 |
sym_maze[i][RP->Ysize - j - 1] = maze[i][j]; |
327 |
} |
328 |
if (sym == SYMMETRY_XY) |
329 |
for (i = 0; i < RP->Xsize / 2 + 1; i++) |
330 |
for (j = 0; j < RP->Ysize / 2 + 1; j++) |
331 |
{ |
332 |
sym_maze[i][j] = maze[i][j]; |
333 |
sym_maze[i][RP->Ysize - j - 1] = maze[i][j]; |
334 |
sym_maze[RP->Xsize - i - 1][j] = maze[i][j]; |
335 |
sym_maze[RP->Xsize - i - 1][RP->Ysize - j - 1] = maze[i][j]; |
336 |
} |
337 |
/* delete the old maze */ |
338 |
for (i = 0; i < Xsize_orig; i++) |
339 |
free (maze[i]); |
340 |
free (maze); |
341 |
/* reconnect disjointed spirals */ |
342 |
if (RP->map_layout_style == LAYOUT_SPIRAL) |
343 |
connect_spirals (RP->Xsize, RP->Ysize, sym, sym_maze); |
344 |
/* reconnect disjointed nethackmazes: the routine for |
345 |
spirals will do the trick? */ |
346 |
if (RP->map_layout_style == LAYOUT_ROGUELIKE) |
347 |
connect_spirals (RP->Xsize, RP->Ysize, sym, sym_maze); |
348 |
|
349 |
return sym_maze; |
350 |
} |
351 |
|
352 |
|
353 |
/* takes a map and rotates it. This completes the |
354 |
onion layouts, making them possibly centered on any wall. |
355 |
It'll modify Xsize and Ysize if they're swapped. |
356 |
*/ |
357 |
|
358 |
char ** |
359 |
rotate_layout (char **maze, int rotation, random_map_params *RP) |
360 |
{ |
361 |
char **new_maze; |
362 |
int i, j; |
363 |
|
364 |
switch (rotation) |
365 |
{ |
366 |
case 0: |
367 |
return maze; |
368 |
break; |
369 |
case 2: /* a reflection */ |
370 |
{ |
371 |
char *newmaze = (char *) malloc (sizeof (char) * RP->Xsize * RP->Ysize); |
372 |
|
373 |
for (i = 0; i < RP->Xsize; i++) |
374 |
{ /* make a copy */ |
375 |
for (j = 0; j < RP->Ysize; j++) |
376 |
{ |
377 |
newmaze[i * RP->Ysize + j] = maze[i][j]; |
378 |
} |
379 |
} |
380 |
for (i = 0; i < RP->Xsize; i++) |
381 |
{ /* copy a reflection back */ |
382 |
for (j = 0; j < RP->Ysize; j++) |
383 |
{ |
384 |
maze[i][j] = newmaze[(RP->Xsize - i - 1) * RP->Ysize + RP->Ysize - j - 1]; |
385 |
} |
386 |
} |
387 |
free (newmaze); |
388 |
return maze; |
389 |
break; |
390 |
} |
391 |
case 1: |
392 |
case 3: |
393 |
{ |
394 |
int swap; |
395 |
new_maze = (char **) calloc (sizeof (char *), RP->Ysize); |
396 |
for (i = 0; i < RP->Ysize; i++) |
397 |
{ |
398 |
new_maze[i] = (char *) calloc (sizeof (char), RP->Xsize); |
399 |
} |
400 |
if (rotation == 1) /* swap x and y */ |
401 |
for (i = 0; i < RP->Xsize; i++) |
402 |
for (j = 0; j < RP->Ysize; j++) |
403 |
new_maze[j][i] = maze[i][j]; |
404 |
|
405 |
if (rotation == 3) |
406 |
{ /* swap x and y */ |
407 |
for (i = 0; i < RP->Xsize; i++) |
408 |
for (j = 0; j < RP->Ysize; j++) |
409 |
new_maze[j][i] = maze[RP->Xsize - i - 1][RP->Ysize - j - 1]; |
410 |
} |
411 |
|
412 |
/* delete the old layout */ |
413 |
for (i = 0; i < RP->Xsize; i++) |
414 |
free (maze[i]); |
415 |
free (maze); |
416 |
|
417 |
swap = RP->Ysize; |
418 |
RP->Ysize = RP->Xsize; |
419 |
RP->Xsize = swap; |
420 |
return new_maze; |
421 |
break; |
422 |
} |
423 |
} |
424 |
return NULL; |
425 |
} |
426 |
|
427 |
/* take a layout and make some rooms in it. |
428 |
--works best on onions.*/ |
429 |
void |
430 |
roomify_layout (char **maze, random_map_params *RP) |
431 |
{ |
432 |
int tries = RP->Xsize * RP->Ysize / 30; |
433 |
int ti; |
434 |
|
435 |
for (ti = 0; ti < tries; ti++) |
436 |
{ |
437 |
int dx, dy; /* starting location for looking at creating a door */ |
438 |
int cx, cy; /* results of checking on creating walls. */ |
439 |
|
440 |
dx = RANDOM () % RP->Xsize; |
441 |
dy = RANDOM () % RP->Ysize; |
442 |
cx = can_make_wall (maze, dx, dy, 0, RP); /* horizontal */ |
443 |
cy = can_make_wall (maze, dx, dy, 1, RP); /* vertical */ |
444 |
if (cx == -1) |
445 |
{ |
446 |
if (cy != -1) |
447 |
make_wall (maze, dx, dy, 1); |
448 |
continue; |
449 |
} |
450 |
if (cy == -1) |
451 |
{ |
452 |
make_wall (maze, dx, dy, 0); |
453 |
continue; |
454 |
} |
455 |
if (cx < cy) |
456 |
make_wall (maze, dx, dy, 0); |
457 |
else |
458 |
make_wall (maze, dx, dy, 1); |
459 |
} |
460 |
} |
461 |
|
462 |
/* checks the layout to see if I can stick a horizontal(dir = 0) wall |
463 |
(or vertical, dir == 1) |
464 |
here which ends up on other walls sensibly. */ |
465 |
|
466 |
int |
467 |
can_make_wall (char **maze, int dx, int dy, int dir, random_map_params *RP) |
468 |
{ |
469 |
int i1; |
470 |
int length = 0; |
471 |
|
472 |
/* dont make walls if we're on the edge. */ |
473 |
if (dx == 0 || dx == (RP->Xsize - 1) || dy == 0 || dy == (RP->Ysize - 1)) |
474 |
return -1; |
475 |
|
476 |
/* don't make walls if we're ON a wall. */ |
477 |
if (maze[dx][dy] != 0) |
478 |
return -1; |
479 |
|
480 |
if (dir == 0) /* horizontal */ |
481 |
{ |
482 |
int y = dy; |
483 |
|
484 |
for (i1 = dx - 1; i1 > 0; i1--) |
485 |
{ |
486 |
int sindex = surround_flag2 (maze, i1, y, RP); |
487 |
|
488 |
if (sindex == 1) |
489 |
break; |
490 |
if (sindex != 0) |
491 |
return -1; /* can't make horiz. wall here */ |
492 |
if (maze[i1][y] != 0) |
493 |
return -1; /* can't make horiz. wall here */ |
494 |
length++; |
495 |
} |
496 |
|
497 |
for (i1 = dx + 1; i1 < RP->Xsize - 1; i1++) |
498 |
{ |
499 |
int sindex = surround_flag2 (maze, i1, y, RP); |
500 |
|
501 |
if (sindex == 2) |
502 |
break; |
503 |
if (sindex != 0) |
504 |
return -1; /* can't make horiz. wall here */ |
505 |
if (maze[i1][y] != 0) |
506 |
return -1; /* can't make horiz. wall here */ |
507 |
length++; |
508 |
} |
509 |
return length; |
510 |
} |
511 |
else |
512 |
{ /* vertical */ |
513 |
int x = dx; |
514 |
|
515 |
for (i1 = dy - 1; i1 > 0; i1--) |
516 |
{ |
517 |
int sindex = surround_flag2 (maze, x, i1, RP); |
518 |
|
519 |
if (sindex == 4) |
520 |
break; |
521 |
if (sindex != 0) |
522 |
return -1; /* can't make vert. wall here */ |
523 |
if (maze[x][i1] != 0) |
524 |
return -1; /* can't make horiz. wall here */ |
525 |
length++; |
526 |
} |
527 |
|
528 |
for (i1 = dy + 1; i1 < RP->Ysize - 1; i1++) |
529 |
{ |
530 |
int sindex = surround_flag2 (maze, x, i1, RP); |
531 |
|
532 |
if (sindex == 8) |
533 |
break; |
534 |
if (sindex != 0) |
535 |
return -1; /* can't make verti. wall here */ |
536 |
if (maze[x][i1] != 0) |
537 |
return -1; /* can't make horiz. wall here */ |
538 |
length++; |
539 |
} |
540 |
return length; |
541 |
} |
542 |
return -1; |
543 |
} |
544 |
|
545 |
|
546 |
int |
547 |
make_wall (char **maze, int x, int y, int dir) |
548 |
{ |
549 |
maze[x][y] = 'D'; /* mark a door */ |
550 |
switch (dir) |
551 |
{ |
552 |
case 0: /* horizontal */ |
553 |
{ |
554 |
int i1; |
555 |
|
556 |
for (i1 = x - 1; maze[i1][y] == 0; i1--) |
557 |
maze[i1][y] = '#'; |
558 |
for (i1 = x + 1; maze[i1][y] == 0; i1++) |
559 |
maze[i1][y] = '#'; |
560 |
break; |
561 |
} |
562 |
case 1: /* vertical */ |
563 |
{ |
564 |
int i1; |
565 |
|
566 |
for (i1 = y - 1; maze[x][i1] == 0; i1--) |
567 |
maze[x][i1] = '#'; |
568 |
for (i1 = y + 1; maze[x][i1] == 0; i1++) |
569 |
maze[x][i1] = '#'; |
570 |
break; |
571 |
} |
572 |
} |
573 |
|
574 |
return 0; |
575 |
} |
576 |
|
577 |
/* puts doors at appropriate locations in a layout. */ |
578 |
void |
579 |
doorify_layout (char **maze, random_map_params *RP) |
580 |
{ |
581 |
int ndoors = RP->Xsize * RP->Ysize / 60; /* reasonable number of doors. */ |
582 |
char *doorlist_x; |
583 |
char *doorlist_y; |
584 |
int doorlocs = 0; /* # of available doorlocations */ |
585 |
int i, j; |
586 |
|
587 |
doorlist_x = (char *) malloc (sizeof (int) * RP->Xsize * RP->Ysize); |
588 |
doorlist_y = (char *) malloc (sizeof (int) * RP->Xsize * RP->Ysize); |
589 |
|
590 |
|
591 |
/* make a list of possible door locations */ |
592 |
for (i = 1; i < RP->Xsize - 1; i++) |
593 |
for (j = 1; j < RP->Ysize - 1; j++) |
594 |
{ |
595 |
int sindex = surround_flag (maze, i, j, RP); |
596 |
|
597 |
if (sindex == 3 || sindex == 12) /* these are possible door sindex */ |
598 |
{ |
599 |
doorlist_x[doorlocs] = i; |
600 |
doorlist_y[doorlocs] = j; |
601 |
doorlocs++; |
602 |
} |
603 |
} |
604 |
|
605 |
while (ndoors > 0 && doorlocs > 0) |
606 |
{ |
607 |
int di; |
608 |
int sindex; |
609 |
|
610 |
di = RANDOM () % doorlocs; |
611 |
i = doorlist_x[di]; |
612 |
j = doorlist_y[di]; |
613 |
sindex = surround_flag (maze, i, j, RP); |
614 |
if (sindex == 3 || sindex == 12) /* these are possible door sindex */ |
615 |
{ |
616 |
maze[i][j] = 'D'; |
617 |
ndoors--; |
618 |
} |
619 |
/* reduce the size of the list */ |
620 |
doorlocs--; |
621 |
doorlist_x[di] = doorlist_x[doorlocs]; |
622 |
doorlist_y[di] = doorlist_y[doorlocs]; |
623 |
} |
624 |
|
625 |
free (doorlist_x); |
626 |
free (doorlist_y); |
627 |
} |
628 |
|
629 |
void |
630 |
write_map_parameters_to_string (char *buf, random_map_params *RP) |
631 |
{ |
632 |
char small_buf[256]; |
633 |
|
634 |
sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize); |
635 |
|
636 |
if (RP->wallstyle[0]) |
637 |
{ |
638 |
sprintf (small_buf, "wallstyle %s\n", RP->wallstyle); |
639 |
strcat (buf, small_buf); |
640 |
} |
641 |
|
642 |
if (RP->floorstyle[0]) |
643 |
{ |
644 |
sprintf (small_buf, "floorstyle %s\n", RP->floorstyle); |
645 |
strcat (buf, small_buf); |
646 |
} |
647 |
|
648 |
if (RP->monsterstyle[0]) |
649 |
{ |
650 |
sprintf (small_buf, "monsterstyle %s\n", RP->monsterstyle); |
651 |
strcat (buf, small_buf); |
652 |
} |
653 |
|
654 |
if (RP->treasurestyle[0]) |
655 |
{ |
656 |
sprintf (small_buf, "treasurestyle %s\n", RP->treasurestyle); |
657 |
strcat (buf, small_buf); |
658 |
} |
659 |
|
660 |
if (RP->layoutstyle[0]) |
661 |
{ |
662 |
sprintf (small_buf, "layoutstyle %s\n", RP->layoutstyle); |
663 |
strcat (buf, small_buf); |
664 |
} |
665 |
|
666 |
if (RP->decorstyle[0]) |
667 |
{ |
668 |
sprintf (small_buf, "decorstyle %s\n", RP->decorstyle); |
669 |
strcat (buf, small_buf); |
670 |
} |
671 |
|
672 |
if (RP->doorstyle[0]) |
673 |
{ |
674 |
sprintf (small_buf, "doorstyle %s\n", RP->doorstyle); |
675 |
strcat (buf, small_buf); |
676 |
} |
677 |
|
678 |
if (RP->exitstyle[0]) |
679 |
{ |
680 |
sprintf (small_buf, "exitstyle %s\n", RP->exitstyle); |
681 |
strcat (buf, small_buf); |
682 |
} |
683 |
|
684 |
if (RP->final_map[0]) |
685 |
{ |
686 |
sprintf (small_buf, "final_map %s\n", RP->final_map); |
687 |
strcat (buf, small_buf); |
688 |
} |
689 |
|
690 |
if (RP->exit_on_final_map[0]) |
691 |
{ |
692 |
sprintf (small_buf, "exit_on_final_map %s\n", RP->exit_on_final_map); |
693 |
strcat (buf, small_buf); |
694 |
} |
695 |
|
696 |
if (RP->this_map[0]) |
697 |
{ |
698 |
sprintf (small_buf, "origin_map %s\n", RP->this_map); |
699 |
strcat (buf, small_buf); |
700 |
} |
701 |
|
702 |
if (RP->expand2x) |
703 |
{ |
704 |
sprintf (small_buf, "expand2x %d\n", RP->expand2x); |
705 |
strcat (buf, small_buf); |
706 |
} |
707 |
|
708 |
if (RP->layoutoptions1) |
709 |
{ |
710 |
sprintf (small_buf, "layoutoptions1 %d\n", RP->layoutoptions1); |
711 |
strcat (buf, small_buf); |
712 |
} |
713 |
|
714 |
|
715 |
if (RP->layoutoptions2) |
716 |
{ |
717 |
sprintf (small_buf, "layoutoptions2 %d\n", RP->layoutoptions2); |
718 |
strcat (buf, small_buf); |
719 |
} |
720 |
|
721 |
|
722 |
if (RP->layoutoptions3) |
723 |
{ |
724 |
sprintf (small_buf, "layoutoptions3 %d\n", RP->layoutoptions3); |
725 |
strcat (buf, small_buf); |
726 |
} |
727 |
|
728 |
if (RP->symmetry) |
729 |
{ |
730 |
sprintf (small_buf, "symmetry %d\n", RP->symmetry); |
731 |
strcat (buf, small_buf); |
732 |
} |
733 |
|
734 |
|
735 |
if (RP->difficulty && RP->difficulty_given) |
736 |
{ |
737 |
sprintf (small_buf, "difficulty %d\n", RP->difficulty); |
738 |
strcat (buf, small_buf); |
739 |
} |
740 |
|
741 |
if (RP->difficulty_increase != 1.0) |
742 |
{ |
743 |
sprintf (small_buf, "difficulty_increase %f\n", RP->difficulty_increase); |
744 |
strcat (buf, small_buf); |
745 |
} |
746 |
|
747 |
sprintf (small_buf, "dungeon_level %d\n", RP->dungeon_level); |
748 |
strcat (buf, small_buf); |
749 |
|
750 |
if (RP->dungeon_depth) |
751 |
{ |
752 |
sprintf (small_buf, "dungeon_depth %d\n", RP->dungeon_depth); |
753 |
strcat (buf, small_buf); |
754 |
} |
755 |
|
756 |
if (RP->decoroptions) |
757 |
{ |
758 |
sprintf (small_buf, "decoroptions %d\n", RP->decoroptions); |
759 |
strcat (buf, small_buf); |
760 |
} |
761 |
|
762 |
if (RP->orientation) |
763 |
{ |
764 |
sprintf (small_buf, "orientation %d\n", RP->orientation); |
765 |
strcat (buf, small_buf); |
766 |
} |
767 |
|
768 |
if (RP->origin_x) |
769 |
{ |
770 |
sprintf (small_buf, "origin_x %d\n", RP->origin_x); |
771 |
strcat (buf, small_buf); |
772 |
} |
773 |
|
774 |
if (RP->origin_y) |
775 |
{ |
776 |
sprintf (small_buf, "origin_y %d\n", RP->origin_y); |
777 |
strcat (buf, small_buf); |
778 |
} |
779 |
|
780 |
if (RP->random_seed) |
781 |
{ |
782 |
/* Add one so that the next map is a bit different */ |
783 |
sprintf (small_buf, "random_seed %d\n", RP->random_seed + 1); |
784 |
strcat (buf, small_buf); |
785 |
} |
786 |
|
787 |
if (RP->treasureoptions) |
788 |
{ |
789 |
sprintf (small_buf, "treasureoptions %d\n", RP->treasureoptions); |
790 |
strcat (buf, small_buf); |
791 |
} |
792 |
} |
793 |
|
794 |
void |
795 |
write_parameters_to_string (char *buf, |
796 |
int xsize_n, |
797 |
int ysize_n, |
798 |
char *wallstyle_n, |
799 |
char *floorstyle_n, |
800 |
char *monsterstyle_n, |
801 |
char *treasurestyle_n, |
802 |
char *layoutstyle_n, |
803 |
char *decorstyle_n, |
804 |
char *doorstyle_n, |
805 |
char *exitstyle_n, |
806 |
char *final_map_n, |
807 |
char *exit_on_final_map_n, |
808 |
char *this_map_n, |
809 |
int layoutoptions1_n, |
810 |
int layoutoptions2_n, |
811 |
int layoutoptions3_n, |
812 |
int symmetry_n, |
813 |
int dungeon_depth_n, |
814 |
int dungeon_level_n, |
815 |
int difficulty_n, |
816 |
int difficulty_given_n, |
817 |
int decoroptions_n, |
818 |
int orientation_n, |
819 |
int origin_x_n, int origin_y_n, int random_seed_n, int treasureoptions_n, float difficulty_increase) |
820 |
{ |
821 |
|
822 |
char small_buf[256]; |
823 |
|
824 |
sprintf (buf, "xsize %d\nysize %d\n", xsize_n, ysize_n); |
825 |
|
826 |
if (wallstyle_n && wallstyle_n[0]) |
827 |
{ |
828 |
sprintf (small_buf, "wallstyle %s\n", wallstyle_n); |
829 |
strcat (buf, small_buf); |
830 |
} |
831 |
|
832 |
if (floorstyle_n && floorstyle_n[0]) |
833 |
{ |
834 |
sprintf (small_buf, "floorstyle %s\n", floorstyle_n); |
835 |
strcat (buf, small_buf); |
836 |
} |
837 |
|
838 |
if (monsterstyle_n && monsterstyle_n[0]) |
839 |
{ |
840 |
sprintf (small_buf, "monsterstyle %s\n", monsterstyle_n); |
841 |
strcat (buf, small_buf); |
842 |
} |
843 |
|
844 |
if (treasurestyle_n && treasurestyle_n[0]) |
845 |
{ |
846 |
sprintf (small_buf, "treasurestyle %s\n", treasurestyle_n); |
847 |
strcat (buf, small_buf); |
848 |
} |
849 |
|
850 |
if (layoutstyle_n && layoutstyle_n[0]) |
851 |
{ |
852 |
sprintf (small_buf, "layoutstyle %s\n", layoutstyle_n); |
853 |
strcat (buf, small_buf); |
854 |
} |
855 |
|
856 |
if (decorstyle_n && decorstyle_n[0]) |
857 |
{ |
858 |
sprintf (small_buf, "decorstyle %s\n", decorstyle_n); |
859 |
strcat (buf, small_buf); |
860 |
} |
861 |
|
862 |
if (doorstyle_n && doorstyle_n[0]) |
863 |
{ |
864 |
sprintf (small_buf, "doorstyle %s\n", doorstyle_n); |
865 |
strcat (buf, small_buf); |
866 |
} |
867 |
|
868 |
if (exitstyle_n && exitstyle_n[0]) |
869 |
{ |
870 |
sprintf (small_buf, "exitstyle %s\n", exitstyle_n); |
871 |
strcat (buf, small_buf); |
872 |
} |
873 |
|
874 |
if (final_map_n && final_map_n[0]) |
875 |
{ |
876 |
sprintf (small_buf, "final_map %s\n", final_map_n); |
877 |
strcat (buf, small_buf); |
878 |
} |
879 |
|
880 |
if (exit_on_final_map_n && exit_on_final_map_n[0]) |
881 |
{ |
882 |
sprintf (small_buf, "exit_on_final_map %s\n", exit_on_final_map_n); |
883 |
strcat (buf, small_buf); |
884 |
} |
885 |
|
886 |
if (this_map_n && this_map_n[0]) |
887 |
{ |
888 |
sprintf (small_buf, "origin_map %s\n", this_map_n); |
889 |
strcat (buf, small_buf); |
890 |
} |
891 |
|
892 |
if (layoutoptions1_n) |
893 |
{ |
894 |
sprintf (small_buf, "layoutoptions1 %d\n", layoutoptions1_n); |
895 |
strcat (buf, small_buf); |
896 |
} |
897 |
|
898 |
if (layoutoptions2_n) |
899 |
{ |
900 |
sprintf (small_buf, "layoutoptions2 %d\n", layoutoptions2_n); |
901 |
strcat (buf, small_buf); |
902 |
} |
903 |
|
904 |
|
905 |
if (layoutoptions3_n) |
906 |
{ |
907 |
sprintf (small_buf, "layoutoptions3 %d\n", layoutoptions3_n); |
908 |
strcat (buf, small_buf); |
909 |
} |
910 |
|
911 |
if (symmetry_n) |
912 |
{ |
913 |
sprintf (small_buf, "symmetry %d\n", symmetry_n); |
914 |
strcat (buf, small_buf); |
915 |
} |
916 |
|
917 |
|
918 |
if (difficulty_n && difficulty_given_n) |
919 |
{ |
920 |
sprintf (small_buf, "difficulty %d\n", difficulty_n); |
921 |
strcat (buf, small_buf); |
922 |
} |
923 |
|
924 |
if (difficulty_increase > 0.001) |
925 |
{ |
926 |
sprintf (small_buf, "difficulty_increase %f\n", difficulty_increase); |
927 |
strcat (buf, small_buf); |
928 |
} |
929 |
|
930 |
sprintf (small_buf, "dungeon_level %d\n", dungeon_level_n); |
931 |
strcat (buf, small_buf); |
932 |
|
933 |
if (dungeon_depth_n) |
934 |
{ |
935 |
sprintf (small_buf, "dungeon_depth %d\n", dungeon_depth_n); |
936 |
strcat (buf, small_buf); |
937 |
} |
938 |
|
939 |
if (decoroptions_n) |
940 |
{ |
941 |
sprintf (small_buf, "decoroptions %d\n", decoroptions_n); |
942 |
strcat (buf, small_buf); |
943 |
} |
944 |
|
945 |
if (orientation_n) |
946 |
{ |
947 |
sprintf (small_buf, "orientation %d\n", orientation_n); |
948 |
strcat (buf, small_buf); |
949 |
} |
950 |
|
951 |
if (origin_x_n) |
952 |
{ |
953 |
sprintf (small_buf, "origin_x %d\n", origin_x_n); |
954 |
strcat (buf, small_buf); |
955 |
} |
956 |
|
957 |
if (origin_y_n) |
958 |
{ |
959 |
sprintf (small_buf, "origin_y %d\n", origin_y_n); |
960 |
strcat (buf, small_buf); |
961 |
} |
962 |
|
963 |
if (random_seed_n) |
964 |
{ |
965 |
/* Add one so that the next map is a bit different */ |
966 |
sprintf (small_buf, "random_seed %d\n", random_seed_n + 1); |
967 |
strcat (buf, small_buf); |
968 |
} |
969 |
|
970 |
if (treasureoptions_n) |
971 |
{ |
972 |
sprintf (small_buf, "treasureoptions %d\n", treasureoptions_n); |
973 |
strcat (buf, small_buf); |
974 |
} |
975 |
|
976 |
|
977 |
} |
978 |
|
979 |
/* copy an object with an inventory... i.e., duplicate the inv too. */ |
980 |
void |
981 |
copy_object_with_inv (object *src_ob, object *dest_ob) |
982 |
{ |
983 |
object *walk, *tmp; |
984 |
|
985 |
src_ob->copy_to (dest_ob); |
986 |
|
987 |
for (walk = src_ob->inv; walk != NULL; walk = walk->below) |
988 |
{ |
989 |
tmp = object::create (); |
990 |
|
991 |
walk->copy_to (tmp); |
992 |
insert_ob_in_ob (tmp, dest_ob); |
993 |
} |
994 |
} |