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