ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/random_map.C
(Generate patch)

Comparing deliantra/server/random_maps/random_map.C (file contents):
Revision 1.4 by root, Thu Sep 14 22:34:02 2006 UTC vs.
Revision 1.11 by root, Sat Dec 30 18:45:28 2006 UTC

29#include <random_map.h> 29#include <random_map.h>
30#include <rproto.h> 30#include <rproto.h>
31#include <sproto.h> 31#include <sproto.h>
32 32
33void 33void
34dump_layout (char **layout, RMParms * RP) 34dump_layout (char **layout, random_map_params * RP)
35{ 35{
36 { 36 {
37 int i, j; 37 int i, j;
38 38
39 for (i = 0; i < RP->Xsize; i++) 39 for (i = 0; i < RP->Xsize; i++)
49 printf ("\n"); 49 printf ("\n");
50 } 50 }
51 } 51 }
52 printf ("\n"); 52 printf ("\n");
53} 53}
54EXTERN FILE *logfile; 54
55mapstruct * 55extern FILE *logfile;
56
57maptile *
56generate_random_map (const char *OutFileName, RMParms * RP) 58generate_random_map (const char *OutFileName, random_map_params * RP)
57{ 59{
58 char **layout, buf[HUGE_BUF]; 60 char **layout, buf[HUGE_BUF];
59 mapstruct *theMap; 61 maptile *theMap;
60 int i; 62 int i;
61 63
62 /* pick a random seed, or use the one from the input file */ 64 /* pick a random seed, or use the one from the input file */
63 if (RP->random_seed == 0) 65 if (RP->random_seed == 0)
64 RP->random_seed = time (0); 66 RP->random_seed = time (0);
68 write_map_parameters_to_string (buf, RP); 70 write_map_parameters_to_string (buf, RP);
69 71
70 if (RP->difficulty == 0) 72 if (RP->difficulty == 0)
71 { 73 {
72 RP->difficulty = RP->dungeon_level; /* use this instead of a map difficulty */ 74 RP->difficulty = RP->dungeon_level; /* use this instead of a map difficulty */
75
73 if (RP->difficulty_increase > 0.001) 76 if (RP->difficulty_increase > 0.001)
74 {
75 RP->difficulty = (int) ((float) RP->dungeon_level * RP->difficulty_increase); 77 RP->difficulty = (int) ((float) RP->dungeon_level * RP->difficulty_increase);
78
76 if (RP->difficulty < 1) 79 if (RP->difficulty < 1)
77 RP->difficulty = 1; 80 RP->difficulty = 1;
78 }
79 } 81 }
80 else 82 else
81 RP->difficulty_given = 1; 83 RP->difficulty_given = 1;
82 84
83 if (RP->Xsize < MIN_RANDOM_MAP_SIZE) 85 if (RP->Xsize < MIN_RANDOM_MAP_SIZE)
84 RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5; 86 RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5;
87
85 if (RP->Ysize < MIN_RANDOM_MAP_SIZE) 88 if (RP->Ysize < MIN_RANDOM_MAP_SIZE)
86 RP->Ysize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5; 89 RP->Ysize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5;
87 90
88 if (RP->expand2x > 0) 91 if (RP->expand2x > 0)
89 { 92 {
110 113
111 /* allocate the map and set the floor */ 114 /* allocate the map and set the floor */
112 theMap = make_map_floor (layout, RP->floorstyle, RP); 115 theMap = make_map_floor (layout, RP->floorstyle, RP);
113 116
114 /* set the name of the map. */ 117 /* set the name of the map. */
115 strcpy (theMap->path, OutFileName); 118 theMap->path = OutFileName;
116 119
117 /* set region */ 120 /* set region */
118 theMap->region = RP->region; 121 theMap->region = RP->region;
119 122
120 /* create walls unless the wallstyle is "none" */ 123 /* create walls unless the wallstyle is "none" */
137 /* create monsters unless the monsterstyle is "none" */ 140 /* create monsters unless the monsterstyle is "none" */
138 if (strcmp (RP->monsterstyle, "none")) 141 if (strcmp (RP->monsterstyle, "none"))
139 place_monsters (theMap, RP->monsterstyle, RP->difficulty, RP); 142 place_monsters (theMap, RP->monsterstyle, RP->difficulty, RP);
140 143
141 /* treasures needs to have a proper difficulty set for the map. */ 144 /* treasures needs to have a proper difficulty set for the map. */
142 theMap->difficulty = calculate_difficulty (theMap); 145 theMap->difficulty = theMap->estimate_difficulty ();
143 146
144 /* create treasure unless the treasurestyle is "none" */ 147 /* create treasure unless the treasurestyle is "none" */
145 if (strcmp (RP->treasurestyle, "none")) 148 if (strcmp (RP->treasurestyle, "none"))
146 place_treasure (theMap, layout, RP->treasurestyle, RP->treasureoptions, RP); 149 place_treasure (theMap, layout, RP->treasurestyle, RP->treasureoptions, RP);
147 150
148 /* create decor unless the decorstyle is "none" */ 151 /* create decor unless the decorstyle is "none" */
149 if (strcmp (RP->decorstyle, "none")) 152 if (strcmp (RP->decorstyle, "none"))
150 put_decor (theMap, layout, RP->decorstyle, RP->decoroptions, RP); 153 put_decor (theMap, layout, RP->decorstyle, RP->decoroptions, RP);
151 154
152 /* generate treasures, etc. */ 155 /* generate treasures, etc. */
153 fix_auto_apply (theMap); 156 theMap->fix_auto_apply ();
154 157
155 unblock_exits (theMap, layout, RP); 158 unblock_exits (theMap, layout, RP);
156 159
157 /* free the layout */ 160 /* free the layout */
158 for (i = 0; i < RP->Xsize; i++) 161 for (i = 0; i < RP->Xsize; i++)
159 free (layout[i]); 162 free (layout[i]);
160 free (layout); 163 free (layout);
161 164
162 theMap->msg = strdup_local (buf); 165 theMap->msg = strdup (buf);
163 166
164 return theMap; 167 return theMap;
165} 168}
166
167 169
168/* function selects the layout function and gives it whatever 170/* function selects the layout function and gives it whatever
169 arguments it needs. */ 171 arguments it needs. */
170char ** 172char **
171layoutgen (RMParms * RP) 173layoutgen (random_map_params * RP)
172{ 174{
173 char **maze = 0; 175 char **maze = 0;
174 int oxsize = RP->Xsize, oysize = RP->Ysize; 176 int oxsize = RP->Xsize, oysize = RP->Ysize;
175 177
176 if (RP->symmetry == RANDOM_SYM) 178 if (RP->symmetry == SYMMETRY_RANDOM)
177 RP->symmetry_used = (RANDOM () % (XY_SYM)) + 1; 179 RP->symmetry_used = (RANDOM () % (SYMMETRY_XY)) + 1;
178 else 180 else
179 RP->symmetry_used = RP->symmetry; 181 RP->symmetry_used = RP->symmetry;
180 182
181 if (RP->symmetry_used == Y_SYM || RP->symmetry_used == XY_SYM) 183 if (RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY)
182 RP->Ysize = RP->Ysize / 2 + 1; 184 RP->Ysize = RP->Ysize / 2 + 1;
183 if (RP->symmetry_used == X_SYM || RP->symmetry_used == XY_SYM) 185 if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY)
184 RP->Xsize = RP->Xsize / 2 + 1; 186 RP->Xsize = RP->Xsize / 2 + 1;
185 187
186 if (RP->Xsize < MIN_RANDOM_MAP_SIZE) 188 if (RP->Xsize < MIN_RANDOM_MAP_SIZE)
187 RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 5; 189 RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 5;
188 if (RP->Ysize < MIN_RANDOM_MAP_SIZE) 190 if (RP->Ysize < MIN_RANDOM_MAP_SIZE)
193 * layout style and then random layout style. Instead, figure out 195 * layout style and then random layout style. Instead, figure out
194 * the numeric layoutstyle, so there is only one area that actually 196 * the numeric layoutstyle, so there is only one area that actually
195 * calls the code to make the maps. 197 * calls the code to make the maps.
196 */ 198 */
197 if (strstr (RP->layoutstyle, "onion")) 199 if (strstr (RP->layoutstyle, "onion"))
198 {
199 RP->map_layout_style = ONION_LAYOUT; 200 RP->map_layout_style = LAYOUT_ONION;
200 }
201 201
202 if (strstr (RP->layoutstyle, "maze")) 202 if (strstr (RP->layoutstyle, "maze"))
203 {
204 RP->map_layout_style = MAZE_LAYOUT; 203 RP->map_layout_style = LAYOUT_MAZE;
205 }
206 204
207 if (strstr (RP->layoutstyle, "spiral")) 205 if (strstr (RP->layoutstyle, "spiral"))
208 {
209 RP->map_layout_style = SPIRAL_LAYOUT; 206 RP->map_layout_style = LAYOUT_SPIRAL;
210 }
211 207
212 if (strstr (RP->layoutstyle, "rogue")) 208 if (strstr (RP->layoutstyle, "rogue"))
213 {
214 RP->map_layout_style = ROGUELIKE_LAYOUT; 209 RP->map_layout_style = LAYOUT_ROGUELIKE;
215 }
216 210
217 if (strstr (RP->layoutstyle, "snake")) 211 if (strstr (RP->layoutstyle, "snake"))
218 {
219 RP->map_layout_style = SNAKE_LAYOUT; 212 RP->map_layout_style = LAYOUT_SNAKE;
220 }
221 213
222 if (strstr (RP->layoutstyle, "squarespiral")) 214 if (strstr (RP->layoutstyle, "squarespiral"))
223 {
224 RP->map_layout_style = SQUARE_SPIRAL_LAYOUT; 215 RP->map_layout_style = LAYOUT_SQUARE_SPIRAL;
225 } 216
226 /* No style found - choose one ranomdly */ 217 /* No style found - choose one ranomdly */
227 if (RP->map_layout_style == 0) 218 if (RP->map_layout_style == LAYOUT_NONE)
228 {
229 RP->map_layout_style = (RANDOM () % NROFLAYOUTS) + 1; 219 RP->map_layout_style = (RANDOM () % (NROFLAYOUTS - 1)) + 1;
230 }
231 220
232 switch (RP->map_layout_style) 221 switch (RP->map_layout_style)
233 { 222 {
234 223 case LAYOUT_ONION:
235 case ONION_LAYOUT:
236 maze = map_gen_onion (RP->Xsize, RP->Ysize, RP->layoutoptions1, RP->layoutoptions2); 224 maze = map_gen_onion (RP->Xsize, RP->Ysize, RP->layoutoptions1, RP->layoutoptions2);
237 if (!(RANDOM () % 3) && !(RP->layoutoptions1 & OPT_WALLS_ONLY)) 225 if (!(RANDOM () % 3) && !(RP->layoutoptions1 & RMOPT_WALLS_ONLY))
238 roomify_layout (maze, RP); 226 roomify_layout (maze, RP);
239 break; 227 break;
240 228
241 case MAZE_LAYOUT: 229 case LAYOUT_MAZE:
242 maze = maze_gen (RP->Xsize, RP->Ysize, RANDOM () % 2); 230 maze = maze_gen (RP->Xsize, RP->Ysize, RANDOM () % 2);
243 if (!(RANDOM () % 2)) 231 if (!(RANDOM () % 2))
244 doorify_layout (maze, RP); 232 doorify_layout (maze, RP);
245 break; 233 break;
246 234
247 case SPIRAL_LAYOUT: 235 case LAYOUT_SPIRAL:
248 maze = map_gen_spiral (RP->Xsize, RP->Ysize, RP->layoutoptions1); 236 maze = map_gen_spiral (RP->Xsize, RP->Ysize, RP->layoutoptions1);
249 if (!(RANDOM () % 2)) 237 if (!(RANDOM () % 2))
250 doorify_layout (maze, RP); 238 doorify_layout (maze, RP);
251 break; 239 break;
252 240
253 case ROGUELIKE_LAYOUT: 241 case LAYOUT_ROGUELIKE:
254 /* Don't put symmetry in rogue maps. There isn't much reason to 242 /* Don't put symmetry in rogue maps. There isn't much reason to
255 * do so in the first place (doesn't make it any more interesting), 243 * do so in the first place (doesn't make it any more interesting),
256 * but more importantly, the symmetry code presumes we are symmetrizing 244 * but more importantly, the symmetry code presumes we are symmetrizing
257 * spirals, or maps with lots of passages - making a symmetric rogue 245 * spirals, or maps with lots of passages - making a symmetric rogue
258 * map fails because its likely that the passages the symmetry process 246 * map fails because its likely that the passages the symmetry process
259 * creates may not connect the rooms. 247 * creates may not connect the rooms.
260 */ 248 */
261 RP->symmetry_used = NO_SYM; 249 RP->symmetry_used = SYMMETRY_NONE;
262 RP->Ysize = oysize; 250 RP->Ysize = oysize;
263 RP->Xsize = oxsize; 251 RP->Xsize = oxsize;
264 maze = roguelike_layout_gen (RP->Xsize, RP->Ysize, RP->layoutoptions1); 252 maze = roguelike_layout_gen (RP->Xsize, RP->Ysize, RP->layoutoptions1);
265 /* no doorifying... done already */ 253 /* no doorifying... done already */
266 break; 254 break;
267 255
268 case SNAKE_LAYOUT: 256 case LAYOUT_SNAKE:
269 maze = make_snake_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); 257 maze = make_snake_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1);
270 if (RANDOM () % 2) 258 if (RANDOM () % 2)
271 roomify_layout (maze, RP); 259 roomify_layout (maze, RP);
272 break; 260 break;
273 261
274 case SQUARE_SPIRAL_LAYOUT: 262 case LAYOUT_SQUARE_SPIRAL:
275 maze = make_square_spiral_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); 263 maze = make_square_spiral_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1);
276 if (RANDOM () % 2) 264 if (RANDOM () % 2)
277 roomify_layout (maze, RP); 265 roomify_layout (maze, RP);
278 break; 266 break;
279 } 267 }
280 268
281 maze = symmetrize_layout (maze, RP->symmetry_used, RP); 269 maze = symmetrize_layout (maze, RP->symmetry_used, RP);
270
282#ifdef RMAP_DEBUG 271#ifdef RMAP_DEBUG
283 dump_layout (maze, RP); 272 dump_layout (maze, RP);
284#endif 273#endif
274
285 if (RP->expand2x) 275 if (RP->expand2x)
286 { 276 {
287 maze = expand2x (maze, RP->Xsize, RP->Ysize); 277 maze = expand2x (maze, RP->Xsize, RP->Ysize);
288 RP->Xsize = RP->Xsize * 2 - 1; 278 RP->Xsize = RP->Xsize * 2 - 1;
289 RP->Ysize = RP->Ysize * 2 - 1; 279 RP->Ysize = RP->Ysize * 2 - 1;
290 } 280 }
281
291 return maze; 282 return maze;
292} 283}
293
294 284
295/* takes a map and makes it symmetric: adjusts Xsize and 285/* takes a map and makes it symmetric: adjusts Xsize and
296Ysize to produce a symmetric map. */ 286Ysize to produce a symmetric map. */
297
298char ** 287char **
299symmetrize_layout (char **maze, int sym, RMParms * RP) 288symmetrize_layout (char **maze, int sym, random_map_params * RP)
300{ 289{
301 int i, j; 290 int i, j;
302 char **sym_maze; 291 char **sym_maze;
303 int Xsize_orig, Ysize_orig; 292 int Xsize_orig, Ysize_orig;
304 293
305 Xsize_orig = RP->Xsize; 294 Xsize_orig = RP->Xsize;
306 Ysize_orig = RP->Ysize; 295 Ysize_orig = RP->Ysize;
307 RP->symmetry_used = sym; /* tell everyone else what sort of symmetry is used. */ 296 RP->symmetry_used = sym; /* tell everyone else what sort of symmetry is used. */
308 if (sym == NO_SYM) 297 if (sym == SYMMETRY_NONE)
309 { 298 {
310 RP->Xsize = Xsize_orig; 299 RP->Xsize = Xsize_orig;
311 RP->Ysize = Ysize_orig; 300 RP->Ysize = Ysize_orig;
312 return maze; 301 return maze;
313 } 302 }
314 /* pick new sizes */ 303 /* pick new sizes */
315 RP->Xsize = ((sym == X_SYM || sym == XY_SYM) ? RP->Xsize * 2 - 3 : RP->Xsize); 304 RP->Xsize = ((sym == SYMMETRY_X || sym == SYMMETRY_XY) ? RP->Xsize * 2 - 3 : RP->Xsize);
316 RP->Ysize = ((sym == Y_SYM || sym == XY_SYM) ? RP->Ysize * 2 - 3 : RP->Ysize); 305 RP->Ysize = ((sym == SYMMETRY_Y || sym == SYMMETRY_XY) ? RP->Ysize * 2 - 3 : RP->Ysize);
317 306
318 sym_maze = (char **) calloc (sizeof (char *), RP->Xsize); 307 sym_maze = (char **) calloc (sizeof (char *), RP->Xsize);
319 for (i = 0; i < RP->Xsize; i++) 308 for (i = 0; i < RP->Xsize; i++)
320 sym_maze[i] = (char *) calloc (sizeof (char), RP->Ysize); 309 sym_maze[i] = (char *) calloc (sizeof (char), RP->Ysize);
321 310
322 if (sym == X_SYM) 311 if (sym == SYMMETRY_X)
323 for (i = 0; i < RP->Xsize / 2 + 1; i++) 312 for (i = 0; i < RP->Xsize / 2 + 1; i++)
324 for (j = 0; j < RP->Ysize; j++) 313 for (j = 0; j < RP->Ysize; j++)
325 { 314 {
326 sym_maze[i][j] = maze[i][j]; 315 sym_maze[i][j] = maze[i][j];
327 sym_maze[RP->Xsize - i - 1][j] = maze[i][j]; 316 sym_maze[RP->Xsize - i - 1][j] = maze[i][j];
328 }; 317 };
329 if (sym == Y_SYM) 318 if (sym == SYMMETRY_Y)
330 for (i = 0; i < RP->Xsize; i++) 319 for (i = 0; i < RP->Xsize; i++)
331 for (j = 0; j < RP->Ysize / 2 + 1; j++) 320 for (j = 0; j < RP->Ysize / 2 + 1; j++)
332 { 321 {
333 sym_maze[i][j] = maze[i][j]; 322 sym_maze[i][j] = maze[i][j];
334 sym_maze[i][RP->Ysize - j - 1] = maze[i][j]; 323 sym_maze[i][RP->Ysize - j - 1] = maze[i][j];
335 } 324 }
336 if (sym == XY_SYM) 325 if (sym == SYMMETRY_XY)
337 for (i = 0; i < RP->Xsize / 2 + 1; i++) 326 for (i = 0; i < RP->Xsize / 2 + 1; i++)
338 for (j = 0; j < RP->Ysize / 2 + 1; j++) 327 for (j = 0; j < RP->Ysize / 2 + 1; j++)
339 { 328 {
340 sym_maze[i][j] = maze[i][j]; 329 sym_maze[i][j] = maze[i][j];
341 sym_maze[i][RP->Ysize - j - 1] = maze[i][j]; 330 sym_maze[i][RP->Ysize - j - 1] = maze[i][j];
345 /* delete the old maze */ 334 /* delete the old maze */
346 for (i = 0; i < Xsize_orig; i++) 335 for (i = 0; i < Xsize_orig; i++)
347 free (maze[i]); 336 free (maze[i]);
348 free (maze); 337 free (maze);
349 /* reconnect disjointed spirals */ 338 /* reconnect disjointed spirals */
350 if (RP->map_layout_style == SPIRAL_LAYOUT) 339 if (RP->map_layout_style == LAYOUT_SPIRAL)
351 connect_spirals (RP->Xsize, RP->Ysize, sym, sym_maze); 340 connect_spirals (RP->Xsize, RP->Ysize, sym, sym_maze);
352 /* reconnect disjointed nethackmazes: the routine for 341 /* reconnect disjointed nethackmazes: the routine for
353 spirals will do the trick? */ 342 spirals will do the trick? */
354 if (RP->map_layout_style == ROGUELIKE_LAYOUT) 343 if (RP->map_layout_style == LAYOUT_ROGUELIKE)
355 connect_spirals (RP->Xsize, RP->Ysize, sym, sym_maze); 344 connect_spirals (RP->Xsize, RP->Ysize, sym, sym_maze);
356 345
357 return sym_maze; 346 return sym_maze;
358} 347}
359 348
362 onion layouts, making them possibly centered on any wall. 351 onion layouts, making them possibly centered on any wall.
363 It'll modify Xsize and Ysize if they're swapped. 352 It'll modify Xsize and Ysize if they're swapped.
364*/ 353*/
365 354
366char ** 355char **
367rotate_layout (char **maze, int rotation, RMParms * RP) 356rotate_layout (char **maze, int rotation, random_map_params * RP)
368{ 357{
369 char **new_maze; 358 char **new_maze;
370 int i, j; 359 int i, j;
371 360
372 switch (rotation) 361 switch (rotation)
373 { 362 {
374 case 0: 363 case 0:
364 return maze;
365 break;
366 case 2: /* a reflection */
367 {
368 char *newmaze = (char *) malloc (sizeof (char) * RP->Xsize * RP->Ysize);
369
370 for (i = 0; i < RP->Xsize; i++)
371 { /* make a copy */
372 for (j = 0; j < RP->Ysize; j++)
373 {
374 newmaze[i * RP->Ysize + j] = maze[i][j];
375 }
376 }
377 for (i = 0; i < RP->Xsize; i++)
378 { /* copy a reflection back */
379 for (j = 0; j < RP->Ysize; j++)
380 {
381 maze[i][j] = newmaze[(RP->Xsize - i - 1) * RP->Ysize + RP->Ysize - j - 1];
382 }
383 }
384 free (newmaze);
375 return maze; 385 return maze;
376 break; 386 break;
377 case 2: /* a reflection */ 387 }
388 case 1:
389 case 3:
390 {
391 int swap;
392 new_maze = (char **) calloc (sizeof (char *), RP->Ysize);
393 for (i = 0; i < RP->Ysize; i++)
378 { 394 {
379 char *newmaze = (char *) malloc (sizeof (char) * RP->Xsize * RP->Ysize); 395 new_maze[i] = (char *) calloc (sizeof (char), RP->Xsize);
380 396 }
397 if (rotation == 1) /* swap x and y */
381 for (i = 0; i < RP->Xsize; i++) 398 for (i = 0; i < RP->Xsize; i++)
382 { /* make a copy */
383 for (j = 0; j < RP->Ysize; j++) 399 for (j = 0; j < RP->Ysize; j++)
384 {
385 newmaze[i * RP->Ysize + j] = maze[i][j]; 400 new_maze[j][i] = maze[i][j];
386 } 401
387 } 402 if (rotation == 3)
388 for (i = 0; i < RP->Xsize; i++) 403 { /* swap x and y */
389 { /* copy a reflection back */
390 for (j = 0; j < RP->Ysize; j++)
391 {
392 maze[i][j] = newmaze[(RP->Xsize - i - 1) * RP->Ysize + RP->Ysize - j - 1];
393 }
394 }
395 free (newmaze);
396 return maze;
397 break;
398 }
399 case 1:
400 case 3:
401 {
402 int swap;
403 new_maze = (char **) calloc (sizeof (char *), RP->Ysize);
404 for (i = 0; i < RP->Ysize; i++)
405 {
406 new_maze[i] = (char *) calloc (sizeof (char), RP->Xsize);
407 }
408 if (rotation == 1) /* swap x and y */
409 for (i = 0; i < RP->Xsize; i++) 404 for (i = 0; i < RP->Xsize; i++)
410 for (j = 0; j < RP->Ysize; j++) 405 for (j = 0; j < RP->Ysize; j++)
411 new_maze[j][i] = maze[i][j];
412
413 if (rotation == 3)
414 { /* swap x and y */
415 for (i = 0; i < RP->Xsize; i++)
416 for (j = 0; j < RP->Ysize; j++)
417 new_maze[j][i] = maze[RP->Xsize - i - 1][RP->Ysize - j - 1]; 406 new_maze[j][i] = maze[RP->Xsize - i - 1][RP->Ysize - j - 1];
418 } 407 }
419 408
420 /* delete the old layout */ 409 /* delete the old layout */
421 for (i = 0; i < RP->Xsize; i++) 410 for (i = 0; i < RP->Xsize; i++)
422 free (maze[i]); 411 free (maze[i]);
423 free (maze); 412 free (maze);
424 413
425 swap = RP->Ysize; 414 swap = RP->Ysize;
426 RP->Ysize = RP->Xsize; 415 RP->Ysize = RP->Xsize;
427 RP->Xsize = swap; 416 RP->Xsize = swap;
428 return new_maze; 417 return new_maze;
429 break; 418 break;
430 } 419 }
431 } 420 }
432 return NULL; 421 return NULL;
433} 422}
434 423
435/* take a layout and make some rooms in it. 424/* take a layout and make some rooms in it.
436 --works best on onions.*/ 425 --works best on onions.*/
437void 426void
438roomify_layout (char **maze, RMParms * RP) 427roomify_layout (char **maze, random_map_params * RP)
439{ 428{
440 int tries = RP->Xsize * RP->Ysize / 30; 429 int tries = RP->Xsize * RP->Ysize / 30;
441 int ti; 430 int ti;
442 431
443 for (ti = 0; ti < tries; ti++) 432 for (ti = 0; ti < tries; ti++)
470/* checks the layout to see if I can stick a horizontal(dir = 0) wall 459/* checks the layout to see if I can stick a horizontal(dir = 0) wall
471 (or vertical, dir == 1) 460 (or vertical, dir == 1)
472 here which ends up on other walls sensibly. */ 461 here which ends up on other walls sensibly. */
473 462
474int 463int
475can_make_wall (char **maze, int dx, int dy, int dir, RMParms * RP) 464can_make_wall (char **maze, int dx, int dy, int dir, random_map_params * RP)
476{ 465{
477 int i1; 466 int i1;
478 int length = 0; 467 int length = 0;
479 468
480 /* dont make walls if we're on the edge. */ 469 /* dont make walls if we're on the edge. */
583} 572}
584 573
585/* puts doors at appropriate locations in a layout. */ 574/* puts doors at appropriate locations in a layout. */
586 575
587void 576void
588doorify_layout (char **maze, RMParms * RP) 577doorify_layout (char **maze, random_map_params * RP)
589{ 578{
590 int ndoors = RP->Xsize * RP->Ysize / 60; /* reasonable number of doors. */ 579 int ndoors = RP->Xsize * RP->Ysize / 60; /* reasonable number of doors. */
591 char *doorlist_x; 580 char *doorlist_x;
592 char *doorlist_y; 581 char *doorlist_y;
593 int doorlocs = 0; /* # of available doorlocations */ 582 int doorlocs = 0; /* # of available doorlocations */
633 free (doorlist_y); 622 free (doorlist_y);
634} 623}
635 624
636 625
637void 626void
638write_map_parameters_to_string (char *buf, RMParms * RP) 627write_map_parameters_to_string (char *buf, random_map_params * RP)
639{ 628{
640
641 char small_buf[256]; 629 char small_buf[256];
642 630
643 sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize); 631 sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize);
644 632
645 if (RP->wallstyle[0]) 633 if (RP->wallstyle[0])
783 if (RP->origin_y) 771 if (RP->origin_y)
784 { 772 {
785 sprintf (small_buf, "origin_y %d\n", RP->origin_y); 773 sprintf (small_buf, "origin_y %d\n", RP->origin_y);
786 strcat (buf, small_buf); 774 strcat (buf, small_buf);
787 } 775 }
776
788 if (RP->random_seed) 777 if (RP->random_seed)
789 { 778 {
790 /* Add one so that the next map is a bit different */ 779 /* Add one so that the next map is a bit different */
791 sprintf (small_buf, "random_seed %d\n", RP->random_seed + 1); 780 sprintf (small_buf, "random_seed %d\n", RP->random_seed + 1);
792 strcat (buf, small_buf); 781 strcat (buf, small_buf);
795 if (RP->treasureoptions) 784 if (RP->treasureoptions)
796 { 785 {
797 sprintf (small_buf, "treasureoptions %d\n", RP->treasureoptions); 786 sprintf (small_buf, "treasureoptions %d\n", RP->treasureoptions);
798 strcat (buf, small_buf); 787 strcat (buf, small_buf);
799 } 788 }
800
801
802} 789}
803 790
804void 791void
805write_parameters_to_string (char *buf, 792write_parameters_to_string (char *buf,
806 int xsize_n, 793 int xsize_n,
968 if (origin_y_n) 955 if (origin_y_n)
969 { 956 {
970 sprintf (small_buf, "origin_y %d\n", origin_y_n); 957 sprintf (small_buf, "origin_y %d\n", origin_y_n);
971 strcat (buf, small_buf); 958 strcat (buf, small_buf);
972 } 959 }
960
973 if (random_seed_n) 961 if (random_seed_n)
974 { 962 {
975 /* Add one so that the next map is a bit different */ 963 /* Add one so that the next map is a bit different */
976 sprintf (small_buf, "random_seed %d\n", random_seed_n + 1); 964 sprintf (small_buf, "random_seed %d\n", random_seed_n + 1);
977 strcat (buf, small_buf); 965 strcat (buf, small_buf);
990void 978void
991copy_object_with_inv (object *src_ob, object *dest_ob) 979copy_object_with_inv (object *src_ob, object *dest_ob)
992{ 980{
993 object *walk, *tmp; 981 object *walk, *tmp;
994 982
995 copy_object (src_ob, dest_ob); 983 src_ob->copy_to (dest_ob);
996 984
997 for (walk = src_ob->inv; walk != NULL; walk = walk->below) 985 for (walk = src_ob->inv; walk != NULL; walk = walk->below)
998 { 986 {
999 tmp = get_object (); 987 tmp = object::create ();
1000 copy_object (walk, tmp); 988 walk->copy_to (tmp);
1001 insert_ob_in_ob (tmp, dest_ob); 989 insert_ob_in_ob (tmp, dest_ob);
1002 } 990 }
1003} 991}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines