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.5 by root, Sat Sep 16 22:24:13 2006 UTC vs.
Revision 1.21 by root, Thu Jan 18 19:42:10 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) 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
6 7 *
7 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
8 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
9 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 11 * (at your option) any later version.
11 12 *
12 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,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 * GNU General Public License for more details.
16 17 *
17 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
18 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 21 *
21 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>
22*/ 23 */
23 24
24#include <time.h> 25#include <time.h>
25#include <stdio.h> 26#include <stdio.h>
26#include <global.h> 27#include <global.h>
27#include <maze_gen.h> 28#include <maze_gen.h>
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, RMParms * 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++)
49 printf ("\n"); 50 printf ("\n");
50 } 51 }
51 } 52 }
52 printf ("\n"); 53 printf ("\n");
53} 54}
54EXTERN FILE *logfile; 55
55maptile * 56bool
56generate_random_map (const char *OutFileName, RMParms * RP) 57maptile::generate_random_map (random_map_params *RP)
57{ 58{
58 char **layout, buf[HUGE_BUF]; 59 char **layout, buf[16384];
59 maptile *theMap;
60 int i; 60 int i;
61 61
62 /* pick a random seed, or use the one from the input file */ 62 /* pick a random seed, or use the one from the input file */
63 if (RP->random_seed == 0) 63 SRANDOM (RP->random_seed ? RP->random_seed + RP->dungeon_level : time (0));
64 RP->random_seed = time (0);
65
66 SRANDOM (RP->random_seed);
67 64
68 write_map_parameters_to_string (buf, RP); 65 write_map_parameters_to_string (buf, RP);
69 66
70 if (RP->difficulty == 0) 67 if (RP->difficulty == 0)
71 { 68 {
72 RP->difficulty = RP->dungeon_level; /* use this instead of a map difficulty */ 69 RP->difficulty = RP->dungeon_level; /* use this instead of a map difficulty */
70
73 if (RP->difficulty_increase > 0.001) 71 if (RP->difficulty_increase > 0.001)
74 {
75 RP->difficulty = (int) ((float) RP->dungeon_level * RP->difficulty_increase); 72 RP->difficulty = (int) ((float) RP->dungeon_level * RP->difficulty_increase);
73
76 if (RP->difficulty < 1) 74 if (RP->difficulty < 1)
77 RP->difficulty = 1; 75 RP->difficulty = 1;
78 }
79 } 76 }
80 else 77 else
81 RP->difficulty_given = 1; 78 RP->difficulty_given = 1;
82 79
83 if (RP->Xsize < MIN_RANDOM_MAP_SIZE) 80 if (RP->Xsize < MIN_RANDOM_MAP_SIZE)
84 RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5; 81 RP->Xsize = MIN_RANDOM_MAP_SIZE + rndm (25) + 5;
82
85 if (RP->Ysize < MIN_RANDOM_MAP_SIZE) 83 if (RP->Ysize < MIN_RANDOM_MAP_SIZE)
86 RP->Ysize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5; 84 RP->Ysize = MIN_RANDOM_MAP_SIZE + rndm (25) + 5;
87 85
88 if (RP->expand2x > 0) 86 if (RP->expand2x > 0)
89 { 87 {
90 RP->Xsize /= 2; 88 RP->Xsize /= 2;
91 RP->Ysize /= 2; 89 RP->Ysize /= 2;
101 RP->dungeon_level += 1; 99 RP->dungeon_level += 1;
102 /* allow constant-difficulty maps. */ 100 /* allow constant-difficulty maps. */
103 /* difficulty+=1; */ 101 /* difficulty+=1; */
104 102
105 /* rotate the layout randomly */ 103 /* rotate the layout randomly */
106 layout = rotate_layout (layout, RANDOM () % 4, RP); 104 layout = rotate_layout (layout, rndm (4), RP);
107#ifdef RMAP_DEBUG 105#ifdef RMAP_DEBUG
108 dump_layout (layout, RP); 106 dump_layout (layout, RP);
109#endif 107#endif
110 108
111 /* allocate the map and set the floor */ 109 /* allocate the map and set the floor */
112 theMap = make_map_floor (layout, RP->floorstyle, RP); 110 make_map_floor (layout, RP->floorstyle, RP);
113
114 /* set the name of the map. */
115 strcpy (theMap->path, OutFileName);
116 111
117 /* set region */ 112 /* set region */
118 theMap->region = RP->region; 113 region = RP->region;
114
115 coroapi::cede ();
119 116
120 /* create walls unless the wallstyle is "none" */ 117 /* create walls unless the wallstyle is "none" */
121 if (strcmp (RP->wallstyle, "none")) 118 if (strcmp (RP->wallstyle, "none"))
122 { 119 {
123 make_map_walls (theMap, layout, RP->wallstyle, RP); 120 make_map_walls (this, layout, RP->wallstyle, RP);
124 121
125 /* place doors unless doorstyle or wallstyle is "none" */ 122 /* place doors unless doorstyle or wallstyle is "none" */
126 if (strcmp (RP->doorstyle, "none")) 123 if (strcmp (RP->doorstyle, "none"))
127 put_doors (theMap, layout, RP->doorstyle, RP); 124 put_doors (this, layout, RP->doorstyle, RP);
128 125
129 } 126 }
127
128 coroapi::cede ();
130 129
131 /* create exits unless the exitstyle is "none" */ 130 /* create exits unless the exitstyle is "none" */
132 if (strcmp (RP->exitstyle, "none")) 131 if (strcmp (RP->exitstyle, "none"))
133 place_exits (theMap, layout, RP->exitstyle, RP->orientation, RP); 132 place_exits (this, layout, RP->exitstyle, RP->orientation, RP);
134 133
134 coroapi::cede ();
135
135 place_specials_in_map (theMap, layout, RP); 136 place_specials_in_map (this, layout, RP);
137
138 coroapi::cede ();
136 139
137 /* create monsters unless the monsterstyle is "none" */ 140 /* create monsters unless the monsterstyle is "none" */
138 if (strcmp (RP->monsterstyle, "none")) 141 if (strcmp (RP->monsterstyle, "none"))
139 place_monsters (theMap, RP->monsterstyle, RP->difficulty, RP); 142 place_monsters (this, RP->monsterstyle, RP->difficulty, RP);
143
144 coroapi::cede ();
140 145
141 /* treasures needs to have a proper difficulty set for the map. */ 146 /* treasures needs to have a proper difficulty set for the map. */
142 theMap->difficulty = calculate_difficulty (theMap); 147 difficulty = estimate_difficulty ();
148
149 coroapi::cede ();
143 150
144 /* create treasure unless the treasurestyle is "none" */ 151 /* create treasure unless the treasurestyle is "none" */
145 if (strcmp (RP->treasurestyle, "none")) 152 if (strcmp (RP->treasurestyle, "none"))
146 place_treasure (theMap, layout, RP->treasurestyle, RP->treasureoptions, RP); 153 place_treasure (this, layout, RP->treasurestyle, RP->treasureoptions, RP);
154
155 coroapi::cede ();
147 156
148 /* create decor unless the decorstyle is "none" */ 157 /* create decor unless the decorstyle is "none" */
149 if (strcmp (RP->decorstyle, "none")) 158 if (strcmp (RP->decorstyle, "none"))
150 put_decor (theMap, layout, RP->decorstyle, RP->decoroptions, RP); 159 put_decor (this, layout, RP->decorstyle, RP->decoroptions, RP);
160
161 coroapi::cede ();
151 162
152 /* generate treasures, etc. */ 163 /* generate treasures, etc. */
153 fix_auto_apply (theMap); 164 fix_auto_apply ();
154 165
166 coroapi::cede ();
155 unblock_exits (theMap, layout, RP); 167 unblock_exits (this, layout, RP);
156 168
157 /* free the layout */ 169 /* free the layout */
158 for (i = 0; i < RP->Xsize; i++) 170 for (i = 0; i < RP->Xsize; i++)
159 free (layout[i]); 171 free (layout[i]);
172
160 free (layout); 173 free (layout);
161 174
162 theMap->msg = strdup_local (buf); 175 msg = strdup (buf);
176 in_memory = MAP_IN_MEMORY;
163 177
164 return theMap; 178 return 1;
165} 179}
166
167 180
168/* function selects the layout function and gives it whatever 181/* function selects the layout function and gives it whatever
169 arguments it needs. */ 182 arguments it needs. */
170char ** 183char **
171layoutgen (RMParms * RP) 184layoutgen (random_map_params *RP)
172{ 185{
173 char **maze = 0; 186 char **maze = 0;
174 int oxsize = RP->Xsize, oysize = RP->Ysize; 187 int oxsize = RP->Xsize, oysize = RP->Ysize;
175 188
176 if (RP->symmetry == RANDOM_SYM) 189 if (RP->symmetry == SYMMETRY_RANDOM)
177 RP->symmetry_used = (RANDOM () % (XY_SYM)) + 1; 190 RP->symmetry_used = (RANDOM () % (SYMMETRY_XY)) + 1;
178 else 191 else
179 RP->symmetry_used = RP->symmetry; 192 RP->symmetry_used = RP->symmetry;
180 193
181 if (RP->symmetry_used == Y_SYM || RP->symmetry_used == XY_SYM) 194 if (RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY)
182 RP->Ysize = RP->Ysize / 2 + 1; 195 RP->Ysize = RP->Ysize / 2 + 1;
183 if (RP->symmetry_used == X_SYM || RP->symmetry_used == XY_SYM) 196 if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY)
184 RP->Xsize = RP->Xsize / 2 + 1; 197 RP->Xsize = RP->Xsize / 2 + 1;
185 198
186 if (RP->Xsize < MIN_RANDOM_MAP_SIZE) 199 if (RP->Xsize < MIN_RANDOM_MAP_SIZE)
187 RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 5; 200 RP->Xsize = MIN_RANDOM_MAP_SIZE + rndm (5);
188 if (RP->Ysize < MIN_RANDOM_MAP_SIZE) 201 if (RP->Ysize < MIN_RANDOM_MAP_SIZE)
189 RP->Ysize = MIN_RANDOM_MAP_SIZE + RANDOM () % 5; 202 RP->Ysize = MIN_RANDOM_MAP_SIZE + rndm (5);
190 RP->map_layout_style = 0; 203 RP->map_layout_style = 0;
191 204
192 /* Redo this - there was a lot of redundant code of checking for preset 205 /* Redo this - there was a lot of redundant code of checking for preset
193 * layout style and then random layout style. Instead, figure out 206 * layout style and then random layout style. Instead, figure out
194 * the numeric layoutstyle, so there is only one area that actually 207 * the numeric layoutstyle, so there is only one area that actually
195 * calls the code to make the maps. 208 * calls the code to make the maps.
196 */ 209 */
197 if (strstr (RP->layoutstyle, "onion")) 210 if (strstr (RP->layoutstyle, "onion"))
198 {
199 RP->map_layout_style = ONION_LAYOUT; 211 RP->map_layout_style = LAYOUT_ONION;
200 }
201 212
202 if (strstr (RP->layoutstyle, "maze")) 213 if (strstr (RP->layoutstyle, "maze"))
203 {
204 RP->map_layout_style = MAZE_LAYOUT; 214 RP->map_layout_style = LAYOUT_MAZE;
205 }
206 215
207 if (strstr (RP->layoutstyle, "spiral")) 216 if (strstr (RP->layoutstyle, "spiral"))
208 {
209 RP->map_layout_style = SPIRAL_LAYOUT; 217 RP->map_layout_style = LAYOUT_SPIRAL;
210 }
211 218
212 if (strstr (RP->layoutstyle, "rogue")) 219 if (strstr (RP->layoutstyle, "rogue"))
213 {
214 RP->map_layout_style = ROGUELIKE_LAYOUT; 220 RP->map_layout_style = LAYOUT_ROGUELIKE;
215 }
216 221
217 if (strstr (RP->layoutstyle, "snake")) 222 if (strstr (RP->layoutstyle, "snake"))
218 {
219 RP->map_layout_style = SNAKE_LAYOUT; 223 RP->map_layout_style = LAYOUT_SNAKE;
220 }
221 224
222 if (strstr (RP->layoutstyle, "squarespiral")) 225 if (strstr (RP->layoutstyle, "squarespiral"))
223 {
224 RP->map_layout_style = SQUARE_SPIRAL_LAYOUT; 226 RP->map_layout_style = LAYOUT_SQUARE_SPIRAL;
225 } 227
226 /* No style found - choose one ranomdly */ 228 /* No style found - choose one ranomdly */
227 if (RP->map_layout_style == 0) 229 if (RP->map_layout_style == LAYOUT_NONE)
228 {
229 RP->map_layout_style = (RANDOM () % NROFLAYOUTS) + 1; 230 RP->map_layout_style = (RANDOM () % (NROFLAYOUTS - 1)) + 1;
230 }
231 231
232 switch (RP->map_layout_style) 232 switch (RP->map_layout_style)
233 { 233 {
234 234 case LAYOUT_ONION:
235 case ONION_LAYOUT:
236 maze = map_gen_onion (RP->Xsize, RP->Ysize, RP->layoutoptions1, RP->layoutoptions2); 235 maze = map_gen_onion (RP->Xsize, RP->Ysize, RP->layoutoptions1, RP->layoutoptions2);
237 if (!(RANDOM () % 3) && !(RP->layoutoptions1 & OPT_WALLS_ONLY)) 236 if (!(rndm (3)) && !(RP->layoutoptions1 & RMOPT_WALLS_ONLY))
238 roomify_layout (maze, RP); 237 roomify_layout (maze, RP);
239 break; 238 break;
240 239
241 case MAZE_LAYOUT: 240 case LAYOUT_MAZE:
242 maze = maze_gen (RP->Xsize, RP->Ysize, RANDOM () % 2); 241 maze = maze_gen (RP->Xsize, RP->Ysize, rndm (2));
243 if (!(RANDOM () % 2)) 242 if (!(rndm (2)))
244 doorify_layout (maze, RP); 243 doorify_layout (maze, RP);
245 break; 244 break;
246 245
247 case SPIRAL_LAYOUT: 246 case LAYOUT_SPIRAL:
248 maze = map_gen_spiral (RP->Xsize, RP->Ysize, RP->layoutoptions1); 247 maze = map_gen_spiral (RP->Xsize, RP->Ysize, RP->layoutoptions1);
249 if (!(RANDOM () % 2)) 248 if (!(rndm (2)))
250 doorify_layout (maze, RP); 249 doorify_layout (maze, RP);
251 break; 250 break;
252 251
253 case ROGUELIKE_LAYOUT: 252 case LAYOUT_ROGUELIKE:
254 /* Don't put symmetry in rogue maps. There isn't much reason to 253 /* Don't put symmetry in rogue maps. There isn't much reason to
255 * do so in the first place (doesn't make it any more interesting), 254 * do so in the first place (doesn't make it any more interesting),
256 * but more importantly, the symmetry code presumes we are symmetrizing 255 * but more importantly, the symmetry code presumes we are symmetrizing
257 * spirals, or maps with lots of passages - making a symmetric rogue 256 * spirals, or maps with lots of passages - making a symmetric rogue
258 * map fails because its likely that the passages the symmetry process 257 * map fails because its likely that the passages the symmetry process
259 * creates may not connect the rooms. 258 * creates may not connect the rooms.
260 */ 259 */
261 RP->symmetry_used = NO_SYM; 260 RP->symmetry_used = SYMMETRY_NONE;
262 RP->Ysize = oysize; 261 RP->Ysize = oysize;
263 RP->Xsize = oxsize; 262 RP->Xsize = oxsize;
264 maze = roguelike_layout_gen (RP->Xsize, RP->Ysize, RP->layoutoptions1); 263 maze = roguelike_layout_gen (RP->Xsize, RP->Ysize, RP->layoutoptions1);
265 /* no doorifying... done already */ 264 /* no doorifying... done already */
266 break; 265 break;
267 266
268 case SNAKE_LAYOUT: 267 case LAYOUT_SNAKE:
269 maze = make_snake_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); 268 maze = make_snake_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1);
270 if (RANDOM () % 2) 269 if (rndm (2))
271 roomify_layout (maze, RP); 270 roomify_layout (maze, RP);
272 break; 271 break;
273 272
274 case SQUARE_SPIRAL_LAYOUT: 273 case LAYOUT_SQUARE_SPIRAL:
275 maze = make_square_spiral_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); 274 maze = make_square_spiral_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1);
276 if (RANDOM () % 2) 275 if (rndm (2))
277 roomify_layout (maze, RP); 276 roomify_layout (maze, RP);
278 break; 277 break;
279 } 278 }
280 279
281 maze = symmetrize_layout (maze, RP->symmetry_used, RP); 280 maze = symmetrize_layout (maze, RP->symmetry_used, RP);
281
282#ifdef RMAP_DEBUG 282#ifdef RMAP_DEBUG
283 dump_layout (maze, RP); 283 dump_layout (maze, RP);
284#endif 284#endif
285
285 if (RP->expand2x) 286 if (RP->expand2x)
286 { 287 {
287 maze = expand2x (maze, RP->Xsize, RP->Ysize); 288 maze = expand2x (maze, RP->Xsize, RP->Ysize);
288 RP->Xsize = RP->Xsize * 2 - 1; 289 RP->Xsize = RP->Xsize * 2 - 1;
289 RP->Ysize = RP->Ysize * 2 - 1; 290 RP->Ysize = RP->Ysize * 2 - 1;
290 } 291 }
292
291 return maze; 293 return maze;
292} 294}
293
294 295
295/* takes a map and makes it symmetric: adjusts Xsize and 296/* takes a map and makes it symmetric: adjusts Xsize and
296Ysize to produce a symmetric map. */ 297Ysize to produce a symmetric map. */
297
298char ** 298char **
299symmetrize_layout (char **maze, int sym, RMParms * RP) 299symmetrize_layout (char **maze, int sym, random_map_params *RP)
300{ 300{
301 int i, j; 301 int i, j;
302 char **sym_maze; 302 char **sym_maze;
303 int Xsize_orig, Ysize_orig; 303 int Xsize_orig, Ysize_orig;
304 304
305 Xsize_orig = RP->Xsize; 305 Xsize_orig = RP->Xsize;
306 Ysize_orig = RP->Ysize; 306 Ysize_orig = RP->Ysize;
307 RP->symmetry_used = sym; /* tell everyone else what sort of symmetry is used. */ 307 RP->symmetry_used = sym; /* tell everyone else what sort of symmetry is used. */
308 if (sym == NO_SYM) 308 if (sym == SYMMETRY_NONE)
309 { 309 {
310 RP->Xsize = Xsize_orig; 310 RP->Xsize = Xsize_orig;
311 RP->Ysize = Ysize_orig; 311 RP->Ysize = Ysize_orig;
312 return maze; 312 return maze;
313 } 313 }
314 /* pick new sizes */ 314 /* pick new sizes */
315 RP->Xsize = ((sym == X_SYM || sym == XY_SYM) ? RP->Xsize * 2 - 3 : RP->Xsize); 315 RP->Xsize = ((sym == SYMMETRY_X || sym == SYMMETRY_XY) ? RP->Xsize * 2 - 3 : RP->Xsize);
316 RP->Ysize = ((sym == Y_SYM || sym == XY_SYM) ? RP->Ysize * 2 - 3 : RP->Ysize); 316 RP->Ysize = ((sym == SYMMETRY_Y || sym == SYMMETRY_XY) ? RP->Ysize * 2 - 3 : RP->Ysize);
317 317
318 sym_maze = (char **) calloc (sizeof (char *), RP->Xsize); 318 sym_maze = (char **) calloc (sizeof (char *), RP->Xsize);
319 for (i = 0; i < RP->Xsize; i++) 319 for (i = 0; i < RP->Xsize; i++)
320 sym_maze[i] = (char *) calloc (sizeof (char), RP->Ysize); 320 sym_maze[i] = (char *) calloc (sizeof (char), RP->Ysize);
321 321
322 if (sym == X_SYM) 322 if (sym == SYMMETRY_X)
323 for (i = 0; i < RP->Xsize / 2 + 1; i++) 323 for (i = 0; i < RP->Xsize / 2 + 1; i++)
324 for (j = 0; j < RP->Ysize; j++) 324 for (j = 0; j < RP->Ysize; j++)
325 { 325 {
326 sym_maze[i][j] = maze[i][j]; 326 sym_maze[i][j] = maze[i][j];
327 sym_maze[RP->Xsize - i - 1][j] = maze[i][j]; 327 sym_maze[RP->Xsize - i - 1][j] = maze[i][j];
328 }; 328 };
329 if (sym == Y_SYM) 329 if (sym == SYMMETRY_Y)
330 for (i = 0; i < RP->Xsize; i++) 330 for (i = 0; i < RP->Xsize; i++)
331 for (j = 0; j < RP->Ysize / 2 + 1; j++) 331 for (j = 0; j < RP->Ysize / 2 + 1; j++)
332 { 332 {
333 sym_maze[i][j] = maze[i][j]; 333 sym_maze[i][j] = maze[i][j];
334 sym_maze[i][RP->Ysize - j - 1] = maze[i][j]; 334 sym_maze[i][RP->Ysize - j - 1] = maze[i][j];
335 } 335 }
336 if (sym == XY_SYM) 336 if (sym == SYMMETRY_XY)
337 for (i = 0; i < RP->Xsize / 2 + 1; i++) 337 for (i = 0; i < RP->Xsize / 2 + 1; i++)
338 for (j = 0; j < RP->Ysize / 2 + 1; j++) 338 for (j = 0; j < RP->Ysize / 2 + 1; j++)
339 { 339 {
340 sym_maze[i][j] = maze[i][j]; 340 sym_maze[i][j] = maze[i][j];
341 sym_maze[i][RP->Ysize - j - 1] = maze[i][j]; 341 sym_maze[i][RP->Ysize - j - 1] = maze[i][j];
345 /* delete the old maze */ 345 /* delete the old maze */
346 for (i = 0; i < Xsize_orig; i++) 346 for (i = 0; i < Xsize_orig; i++)
347 free (maze[i]); 347 free (maze[i]);
348 free (maze); 348 free (maze);
349 /* reconnect disjointed spirals */ 349 /* reconnect disjointed spirals */
350 if (RP->map_layout_style == SPIRAL_LAYOUT) 350 if (RP->map_layout_style == LAYOUT_SPIRAL)
351 connect_spirals (RP->Xsize, RP->Ysize, sym, sym_maze); 351 connect_spirals (RP->Xsize, RP->Ysize, sym, sym_maze);
352 /* reconnect disjointed nethackmazes: the routine for 352 /* reconnect disjointed nethackmazes: the routine for
353 spirals will do the trick? */ 353 spirals will do the trick? */
354 if (RP->map_layout_style == ROGUELIKE_LAYOUT) 354 if (RP->map_layout_style == LAYOUT_ROGUELIKE)
355 connect_spirals (RP->Xsize, RP->Ysize, sym, sym_maze); 355 connect_spirals (RP->Xsize, RP->Ysize, sym, sym_maze);
356 356
357 return sym_maze; 357 return sym_maze;
358} 358}
359 359
362 onion layouts, making them possibly centered on any wall. 362 onion layouts, making them possibly centered on any wall.
363 It'll modify Xsize and Ysize if they're swapped. 363 It'll modify Xsize and Ysize if they're swapped.
364*/ 364*/
365 365
366char ** 366char **
367rotate_layout (char **maze, int rotation, RMParms * RP) 367rotate_layout (char **maze, int rotation, random_map_params *RP)
368{ 368{
369 char **new_maze; 369 char **new_maze;
370 int i, j; 370 int i, j;
371 371
372 switch (rotation) 372 switch (rotation)
373 { 373 {
374 case 0: 374 case 0:
375 return maze;
376 break;
377 case 2: /* a reflection */
378 {
379 char *newmaze = (char *) malloc (sizeof (char) * RP->Xsize * RP->Ysize);
380
381 for (i = 0; i < RP->Xsize; i++)
382 { /* make a copy */
383 for (j = 0; j < RP->Ysize; j++)
384 {
385 newmaze[i * RP->Ysize + j] = maze[i][j];
386 }
387 }
388 for (i = 0; i < RP->Xsize; i++)
389 { /* copy a reflection back */
390 for (j = 0; j < RP->Ysize; j++)
391 {
392 maze[i][j] = newmaze[(RP->Xsize - i - 1) * RP->Ysize + RP->Ysize - j - 1];
393 }
394 }
395 free (newmaze);
375 return maze; 396 return maze;
376 break; 397 break;
377 case 2: /* a reflection */ 398 }
399 case 1:
400 case 3:
401 {
402 int swap;
403 new_maze = (char **) calloc (sizeof (char *), RP->Ysize);
404 for (i = 0; i < RP->Ysize; i++)
378 { 405 {
379 char *newmaze = (char *) malloc (sizeof (char) * RP->Xsize * RP->Ysize); 406 new_maze[i] = (char *) calloc (sizeof (char), RP->Xsize);
380 407 }
408 if (rotation == 1) /* swap x and y */
381 for (i = 0; i < RP->Xsize; i++) 409 for (i = 0; i < RP->Xsize; i++)
382 { /* make a copy */
383 for (j = 0; j < RP->Ysize; j++) 410 for (j = 0; j < RP->Ysize; j++)
384 {
385 newmaze[i * RP->Ysize + j] = maze[i][j]; 411 new_maze[j][i] = maze[i][j];
386 } 412
387 } 413 if (rotation == 3)
388 for (i = 0; i < RP->Xsize; i++) 414 { /* swap x and y */
389 { /* copy a reflection back */
390 for (j = 0; j < RP->Ysize; j++)
391 {
392 maze[i][j] = newmaze[(RP->Xsize - i - 1) * RP->Ysize + RP->Ysize - j - 1];
393 }
394 }
395 free (newmaze);
396 return maze;
397 break;
398 }
399 case 1:
400 case 3:
401 {
402 int swap;
403 new_maze = (char **) calloc (sizeof (char *), RP->Ysize);
404 for (i = 0; i < RP->Ysize; i++)
405 {
406 new_maze[i] = (char *) calloc (sizeof (char), RP->Xsize);
407 }
408 if (rotation == 1) /* swap x and y */
409 for (i = 0; i < RP->Xsize; i++) 415 for (i = 0; i < RP->Xsize; i++)
410 for (j = 0; j < RP->Ysize; j++) 416 for (j = 0; j < RP->Ysize; j++)
411 new_maze[j][i] = maze[i][j];
412
413 if (rotation == 3)
414 { /* swap x and y */
415 for (i = 0; i < RP->Xsize; i++)
416 for (j = 0; j < RP->Ysize; j++)
417 new_maze[j][i] = maze[RP->Xsize - i - 1][RP->Ysize - j - 1]; 417 new_maze[j][i] = maze[RP->Xsize - i - 1][RP->Ysize - j - 1];
418 } 418 }
419 419
420 /* delete the old layout */ 420 /* delete the old layout */
421 for (i = 0; i < RP->Xsize; i++) 421 for (i = 0; i < RP->Xsize; i++)
422 free (maze[i]); 422 free (maze[i]);
423 free (maze); 423 free (maze);
424 424
425 swap = RP->Ysize; 425 swap = RP->Ysize;
426 RP->Ysize = RP->Xsize; 426 RP->Ysize = RP->Xsize;
427 RP->Xsize = swap; 427 RP->Xsize = swap;
428 return new_maze; 428 return new_maze;
429 break; 429 break;
430 } 430 }
431 } 431 }
432 return NULL; 432 return NULL;
433} 433}
434 434
435/* take a layout and make some rooms in it. 435/* take a layout and make some rooms in it.
436 --works best on onions.*/ 436 --works best on onions.*/
437void 437void
438roomify_layout (char **maze, RMParms * RP) 438roomify_layout (char **maze, random_map_params *RP)
439{ 439{
440 int tries = RP->Xsize * RP->Ysize / 30; 440 int tries = RP->Xsize * RP->Ysize / 30;
441 int ti; 441 int ti;
442 442
443 for (ti = 0; ti < tries; ti++) 443 for (ti = 0; ti < tries; ti++)
470/* checks the layout to see if I can stick a horizontal(dir = 0) wall 470/* checks the layout to see if I can stick a horizontal(dir = 0) wall
471 (or vertical, dir == 1) 471 (or vertical, dir == 1)
472 here which ends up on other walls sensibly. */ 472 here which ends up on other walls sensibly. */
473 473
474int 474int
475can_make_wall (char **maze, int dx, int dy, int dir, RMParms * RP) 475can_make_wall (char **maze, int dx, int dy, int dir, random_map_params *RP)
476{ 476{
477 int i1; 477 int i1;
478 int length = 0; 478 int length = 0;
479 479
480 /* dont make walls if we're on the edge. */ 480 /* dont make walls if we're on the edge. */
555make_wall (char **maze, int x, int y, int dir) 555make_wall (char **maze, int x, int y, int dir)
556{ 556{
557 maze[x][y] = 'D'; /* mark a door */ 557 maze[x][y] = 'D'; /* mark a door */
558 switch (dir) 558 switch (dir)
559 { 559 {
560 case 0: /* horizontal */ 560 case 0: /* horizontal */
561 { 561 {
562 int i1; 562 int i1;
563 563
564 for (i1 = x - 1; maze[i1][y] == 0; i1--) 564 for (i1 = x - 1; maze[i1][y] == 0; i1--)
565 maze[i1][y] = '#'; 565 maze[i1][y] = '#';
566 for (i1 = x + 1; maze[i1][y] == 0; i1++) 566 for (i1 = x + 1; maze[i1][y] == 0; i1++)
567 maze[i1][y] = '#'; 567 maze[i1][y] = '#';
568 break; 568 break;
569 } 569 }
570 case 1: /* vertical */ 570 case 1: /* vertical */
571 { 571 {
572 int i1; 572 int i1;
573 573
574 for (i1 = y - 1; maze[x][i1] == 0; i1--) 574 for (i1 = y - 1; maze[x][i1] == 0; i1--)
575 maze[x][i1] = '#'; 575 maze[x][i1] = '#';
576 for (i1 = y + 1; maze[x][i1] == 0; i1++) 576 for (i1 = y + 1; maze[x][i1] == 0; i1++)
577 maze[x][i1] = '#'; 577 maze[x][i1] = '#';
578 break; 578 break;
579 } 579 }
580 } 580 }
581 581
582 return 0; 582 return 0;
583} 583}
584 584
585/* puts doors at appropriate locations in a layout. */ 585/* puts doors at appropriate locations in a layout. */
586
587void 586void
588doorify_layout (char **maze, RMParms * RP) 587doorify_layout (char **maze, random_map_params *RP)
589{ 588{
590 int ndoors = RP->Xsize * RP->Ysize / 60; /* reasonable number of doors. */ 589 int ndoors = RP->Xsize * RP->Ysize / 60; /* reasonable number of doors. */
591 char *doorlist_x; 590 char *doorlist_x;
592 char *doorlist_y; 591 char *doorlist_y;
593 int doorlocs = 0; /* # of available doorlocations */ 592 int doorlocs = 0; /* # of available doorlocations */
608 doorlist_x[doorlocs] = i; 607 doorlist_x[doorlocs] = i;
609 doorlist_y[doorlocs] = j; 608 doorlist_y[doorlocs] = j;
610 doorlocs++; 609 doorlocs++;
611 } 610 }
612 } 611 }
612
613 while (ndoors > 0 && doorlocs > 0) 613 while (ndoors > 0 && doorlocs > 0)
614 { 614 {
615 int di; 615 int di;
616 int sindex; 616 int sindex;
617 617
627 /* reduce the size of the list */ 627 /* reduce the size of the list */
628 doorlocs--; 628 doorlocs--;
629 doorlist_x[di] = doorlist_x[doorlocs]; 629 doorlist_x[di] = doorlist_x[doorlocs];
630 doorlist_y[di] = doorlist_y[doorlocs]; 630 doorlist_y[di] = doorlist_y[doorlocs];
631 } 631 }
632
632 free (doorlist_x); 633 free (doorlist_x);
633 free (doorlist_y); 634 free (doorlist_y);
634} 635}
635 636
636
637void 637void
638write_map_parameters_to_string (char *buf, RMParms * RP) 638write_map_parameters_to_string (char *buf, random_map_params *RP)
639{ 639{
640
641 char small_buf[256]; 640 char small_buf[16384];
642 641
643 sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize); 642 sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize);
644 643
645 if (RP->wallstyle[0]) 644 if (RP->wallstyle[0])
646 { 645 {
688 { 687 {
689 sprintf (small_buf, "exitstyle %s\n", RP->exitstyle); 688 sprintf (small_buf, "exitstyle %s\n", RP->exitstyle);
690 strcat (buf, small_buf); 689 strcat (buf, small_buf);
691 } 690 }
692 691
693 if (RP->final_map[0]) 692 if (RP->final_map.length ())
694 { 693 {
695 sprintf (small_buf, "final_map %s\n", RP->final_map); 694 sprintf (small_buf, "final_map %s\n", &RP->final_map);
696 strcat (buf, small_buf); 695 strcat (buf, small_buf);
697 } 696 }
698 697
699 if (RP->exit_on_final_map[0]) 698 if (RP->exit_on_final_map[0])
700 { 699 {
701 sprintf (small_buf, "exit_on_final_map %s\n", RP->exit_on_final_map); 700 sprintf (small_buf, "exit_on_final_map %s\n", RP->exit_on_final_map);
702 strcat (buf, small_buf); 701 strcat (buf, small_buf);
703 } 702 }
704 703
705 if (RP->this_map[0]) 704 if (RP->this_map.length ())
706 { 705 {
707 sprintf (small_buf, "origin_map %s\n", RP->this_map); 706 sprintf (small_buf, "origin_map %s\n", &RP->this_map);
708 strcat (buf, small_buf); 707 strcat (buf, small_buf);
709 } 708 }
710 709
711 if (RP->expand2x) 710 if (RP->expand2x)
712 { 711 {
718 { 717 {
719 sprintf (small_buf, "layoutoptions1 %d\n", RP->layoutoptions1); 718 sprintf (small_buf, "layoutoptions1 %d\n", RP->layoutoptions1);
720 strcat (buf, small_buf); 719 strcat (buf, small_buf);
721 } 720 }
722 721
723
724 if (RP->layoutoptions2) 722 if (RP->layoutoptions2)
725 { 723 {
726 sprintf (small_buf, "layoutoptions2 %d\n", RP->layoutoptions2); 724 sprintf (small_buf, "layoutoptions2 %d\n", RP->layoutoptions2);
727 strcat (buf, small_buf); 725 strcat (buf, small_buf);
728 } 726 }
729 727
730
731 if (RP->layoutoptions3) 728 if (RP->layoutoptions3)
732 { 729 {
733 sprintf (small_buf, "layoutoptions3 %d\n", RP->layoutoptions3); 730 sprintf (small_buf, "layoutoptions3 %d\n", RP->layoutoptions3);
734 strcat (buf, small_buf); 731 strcat (buf, small_buf);
735 } 732 }
737 if (RP->symmetry) 734 if (RP->symmetry)
738 { 735 {
739 sprintf (small_buf, "symmetry %d\n", RP->symmetry); 736 sprintf (small_buf, "symmetry %d\n", RP->symmetry);
740 strcat (buf, small_buf); 737 strcat (buf, small_buf);
741 } 738 }
742
743 739
744 if (RP->difficulty && RP->difficulty_given) 740 if (RP->difficulty && RP->difficulty_given)
745 { 741 {
746 sprintf (small_buf, "difficulty %d\n", RP->difficulty); 742 sprintf (small_buf, "difficulty %d\n", RP->difficulty);
747 strcat (buf, small_buf); 743 strcat (buf, small_buf);
783 if (RP->origin_y) 779 if (RP->origin_y)
784 { 780 {
785 sprintf (small_buf, "origin_y %d\n", RP->origin_y); 781 sprintf (small_buf, "origin_y %d\n", RP->origin_y);
786 strcat (buf, small_buf); 782 strcat (buf, small_buf);
787 } 783 }
784
785 if (RP->treasureoptions)
786 {
787 sprintf (small_buf, "treasureoptions %d\n", RP->treasureoptions);
788 strcat (buf, small_buf);
789 }
790
788 if (RP->random_seed) 791 if (RP->random_seed)
789 { 792 {
790 /* Add one so that the next map is a bit different */
791 sprintf (small_buf, "random_seed %d\n", RP->random_seed + 1); 793 sprintf (small_buf, "random_seed %d\n", RP->random_seed);
792 strcat (buf, small_buf); 794 strcat (buf, small_buf);
793 }
794
795 if (RP->treasureoptions)
796 { 795 }
797 sprintf (small_buf, "treasureoptions %d\n", RP->treasureoptions); 796
798 strcat (buf, small_buf); 797 if (RP->custom)
799 } 798 {
800 799 sprintf (small_buf, "custom %s\n", RP->custom);
801 800 strcat (buf, small_buf);
801 }
802} 802}
803 803
804void 804void
805write_parameters_to_string (char *buf, 805write_parameters_to_string (char *buf,
806 int xsize_n, 806 int xsize_n,
826 int difficulty_given_n, 826 int difficulty_given_n,
827 int decoroptions_n, 827 int decoroptions_n,
828 int orientation_n, 828 int orientation_n,
829 int origin_x_n, int origin_y_n, int random_seed_n, int treasureoptions_n, float difficulty_increase) 829 int origin_x_n, int origin_y_n, int random_seed_n, int treasureoptions_n, float difficulty_increase)
830{ 830{
831
832 char small_buf[256]; 831 char small_buf[16384];
833 832
834 sprintf (buf, "xsize %d\nysize %d\n", xsize_n, ysize_n); 833 sprintf (buf, "xsize %d\nysize %d\n", xsize_n, ysize_n);
835 834
836 if (wallstyle_n && wallstyle_n[0]) 835 if (wallstyle_n && wallstyle_n[0])
837 { 836 {
902 if (layoutoptions1_n) 901 if (layoutoptions1_n)
903 { 902 {
904 sprintf (small_buf, "layoutoptions1 %d\n", layoutoptions1_n); 903 sprintf (small_buf, "layoutoptions1 %d\n", layoutoptions1_n);
905 strcat (buf, small_buf); 904 strcat (buf, small_buf);
906 } 905 }
907
908 906
909 if (layoutoptions2_n) 907 if (layoutoptions2_n)
910 { 908 {
911 sprintf (small_buf, "layoutoptions2 %d\n", layoutoptions2_n); 909 sprintf (small_buf, "layoutoptions2 %d\n", layoutoptions2_n);
912 strcat (buf, small_buf); 910 strcat (buf, small_buf);
968 if (origin_y_n) 966 if (origin_y_n)
969 { 967 {
970 sprintf (small_buf, "origin_y %d\n", origin_y_n); 968 sprintf (small_buf, "origin_y %d\n", origin_y_n);
971 strcat (buf, small_buf); 969 strcat (buf, small_buf);
972 } 970 }
971
973 if (random_seed_n) 972 if (random_seed_n)
974 { 973 {
975 /* Add one so that the next map is a bit different */ 974 /* Add one so that the next map is a bit different */
976 sprintf (small_buf, "random_seed %d\n", random_seed_n + 1); 975 sprintf (small_buf, "random_seed %d\n", random_seed_n + 1);
977 strcat (buf, small_buf); 976 strcat (buf, small_buf);
980 if (treasureoptions_n) 979 if (treasureoptions_n)
981 { 980 {
982 sprintf (small_buf, "treasureoptions %d\n", treasureoptions_n); 981 sprintf (small_buf, "treasureoptions %d\n", treasureoptions_n);
983 strcat (buf, small_buf); 982 strcat (buf, small_buf);
984 } 983 }
985
986
987} 984}
988 985
989/* copy an object with an inventory... i.e., duplicate the inv too. */ 986/* copy an object with an inventory... i.e., duplicate the inv too. */
990void 987void
991copy_object_with_inv (object *src_ob, object *dest_ob) 988copy_object_with_inv (object *src_ob, object *dest_ob)
992{ 989{
993 object *walk, *tmp; 990 object *walk, *tmp;
994 991
995 copy_object (src_ob, dest_ob); 992 src_ob->copy_to (dest_ob);
996 993
997 for (walk = src_ob->inv; walk != NULL; walk = walk->below) 994 for (walk = src_ob->inv; walk; walk = walk->below)
998 { 995 {
999 tmp = get_object (); 996 tmp = object::create ();
1000 copy_object (walk, tmp); 997
998 walk->copy_to (tmp);
1001 insert_ob_in_ob (tmp, dest_ob); 999 insert_ob_in_ob (tmp, dest_ob);
1002 } 1000 }
1003} 1001}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines