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.12 by root, Sun Dec 31 17:17:23 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, random_map_params * 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++)
53} 54}
54 55
55extern FILE *logfile; 56extern FILE *logfile;
56 57
57maptile * 58maptile *
58generate_random_map (const char *OutFileName, random_map_params * RP) 59generate_random_map (const char *OutFileName, random_map_params *RP)
59{ 60{
60 char **layout, buf[HUGE_BUF]; 61 char **layout, buf[HUGE_BUF];
61 maptile *theMap; 62 maptile *theMap;
62 int i; 63 int i;
63 64
170} 171}
171 172
172/* function selects the layout function and gives it whatever 173/* function selects the layout function and gives it whatever
173 arguments it needs. */ 174 arguments it needs. */
174char ** 175char **
175layoutgen (random_map_params * RP) 176layoutgen (random_map_params *RP)
176{ 177{
177 char **maze = 0; 178 char **maze = 0;
178 int oxsize = RP->Xsize, oysize = RP->Ysize; 179 int oxsize = RP->Xsize, oysize = RP->Ysize;
179 180
180 if (RP->symmetry == SYMMETRY_RANDOM) 181 if (RP->symmetry == SYMMETRY_RANDOM)
285} 286}
286 287
287/* takes a map and makes it symmetric: adjusts Xsize and 288/* takes a map and makes it symmetric: adjusts Xsize and
288Ysize to produce a symmetric map. */ 289Ysize to produce a symmetric map. */
289char ** 290char **
290symmetrize_layout (char **maze, int sym, random_map_params * RP) 291symmetrize_layout (char **maze, int sym, random_map_params *RP)
291{ 292{
292 int i, j; 293 int i, j;
293 char **sym_maze; 294 char **sym_maze;
294 int Xsize_orig, Ysize_orig; 295 int Xsize_orig, Ysize_orig;
295 296
353 onion layouts, making them possibly centered on any wall. 354 onion layouts, making them possibly centered on any wall.
354 It'll modify Xsize and Ysize if they're swapped. 355 It'll modify Xsize and Ysize if they're swapped.
355*/ 356*/
356 357
357char ** 358char **
358rotate_layout (char **maze, int rotation, random_map_params * RP) 359rotate_layout (char **maze, int rotation, random_map_params *RP)
359{ 360{
360 char **new_maze; 361 char **new_maze;
361 int i, j; 362 int i, j;
362 363
363 switch (rotation) 364 switch (rotation)
364 { 365 {
365 case 0: 366 case 0:
366 return maze; 367 return maze;
367 break; 368 break;
368 case 2: /* a reflection */ 369 case 2: /* a reflection */
369 { 370 {
370 char *newmaze = (char *) malloc (sizeof (char) * RP->Xsize * RP->Ysize); 371 char *newmaze = (char *) malloc (sizeof (char) * RP->Xsize * RP->Ysize);
371 372
372 for (i = 0; i < RP->Xsize; i++) 373 for (i = 0; i < RP->Xsize; i++)
373 { /* make a copy */ 374 { /* make a copy */
374 for (j = 0; j < RP->Ysize; j++) 375 for (j = 0; j < RP->Ysize; j++)
375 { 376 {
376 newmaze[i * RP->Ysize + j] = maze[i][j]; 377 newmaze[i * RP->Ysize + j] = maze[i][j];
377 } 378 }
378 } 379 }
379 for (i = 0; i < RP->Xsize; i++) 380 for (i = 0; i < RP->Xsize; i++)
380 { /* copy a reflection back */ 381 { /* copy a reflection back */
381 for (j = 0; j < RP->Ysize; j++) 382 for (j = 0; j < RP->Ysize; j++)
382 { 383 {
383 maze[i][j] = newmaze[(RP->Xsize - i - 1) * RP->Ysize + RP->Ysize - j - 1]; 384 maze[i][j] = newmaze[(RP->Xsize - i - 1) * RP->Ysize + RP->Ysize - j - 1];
384 } 385 }
385 } 386 }
394 new_maze = (char **) calloc (sizeof (char *), RP->Ysize); 395 new_maze = (char **) calloc (sizeof (char *), RP->Ysize);
395 for (i = 0; i < RP->Ysize; i++) 396 for (i = 0; i < RP->Ysize; i++)
396 { 397 {
397 new_maze[i] = (char *) calloc (sizeof (char), RP->Xsize); 398 new_maze[i] = (char *) calloc (sizeof (char), RP->Xsize);
398 } 399 }
399 if (rotation == 1) /* swap x and y */ 400 if (rotation == 1) /* swap x and y */
400 for (i = 0; i < RP->Xsize; i++) 401 for (i = 0; i < RP->Xsize; i++)
401 for (j = 0; j < RP->Ysize; j++) 402 for (j = 0; j < RP->Ysize; j++)
402 new_maze[j][i] = maze[i][j]; 403 new_maze[j][i] = maze[i][j];
403 404
404 if (rotation == 3) 405 if (rotation == 3)
405 { /* swap x and y */ 406 { /* swap x and y */
406 for (i = 0; i < RP->Xsize; i++) 407 for (i = 0; i < RP->Xsize; i++)
407 for (j = 0; j < RP->Ysize; j++) 408 for (j = 0; j < RP->Ysize; j++)
408 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];
409 } 410 }
410 411
424} 425}
425 426
426/* take a layout and make some rooms in it. 427/* take a layout and make some rooms in it.
427 --works best on onions.*/ 428 --works best on onions.*/
428void 429void
429roomify_layout (char **maze, random_map_params * RP) 430roomify_layout (char **maze, random_map_params *RP)
430{ 431{
431 int tries = RP->Xsize * RP->Ysize / 30; 432 int tries = RP->Xsize * RP->Ysize / 30;
432 int ti; 433 int ti;
433 434
434 for (ti = 0; ti < tries; ti++) 435 for (ti = 0; ti < tries; ti++)
461/* 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
462 (or vertical, dir == 1) 463 (or vertical, dir == 1)
463 here which ends up on other walls sensibly. */ 464 here which ends up on other walls sensibly. */
464 465
465int 466int
466can_make_wall (char **maze, int dx, int dy, int dir, random_map_params * RP) 467can_make_wall (char **maze, int dx, int dy, int dir, random_map_params *RP)
467{ 468{
468 int i1; 469 int i1;
469 int length = 0; 470 int length = 0;
470 471
471 /* dont make walls if we're on the edge. */ 472 /* dont make walls if we're on the edge. */
546make_wall (char **maze, int x, int y, int dir) 547make_wall (char **maze, int x, int y, int dir)
547{ 548{
548 maze[x][y] = 'D'; /* mark a door */ 549 maze[x][y] = 'D'; /* mark a door */
549 switch (dir) 550 switch (dir)
550 { 551 {
551 case 0: /* horizontal */ 552 case 0: /* horizontal */
552 { 553 {
553 int i1; 554 int i1;
554 555
555 for (i1 = x - 1; maze[i1][y] == 0; i1--) 556 for (i1 = x - 1; maze[i1][y] == 0; i1--)
556 maze[i1][y] = '#'; 557 maze[i1][y] = '#';
557 for (i1 = x + 1; maze[i1][y] == 0; i1++) 558 for (i1 = x + 1; maze[i1][y] == 0; i1++)
558 maze[i1][y] = '#'; 559 maze[i1][y] = '#';
559 break; 560 break;
560 } 561 }
561 case 1: /* vertical */ 562 case 1: /* vertical */
562 { 563 {
563 int i1; 564 int i1;
564 565
565 for (i1 = y - 1; maze[x][i1] == 0; i1--) 566 for (i1 = y - 1; maze[x][i1] == 0; i1--)
566 maze[x][i1] = '#'; 567 maze[x][i1] = '#';
567 for (i1 = y + 1; maze[x][i1] == 0; i1++) 568 for (i1 = y + 1; maze[x][i1] == 0; i1++)
568 maze[x][i1] = '#'; 569 maze[x][i1] = '#';
569 break; 570 break;
570 } 571 }
571 } 572 }
572 573
573 return 0; 574 return 0;
574} 575}
575 576
576/* puts doors at appropriate locations in a layout. */ 577/* puts doors at appropriate locations in a layout. */
577void 578void
578doorify_layout (char **maze, random_map_params * RP) 579doorify_layout (char **maze, random_map_params *RP)
579{ 580{
580 int ndoors = RP->Xsize * RP->Ysize / 60; /* reasonable number of doors. */ 581 int ndoors = RP->Xsize * RP->Ysize / 60; /* reasonable number of doors. */
581 char *doorlist_x; 582 char *doorlist_x;
582 char *doorlist_y; 583 char *doorlist_y;
583 int doorlocs = 0; /* # of available doorlocations */ 584 int doorlocs = 0; /* # of available doorlocations */
624 free (doorlist_x); 625 free (doorlist_x);
625 free (doorlist_y); 626 free (doorlist_y);
626} 627}
627 628
628void 629void
629write_map_parameters_to_string (char *buf, random_map_params * RP) 630write_map_parameters_to_string (char *buf, random_map_params *RP)
630{ 631{
631 char small_buf[256]; 632 char small_buf[256];
632 633
633 sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize); 634 sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize);
634 635
984 src_ob->copy_to (dest_ob); 985 src_ob->copy_to (dest_ob);
985 986
986 for (walk = src_ob->inv; walk != NULL; walk = walk->below) 987 for (walk = src_ob->inv; walk != NULL; walk = walk->below)
987 { 988 {
988 tmp = object::create (); 989 tmp = object::create ();
990
989 walk->copy_to (tmp); 991 walk->copy_to (tmp);
990 insert_ob_in_ob (tmp, dest_ob); 992 insert_ob_in_ob (tmp, dest_ob);
991 } 993 }
992} 994}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines