|
|
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 | |
33 | void |
34 | void |
34 | dump_layout (char **layout, random_map_params * RP) |
35 | dump_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 | |
55 | extern FILE *logfile; |
56 | extern FILE *logfile; |
56 | |
57 | |
57 | maptile * |
58 | maptile * |
58 | generate_random_map (const char *OutFileName, random_map_params * RP) |
59 | generate_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 | |
… | |
… | |
158 | unblock_exits (theMap, layout, RP); |
159 | unblock_exits (theMap, layout, RP); |
159 | |
160 | |
160 | /* free the layout */ |
161 | /* free the layout */ |
161 | for (i = 0; i < RP->Xsize; i++) |
162 | for (i = 0; i < RP->Xsize; i++) |
162 | free (layout[i]); |
163 | free (layout[i]); |
|
|
164 | |
163 | free (layout); |
165 | free (layout); |
164 | |
166 | |
165 | theMap->msg = strdup (buf); |
167 | theMap->msg = strdup (buf); |
|
|
168 | theMap->in_memory = MAP_IN_MEMORY; |
166 | |
169 | |
167 | return theMap; |
170 | return theMap; |
168 | } |
171 | } |
169 | |
172 | |
170 | /* function selects the layout function and gives it whatever |
173 | /* function selects the layout function and gives it whatever |
171 | arguments it needs. */ |
174 | arguments it needs. */ |
172 | char ** |
175 | char ** |
173 | layoutgen (random_map_params * RP) |
176 | layoutgen (random_map_params *RP) |
174 | { |
177 | { |
175 | char **maze = 0; |
178 | char **maze = 0; |
176 | int oxsize = RP->Xsize, oysize = RP->Ysize; |
179 | int oxsize = RP->Xsize, oysize = RP->Ysize; |
177 | |
180 | |
178 | if (RP->symmetry == SYMMETRY_RANDOM) |
181 | if (RP->symmetry == SYMMETRY_RANDOM) |
… | |
… | |
283 | } |
286 | } |
284 | |
287 | |
285 | /* takes a map and makes it symmetric: adjusts Xsize and |
288 | /* takes a map and makes it symmetric: adjusts Xsize and |
286 | Ysize to produce a symmetric map. */ |
289 | Ysize to produce a symmetric map. */ |
287 | char ** |
290 | char ** |
288 | symmetrize_layout (char **maze, int sym, random_map_params * RP) |
291 | symmetrize_layout (char **maze, int sym, random_map_params *RP) |
289 | { |
292 | { |
290 | int i, j; |
293 | int i, j; |
291 | char **sym_maze; |
294 | char **sym_maze; |
292 | int Xsize_orig, Ysize_orig; |
295 | int Xsize_orig, Ysize_orig; |
293 | |
296 | |
… | |
… | |
351 | onion layouts, making them possibly centered on any wall. |
354 | onion layouts, making them possibly centered on any wall. |
352 | It'll modify Xsize and Ysize if they're swapped. |
355 | It'll modify Xsize and Ysize if they're swapped. |
353 | */ |
356 | */ |
354 | |
357 | |
355 | char ** |
358 | char ** |
356 | rotate_layout (char **maze, int rotation, random_map_params * RP) |
359 | rotate_layout (char **maze, int rotation, random_map_params *RP) |
357 | { |
360 | { |
358 | char **new_maze; |
361 | char **new_maze; |
359 | int i, j; |
362 | int i, j; |
360 | |
363 | |
361 | switch (rotation) |
364 | switch (rotation) |
362 | { |
365 | { |
363 | case 0: |
366 | case 0: |
364 | return maze; |
367 | return maze; |
365 | break; |
368 | break; |
366 | case 2: /* a reflection */ |
369 | case 2: /* a reflection */ |
367 | { |
370 | { |
368 | char *newmaze = (char *) malloc (sizeof (char) * RP->Xsize * RP->Ysize); |
371 | char *newmaze = (char *) malloc (sizeof (char) * RP->Xsize * RP->Ysize); |
369 | |
372 | |
370 | for (i = 0; i < RP->Xsize; i++) |
373 | for (i = 0; i < RP->Xsize; i++) |
371 | { /* make a copy */ |
374 | { /* make a copy */ |
372 | for (j = 0; j < RP->Ysize; j++) |
375 | for (j = 0; j < RP->Ysize; j++) |
373 | { |
376 | { |
374 | newmaze[i * RP->Ysize + j] = maze[i][j]; |
377 | newmaze[i * RP->Ysize + j] = maze[i][j]; |
375 | } |
378 | } |
376 | } |
379 | } |
377 | for (i = 0; i < RP->Xsize; i++) |
380 | for (i = 0; i < RP->Xsize; i++) |
378 | { /* copy a reflection back */ |
381 | { /* copy a reflection back */ |
379 | for (j = 0; j < RP->Ysize; j++) |
382 | for (j = 0; j < RP->Ysize; j++) |
380 | { |
383 | { |
381 | 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]; |
382 | } |
385 | } |
383 | } |
386 | } |
… | |
… | |
392 | new_maze = (char **) calloc (sizeof (char *), RP->Ysize); |
395 | new_maze = (char **) calloc (sizeof (char *), RP->Ysize); |
393 | for (i = 0; i < RP->Ysize; i++) |
396 | for (i = 0; i < RP->Ysize; i++) |
394 | { |
397 | { |
395 | new_maze[i] = (char *) calloc (sizeof (char), RP->Xsize); |
398 | new_maze[i] = (char *) calloc (sizeof (char), RP->Xsize); |
396 | } |
399 | } |
397 | if (rotation == 1) /* swap x and y */ |
400 | if (rotation == 1) /* swap x and y */ |
398 | for (i = 0; i < RP->Xsize; i++) |
401 | for (i = 0; i < RP->Xsize; i++) |
399 | for (j = 0; j < RP->Ysize; j++) |
402 | for (j = 0; j < RP->Ysize; j++) |
400 | new_maze[j][i] = maze[i][j]; |
403 | new_maze[j][i] = maze[i][j]; |
401 | |
404 | |
402 | if (rotation == 3) |
405 | if (rotation == 3) |
403 | { /* swap x and y */ |
406 | { /* swap x and y */ |
404 | for (i = 0; i < RP->Xsize; i++) |
407 | for (i = 0; i < RP->Xsize; i++) |
405 | for (j = 0; j < RP->Ysize; j++) |
408 | for (j = 0; j < RP->Ysize; j++) |
406 | 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]; |
407 | } |
410 | } |
408 | |
411 | |
… | |
… | |
422 | } |
425 | } |
423 | |
426 | |
424 | /* take a layout and make some rooms in it. |
427 | /* take a layout and make some rooms in it. |
425 | --works best on onions.*/ |
428 | --works best on onions.*/ |
426 | void |
429 | void |
427 | roomify_layout (char **maze, random_map_params * RP) |
430 | roomify_layout (char **maze, random_map_params *RP) |
428 | { |
431 | { |
429 | int tries = RP->Xsize * RP->Ysize / 30; |
432 | int tries = RP->Xsize * RP->Ysize / 30; |
430 | int ti; |
433 | int ti; |
431 | |
434 | |
432 | for (ti = 0; ti < tries; ti++) |
435 | for (ti = 0; ti < tries; ti++) |
… | |
… | |
459 | /* 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 |
460 | (or vertical, dir == 1) |
463 | (or vertical, dir == 1) |
461 | here which ends up on other walls sensibly. */ |
464 | here which ends up on other walls sensibly. */ |
462 | |
465 | |
463 | int |
466 | int |
464 | can_make_wall (char **maze, int dx, int dy, int dir, random_map_params * RP) |
467 | can_make_wall (char **maze, int dx, int dy, int dir, random_map_params *RP) |
465 | { |
468 | { |
466 | int i1; |
469 | int i1; |
467 | int length = 0; |
470 | int length = 0; |
468 | |
471 | |
469 | /* dont make walls if we're on the edge. */ |
472 | /* dont make walls if we're on the edge. */ |
… | |
… | |
544 | make_wall (char **maze, int x, int y, int dir) |
547 | make_wall (char **maze, int x, int y, int dir) |
545 | { |
548 | { |
546 | maze[x][y] = 'D'; /* mark a door */ |
549 | maze[x][y] = 'D'; /* mark a door */ |
547 | switch (dir) |
550 | switch (dir) |
548 | { |
551 | { |
549 | case 0: /* horizontal */ |
552 | case 0: /* horizontal */ |
550 | { |
553 | { |
551 | int i1; |
554 | int i1; |
552 | |
555 | |
553 | for (i1 = x - 1; maze[i1][y] == 0; i1--) |
556 | for (i1 = x - 1; maze[i1][y] == 0; i1--) |
554 | maze[i1][y] = '#'; |
557 | maze[i1][y] = '#'; |
555 | for (i1 = x + 1; maze[i1][y] == 0; i1++) |
558 | for (i1 = x + 1; maze[i1][y] == 0; i1++) |
556 | maze[i1][y] = '#'; |
559 | maze[i1][y] = '#'; |
557 | break; |
560 | break; |
558 | } |
561 | } |
559 | case 1: /* vertical */ |
562 | case 1: /* vertical */ |
560 | { |
563 | { |
561 | int i1; |
564 | int i1; |
562 | |
565 | |
563 | for (i1 = y - 1; maze[x][i1] == 0; i1--) |
566 | for (i1 = y - 1; maze[x][i1] == 0; i1--) |
564 | maze[x][i1] = '#'; |
567 | maze[x][i1] = '#'; |
565 | for (i1 = y + 1; maze[x][i1] == 0; i1++) |
568 | for (i1 = y + 1; maze[x][i1] == 0; i1++) |
566 | maze[x][i1] = '#'; |
569 | maze[x][i1] = '#'; |
567 | break; |
570 | break; |
568 | } |
571 | } |
569 | } |
572 | } |
570 | |
573 | |
571 | return 0; |
574 | return 0; |
572 | } |
575 | } |
573 | |
576 | |
574 | /* puts doors at appropriate locations in a layout. */ |
577 | /* puts doors at appropriate locations in a layout. */ |
575 | |
|
|
576 | void |
578 | void |
577 | doorify_layout (char **maze, random_map_params * RP) |
579 | doorify_layout (char **maze, random_map_params *RP) |
578 | { |
580 | { |
579 | int ndoors = RP->Xsize * RP->Ysize / 60; /* reasonable number of doors. */ |
581 | int ndoors = RP->Xsize * RP->Ysize / 60; /* reasonable number of doors. */ |
580 | char *doorlist_x; |
582 | char *doorlist_x; |
581 | char *doorlist_y; |
583 | char *doorlist_y; |
582 | int doorlocs = 0; /* # of available doorlocations */ |
584 | int doorlocs = 0; /* # of available doorlocations */ |
… | |
… | |
597 | doorlist_x[doorlocs] = i; |
599 | doorlist_x[doorlocs] = i; |
598 | doorlist_y[doorlocs] = j; |
600 | doorlist_y[doorlocs] = j; |
599 | doorlocs++; |
601 | doorlocs++; |
600 | } |
602 | } |
601 | } |
603 | } |
|
|
604 | |
602 | while (ndoors > 0 && doorlocs > 0) |
605 | while (ndoors > 0 && doorlocs > 0) |
603 | { |
606 | { |
604 | int di; |
607 | int di; |
605 | int sindex; |
608 | int sindex; |
606 | |
609 | |
… | |
… | |
616 | /* reduce the size of the list */ |
619 | /* reduce the size of the list */ |
617 | doorlocs--; |
620 | doorlocs--; |
618 | doorlist_x[di] = doorlist_x[doorlocs]; |
621 | doorlist_x[di] = doorlist_x[doorlocs]; |
619 | doorlist_y[di] = doorlist_y[doorlocs]; |
622 | doorlist_y[di] = doorlist_y[doorlocs]; |
620 | } |
623 | } |
|
|
624 | |
621 | free (doorlist_x); |
625 | free (doorlist_x); |
622 | free (doorlist_y); |
626 | free (doorlist_y); |
623 | } |
627 | } |
624 | |
628 | |
625 | |
|
|
626 | void |
629 | void |
627 | write_map_parameters_to_string (char *buf, random_map_params * RP) |
630 | write_map_parameters_to_string (char *buf, random_map_params *RP) |
628 | { |
631 | { |
629 | char small_buf[256]; |
632 | char small_buf[256]; |
630 | |
633 | |
631 | sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize); |
634 | sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize); |
632 | |
635 | |
… | |
… | |
890 | { |
893 | { |
891 | sprintf (small_buf, "layoutoptions1 %d\n", layoutoptions1_n); |
894 | sprintf (small_buf, "layoutoptions1 %d\n", layoutoptions1_n); |
892 | strcat (buf, small_buf); |
895 | strcat (buf, small_buf); |
893 | } |
896 | } |
894 | |
897 | |
895 | |
|
|
896 | if (layoutoptions2_n) |
898 | if (layoutoptions2_n) |
897 | { |
899 | { |
898 | sprintf (small_buf, "layoutoptions2 %d\n", layoutoptions2_n); |
900 | sprintf (small_buf, "layoutoptions2 %d\n", layoutoptions2_n); |
899 | strcat (buf, small_buf); |
901 | strcat (buf, small_buf); |
900 | } |
902 | } |
… | |
… | |
983 | src_ob->copy_to (dest_ob); |
985 | src_ob->copy_to (dest_ob); |
984 | |
986 | |
985 | for (walk = src_ob->inv; walk != NULL; walk = walk->below) |
987 | for (walk = src_ob->inv; walk != NULL; walk = walk->below) |
986 | { |
988 | { |
987 | tmp = object::create (); |
989 | tmp = object::create (); |
|
|
990 | |
988 | walk->copy_to (tmp); |
991 | walk->copy_to (tmp); |
989 | insert_ob_in_ob (tmp, dest_ob); |
992 | insert_ob_in_ob (tmp, dest_ob); |
990 | } |
993 | } |
991 | } |
994 | } |