1 | /* |
1 | /* |
2 | * CrossFire, A Multiplayer game for X-windows |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
3 | * |
3 | * |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
5 | * Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
8 | * Crossfire TRT is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program; if not, write to the Free Software |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
|
21 | * |
20 | * |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
21 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
23 | */ |
22 | */ |
24 | |
23 | |
25 | #include <time.h> |
24 | #include <time.h> |
26 | #include <stdio.h> |
25 | #include <stdio.h> |
27 | #include <global.h> |
26 | #include <global.h> |
… | |
… | |
29 | #include <room_gen.h> |
28 | #include <room_gen.h> |
30 | #include <random_map.h> |
29 | #include <random_map.h> |
31 | #include <rproto.h> |
30 | #include <rproto.h> |
32 | #include <sproto.h> |
31 | #include <sproto.h> |
33 | |
32 | |
34 | #define CEDE coroapi::cede (); rndm.seed (RP->random_seed + __LINE__); |
33 | #define CEDE coroapi::cede_to_tick (); rndm.seed (RP->random_seed + __LINE__); |
35 | |
34 | |
36 | void |
35 | void |
37 | dump_layout (char **layout, random_map_params *RP) |
36 | dump_layout (char **layout, random_map_params *RP) |
38 | { |
37 | { |
39 | { |
38 | { |
… | |
… | |
90 | |
89 | |
91 | if (RP->Ysize < MIN_RANDOM_MAP_SIZE) |
90 | if (RP->Ysize < MIN_RANDOM_MAP_SIZE) |
92 | RP->Ysize = MIN_RANDOM_MAP_SIZE + rndm (25) + 5; |
91 | RP->Ysize = MIN_RANDOM_MAP_SIZE + rndm (25) + 5; |
93 | |
92 | |
94 | if (RP->symmetry == SYMMETRY_RANDOM) |
93 | if (RP->symmetry == SYMMETRY_RANDOM) |
95 | RP->symmetry_used = (RANDOM () % (SYMMETRY_XY)) + 1; |
94 | RP->symmetry_used = rndm (SYMMETRY_XY) + 1; |
96 | else |
95 | else |
97 | RP->symmetry_used = RP->symmetry; |
96 | RP->symmetry_used = RP->symmetry; |
98 | |
97 | |
99 | if (RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY) |
98 | if (RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY) |
100 | RP->Ysize = RP->Ysize / 2 + 1; |
99 | RP->Ysize = RP->Ysize / 2 + 1; |
… | |
… | |
133 | if (strstr (RP->layoutstyle, "squarespiral")) |
132 | if (strstr (RP->layoutstyle, "squarespiral")) |
134 | RP->map_layout_style = LAYOUT_SQUARE_SPIRAL; |
133 | RP->map_layout_style = LAYOUT_SQUARE_SPIRAL; |
135 | |
134 | |
136 | /* No style found - choose one randomly */ |
135 | /* No style found - choose one randomly */ |
137 | if (RP->map_layout_style == LAYOUT_NONE) |
136 | if (RP->map_layout_style == LAYOUT_NONE) |
138 | RP->map_layout_style = (RANDOM () % (NROFLAYOUTS - 1)) + 1; |
137 | RP->map_layout_style = rndm (NROFLAYOUTS - 1) + 1; |
139 | |
138 | |
140 | layout = layoutgen (RP); |
139 | layout = layoutgen (RP); |
141 | |
140 | |
142 | #ifdef RMAP_DEBUG |
141 | #ifdef RMAP_DEBUG |
143 | dump_layout (layout, RP); |
142 | dump_layout (layout, RP); |
… | |
… | |
156 | |
155 | |
157 | /* allocate the map and set the floor */ |
156 | /* allocate the map and set the floor */ |
158 | make_map_floor (layout, RP->floorstyle, RP); |
157 | make_map_floor (layout, RP->floorstyle, RP); |
159 | |
158 | |
160 | /* set region */ |
159 | /* set region */ |
161 | region = RP->region; |
160 | default_region = RP->region; |
162 | |
161 | |
163 | CEDE; |
162 | CEDE; |
164 | |
163 | |
165 | /* create walls unless the wallstyle is "none" */ |
164 | /* create walls unless the wallstyle is "none" */ |
166 | if (strcmp (RP->wallstyle, "none")) |
165 | if (strcmp (RP->wallstyle, "none")) |
… | |
… | |
450 | for (ti = 0; ti < tries; ti++) |
449 | for (ti = 0; ti < tries; ti++) |
451 | { |
450 | { |
452 | int dx, dy; /* starting location for looking at creating a door */ |
451 | int dx, dy; /* starting location for looking at creating a door */ |
453 | int cx, cy; /* results of checking on creating walls. */ |
452 | int cx, cy; /* results of checking on creating walls. */ |
454 | |
453 | |
455 | dx = RANDOM () % RP->Xsize; |
454 | dx = rndm (RP->Xsize); |
456 | dy = RANDOM () % RP->Ysize; |
455 | dy = rndm (RP->Ysize); |
|
|
456 | |
457 | cx = can_make_wall (maze, dx, dy, 0, RP); /* horizontal */ |
457 | cx = can_make_wall (maze, dx, dy, 0, RP); /* horizontal */ |
458 | cy = can_make_wall (maze, dx, dy, 1, RP); /* vertical */ |
458 | cy = can_make_wall (maze, dx, dy, 1, RP); /* vertical */ |
459 | if (cx == -1) |
459 | if (cx == -1) |
460 | { |
460 | { |
461 | if (cy != -1) |
461 | if (cy != -1) |
462 | make_wall (maze, dx, dy, 1); |
462 | make_wall (maze, dx, dy, 1); |
|
|
463 | |
463 | continue; |
464 | continue; |
464 | } |
465 | } |
|
|
466 | |
465 | if (cy == -1) |
467 | if (cy == -1) |
466 | { |
468 | { |
467 | make_wall (maze, dx, dy, 0); |
469 | make_wall (maze, dx, dy, 0); |
468 | continue; |
470 | continue; |
469 | } |
471 | } |
|
|
472 | |
470 | if (cx < cy) |
473 | if (cx < cy) |
471 | make_wall (maze, dx, dy, 0); |
474 | make_wall (maze, dx, dy, 0); |
472 | else |
475 | else |
473 | make_wall (maze, dx, dy, 1); |
476 | make_wall (maze, dx, dy, 1); |
474 | } |
477 | } |
… | |
… | |
620 | while (ndoors > 0 && doorlocs > 0) |
623 | while (ndoors > 0 && doorlocs > 0) |
621 | { |
624 | { |
622 | int di; |
625 | int di; |
623 | int sindex; |
626 | int sindex; |
624 | |
627 | |
625 | di = RANDOM () % doorlocs; |
628 | di = rndm (doorlocs); |
626 | i = doorlist_x[di]; |
629 | i = doorlist_x[di]; |
627 | j = doorlist_y[di]; |
630 | j = doorlist_y[di]; |
628 | sindex = surround_flag (maze, i, j, RP); |
631 | sindex = surround_flag (maze, i, j, RP); |
|
|
632 | |
629 | if (sindex == 3 || sindex == 12) /* these are possible door sindex */ |
633 | if (sindex == 3 || sindex == 12) /* these are possible door sindex */ |
630 | { |
634 | { |
631 | maze[i][j] = 'D'; |
635 | maze[i][j] = 'D'; |
632 | ndoors--; |
636 | ndoors--; |
633 | } |
637 | } |
|
|
638 | |
634 | /* reduce the size of the list */ |
639 | /* reduce the size of the list */ |
635 | doorlocs--; |
640 | doorlocs--; |
636 | doorlist_x[di] = doorlist_x[doorlocs]; |
641 | doorlist_x[di] = doorlist_x[doorlocs]; |
637 | doorlist_y[di] = doorlist_y[doorlocs]; |
642 | doorlist_y[di] = doorlist_y[doorlocs]; |
638 | } |
643 | } |
… | |
… | |
795 | strcat (buf, small_buf); |
800 | strcat (buf, small_buf); |
796 | } |
801 | } |
797 | |
802 | |
798 | if (RP->random_seed) |
803 | if (RP->random_seed) |
799 | { |
804 | { |
800 | sprintf (small_buf, "random_seed %d\n", RP->random_seed); |
805 | sprintf (small_buf, "random_seed %u\n", RP->random_seed); |
801 | strcat (buf, small_buf); |
806 | strcat (buf, small_buf); |
802 | } |
807 | } |
803 | |
808 | |
804 | if (RP->custom) |
809 | if (RP->custom) |
805 | { |
810 | { |
… | |
… | |
810 | |
815 | |
811 | void |
816 | void |
812 | write_parameters_to_string (char *buf, |
817 | write_parameters_to_string (char *buf, |
813 | int xsize_n, |
818 | int xsize_n, |
814 | int ysize_n, |
819 | int ysize_n, |
815 | char *wallstyle_n, |
820 | const char *wallstyle_n, |
816 | char *floorstyle_n, |
821 | const char *floorstyle_n, |
817 | char *monsterstyle_n, |
822 | const char *monsterstyle_n, |
818 | char *treasurestyle_n, |
823 | const char *treasurestyle_n, |
819 | char *layoutstyle_n, |
824 | const char *layoutstyle_n, |
820 | char *decorstyle_n, |
825 | const char *decorstyle_n, |
821 | char *doorstyle_n, |
826 | const char *doorstyle_n, |
822 | char *exitstyle_n, |
827 | const char *exitstyle_n, |
823 | char *final_map_n, |
828 | const char *final_map_n, |
824 | char *exit_on_final_map_n, |
829 | const char *exit_on_final_map_n, |
825 | char *this_map_n, |
830 | const char *this_map_n, |
826 | int layoutoptions1_n, |
831 | int layoutoptions1_n, |
827 | int layoutoptions2_n, |
832 | int layoutoptions2_n, |
828 | int layoutoptions3_n, |
833 | int layoutoptions3_n, |
829 | int symmetry_n, |
834 | int symmetry_n, |
830 | int dungeon_depth_n, |
835 | int dungeon_depth_n, |
831 | int dungeon_level_n, |
836 | int dungeon_level_n, |
832 | int difficulty_n, |
837 | int difficulty_n, |
833 | int difficulty_given_n, |
838 | int difficulty_given_n, |
834 | int decoroptions_n, |
839 | int decoroptions_n, |
835 | int orientation_n, |
840 | int orientation_n, |
836 | int origin_x_n, int origin_y_n, int random_seed_n, int treasureoptions_n, float difficulty_increase) |
841 | int origin_x_n, |
|
|
842 | int origin_y_n, |
|
|
843 | uint32_t random_seed_n, |
|
|
844 | int treasureoptions_n, |
|
|
845 | float difficulty_increase) |
837 | { |
846 | { |
838 | char small_buf[16384]; |
847 | char small_buf[16384]; |
839 | |
848 | |
840 | sprintf (buf, "xsize %d\nysize %d\n", xsize_n, ysize_n); |
849 | sprintf (buf, "xsize %d\nysize %d\n", xsize_n, ysize_n); |
841 | |
850 | |
… | |
… | |
977 | } |
986 | } |
978 | |
987 | |
979 | if (random_seed_n) |
988 | if (random_seed_n) |
980 | { |
989 | { |
981 | /* Add one so that the next map is a bit different */ |
990 | /* Add one so that the next map is a bit different */ |
982 | sprintf (small_buf, "random_seed %d\n", random_seed_n + 1); |
991 | sprintf (small_buf, "random_seed %u\n", random_seed_n + 1); |
983 | strcat (buf, small_buf); |
992 | strcat (buf, small_buf); |
984 | } |
993 | } |
985 | |
994 | |
986 | if (treasureoptions_n) |
995 | if (treasureoptions_n) |
987 | { |
996 | { |