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.6 by root, Fri Sep 29 20:12:32 2006 UTC vs.
Revision 1.13 by root, Sun Dec 31 19:02:24 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines