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.3 by root, Sun Sep 10 16:06:37 2006 UTC vs.
Revision 1.12 by root, Sun Dec 31 17:17:23 2006 UTC

1
2/*
3 * static char *rcsid_random_map_c =
4 * "$Id: random_map.C,v 1.3 2006/09/10 16:06:37 root Exp $";
5 */
6
7/* 1/*
8 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
9 3
10 Copyright (C) 2001 Mark Wedel & Crossfire Development Team 4 Copyright (C) 2001 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen 5 Copyright (C) 1992 Frank Tore Johansen
22 16
23 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 20
27 The authors can be reached via e-mail at crossfire-devel@real-time.com 21 The authors can be reached via e-mail at <crossfire@schmorp.de>
28*/ 22*/
29 23
30#include <time.h> 24#include <time.h>
31#include <stdio.h> 25#include <stdio.h>
32#include <global.h> 26#include <global.h>
35#include <random_map.h> 29#include <random_map.h>
36#include <rproto.h> 30#include <rproto.h>
37#include <sproto.h> 31#include <sproto.h>
38 32
39void 33void
40dump_layout (char **layout, RMParms * RP) 34dump_layout (char **layout, random_map_params * RP)
41{ 35{
42 { 36 {
43 int i, j; 37 int i, j;
44 38
45 for (i = 0; i < RP->Xsize; i++) 39 for (i = 0; i < RP->Xsize; i++)
55 printf ("\n"); 49 printf ("\n");
56 } 50 }
57 } 51 }
58 printf ("\n"); 52 printf ("\n");
59} 53}
60EXTERN FILE *logfile; 54
61mapstruct * 55extern FILE *logfile;
56
57maptile *
62generate_random_map (const char *OutFileName, RMParms * RP) 58generate_random_map (const char *OutFileName, random_map_params * RP)
63{ 59{
64 char **layout, buf[HUGE_BUF]; 60 char **layout, buf[HUGE_BUF];
65 mapstruct *theMap; 61 maptile *theMap;
66 int i; 62 int i;
67 63
68 /* 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 */
69 if (RP->random_seed == 0) 65 if (RP->random_seed == 0)
70 RP->random_seed = time (0); 66 RP->random_seed = time (0);
74 write_map_parameters_to_string (buf, RP); 70 write_map_parameters_to_string (buf, RP);
75 71
76 if (RP->difficulty == 0) 72 if (RP->difficulty == 0)
77 { 73 {
78 RP->difficulty = RP->dungeon_level; /* use this instead of a map difficulty */ 74 RP->difficulty = RP->dungeon_level; /* use this instead of a map difficulty */
75
79 if (RP->difficulty_increase > 0.001) 76 if (RP->difficulty_increase > 0.001)
80 {
81 RP->difficulty = (int) ((float) RP->dungeon_level * RP->difficulty_increase); 77 RP->difficulty = (int) ((float) RP->dungeon_level * RP->difficulty_increase);
78
82 if (RP->difficulty < 1) 79 if (RP->difficulty < 1)
83 RP->difficulty = 1; 80 RP->difficulty = 1;
84 }
85 } 81 }
86 else 82 else
87 RP->difficulty_given = 1; 83 RP->difficulty_given = 1;
88 84
89 if (RP->Xsize < MIN_RANDOM_MAP_SIZE) 85 if (RP->Xsize < MIN_RANDOM_MAP_SIZE)
90 RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5; 86 RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5;
87
91 if (RP->Ysize < MIN_RANDOM_MAP_SIZE) 88 if (RP->Ysize < MIN_RANDOM_MAP_SIZE)
92 RP->Ysize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5; 89 RP->Ysize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5;
93 90
94 if (RP->expand2x > 0) 91 if (RP->expand2x > 0)
95 { 92 {
116 113
117 /* allocate the map and set the floor */ 114 /* allocate the map and set the floor */
118 theMap = make_map_floor (layout, RP->floorstyle, RP); 115 theMap = make_map_floor (layout, RP->floorstyle, RP);
119 116
120 /* set the name of the map. */ 117 /* set the name of the map. */
121 strcpy (theMap->path, OutFileName); 118 theMap->path = OutFileName;
122 119
123 /* set region */ 120 /* set region */
124 theMap->region = RP->region; 121 theMap->region = RP->region;
125 122
126 /* create walls unless the wallstyle is "none" */ 123 /* create walls unless the wallstyle is "none" */
143 /* create monsters unless the monsterstyle is "none" */ 140 /* create monsters unless the monsterstyle is "none" */
144 if (strcmp (RP->monsterstyle, "none")) 141 if (strcmp (RP->monsterstyle, "none"))
145 place_monsters (theMap, RP->monsterstyle, RP->difficulty, RP); 142 place_monsters (theMap, RP->monsterstyle, RP->difficulty, RP);
146 143
147 /* treasures needs to have a proper difficulty set for the map. */ 144 /* treasures needs to have a proper difficulty set for the map. */
148 theMap->difficulty = calculate_difficulty (theMap); 145 theMap->difficulty = theMap->estimate_difficulty ();
149 146
150 /* create treasure unless the treasurestyle is "none" */ 147 /* create treasure unless the treasurestyle is "none" */
151 if (strcmp (RP->treasurestyle, "none")) 148 if (strcmp (RP->treasurestyle, "none"))
152 place_treasure (theMap, layout, RP->treasurestyle, RP->treasureoptions, RP); 149 place_treasure (theMap, layout, RP->treasurestyle, RP->treasureoptions, RP);
153 150
154 /* create decor unless the decorstyle is "none" */ 151 /* create decor unless the decorstyle is "none" */
155 if (strcmp (RP->decorstyle, "none")) 152 if (strcmp (RP->decorstyle, "none"))
156 put_decor (theMap, layout, RP->decorstyle, RP->decoroptions, RP); 153 put_decor (theMap, layout, RP->decorstyle, RP->decoroptions, RP);
157 154
158 /* generate treasures, etc. */ 155 /* generate treasures, etc. */
159 fix_auto_apply (theMap); 156 theMap->fix_auto_apply ();
160 157
161 unblock_exits (theMap, layout, RP); 158 unblock_exits (theMap, layout, RP);
162 159
163 /* free the layout */ 160 /* free the layout */
164 for (i = 0; i < RP->Xsize; i++) 161 for (i = 0; i < RP->Xsize; i++)
165 free (layout[i]); 162 free (layout[i]);
163
166 free (layout); 164 free (layout);
167 165
168 theMap->msg = strdup_local (buf); 166 theMap->msg = strdup (buf);
167 theMap->in_memory = MAP_IN_MEMORY;
169 168
170 return theMap; 169 return theMap;
171} 170}
172
173 171
174/* function selects the layout function and gives it whatever 172/* function selects the layout function and gives it whatever
175 arguments it needs. */ 173 arguments it needs. */
176char ** 174char **
177layoutgen (RMParms * RP) 175layoutgen (random_map_params * RP)
178{ 176{
179 char **maze = 0; 177 char **maze = 0;
180 int oxsize = RP->Xsize, oysize = RP->Ysize; 178 int oxsize = RP->Xsize, oysize = RP->Ysize;
181 179
182 if (RP->symmetry == RANDOM_SYM) 180 if (RP->symmetry == SYMMETRY_RANDOM)
183 RP->symmetry_used = (RANDOM () % (XY_SYM)) + 1; 181 RP->symmetry_used = (RANDOM () % (SYMMETRY_XY)) + 1;
184 else 182 else
185 RP->symmetry_used = RP->symmetry; 183 RP->symmetry_used = RP->symmetry;
186 184
187 if (RP->symmetry_used == Y_SYM || RP->symmetry_used == XY_SYM) 185 if (RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY)
188 RP->Ysize = RP->Ysize / 2 + 1; 186 RP->Ysize = RP->Ysize / 2 + 1;
189 if (RP->symmetry_used == X_SYM || RP->symmetry_used == XY_SYM) 187 if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY)
190 RP->Xsize = RP->Xsize / 2 + 1; 188 RP->Xsize = RP->Xsize / 2 + 1;
191 189
192 if (RP->Xsize < MIN_RANDOM_MAP_SIZE) 190 if (RP->Xsize < MIN_RANDOM_MAP_SIZE)
193 RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 5; 191 RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 5;
194 if (RP->Ysize < MIN_RANDOM_MAP_SIZE) 192 if (RP->Ysize < MIN_RANDOM_MAP_SIZE)
199 * layout style and then random layout style. Instead, figure out 197 * layout style and then random layout style. Instead, figure out
200 * the numeric layoutstyle, so there is only one area that actually 198 * the numeric layoutstyle, so there is only one area that actually
201 * calls the code to make the maps. 199 * calls the code to make the maps.
202 */ 200 */
203 if (strstr (RP->layoutstyle, "onion")) 201 if (strstr (RP->layoutstyle, "onion"))
204 {
205 RP->map_layout_style = ONION_LAYOUT; 202 RP->map_layout_style = LAYOUT_ONION;
206 }
207 203
208 if (strstr (RP->layoutstyle, "maze")) 204 if (strstr (RP->layoutstyle, "maze"))
209 {
210 RP->map_layout_style = MAZE_LAYOUT; 205 RP->map_layout_style = LAYOUT_MAZE;
211 }
212 206
213 if (strstr (RP->layoutstyle, "spiral")) 207 if (strstr (RP->layoutstyle, "spiral"))
214 {
215 RP->map_layout_style = SPIRAL_LAYOUT; 208 RP->map_layout_style = LAYOUT_SPIRAL;
216 }
217 209
218 if (strstr (RP->layoutstyle, "rogue")) 210 if (strstr (RP->layoutstyle, "rogue"))
219 {
220 RP->map_layout_style = ROGUELIKE_LAYOUT; 211 RP->map_layout_style = LAYOUT_ROGUELIKE;
221 }
222 212
223 if (strstr (RP->layoutstyle, "snake")) 213 if (strstr (RP->layoutstyle, "snake"))
224 {
225 RP->map_layout_style = SNAKE_LAYOUT; 214 RP->map_layout_style = LAYOUT_SNAKE;
226 }
227 215
228 if (strstr (RP->layoutstyle, "squarespiral")) 216 if (strstr (RP->layoutstyle, "squarespiral"))
229 {
230 RP->map_layout_style = SQUARE_SPIRAL_LAYOUT; 217 RP->map_layout_style = LAYOUT_SQUARE_SPIRAL;
231 } 218
232 /* No style found - choose one ranomdly */ 219 /* No style found - choose one ranomdly */
233 if (RP->map_layout_style == 0) 220 if (RP->map_layout_style == LAYOUT_NONE)
234 {
235 RP->map_layout_style = (RANDOM () % NROFLAYOUTS) + 1; 221 RP->map_layout_style = (RANDOM () % (NROFLAYOUTS - 1)) + 1;
236 }
237 222
238 switch (RP->map_layout_style) 223 switch (RP->map_layout_style)
239 { 224 {
240 225 case LAYOUT_ONION:
241 case ONION_LAYOUT:
242 maze = map_gen_onion (RP->Xsize, RP->Ysize, RP->layoutoptions1, RP->layoutoptions2); 226 maze = map_gen_onion (RP->Xsize, RP->Ysize, RP->layoutoptions1, RP->layoutoptions2);
243 if (!(RANDOM () % 3) && !(RP->layoutoptions1 & OPT_WALLS_ONLY)) 227 if (!(RANDOM () % 3) && !(RP->layoutoptions1 & RMOPT_WALLS_ONLY))
244 roomify_layout (maze, RP); 228 roomify_layout (maze, RP);
245 break; 229 break;
246 230
247 case MAZE_LAYOUT: 231 case LAYOUT_MAZE:
248 maze = maze_gen (RP->Xsize, RP->Ysize, RANDOM () % 2); 232 maze = maze_gen (RP->Xsize, RP->Ysize, RANDOM () % 2);
249 if (!(RANDOM () % 2)) 233 if (!(RANDOM () % 2))
250 doorify_layout (maze, RP); 234 doorify_layout (maze, RP);
251 break; 235 break;
252 236
253 case SPIRAL_LAYOUT: 237 case LAYOUT_SPIRAL:
254 maze = map_gen_spiral (RP->Xsize, RP->Ysize, RP->layoutoptions1); 238 maze = map_gen_spiral (RP->Xsize, RP->Ysize, RP->layoutoptions1);
255 if (!(RANDOM () % 2)) 239 if (!(RANDOM () % 2))
256 doorify_layout (maze, RP); 240 doorify_layout (maze, RP);
257 break; 241 break;
258 242
259 case ROGUELIKE_LAYOUT: 243 case LAYOUT_ROGUELIKE:
260 /* Don't put symmetry in rogue maps. There isn't much reason to 244 /* Don't put symmetry in rogue maps. There isn't much reason to
261 * do so in the first place (doesn't make it any more interesting), 245 * do so in the first place (doesn't make it any more interesting),
262 * but more importantly, the symmetry code presumes we are symmetrizing 246 * but more importantly, the symmetry code presumes we are symmetrizing
263 * spirals, or maps with lots of passages - making a symmetric rogue 247 * spirals, or maps with lots of passages - making a symmetric rogue
264 * map fails because its likely that the passages the symmetry process 248 * map fails because its likely that the passages the symmetry process
265 * creates may not connect the rooms. 249 * creates may not connect the rooms.
266 */ 250 */
267 RP->symmetry_used = NO_SYM; 251 RP->symmetry_used = SYMMETRY_NONE;
268 RP->Ysize = oysize; 252 RP->Ysize = oysize;
269 RP->Xsize = oxsize; 253 RP->Xsize = oxsize;
270 maze = roguelike_layout_gen (RP->Xsize, RP->Ysize, RP->layoutoptions1); 254 maze = roguelike_layout_gen (RP->Xsize, RP->Ysize, RP->layoutoptions1);
271 /* no doorifying... done already */ 255 /* no doorifying... done already */
272 break; 256 break;
273 257
274 case SNAKE_LAYOUT: 258 case LAYOUT_SNAKE:
275 maze = make_snake_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); 259 maze = make_snake_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1);
276 if (RANDOM () % 2) 260 if (RANDOM () % 2)
277 roomify_layout (maze, RP); 261 roomify_layout (maze, RP);
278 break; 262 break;
279 263
280 case SQUARE_SPIRAL_LAYOUT: 264 case LAYOUT_SQUARE_SPIRAL:
281 maze = make_square_spiral_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); 265 maze = make_square_spiral_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1);
282 if (RANDOM () % 2) 266 if (RANDOM () % 2)
283 roomify_layout (maze, RP); 267 roomify_layout (maze, RP);
284 break; 268 break;
285 } 269 }
286 270
287 maze = symmetrize_layout (maze, RP->symmetry_used, RP); 271 maze = symmetrize_layout (maze, RP->symmetry_used, RP);
272
288#ifdef RMAP_DEBUG 273#ifdef RMAP_DEBUG
289 dump_layout (maze, RP); 274 dump_layout (maze, RP);
290#endif 275#endif
276
291 if (RP->expand2x) 277 if (RP->expand2x)
292 { 278 {
293 maze = expand2x (maze, RP->Xsize, RP->Ysize); 279 maze = expand2x (maze, RP->Xsize, RP->Ysize);
294 RP->Xsize = RP->Xsize * 2 - 1; 280 RP->Xsize = RP->Xsize * 2 - 1;
295 RP->Ysize = RP->Ysize * 2 - 1; 281 RP->Ysize = RP->Ysize * 2 - 1;
296 } 282 }
283
297 return maze; 284 return maze;
298} 285}
299
300 286
301/* takes a map and makes it symmetric: adjusts Xsize and 287/* takes a map and makes it symmetric: adjusts Xsize and
302Ysize to produce a symmetric map. */ 288Ysize to produce a symmetric map. */
303
304char ** 289char **
305symmetrize_layout (char **maze, int sym, RMParms * RP) 290symmetrize_layout (char **maze, int sym, random_map_params * RP)
306{ 291{
307 int i, j; 292 int i, j;
308 char **sym_maze; 293 char **sym_maze;
309 int Xsize_orig, Ysize_orig; 294 int Xsize_orig, Ysize_orig;
310 295
311 Xsize_orig = RP->Xsize; 296 Xsize_orig = RP->Xsize;
312 Ysize_orig = RP->Ysize; 297 Ysize_orig = RP->Ysize;
313 RP->symmetry_used = sym; /* tell everyone else what sort of symmetry is used. */ 298 RP->symmetry_used = sym; /* tell everyone else what sort of symmetry is used. */
314 if (sym == NO_SYM) 299 if (sym == SYMMETRY_NONE)
315 { 300 {
316 RP->Xsize = Xsize_orig; 301 RP->Xsize = Xsize_orig;
317 RP->Ysize = Ysize_orig; 302 RP->Ysize = Ysize_orig;
318 return maze; 303 return maze;
319 } 304 }
320 /* pick new sizes */ 305 /* pick new sizes */
321 RP->Xsize = ((sym == X_SYM || sym == XY_SYM) ? RP->Xsize * 2 - 3 : RP->Xsize); 306 RP->Xsize = ((sym == SYMMETRY_X || sym == SYMMETRY_XY) ? RP->Xsize * 2 - 3 : RP->Xsize);
322 RP->Ysize = ((sym == Y_SYM || sym == XY_SYM) ? RP->Ysize * 2 - 3 : RP->Ysize); 307 RP->Ysize = ((sym == SYMMETRY_Y || sym == SYMMETRY_XY) ? RP->Ysize * 2 - 3 : RP->Ysize);
323 308
324 sym_maze = (char **) calloc (sizeof (char *), RP->Xsize); 309 sym_maze = (char **) calloc (sizeof (char *), RP->Xsize);
325 for (i = 0; i < RP->Xsize; i++) 310 for (i = 0; i < RP->Xsize; i++)
326 sym_maze[i] = (char *) calloc (sizeof (char), RP->Ysize); 311 sym_maze[i] = (char *) calloc (sizeof (char), RP->Ysize);
327 312
328 if (sym == X_SYM) 313 if (sym == SYMMETRY_X)
329 for (i = 0; i < RP->Xsize / 2 + 1; i++) 314 for (i = 0; i < RP->Xsize / 2 + 1; i++)
330 for (j = 0; j < RP->Ysize; j++) 315 for (j = 0; j < RP->Ysize; j++)
331 { 316 {
332 sym_maze[i][j] = maze[i][j]; 317 sym_maze[i][j] = maze[i][j];
333 sym_maze[RP->Xsize - i - 1][j] = maze[i][j]; 318 sym_maze[RP->Xsize - i - 1][j] = maze[i][j];
334 }; 319 };
335 if (sym == Y_SYM) 320 if (sym == SYMMETRY_Y)
336 for (i = 0; i < RP->Xsize; i++) 321 for (i = 0; i < RP->Xsize; i++)
337 for (j = 0; j < RP->Ysize / 2 + 1; j++) 322 for (j = 0; j < RP->Ysize / 2 + 1; j++)
338 { 323 {
339 sym_maze[i][j] = maze[i][j]; 324 sym_maze[i][j] = maze[i][j];
340 sym_maze[i][RP->Ysize - j - 1] = maze[i][j]; 325 sym_maze[i][RP->Ysize - j - 1] = maze[i][j];
341 } 326 }
342 if (sym == XY_SYM) 327 if (sym == SYMMETRY_XY)
343 for (i = 0; i < RP->Xsize / 2 + 1; i++) 328 for (i = 0; i < RP->Xsize / 2 + 1; i++)
344 for (j = 0; j < RP->Ysize / 2 + 1; j++) 329 for (j = 0; j < RP->Ysize / 2 + 1; j++)
345 { 330 {
346 sym_maze[i][j] = maze[i][j]; 331 sym_maze[i][j] = maze[i][j];
347 sym_maze[i][RP->Ysize - j - 1] = maze[i][j]; 332 sym_maze[i][RP->Ysize - j - 1] = maze[i][j];
351 /* delete the old maze */ 336 /* delete the old maze */
352 for (i = 0; i < Xsize_orig; i++) 337 for (i = 0; i < Xsize_orig; i++)
353 free (maze[i]); 338 free (maze[i]);
354 free (maze); 339 free (maze);
355 /* reconnect disjointed spirals */ 340 /* reconnect disjointed spirals */
356 if (RP->map_layout_style == SPIRAL_LAYOUT) 341 if (RP->map_layout_style == LAYOUT_SPIRAL)
357 connect_spirals (RP->Xsize, RP->Ysize, sym, sym_maze); 342 connect_spirals (RP->Xsize, RP->Ysize, sym, sym_maze);
358 /* reconnect disjointed nethackmazes: the routine for 343 /* reconnect disjointed nethackmazes: the routine for
359 spirals will do the trick? */ 344 spirals will do the trick? */
360 if (RP->map_layout_style == ROGUELIKE_LAYOUT) 345 if (RP->map_layout_style == LAYOUT_ROGUELIKE)
361 connect_spirals (RP->Xsize, RP->Ysize, sym, sym_maze); 346 connect_spirals (RP->Xsize, RP->Ysize, sym, sym_maze);
362 347
363 return sym_maze; 348 return sym_maze;
364} 349}
365 350
368 onion layouts, making them possibly centered on any wall. 353 onion layouts, making them possibly centered on any wall.
369 It'll modify Xsize and Ysize if they're swapped. 354 It'll modify Xsize and Ysize if they're swapped.
370*/ 355*/
371 356
372char ** 357char **
373rotate_layout (char **maze, int rotation, RMParms * RP) 358rotate_layout (char **maze, int rotation, random_map_params * RP)
374{ 359{
375 char **new_maze; 360 char **new_maze;
376 int i, j; 361 int i, j;
377 362
378 switch (rotation) 363 switch (rotation)
379 { 364 {
380 case 0: 365 case 0:
366 return maze;
367 break;
368 case 2: /* a reflection */
369 {
370 char *newmaze = (char *) malloc (sizeof (char) * RP->Xsize * RP->Ysize);
371
372 for (i = 0; i < RP->Xsize; i++)
373 { /* make a copy */
374 for (j = 0; j < RP->Ysize; j++)
375 {
376 newmaze[i * RP->Ysize + j] = maze[i][j];
377 }
378 }
379 for (i = 0; i < RP->Xsize; i++)
380 { /* copy a reflection back */
381 for (j = 0; j < RP->Ysize; j++)
382 {
383 maze[i][j] = newmaze[(RP->Xsize - i - 1) * RP->Ysize + RP->Ysize - j - 1];
384 }
385 }
386 free (newmaze);
381 return maze; 387 return maze;
382 break; 388 break;
383 case 2: /* a reflection */ 389 }
390 case 1:
391 case 3:
392 {
393 int swap;
394 new_maze = (char **) calloc (sizeof (char *), RP->Ysize);
395 for (i = 0; i < RP->Ysize; i++)
384 { 396 {
385 char *newmaze = (char *) malloc (sizeof (char) * RP->Xsize * RP->Ysize); 397 new_maze[i] = (char *) calloc (sizeof (char), RP->Xsize);
386 398 }
399 if (rotation == 1) /* swap x and y */
387 for (i = 0; i < RP->Xsize; i++) 400 for (i = 0; i < RP->Xsize; i++)
388 { /* make a copy */
389 for (j = 0; j < RP->Ysize; j++) 401 for (j = 0; j < RP->Ysize; j++)
390 {
391 newmaze[i * RP->Ysize + j] = maze[i][j]; 402 new_maze[j][i] = maze[i][j];
392 } 403
393 } 404 if (rotation == 3)
394 for (i = 0; i < RP->Xsize; i++) 405 { /* swap x and y */
395 { /* copy a reflection back */
396 for (j = 0; j < RP->Ysize; j++)
397 {
398 maze[i][j] = newmaze[(RP->Xsize - i - 1) * RP->Ysize + RP->Ysize - j - 1];
399 }
400 }
401 free (newmaze);
402 return maze;
403 break;
404 }
405 case 1:
406 case 3:
407 {
408 int swap;
409 new_maze = (char **) calloc (sizeof (char *), RP->Ysize);
410 for (i = 0; i < RP->Ysize; i++)
411 {
412 new_maze[i] = (char *) calloc (sizeof (char), RP->Xsize);
413 }
414 if (rotation == 1) /* swap x and y */
415 for (i = 0; i < RP->Xsize; i++) 406 for (i = 0; i < RP->Xsize; i++)
416 for (j = 0; j < RP->Ysize; j++) 407 for (j = 0; j < RP->Ysize; j++)
417 new_maze[j][i] = maze[i][j];
418
419 if (rotation == 3)
420 { /* swap x and y */
421 for (i = 0; i < RP->Xsize; i++)
422 for (j = 0; j < RP->Ysize; j++)
423 new_maze[j][i] = maze[RP->Xsize - i - 1][RP->Ysize - j - 1]; 408 new_maze[j][i] = maze[RP->Xsize - i - 1][RP->Ysize - j - 1];
424 } 409 }
425 410
426 /* delete the old layout */ 411 /* delete the old layout */
427 for (i = 0; i < RP->Xsize; i++) 412 for (i = 0; i < RP->Xsize; i++)
428 free (maze[i]); 413 free (maze[i]);
429 free (maze); 414 free (maze);
430 415
431 swap = RP->Ysize; 416 swap = RP->Ysize;
432 RP->Ysize = RP->Xsize; 417 RP->Ysize = RP->Xsize;
433 RP->Xsize = swap; 418 RP->Xsize = swap;
434 return new_maze; 419 return new_maze;
435 break; 420 break;
436 } 421 }
437 } 422 }
438 return NULL; 423 return NULL;
439} 424}
440 425
441/* take a layout and make some rooms in it. 426/* take a layout and make some rooms in it.
442 --works best on onions.*/ 427 --works best on onions.*/
443void 428void
444roomify_layout (char **maze, RMParms * RP) 429roomify_layout (char **maze, random_map_params * RP)
445{ 430{
446 int tries = RP->Xsize * RP->Ysize / 30; 431 int tries = RP->Xsize * RP->Ysize / 30;
447 int ti; 432 int ti;
448 433
449 for (ti = 0; ti < tries; ti++) 434 for (ti = 0; ti < tries; ti++)
476/* checks the layout to see if I can stick a horizontal(dir = 0) wall 461/* checks the layout to see if I can stick a horizontal(dir = 0) wall
477 (or vertical, dir == 1) 462 (or vertical, dir == 1)
478 here which ends up on other walls sensibly. */ 463 here which ends up on other walls sensibly. */
479 464
480int 465int
481can_make_wall (char **maze, int dx, int dy, int dir, RMParms * RP) 466can_make_wall (char **maze, int dx, int dy, int dir, random_map_params * RP)
482{ 467{
483 int i1; 468 int i1;
484 int length = 0; 469 int length = 0;
485 470
486 /* dont make walls if we're on the edge. */ 471 /* dont make walls if we're on the edge. */
587 572
588 return 0; 573 return 0;
589} 574}
590 575
591/* puts doors at appropriate locations in a layout. */ 576/* puts doors at appropriate locations in a layout. */
592
593void 577void
594doorify_layout (char **maze, RMParms * RP) 578doorify_layout (char **maze, random_map_params * RP)
595{ 579{
596 int ndoors = RP->Xsize * RP->Ysize / 60; /* reasonable number of doors. */ 580 int ndoors = RP->Xsize * RP->Ysize / 60; /* reasonable number of doors. */
597 char *doorlist_x; 581 char *doorlist_x;
598 char *doorlist_y; 582 char *doorlist_y;
599 int doorlocs = 0; /* # of available doorlocations */ 583 int doorlocs = 0; /* # of available doorlocations */
614 doorlist_x[doorlocs] = i; 598 doorlist_x[doorlocs] = i;
615 doorlist_y[doorlocs] = j; 599 doorlist_y[doorlocs] = j;
616 doorlocs++; 600 doorlocs++;
617 } 601 }
618 } 602 }
603
619 while (ndoors > 0 && doorlocs > 0) 604 while (ndoors > 0 && doorlocs > 0)
620 { 605 {
621 int di; 606 int di;
622 int sindex; 607 int sindex;
623 608
633 /* reduce the size of the list */ 618 /* reduce the size of the list */
634 doorlocs--; 619 doorlocs--;
635 doorlist_x[di] = doorlist_x[doorlocs]; 620 doorlist_x[di] = doorlist_x[doorlocs];
636 doorlist_y[di] = doorlist_y[doorlocs]; 621 doorlist_y[di] = doorlist_y[doorlocs];
637 } 622 }
623
638 free (doorlist_x); 624 free (doorlist_x);
639 free (doorlist_y); 625 free (doorlist_y);
640} 626}
641 627
642
643void 628void
644write_map_parameters_to_string (char *buf, RMParms * RP) 629write_map_parameters_to_string (char *buf, random_map_params * RP)
645{ 630{
646
647 char small_buf[256]; 631 char small_buf[256];
648 632
649 sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize); 633 sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize);
650 634
651 if (RP->wallstyle[0]) 635 if (RP->wallstyle[0])
789 if (RP->origin_y) 773 if (RP->origin_y)
790 { 774 {
791 sprintf (small_buf, "origin_y %d\n", RP->origin_y); 775 sprintf (small_buf, "origin_y %d\n", RP->origin_y);
792 strcat (buf, small_buf); 776 strcat (buf, small_buf);
793 } 777 }
778
794 if (RP->random_seed) 779 if (RP->random_seed)
795 { 780 {
796 /* Add one so that the next map is a bit different */ 781 /* Add one so that the next map is a bit different */
797 sprintf (small_buf, "random_seed %d\n", RP->random_seed + 1); 782 sprintf (small_buf, "random_seed %d\n", RP->random_seed + 1);
798 strcat (buf, small_buf); 783 strcat (buf, small_buf);
801 if (RP->treasureoptions) 786 if (RP->treasureoptions)
802 { 787 {
803 sprintf (small_buf, "treasureoptions %d\n", RP->treasureoptions); 788 sprintf (small_buf, "treasureoptions %d\n", RP->treasureoptions);
804 strcat (buf, small_buf); 789 strcat (buf, small_buf);
805 } 790 }
806
807
808} 791}
809 792
810void 793void
811write_parameters_to_string (char *buf, 794write_parameters_to_string (char *buf,
812 int xsize_n, 795 int xsize_n,
909 { 892 {
910 sprintf (small_buf, "layoutoptions1 %d\n", layoutoptions1_n); 893 sprintf (small_buf, "layoutoptions1 %d\n", layoutoptions1_n);
911 strcat (buf, small_buf); 894 strcat (buf, small_buf);
912 } 895 }
913 896
914
915 if (layoutoptions2_n) 897 if (layoutoptions2_n)
916 { 898 {
917 sprintf (small_buf, "layoutoptions2 %d\n", layoutoptions2_n); 899 sprintf (small_buf, "layoutoptions2 %d\n", layoutoptions2_n);
918 strcat (buf, small_buf); 900 strcat (buf, small_buf);
919 } 901 }
974 if (origin_y_n) 956 if (origin_y_n)
975 { 957 {
976 sprintf (small_buf, "origin_y %d\n", origin_y_n); 958 sprintf (small_buf, "origin_y %d\n", origin_y_n);
977 strcat (buf, small_buf); 959 strcat (buf, small_buf);
978 } 960 }
961
979 if (random_seed_n) 962 if (random_seed_n)
980 { 963 {
981 /* Add one so that the next map is a bit different */ 964 /* Add one so that the next map is a bit different */
982 sprintf (small_buf, "random_seed %d\n", random_seed_n + 1); 965 sprintf (small_buf, "random_seed %d\n", random_seed_n + 1);
983 strcat (buf, small_buf); 966 strcat (buf, small_buf);
996void 979void
997copy_object_with_inv (object *src_ob, object *dest_ob) 980copy_object_with_inv (object *src_ob, object *dest_ob)
998{ 981{
999 object *walk, *tmp; 982 object *walk, *tmp;
1000 983
1001 copy_object (src_ob, dest_ob); 984 src_ob->copy_to (dest_ob);
1002 985
1003 for (walk = src_ob->inv; walk != NULL; walk = walk->below) 986 for (walk = src_ob->inv; walk != NULL; walk = walk->below)
1004 { 987 {
1005 tmp = get_object (); 988 tmp = object::create ();
1006 copy_object (walk, tmp); 989 walk->copy_to (tmp);
1007 insert_ob_in_ob (tmp, dest_ob); 990 insert_ob_in_ob (tmp, dest_ob);
1008 } 991 }
1009} 992}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines