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.18 by root, Thu Jan 11 00:41:08 2007 UTC vs.
Revision 1.22 by root, Fri Jan 19 15:29:52 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game for X-windows
3 3 *
4 Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
5 Copyright (C) 2001 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2001 Mark Wedel & Crossfire Development Team
6 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
7 7 *
8 This program is free software; you can redistribute it and/or modify 8 * This program 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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 21 *
22 The authors can be reached via e-mail at <crossfire@schmorp.de> 22 * The authors can be reached via e-mail at <crossfire@schmorp.de>
23*/ 23 */
24 24
25#include <time.h> 25#include <time.h>
26#include <stdio.h> 26#include <stdio.h>
27#include <global.h> 27#include <global.h>
28#include <maze_gen.h> 28#include <maze_gen.h>
29#include <room_gen.h> 29#include <room_gen.h>
30#include <random_map.h> 30#include <random_map.h>
31#include <rproto.h> 31#include <rproto.h>
32#include <sproto.h> 32#include <sproto.h>
33
34#define CEDE coroapi::cede (); rndm.seed (RP->random_seed + __LINE__);
33 35
34void 36void
35dump_layout (char **layout, random_map_params *RP) 37dump_layout (char **layout, random_map_params *RP)
36{ 38{
37 { 39 {
51 } 53 }
52 } 54 }
53 printf ("\n"); 55 printf ("\n");
54} 56}
55 57
56maptile * 58bool
57generate_random_map (const char *OutFileName, random_map_params *RP) 59maptile::generate_random_map (random_map_params *RP)
58{ 60{
59 char **layout, buf[16384]; 61 char **layout, buf[16384];
60 maptile *theMap;
61 int i; 62 int i;
62 63
63 /* 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 */
64 SRANDOM (RP->random_seed ? RP->random_seed + RP->dungeon_level : time (0)); 65 RP->random_seed = RP->random_seed
66 ? RP->random_seed + RP->dungeon_level
67 : time (0);
68 CEDE;
65 69
66 write_map_parameters_to_string (buf, RP); 70 write_map_parameters_to_string (buf, RP);
67 71
68 if (RP->difficulty == 0) 72 if (RP->difficulty == 0)
69 { 73 {
77 } 81 }
78 else 82 else
79 RP->difficulty_given = 1; 83 RP->difficulty_given = 1;
80 84
81 if (RP->Xsize < MIN_RANDOM_MAP_SIZE) 85 if (RP->Xsize < MIN_RANDOM_MAP_SIZE)
82 RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5; 86 RP->Xsize = MIN_RANDOM_MAP_SIZE + rndm (25) + 5;
83 87
84 if (RP->Ysize < MIN_RANDOM_MAP_SIZE) 88 if (RP->Ysize < MIN_RANDOM_MAP_SIZE)
85 RP->Ysize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5; 89 RP->Ysize = MIN_RANDOM_MAP_SIZE + rndm (25) + 5;
86
87 if (RP->expand2x > 0)
88 {
89 RP->Xsize /= 2;
90 RP->Ysize /= 2;
91 }
92
93 layout = layoutgen (RP);
94
95#ifdef RMAP_DEBUG
96 dump_layout (layout, RP);
97#endif
98
99 /* increment these for the current map */
100 RP->dungeon_level += 1;
101 /* allow constant-difficulty maps. */
102 /* difficulty+=1; */
103
104 /* rotate the layout randomly */
105 layout = rotate_layout (layout, RANDOM () % 4, RP);
106#ifdef RMAP_DEBUG
107 dump_layout (layout, RP);
108#endif
109
110 /* allocate the map and set the floor */
111 theMap = make_map_floor (layout, RP->floorstyle, RP);
112
113 /* set the name of the map. */
114 theMap->path = OutFileName;
115
116 /* set region */
117 theMap->region = RP->region;
118
119 coroapi::cede ();
120 /* create walls unless the wallstyle is "none" */
121 if (strcmp (RP->wallstyle, "none"))
122 {
123 make_map_walls (theMap, layout, RP->wallstyle, RP);
124
125 /* place doors unless doorstyle or wallstyle is "none" */
126 if (strcmp (RP->doorstyle, "none"))
127 put_doors (theMap, layout, RP->doorstyle, RP);
128
129 }
130
131 coroapi::cede ();
132 /* create exits unless the exitstyle is "none" */
133 if (strcmp (RP->exitstyle, "none"))
134 place_exits (theMap, layout, RP->exitstyle, RP->orientation, RP);
135
136 coroapi::cede ();
137 place_specials_in_map (theMap, layout, RP);
138
139 coroapi::cede ();
140 /* create monsters unless the monsterstyle is "none" */
141 if (strcmp (RP->monsterstyle, "none"))
142 place_monsters (theMap, RP->monsterstyle, RP->difficulty, RP);
143
144 coroapi::cede ();
145 /* treasures needs to have a proper difficulty set for the map. */
146 theMap->difficulty = theMap->estimate_difficulty ();
147
148 coroapi::cede ();
149 /* create treasure unless the treasurestyle is "none" */
150 if (strcmp (RP->treasurestyle, "none"))
151 place_treasure (theMap, layout, RP->treasurestyle, RP->treasureoptions, RP);
152
153 coroapi::cede ();
154 /* create decor unless the decorstyle is "none" */
155 if (strcmp (RP->decorstyle, "none"))
156 put_decor (theMap, layout, RP->decorstyle, RP->decoroptions, RP);
157
158 coroapi::cede ();
159 /* generate treasures, etc. */
160 theMap->fix_auto_apply ();
161
162 coroapi::cede ();
163 unblock_exits (theMap, layout, RP);
164
165 /* free the layout */
166 for (i = 0; i < RP->Xsize; i++)
167 free (layout[i]);
168
169 free (layout);
170
171 theMap->msg = strdup (buf);
172 theMap->in_memory = MAP_IN_MEMORY;
173
174 return theMap;
175}
176
177/* function selects the layout function and gives it whatever
178 arguments it needs. */
179char **
180layoutgen (random_map_params *RP)
181{
182 char **maze = 0;
183 int oxsize = RP->Xsize, oysize = RP->Ysize;
184 90
185 if (RP->symmetry == SYMMETRY_RANDOM) 91 if (RP->symmetry == SYMMETRY_RANDOM)
186 RP->symmetry_used = (RANDOM () % (SYMMETRY_XY)) + 1; 92 RP->symmetry_used = (RANDOM () % (SYMMETRY_XY)) + 1;
187 else 93 else
188 RP->symmetry_used = RP->symmetry; 94 RP->symmetry_used = RP->symmetry;
190 if (RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY) 96 if (RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY)
191 RP->Ysize = RP->Ysize / 2 + 1; 97 RP->Ysize = RP->Ysize / 2 + 1;
192 if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY) 98 if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY)
193 RP->Xsize = RP->Xsize / 2 + 1; 99 RP->Xsize = RP->Xsize / 2 + 1;
194 100
195 if (RP->Xsize < MIN_RANDOM_MAP_SIZE) 101 if (RP->expand2x > 0)
196 RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 5; 102 {
197 if (RP->Ysize < MIN_RANDOM_MAP_SIZE) 103 RP->Xsize /= 2;
198 RP->Ysize = MIN_RANDOM_MAP_SIZE + RANDOM () % 5; 104 RP->Ysize /= 2;
105 }
106
199 RP->map_layout_style = 0; 107 RP->map_layout_style = LAYOUT_NONE;
200 108
201 /* Redo this - there was a lot of redundant code of checking for preset 109 /* Redo this - there was a lot of redundant code of checking for preset
202 * layout style and then random layout style. Instead, figure out 110 * layout style and then random layout style. Instead, figure out
203 * the numeric layoutstyle, so there is only one area that actually 111 * the numeric layoutstyle, so there is only one area that actually
204 * calls the code to make the maps. 112 * calls the code to make the maps.
219 RP->map_layout_style = LAYOUT_SNAKE; 127 RP->map_layout_style = LAYOUT_SNAKE;
220 128
221 if (strstr (RP->layoutstyle, "squarespiral")) 129 if (strstr (RP->layoutstyle, "squarespiral"))
222 RP->map_layout_style = LAYOUT_SQUARE_SPIRAL; 130 RP->map_layout_style = LAYOUT_SQUARE_SPIRAL;
223 131
224 /* No style found - choose one ranomdly */ 132 /* No style found - choose one randomly */
225 if (RP->map_layout_style == LAYOUT_NONE) 133 if (RP->map_layout_style == LAYOUT_NONE)
226 RP->map_layout_style = (RANDOM () % (NROFLAYOUTS - 1)) + 1; 134 RP->map_layout_style = (RANDOM () % (NROFLAYOUTS - 1)) + 1;
227 135
136 layout = layoutgen (RP);
137
138#ifdef RMAP_DEBUG
139 dump_layout (layout, RP);
140#endif
141
142 /* increment these for the current map */
143 RP->dungeon_level += 1;
144 /* allow constant-difficulty maps. */
145 /* difficulty+=1; */
146
147 /* rotate the layout randomly */
148 layout = rotate_layout (layout, rndm (4), RP);
149#ifdef RMAP_DEBUG
150 dump_layout (layout, RP);
151#endif
152
153 /* allocate the map and set the floor */
154 make_map_floor (layout, RP->floorstyle, RP);
155
156 /* set region */
157 region = RP->region;
158
159 CEDE;
160
161 /* create walls unless the wallstyle is "none" */
162 if (strcmp (RP->wallstyle, "none"))
163 {
164 make_map_walls (this, layout, RP->wallstyle, RP);
165
166 /* place doors unless doorstyle or wallstyle is "none" */
167 if (strcmp (RP->doorstyle, "none"))
168 put_doors (this, layout, RP->doorstyle, RP);
169
170 }
171
172 CEDE;
173
174 /* create exits unless the exitstyle is "none" */
175 if (strcmp (RP->exitstyle, "none"))
176 place_exits (this, layout, RP->exitstyle, RP->orientation, RP);
177
178 CEDE;
179
180 place_specials_in_map (this, layout, RP);
181
182 CEDE;
183
184 /* create monsters unless the monsterstyle is "none" */
185 if (strcmp (RP->monsterstyle, "none"))
186 place_monsters (this, RP->monsterstyle, RP->difficulty, RP);
187
188 CEDE;
189
190 /* treasures needs to have a proper difficulty set for the map. */
191 difficulty = estimate_difficulty ();
192
193 CEDE;
194
195 /* create treasure unless the treasurestyle is "none" */
196 if (strcmp (RP->treasurestyle, "none"))
197 place_treasure (this, layout, RP->treasurestyle, RP->treasureoptions, RP);
198
199 CEDE;
200
201 /* create decor unless the decorstyle is "none" */
202 if (strcmp (RP->decorstyle, "none"))
203 put_decor (this, layout, RP->decorstyle, RP->decoroptions, RP);
204
205 CEDE;
206
207 /* generate treasures, etc. */
208 fix_auto_apply ();
209
210 CEDE;
211
212 unblock_exits (this, layout, RP);
213
214 /* free the layout */
215 for (i = 0; i < RP->Xsize; i++)
216 free (layout[i]);
217
218 free (layout);
219
220 msg = strdup (buf);
221 in_memory = MAP_IN_MEMORY;
222
223 CEDE;
224
225 return 1;
226}
227
228/* function selects the layout function and gives it whatever
229 arguments it needs. */
230char **
231layoutgen (random_map_params *RP)
232{
233 char **maze = 0;
234 int oxsize = RP->Xsize, oysize = RP->Ysize;
235
228 switch (RP->map_layout_style) 236 switch (RP->map_layout_style)
229 { 237 {
230 case LAYOUT_ONION: 238 case LAYOUT_ONION:
231 maze = map_gen_onion (RP->Xsize, RP->Ysize, RP->layoutoptions1, RP->layoutoptions2); 239 maze = map_gen_onion (RP->Xsize, RP->Ysize, RP->layoutoptions1, RP->layoutoptions2);
232 if (!(RANDOM () % 3) && !(RP->layoutoptions1 & RMOPT_WALLS_ONLY)) 240 if (!(rndm (3)) && !(RP->layoutoptions1 & RMOPT_WALLS_ONLY))
233 roomify_layout (maze, RP); 241 roomify_layout (maze, RP);
234 break; 242 break;
235 243
236 case LAYOUT_MAZE: 244 case LAYOUT_MAZE:
237 maze = maze_gen (RP->Xsize, RP->Ysize, RANDOM () % 2); 245 maze = maze_gen (RP->Xsize, RP->Ysize, rndm (2));
238 if (!(RANDOM () % 2)) 246 if (!(rndm (2)))
239 doorify_layout (maze, RP); 247 doorify_layout (maze, RP);
240 break; 248 break;
241 249
242 case LAYOUT_SPIRAL: 250 case LAYOUT_SPIRAL:
243 maze = map_gen_spiral (RP->Xsize, RP->Ysize, RP->layoutoptions1); 251 maze = map_gen_spiral (RP->Xsize, RP->Ysize, RP->layoutoptions1);
244 if (!(RANDOM () % 2)) 252 if (!(rndm (2)))
245 doorify_layout (maze, RP); 253 doorify_layout (maze, RP);
246 break; 254 break;
247 255
248 case LAYOUT_ROGUELIKE: 256 case LAYOUT_ROGUELIKE:
249 /* Don't put symmetry in rogue maps. There isn't much reason to 257 /* Don't put symmetry in rogue maps. There isn't much reason to
260 /* no doorifying... done already */ 268 /* no doorifying... done already */
261 break; 269 break;
262 270
263 case LAYOUT_SNAKE: 271 case LAYOUT_SNAKE:
264 maze = make_snake_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); 272 maze = make_snake_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1);
265 if (RANDOM () % 2) 273 if (rndm (2))
266 roomify_layout (maze, RP); 274 roomify_layout (maze, RP);
267 break; 275 break;
268 276
269 case LAYOUT_SQUARE_SPIRAL: 277 case LAYOUT_SQUARE_SPIRAL:
270 maze = make_square_spiral_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); 278 maze = make_square_spiral_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1);
271 if (RANDOM () % 2) 279 if (rndm (2))
272 roomify_layout (maze, RP); 280 roomify_layout (maze, RP);
273 break; 281 break;
274 } 282 }
275 283
276 maze = symmetrize_layout (maze, RP->symmetry_used, RP); 284 maze = symmetrize_layout (maze, RP->symmetry_used, RP);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines