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.2 by root, Tue Aug 29 08:01:36 2006 UTC vs.
Revision 1.22 by root, Fri Jan 19 15:29:52 2007 UTC

1/* 1/*
2 * static char *rcsid_random_map_c = 2 * CrossFire, A Multiplayer game for X-windows
3 * "$Id: random_map.C,v 1.2 2006/08/29 08:01:36 root Exp $"; 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
5 * Copyright (C) 2001 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen
7 *
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
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
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
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 * The authors can be reached via e-mail at <crossfire@schmorp.de>
4 */ 23 */
5
6/*
7 CrossFire, A Multiplayer game for X-windows
8
9 Copyright (C) 2001 Mark Wedel & Crossfire Development Team
10 Copyright (C) 1992 Frank Tore Johansen
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25
26 The authors can be reached via e-mail at crossfire-devel@real-time.com
27*/
28 24
29#include <time.h> 25#include <time.h>
30#include <stdio.h> 26#include <stdio.h>
31#include <global.h> 27#include <global.h>
32#include <maze_gen.h> 28#include <maze_gen.h>
33#include <room_gen.h> 29#include <room_gen.h>
34#include <random_map.h> 30#include <random_map.h>
35#include <rproto.h> 31#include <rproto.h>
36#include <sproto.h> 32#include <sproto.h>
37 33
38void dump_layout(char **layout,RMParms *RP) { 34#define CEDE coroapi::cede (); rndm.seed (RP->random_seed + __LINE__);
35
36void
37dump_layout (char **layout, random_map_params *RP)
38{
39 {
39 { int i,j; 40 int i, j;
41
40 for(i=0;i<RP->Xsize;i++) { 42 for (i = 0; i < RP->Xsize; i++)
43 {
41 for(j=0;j<RP->Ysize;j++) { 44 for (j = 0; j < RP->Ysize; j++)
42 if(layout[i][j]==0) layout[i][j]=' '; 45 {
46 if (layout[i][j] == 0)
47 layout[i][j] = ' ';
43 printf("%c",layout[i][j]); 48 printf ("%c", layout[i][j]);
44 if(layout[i][j]==' ') layout[i][j]=0; 49 if (layout[i][j] == ' ')
50 layout[i][j] = 0;
51 }
52 printf ("\n");
45 } 53 }
54 }
46 printf("\n"); 55 printf ("\n");
47 }}
48 printf("\n");
49} 56}
50EXTERN FILE *logfile; 57
51mapstruct *generate_random_map(const char *OutFileName, RMParms *RP) { 58bool
59maptile::generate_random_map (random_map_params *RP)
60{
52 char **layout, buf[HUGE_BUF]; 61 char **layout, buf[16384];
53 mapstruct *theMap;
54 int i; 62 int i;
55 63
56 /* 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 */
57 if(RP->random_seed == 0) 65 RP->random_seed = RP->random_seed
58 RP->random_seed=time(0); 66 ? RP->random_seed + RP->dungeon_level
67 : time (0);
68 CEDE;
59 69
60 SRANDOM(RP->random_seed);
61
62 write_map_parameters_to_string(buf, RP); 70 write_map_parameters_to_string (buf, RP);
63 71
64 if(RP->difficulty==0) { 72 if (RP->difficulty == 0)
73 {
65 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
66 if (RP->difficulty_increase > 0.001) { 76 if (RP->difficulty_increase > 0.001)
67 RP->difficulty = (int)((float)RP->dungeon_level * RP->difficulty_increase); 77 RP->difficulty = (int) ((float) RP->dungeon_level * RP->difficulty_increase);
68 if (RP->difficulty < 1) RP->difficulty=1; 78
69 } 79 if (RP->difficulty < 1)
80 RP->difficulty = 1;
70 } 81 }
71 else 82 else
72 RP->difficulty_given=1; 83 RP->difficulty_given = 1;
73 84
74 if(RP->Xsize<MIN_RANDOM_MAP_SIZE) RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM()%25 + 5; 85 if (RP->Xsize < MIN_RANDOM_MAP_SIZE)
75 if(RP->Ysize<MIN_RANDOM_MAP_SIZE) RP->Ysize = MIN_RANDOM_MAP_SIZE + RANDOM()%25 + 5; 86 RP->Xsize = MIN_RANDOM_MAP_SIZE + rndm (25) + 5;
76 87
88 if (RP->Ysize < MIN_RANDOM_MAP_SIZE)
89 RP->Ysize = MIN_RANDOM_MAP_SIZE + rndm (25) + 5;
90
91 if (RP->symmetry == SYMMETRY_RANDOM)
92 RP->symmetry_used = (RANDOM () % (SYMMETRY_XY)) + 1;
93 else
94 RP->symmetry_used = RP->symmetry;
95
96 if (RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY)
97 RP->Ysize = RP->Ysize / 2 + 1;
98 if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY)
99 RP->Xsize = RP->Xsize / 2 + 1;
100
77 if(RP->expand2x > 0) { 101 if (RP->expand2x > 0)
102 {
78 RP->Xsize /=2; 103 RP->Xsize /= 2;
79 RP->Ysize /=2; 104 RP->Ysize /= 2;
80 } 105 }
81 106
107 RP->map_layout_style = LAYOUT_NONE;
108
109 /* Redo this - there was a lot of redundant code of checking for preset
110 * layout style and then random layout style. Instead, figure out
111 * the numeric layoutstyle, so there is only one area that actually
112 * calls the code to make the maps.
113 */
114 if (strstr (RP->layoutstyle, "onion"))
115 RP->map_layout_style = LAYOUT_ONION;
116
117 if (strstr (RP->layoutstyle, "maze"))
118 RP->map_layout_style = LAYOUT_MAZE;
119
120 if (strstr (RP->layoutstyle, "spiral"))
121 RP->map_layout_style = LAYOUT_SPIRAL;
122
123 if (strstr (RP->layoutstyle, "rogue"))
124 RP->map_layout_style = LAYOUT_ROGUELIKE;
125
126 if (strstr (RP->layoutstyle, "snake"))
127 RP->map_layout_style = LAYOUT_SNAKE;
128
129 if (strstr (RP->layoutstyle, "squarespiral"))
130 RP->map_layout_style = LAYOUT_SQUARE_SPIRAL;
131
132 /* No style found - choose one randomly */
133 if (RP->map_layout_style == LAYOUT_NONE)
134 RP->map_layout_style = (RANDOM () % (NROFLAYOUTS - 1)) + 1;
135
82 layout = layoutgen(RP); 136 layout = layoutgen (RP);
83 137
84#ifdef RMAP_DEBUG 138#ifdef RMAP_DEBUG
85 dump_layout(layout,RP); 139 dump_layout (layout, RP);
86#endif 140#endif
87 141
88 /* increment these for the current map */ 142 /* increment these for the current map */
89 RP->dungeon_level+=1; 143 RP->dungeon_level += 1;
90 /* allow constant-difficulty maps. */ 144 /* allow constant-difficulty maps. */
91 /* difficulty+=1; */ 145 /* difficulty+=1; */
92 146
93 /* rotate the layout randomly */ 147 /* rotate the layout randomly */
94 layout=rotate_layout(layout,RANDOM()%4,RP); 148 layout = rotate_layout (layout, rndm (4), RP);
95#ifdef RMAP_DEBUG 149#ifdef RMAP_DEBUG
96 dump_layout(layout,RP); 150 dump_layout (layout, RP);
97#endif 151#endif
98 152
99 /* allocate the map and set the floor */ 153 /* allocate the map and set the floor */
100 theMap = make_map_floor(layout,RP->floorstyle,RP); 154 make_map_floor (layout, RP->floorstyle, RP);
101 155
102 /* set the name of the map. */
103 strcpy(theMap->path,OutFileName);
104
105 /* set region */ 156 /* set region */
106 theMap->region=RP->region; 157 region = RP->region;
107 158
159 CEDE;
160
108 /* create walls unless the wallstyle is "none" */ 161 /* create walls unless the wallstyle is "none" */
109 if (strcmp (RP->wallstyle, "none")) { 162 if (strcmp (RP->wallstyle, "none"))
163 {
110 make_map_walls(theMap,layout,RP->wallstyle,RP); 164 make_map_walls (this, layout, RP->wallstyle, RP);
111 165
112 /* place doors unless doorstyle or wallstyle is "none"*/ 166 /* place doors unless doorstyle or wallstyle is "none" */
113 if (strcmp (RP->doorstyle, "none")) 167 if (strcmp (RP->doorstyle, "none"))
114 put_doors(theMap,layout,RP->doorstyle,RP); 168 put_doors (this, layout, RP->doorstyle, RP);
115
116 }
117 169
170 }
171
172 CEDE;
173
118 /* create exits unless the exitstyle is "none" */ 174 /* create exits unless the exitstyle is "none" */
119 if (strcmp (RP->exitstyle, "none")) 175 if (strcmp (RP->exitstyle, "none"))
120 place_exits(theMap,layout,RP->exitstyle,RP->orientation,RP); 176 place_exits (this, layout, RP->exitstyle, RP->orientation, RP);
121 177
178 CEDE;
179
122 place_specials_in_map(theMap,layout,RP); 180 place_specials_in_map (this, layout, RP);
123 181
182 CEDE;
183
124 /* create monsters unless the monsterstyle is "none" */ 184 /* create monsters unless the monsterstyle is "none" */
125 if (strcmp (RP->monsterstyle, "none")) 185 if (strcmp (RP->monsterstyle, "none"))
126 place_monsters(theMap,RP->monsterstyle,RP->difficulty,RP); 186 place_monsters (this, RP->monsterstyle, RP->difficulty, RP);
127 187
188 CEDE;
189
128 /* treasures needs to have a proper difficulty set for the map. */ 190 /* treasures needs to have a proper difficulty set for the map. */
129 theMap->difficulty=calculate_difficulty(theMap); 191 difficulty = estimate_difficulty ();
130 192
193 CEDE;
194
131 /* create treasure unless the treasurestyle is "none" */ 195 /* create treasure unless the treasurestyle is "none" */
132 if (strcmp (RP->treasurestyle, "none")) 196 if (strcmp (RP->treasurestyle, "none"))
133 place_treasure(theMap,layout,RP->treasurestyle,RP->treasureoptions,RP); 197 place_treasure (this, layout, RP->treasurestyle, RP->treasureoptions, RP);
134 198
199 CEDE;
200
135 /* create decor unless the decorstyle is "none" */ 201 /* create decor unless the decorstyle is "none" */
136 if (strcmp (RP->decorstyle, "none")) 202 if (strcmp (RP->decorstyle, "none"))
137 put_decor(theMap,layout,RP->decorstyle,RP->decoroptions,RP); 203 put_decor (this, layout, RP->decorstyle, RP->decoroptions, RP);
138 204
205 CEDE;
206
139 /* generate treasures, etc. */ 207 /* generate treasures, etc. */
140 fix_auto_apply(theMap); 208 fix_auto_apply ();
141 209
210 CEDE;
211
142 unblock_exits(theMap,layout,RP); 212 unblock_exits (this, layout, RP);
143 213
144 /* free the layout */ 214 /* free the layout */
145 for(i=0;i<RP->Xsize;i++) 215 for (i = 0; i < RP->Xsize; i++)
146 free(layout[i]); 216 free (layout[i]);
217
147 free(layout); 218 free (layout);
148 219
149 theMap->msg = strdup_local(buf); 220 msg = strdup (buf);
150 221 in_memory = MAP_IN_MEMORY;
151 return theMap;
152}
153 222
223 CEDE;
224
225 return 1;
226}
154 227
155/* function selects the layout function and gives it whatever 228/* function selects the layout function and gives it whatever
156 arguments it needs. */ 229 arguments it needs. */
157char **layoutgen(RMParms *RP) { 230char **
231layoutgen (random_map_params *RP)
232{
158 char **maze=0; 233 char **maze = 0;
159 int oxsize= RP->Xsize, oysize=RP->Ysize; 234 int oxsize = RP->Xsize, oysize = RP->Ysize;
160 235
161 if(RP->symmetry == RANDOM_SYM)
162 RP->symmetry_used = (RANDOM() % ( XY_SYM))+1;
163 else RP->symmetry_used = RP->symmetry;
164
165 if(RP->symmetry_used==Y_SYM||RP->symmetry_used==XY_SYM) RP->Ysize = RP->Ysize/2+1;
166 if(RP->symmetry_used==X_SYM||RP->symmetry_used==XY_SYM) RP->Xsize = RP->Xsize/2+1;
167
168 if(RP->Xsize<MIN_RANDOM_MAP_SIZE) RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM()%5;
169 if(RP->Ysize<MIN_RANDOM_MAP_SIZE) RP->Ysize = MIN_RANDOM_MAP_SIZE + RANDOM()%5;
170 RP->map_layout_style = 0;
171
172 /* Redo this - there was a lot of redundant code of checking for preset
173 * layout style and then random layout style. Instead, figure out
174 * the numeric layoutstyle, so there is only one area that actually
175 * calls the code to make the maps.
176 */
177 if(strstr(RP->layoutstyle,"onion")) {
178 RP->map_layout_style = ONION_LAYOUT;
179 }
180
181 if(strstr(RP->layoutstyle,"maze")) {
182 RP->map_layout_style = MAZE_LAYOUT;
183 }
184
185 if(strstr(RP->layoutstyle,"spiral")) {
186 RP->map_layout_style = SPIRAL_LAYOUT;
187 }
188
189 if(strstr(RP->layoutstyle,"rogue")) {
190 RP->map_layout_style = ROGUELIKE_LAYOUT;
191 }
192
193 if(strstr(RP->layoutstyle,"snake")) {
194 RP->map_layout_style = SNAKE_LAYOUT;
195 }
196
197 if(strstr(RP->layoutstyle,"squarespiral")) {
198 RP->map_layout_style = SQUARE_SPIRAL_LAYOUT;
199 }
200 /* No style found - choose one ranomdly */
201 if (RP->map_layout_style == 0) {
202 RP->map_layout_style = (RANDOM() % NROFLAYOUTS) + 1;
203 }
204
205 switch(RP->map_layout_style) { 236 switch (RP->map_layout_style)
206 237 {
207 case ONION_LAYOUT: 238 case LAYOUT_ONION:
208 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);
209 if(!(RANDOM()%3)&& !(RP->layoutoptions1 & OPT_WALLS_ONLY)) roomify_layout(maze,RP); 240 if (!(rndm (3)) && !(RP->layoutoptions1 & RMOPT_WALLS_ONLY))
241 roomify_layout (maze, RP);
210 break; 242 break;
211 243
212 case MAZE_LAYOUT: 244 case LAYOUT_MAZE:
213 maze = maze_gen(RP->Xsize,RP->Ysize,RANDOM()%2); 245 maze = maze_gen (RP->Xsize, RP->Ysize, rndm (2));
214 if(!(RANDOM()%2)) doorify_layout(maze,RP); 246 if (!(rndm (2)))
247 doorify_layout (maze, RP);
215 break; 248 break;
216 249
217 case SPIRAL_LAYOUT: 250 case LAYOUT_SPIRAL:
218 maze = map_gen_spiral(RP->Xsize,RP->Ysize,RP->layoutoptions1); 251 maze = map_gen_spiral (RP->Xsize, RP->Ysize, RP->layoutoptions1);
219 if(!(RANDOM()%2)) doorify_layout(maze,RP); 252 if (!(rndm (2)))
253 doorify_layout (maze, RP);
220 break; 254 break;
221 255
222 case ROGUELIKE_LAYOUT: 256 case LAYOUT_ROGUELIKE:
223 /* 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
224 * do so in the first place (doesn't make it any more interesting), 258 * do so in the first place (doesn't make it any more interesting),
225 * but more importantly, the symmetry code presumes we are symmetrizing 259 * but more importantly, the symmetry code presumes we are symmetrizing
226 * spirals, or maps with lots of passages - making a symmetric rogue 260 * spirals, or maps with lots of passages - making a symmetric rogue
227 * map fails because its likely that the passages the symmetry process 261 * map fails because its likely that the passages the symmetry process
228 * creates may not connect the rooms. 262 * creates may not connect the rooms.
229 */ 263 */
230 RP->symmetry_used = NO_SYM; 264 RP->symmetry_used = SYMMETRY_NONE;
231 RP->Ysize = oysize; 265 RP->Ysize = oysize;
232 RP->Xsize = oxsize; 266 RP->Xsize = oxsize;
233 maze = roguelike_layout_gen(RP->Xsize,RP->Ysize,RP->layoutoptions1); 267 maze = roguelike_layout_gen (RP->Xsize, RP->Ysize, RP->layoutoptions1);
234 /* no doorifying... done already */ 268 /* no doorifying... done already */
235 break; 269 break;
236 270
237 case SNAKE_LAYOUT: 271 case LAYOUT_SNAKE:
238 maze = make_snake_layout(RP->Xsize,RP->Ysize,RP->layoutoptions1); 272 maze = make_snake_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1);
239 if(RANDOM()%2) roomify_layout(maze,RP); 273 if (rndm (2))
274 roomify_layout (maze, RP);
240 break; 275 break;
241 276
242 case SQUARE_SPIRAL_LAYOUT: 277 case LAYOUT_SQUARE_SPIRAL:
243 maze = make_square_spiral_layout(RP->Xsize,RP->Ysize,RP->layoutoptions1); 278 maze = make_square_spiral_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1);
244 if(RANDOM()%2) roomify_layout(maze,RP); 279 if (rndm (2))
280 roomify_layout (maze, RP);
245 break; 281 break;
246 } 282 }
247 283
248 maze = symmetrize_layout(maze, RP->symmetry_used,RP); 284 maze = symmetrize_layout (maze, RP->symmetry_used, RP);
285
249#ifdef RMAP_DEBUG 286#ifdef RMAP_DEBUG
250 dump_layout(maze,RP); 287 dump_layout (maze, RP);
251#endif 288#endif
289
252 if(RP->expand2x) { 290 if (RP->expand2x)
291 {
253 maze = expand2x(maze,RP->Xsize,RP->Ysize); 292 maze = expand2x (maze, RP->Xsize, RP->Ysize);
254 RP->Xsize = RP->Xsize * 2 -1; 293 RP->Xsize = RP->Xsize * 2 - 1;
255 RP->Ysize = RP->Ysize * 2 -1; 294 RP->Ysize = RP->Ysize * 2 - 1;
256 } 295 }
296
257 return maze; 297 return maze;
258} 298}
259
260 299
261/* takes a map and makes it symmetric: adjusts Xsize and 300/* takes a map and makes it symmetric: adjusts Xsize and
262Ysize to produce a symmetric map. */ 301Ysize to produce a symmetric map. */
263 302char **
264char **symmetrize_layout(char **maze, int sym,RMParms *RP) { 303symmetrize_layout (char **maze, int sym, random_map_params *RP)
304{
265 int i,j; 305 int i, j;
266 char **sym_maze; 306 char **sym_maze;
267 int Xsize_orig,Ysize_orig; 307 int Xsize_orig, Ysize_orig;
308
268 Xsize_orig = RP->Xsize; 309 Xsize_orig = RP->Xsize;
269 Ysize_orig = RP->Ysize; 310 Ysize_orig = RP->Ysize;
270 RP->symmetry_used = sym; /* tell everyone else what sort of symmetry is used.*/ 311 RP->symmetry_used = sym; /* tell everyone else what sort of symmetry is used. */
271 if(sym == NO_SYM) { 312 if (sym == SYMMETRY_NONE)
313 {
272 RP->Xsize = Xsize_orig; 314 RP->Xsize = Xsize_orig;
273 RP->Ysize = Ysize_orig; 315 RP->Ysize = Ysize_orig;
274 return maze; 316 return maze;
275 } 317 }
276 /* pick new sizes */ 318 /* pick new sizes */
277 RP->Xsize = ((sym==X_SYM||sym==XY_SYM)?RP->Xsize*2-3:RP->Xsize); 319 RP->Xsize = ((sym == SYMMETRY_X || sym == SYMMETRY_XY) ? RP->Xsize * 2 - 3 : RP->Xsize);
278 RP->Ysize = ((sym==Y_SYM||sym==XY_SYM)?RP->Ysize*2-3:RP->Ysize); 320 RP->Ysize = ((sym == SYMMETRY_Y || sym == SYMMETRY_XY) ? RP->Ysize * 2 - 3 : RP->Ysize);
279 321
280 sym_maze = (char **)calloc(sizeof(char*),RP->Xsize); 322 sym_maze = (char **) calloc (sizeof (char *), RP->Xsize);
281 for(i=0;i<RP->Xsize;i++) 323 for (i = 0; i < RP->Xsize; i++)
282 sym_maze[i] = (char *)calloc(sizeof(char),RP->Ysize); 324 sym_maze[i] = (char *) calloc (sizeof (char), RP->Ysize);
283 325
284 if(sym==X_SYM) 326 if (sym == SYMMETRY_X)
285 for(i=0;i<RP->Xsize/2+1;i++) 327 for (i = 0; i < RP->Xsize / 2 + 1; i++)
286 for(j=0;j<RP->Ysize;j++) { 328 for (j = 0; j < RP->Ysize; j++)
329 {
287 sym_maze[i][j] = maze[i][j]; 330 sym_maze[i][j] = maze[i][j];
288 sym_maze[RP->Xsize - i-1][j] = maze[i][j]; 331 sym_maze[RP->Xsize - i - 1][j] = maze[i][j];
289 }; 332 };
290 if(sym==Y_SYM) 333 if (sym == SYMMETRY_Y)
291 for(i=0;i<RP->Xsize;i++) 334 for (i = 0; i < RP->Xsize; i++)
292 for(j=0;j<RP->Ysize/2+1;j++) { 335 for (j = 0; j < RP->Ysize / 2 + 1; j++)
336 {
293 sym_maze[i][j] = maze[i][j]; 337 sym_maze[i][j] = maze[i][j];
294 sym_maze[i][RP->Ysize-j-1] = maze[i][j]; 338 sym_maze[i][RP->Ysize - j - 1] = maze[i][j];
295 } 339 }
296 if(sym==XY_SYM) 340 if (sym == SYMMETRY_XY)
297 for(i=0;i<RP->Xsize/2+1;i++) 341 for (i = 0; i < RP->Xsize / 2 + 1; i++)
298 for(j=0;j<RP->Ysize/2+1;j++) { 342 for (j = 0; j < RP->Ysize / 2 + 1; j++)
343 {
299 sym_maze[i][j] = maze[i][j]; 344 sym_maze[i][j] = maze[i][j];
300 sym_maze[i][RP->Ysize-j-1] = maze[i][j]; 345 sym_maze[i][RP->Ysize - j - 1] = maze[i][j];
301 sym_maze[RP->Xsize - i-1][j] = maze[i][j]; 346 sym_maze[RP->Xsize - i - 1][j] = maze[i][j];
302 sym_maze[RP->Xsize - i-1][RP->Ysize-j-1] = maze[i][j]; 347 sym_maze[RP->Xsize - i - 1][RP->Ysize - j - 1] = maze[i][j];
303 } 348 }
304 /* delete the old maze */ 349 /* delete the old maze */
305 for(i=0;i<Xsize_orig;i++) 350 for (i = 0; i < Xsize_orig; i++)
306 free(maze[i]); 351 free (maze[i]);
307 free(maze); 352 free (maze);
308 /* reconnect disjointed spirals */ 353 /* reconnect disjointed spirals */
309 if(RP->map_layout_style==SPIRAL_LAYOUT) 354 if (RP->map_layout_style == LAYOUT_SPIRAL)
310 connect_spirals(RP->Xsize,RP->Ysize,sym,sym_maze); 355 connect_spirals (RP->Xsize, RP->Ysize, sym, sym_maze);
311 /* reconnect disjointed nethackmazes: the routine for 356 /* reconnect disjointed nethackmazes: the routine for
312 spirals will do the trick?*/ 357 spirals will do the trick? */
313 if(RP->map_layout_style==ROGUELIKE_LAYOUT) 358 if (RP->map_layout_style == LAYOUT_ROGUELIKE)
314 connect_spirals(RP->Xsize,RP->Ysize,sym,sym_maze); 359 connect_spirals (RP->Xsize, RP->Ysize, sym, sym_maze);
315 360
316 return sym_maze; 361 return sym_maze;
317} 362}
318 363
319 364
320/* takes a map and rotates it. This completes the 365/* takes a map and rotates it. This completes the
321 onion layouts, making them possibly centered on any wall. 366 onion layouts, making them possibly centered on any wall.
322 It'll modify Xsize and Ysize if they're swapped. 367 It'll modify Xsize and Ysize if they're swapped.
323*/ 368*/
324 369
370char **
325char ** rotate_layout(char **maze,int rotation,RMParms *RP) { 371rotate_layout (char **maze, int rotation, random_map_params *RP)
372{
326 char **new_maze; 373 char **new_maze;
327 int i,j; 374 int i, j;
328 375
329 switch(rotation) { 376 switch (rotation)
377 {
330 case 0: 378 case 0:
331 return maze;
332 break;
333 case 2: /* a reflection */
334 {
335 char *newmaze= (char *) malloc(sizeof(char) * RP->Xsize*RP->Ysize);
336 for(i=0;i<RP->Xsize;i++) { /* make a copy */
337 for(j=0;j<RP->Ysize;j++) {
338 newmaze[i * RP->Ysize + j] = maze[i][j];
339 }
340 }
341 for(i=0;i<RP->Xsize;i++) { /* copy a reflection back */
342 for(j=0;j<RP->Ysize;j++) {
343 maze[i][j]= newmaze[(RP->Xsize-i-1)*RP->Ysize + RP->Ysize-j-1];
344 }
345 }
346 free(newmaze);
347 return maze; 379 return maze;
348 break; 380 break;
349 } 381 case 2: /* a reflection */
382 {
383 char *newmaze = (char *) malloc (sizeof (char) * RP->Xsize * RP->Ysize);
384
385 for (i = 0; i < RP->Xsize; i++)
386 { /* make a copy */
387 for (j = 0; j < RP->Ysize; j++)
388 {
389 newmaze[i * RP->Ysize + j] = maze[i][j];
390 }
391 }
392 for (i = 0; i < RP->Xsize; i++)
393 { /* copy a reflection back */
394 for (j = 0; j < RP->Ysize; j++)
395 {
396 maze[i][j] = newmaze[(RP->Xsize - i - 1) * RP->Ysize + RP->Ysize - j - 1];
397 }
398 }
399 free (newmaze);
400 return maze;
401 break;
402 }
350 case 1: 403 case 1:
351 case 3: 404 case 3:
405 {
352 { int swap; 406 int swap;
353 new_maze = (char **) calloc(sizeof(char *),RP->Ysize); 407 new_maze = (char **) calloc (sizeof (char *), RP->Ysize);
354 for(i=0;i<RP->Ysize;i++) { 408 for (i = 0; i < RP->Ysize; i++)
409 {
355 new_maze[i] = (char *) calloc(sizeof(char),RP->Xsize); 410 new_maze[i] = (char *) calloc (sizeof (char), RP->Xsize);
356 } 411 }
357 if(rotation == 1) /* swap x and y */ 412 if (rotation == 1) /* swap x and y */
358 for(i=0;i<RP->Xsize;i++) 413 for (i = 0; i < RP->Xsize; i++)
359 for(j=0;j<RP->Ysize;j++) 414 for (j = 0; j < RP->Ysize; j++)
360 new_maze[j][i] = maze[i][j]; 415 new_maze[j][i] = maze[i][j];
361 416
362 if(rotation == 3) { /* swap x and y */ 417 if (rotation == 3)
418 { /* swap x and y */
363 for(i=0;i<RP->Xsize;i++) 419 for (i = 0; i < RP->Xsize; i++)
364 for(j=0;j<RP->Ysize;j++) 420 for (j = 0; j < RP->Ysize; j++)
365 new_maze[j][i] = maze[RP->Xsize -i-1][RP->Ysize - j-1]; 421 new_maze[j][i] = maze[RP->Xsize - i - 1][RP->Ysize - j - 1];
366 } 422 }
367 423
368 /* delete the old layout */ 424 /* delete the old layout */
369 for(i=0;i<RP->Xsize;i++) 425 for (i = 0; i < RP->Xsize; i++)
370 free(maze[i]); 426 free (maze[i]);
371 free(maze); 427 free (maze);
372 428
373 swap = RP->Ysize; 429 swap = RP->Ysize;
374 RP->Ysize = RP->Xsize; 430 RP->Ysize = RP->Xsize;
375 RP->Xsize = swap; 431 RP->Xsize = swap;
376 return new_maze; 432 return new_maze;
377 break; 433 break;
378 } 434 }
379 } 435 }
380 return NULL; 436 return NULL;
381} 437}
382 438
383/* take a layout and make some rooms in it. 439/* take a layout and make some rooms in it.
384 --works best on onions.*/ 440 --works best on onions.*/
385void roomify_layout(char **maze,RMParms *RP) { 441void
442roomify_layout (char **maze, random_map_params *RP)
443{
386 int tries = RP->Xsize*RP->Ysize/30; 444 int tries = RP->Xsize * RP->Ysize / 30;
387 int ti; 445 int ti;
388 446
389 for(ti=0;ti<tries;ti++) { 447 for (ti = 0; ti < tries; ti++)
448 {
390 int dx,dy; /* starting location for looking at creating a door */ 449 int dx, dy; /* starting location for looking at creating a door */
391 int cx,cy; /* results of checking on creating walls. */ 450 int cx, cy; /* results of checking on creating walls. */
451
392 dx = RANDOM() % RP->Xsize; 452 dx = RANDOM () % RP->Xsize;
393 dy = RANDOM() % RP->Ysize; 453 dy = RANDOM () % RP->Ysize;
394 cx = can_make_wall(maze,dx,dy,0,RP); /* horizontal */ 454 cx = can_make_wall (maze, dx, dy, 0, RP); /* horizontal */
395 cy = can_make_wall(maze,dx,dy,1,RP); /* vertical */ 455 cy = can_make_wall (maze, dx, dy, 1, RP); /* vertical */
396 if(cx == -1) { 456 if (cx == -1)
457 {
458 if (cy != -1)
459 make_wall (maze, dx, dy, 1);
460 continue;
461 }
397 if(cy != -1) 462 if (cy == -1)
463 {
464 make_wall (maze, dx, dy, 0);
465 continue;
466 }
467 if (cx < cy)
468 make_wall (maze, dx, dy, 0);
469 else
398 make_wall(maze,dx,dy,1); 470 make_wall (maze, dx, dy, 1);
399 continue;
400 }
401 if(cy == -1) {
402 make_wall(maze,dx,dy,0);
403 continue;
404 }
405 if(cx < cy) make_wall(maze,dx,dy,0);
406 else make_wall(maze,dx,dy,1);
407 } 471 }
408} 472}
409 473
410/* checks the layout to see if I can stick a horizontal(dir = 0) wall 474/* checks the layout to see if I can stick a horizontal(dir = 0) wall
411 (or vertical, dir == 1) 475 (or vertical, dir == 1)
412 here which ends up on other walls sensibly. */ 476 here which ends up on other walls sensibly. */
413 477
478int
414int can_make_wall(char **maze,int dx,int dy,int dir,RMParms *RP) { 479can_make_wall (char **maze, int dx, int dy, int dir, random_map_params *RP)
480{
415 int i1; 481 int i1;
416 int length=0; 482 int length = 0;
417 483
418 /* dont make walls if we're on the edge. */ 484 /* dont make walls if we're on the edge. */
419 if(dx == 0 || dx == (RP->Xsize -1) || dy == 0 || dy == (RP->Ysize-1)) return -1; 485 if (dx == 0 || dx == (RP->Xsize - 1) || dy == 0 || dy == (RP->Ysize - 1))
486 return -1;
420 487
421 /* don't make walls if we're ON a wall. */ 488 /* don't make walls if we're ON a wall. */
422 if(maze[dx][dy]!=0) return -1; 489 if (maze[dx][dy] != 0)
490 return -1;
423 491
424 if(dir==0) /* horizontal */ 492 if (dir == 0) /* horizontal */
425 { 493 {
426 int y = dy; 494 int y = dy;
495
427 for(i1=dx-1;i1>0;i1--) { 496 for (i1 = dx - 1; i1 > 0; i1--)
497 {
428 int sindex=surround_flag2(maze,i1,y,RP); 498 int sindex = surround_flag2 (maze, i1, y, RP);
499
429 if(sindex == 1) break; 500 if (sindex == 1)
501 break;
502 if (sindex != 0)
430 if(sindex != 0) return -1; /* can't make horiz. wall here */ 503 return -1; /* can't make horiz. wall here */
504 if (maze[i1][y] != 0)
431 if(maze[i1][y]!=0) return -1; /* can't make horiz. wall here */ 505 return -1; /* can't make horiz. wall here */
432 length++; 506 length++;
433 }
434 507 }
508
435 for(i1=dx+1;i1<RP->Xsize-1;i1++) { 509 for (i1 = dx + 1; i1 < RP->Xsize - 1; i1++)
510 {
436 int sindex=surround_flag2(maze,i1,y,RP); 511 int sindex = surround_flag2 (maze, i1, y, RP);
512
437 if(sindex == 2) break; 513 if (sindex == 2)
514 break;
515 if (sindex != 0)
438 if(sindex != 0) return -1; /* can't make horiz. wall here */ 516 return -1; /* can't make horiz. wall here */
517 if (maze[i1][y] != 0)
439 if(maze[i1][y]!=0) return -1; /* can't make horiz. wall here */ 518 return -1; /* can't make horiz. wall here */
440 length++; 519 length++;
441 } 520 }
442 return length; 521 return length;
443 } 522 }
444 else { /* vertical */ 523 else
524 { /* vertical */
445 int x = dx; 525 int x = dx;
526
446 for(i1=dy-1;i1>0;i1--) { 527 for (i1 = dy - 1; i1 > 0; i1--)
447 int sindex=surround_flag2(maze,x,i1,RP);
448 if(sindex == 4) break;
449 if(sindex != 0) return -1; /* can't make vert. wall here */
450 if(maze[x][i1]!=0) return -1; /* can't make horiz. wall here */
451 length++;
452 }
453 528 {
454 for(i1=dy+1;i1<RP->Ysize-1;i1++) {
455 int sindex=surround_flag2(maze,x,i1,RP); 529 int sindex = surround_flag2 (maze, x, i1, RP);
456 if(sindex == 8) break; 530
531 if (sindex == 4)
532 break;
533 if (sindex != 0)
457 if(sindex != 0) return -1; /* can't make verti. wall here */ 534 return -1; /* can't make vert. wall here */
535 if (maze[x][i1] != 0)
458 if(maze[x][i1]!=0) return -1; /* can't make horiz. wall here */ 536 return -1; /* can't make horiz. wall here */
459 length++; 537 length++;
460 } 538 }
539
540 for (i1 = dy + 1; i1 < RP->Ysize - 1; i1++)
541 {
542 int sindex = surround_flag2 (maze, x, i1, RP);
543
544 if (sindex == 8)
545 break;
546 if (sindex != 0)
547 return -1; /* can't make verti. wall here */
548 if (maze[x][i1] != 0)
549 return -1; /* can't make horiz. wall here */
550 length++;
551 }
461 return length; 552 return length;
462 } 553 }
463 return -1; 554 return -1;
464} 555}
465 556
466 557
558int
467int make_wall(char **maze,int x, int y, int dir){ 559make_wall (char **maze, int x, int y, int dir)
560{
468 maze[x][y] = 'D'; /* mark a door */ 561 maze[x][y] = 'D'; /* mark a door */
469 switch(dir) { 562 switch (dir)
470 case 0: /* horizontal */
471 { 563 {
564 case 0: /* horizontal */
565 {
472 int i1; 566 int i1;
567
473 for(i1 = x-1;maze[i1][y]==0;i1--) 568 for (i1 = x - 1; maze[i1][y] == 0; i1--)
474 maze[i1][y]='#'; 569 maze[i1][y] = '#';
475 for(i1 = x+1;maze[i1][y]==0;i1++) 570 for (i1 = x + 1; maze[i1][y] == 0; i1++)
476 maze[i1][y]='#'; 571 maze[i1][y] = '#';
477 break; 572 break;
478 } 573 }
479 case 1: /* vertical */ 574 case 1: /* vertical */
480 { 575 {
481 int i1; 576 int i1;
577
482 for(i1 = y-1;maze[x][i1]==0;i1--) 578 for (i1 = y - 1; maze[x][i1] == 0; i1--)
483 maze[x][i1]='#'; 579 maze[x][i1] = '#';
484 for(i1 = y+1;maze[x][i1]==0;i1++) 580 for (i1 = y + 1; maze[x][i1] == 0; i1++)
485 maze[x][i1]='#'; 581 maze[x][i1] = '#';
486 break; 582 break;
583 }
487 } 584 }
488 }
489 585
490 return 0; 586 return 0;
491} 587}
492 588
493/* puts doors at appropriate locations in a layout. */ 589/* puts doors at appropriate locations in a layout. */
494 590void
495void doorify_layout(char **maze,RMParms *RP) { 591doorify_layout (char **maze, random_map_params *RP)
592{
496 int ndoors = RP->Xsize*RP->Ysize/60; /* reasonable number of doors. */ 593 int ndoors = RP->Xsize * RP->Ysize / 60; /* reasonable number of doors. */
497 char *doorlist_x; 594 char *doorlist_x;
498 char *doorlist_y; 595 char *doorlist_y;
499 int doorlocs = 0; /* # of available doorlocations */ 596 int doorlocs = 0; /* # of available doorlocations */
500 int i,j; 597 int i, j;
501 598
502 doorlist_x = (char *) malloc(sizeof(int) * RP->Xsize*RP->Ysize); 599 doorlist_x = (char *) malloc (sizeof (int) * RP->Xsize * RP->Ysize);
503 doorlist_y = (char *) malloc(sizeof(int) * RP->Xsize*RP->Ysize); 600 doorlist_y = (char *) malloc (sizeof (int) * RP->Xsize * RP->Ysize);
504 601
505 602
506 /* make a list of possible door locations */ 603 /* make a list of possible door locations */
507 for(i=1;i<RP->Xsize-1;i++) 604 for (i = 1; i < RP->Xsize - 1; i++)
508 for(j=1;j<RP->Ysize-1;j++) { 605 for (j = 1; j < RP->Ysize - 1; j++)
509 int sindex = surround_flag(maze,i,j,RP);
510 if(sindex == 3 || sindex == 12) /* these are possible door sindex*/
511 {
512 doorlist_x[doorlocs]=i;
513 doorlist_y[doorlocs]=j;
514 doorlocs++;
515 }
516 }
517 while(ndoors > 0 && doorlocs > 0) {
518 int di;
519 int sindex;
520 di = RANDOM() % doorlocs;
521 i=doorlist_x[di];
522 j=doorlist_y[di];
523 sindex= surround_flag(maze,i,j,RP);
524 if(sindex == 3 || sindex == 12) /* these are possible door sindex*/
525 { 606 {
526 maze[i][j] = 'D'; 607 int sindex = surround_flag (maze, i, j, RP);
527 ndoors--; 608
609 if (sindex == 3 || sindex == 12) /* these are possible door sindex */
610 {
611 doorlist_x[doorlocs] = i;
612 doorlist_y[doorlocs] = j;
613 doorlocs++;
614 }
528 } 615 }
616
617 while (ndoors > 0 && doorlocs > 0)
618 {
619 int di;
620 int sindex;
621
622 di = RANDOM () % doorlocs;
623 i = doorlist_x[di];
624 j = doorlist_y[di];
625 sindex = surround_flag (maze, i, j, RP);
626 if (sindex == 3 || sindex == 12) /* these are possible door sindex */
627 {
628 maze[i][j] = 'D';
629 ndoors--;
630 }
529 /* reduce the size of the list */ 631 /* reduce the size of the list */
530 doorlocs--; 632 doorlocs--;
531 doorlist_x[di]=doorlist_x[doorlocs]; 633 doorlist_x[di] = doorlist_x[doorlocs];
532 doorlist_y[di]=doorlist_y[doorlocs]; 634 doorlist_y[di] = doorlist_y[doorlocs];
533 } 635 }
636
534 free(doorlist_x); 637 free (doorlist_x);
535 free(doorlist_y); 638 free (doorlist_y);
536} 639}
537 640
538 641void
539void write_map_parameters_to_string(char *buf,RMParms *RP) { 642write_map_parameters_to_string (char *buf, random_map_params *RP)
540 643{
541 char small_buf[256]; 644 char small_buf[16384];
645
542 sprintf(buf,"xsize %d\nysize %d\n",RP->Xsize,RP->Ysize); 646 sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize);
543 647
544 if(RP->wallstyle[0]) { 648 if (RP->wallstyle[0])
649 {
545 sprintf(small_buf,"wallstyle %s\n",RP->wallstyle); 650 sprintf (small_buf, "wallstyle %s\n", RP->wallstyle);
546 strcat(buf,small_buf); 651 strcat (buf, small_buf);
547 } 652 }
548 653
549 if(RP->floorstyle[0]) { 654 if (RP->floorstyle[0])
655 {
550 sprintf(small_buf,"floorstyle %s\n",RP->floorstyle); 656 sprintf (small_buf, "floorstyle %s\n", RP->floorstyle);
551 strcat(buf,small_buf); 657 strcat (buf, small_buf);
552 } 658 }
553 659
554 if(RP->monsterstyle[0]) { 660 if (RP->monsterstyle[0])
661 {
555 sprintf(small_buf,"monsterstyle %s\n",RP->monsterstyle); 662 sprintf (small_buf, "monsterstyle %s\n", RP->monsterstyle);
556 strcat(buf,small_buf); 663 strcat (buf, small_buf);
557 } 664 }
558 665
559 if(RP->treasurestyle[0]) { 666 if (RP->treasurestyle[0])
667 {
560 sprintf(small_buf,"treasurestyle %s\n",RP->treasurestyle); 668 sprintf (small_buf, "treasurestyle %s\n", RP->treasurestyle);
561 strcat(buf,small_buf); 669 strcat (buf, small_buf);
562 } 670 }
563 671
564 if(RP->layoutstyle[0]) { 672 if (RP->layoutstyle[0])
673 {
565 sprintf(small_buf,"layoutstyle %s\n",RP->layoutstyle); 674 sprintf (small_buf, "layoutstyle %s\n", RP->layoutstyle);
566 strcat(buf,small_buf); 675 strcat (buf, small_buf);
567 } 676 }
568 677
569 if(RP->decorstyle[0]) { 678 if (RP->decorstyle[0])
679 {
570 sprintf(small_buf,"decorstyle %s\n",RP->decorstyle); 680 sprintf (small_buf, "decorstyle %s\n", RP->decorstyle);
571 strcat(buf,small_buf); 681 strcat (buf, small_buf);
572 } 682 }
573 683
574 if(RP->doorstyle[0]) { 684 if (RP->doorstyle[0])
685 {
575 sprintf(small_buf,"doorstyle %s\n",RP->doorstyle); 686 sprintf (small_buf, "doorstyle %s\n", RP->doorstyle);
576 strcat(buf,small_buf); 687 strcat (buf, small_buf);
577 } 688 }
578 689
579 if(RP->exitstyle[0]) { 690 if (RP->exitstyle[0])
691 {
580 sprintf(small_buf,"exitstyle %s\n",RP->exitstyle); 692 sprintf (small_buf, "exitstyle %s\n", RP->exitstyle);
581 strcat(buf,small_buf); 693 strcat (buf, small_buf);
582 } 694 }
583 695
584 if(RP->final_map[0]) { 696 if (RP->final_map.length ())
697 {
585 sprintf(small_buf,"final_map %s\n",RP->final_map); 698 sprintf (small_buf, "final_map %s\n", &RP->final_map);
586 strcat(buf,small_buf); 699 strcat (buf, small_buf);
587 } 700 }
588 701
589 if(RP->exit_on_final_map[0]) { 702 if (RP->exit_on_final_map[0])
703 {
590 sprintf(small_buf,"exit_on_final_map %s\n",RP->exit_on_final_map); 704 sprintf (small_buf, "exit_on_final_map %s\n", RP->exit_on_final_map);
591 strcat(buf,small_buf); 705 strcat (buf, small_buf);
592 } 706 }
593 707
594 if(RP->this_map[0]) { 708 if (RP->this_map.length ())
709 {
595 sprintf(small_buf,"origin_map %s\n",RP->this_map); 710 sprintf (small_buf, "origin_map %s\n", &RP->this_map);
596 strcat(buf,small_buf); 711 strcat (buf, small_buf);
597 } 712 }
598 713
599 if(RP->expand2x) { 714 if (RP->expand2x)
715 {
600 sprintf(small_buf,"expand2x %d\n",RP->expand2x); 716 sprintf (small_buf, "expand2x %d\n", RP->expand2x);
601 strcat(buf,small_buf); 717 strcat (buf, small_buf);
602 } 718 }
603 719
604 if(RP->layoutoptions1) { 720 if (RP->layoutoptions1)
721 {
605 sprintf(small_buf,"layoutoptions1 %d\n",RP->layoutoptions1); 722 sprintf (small_buf, "layoutoptions1 %d\n", RP->layoutoptions1);
606 strcat(buf,small_buf); 723 strcat (buf, small_buf);
607 } 724 }
608 725
609
610 if(RP->layoutoptions2) { 726 if (RP->layoutoptions2)
727 {
611 sprintf(small_buf,"layoutoptions2 %d\n",RP->layoutoptions2); 728 sprintf (small_buf, "layoutoptions2 %d\n", RP->layoutoptions2);
612 strcat(buf,small_buf); 729 strcat (buf, small_buf);
613 } 730 }
614 731
615
616 if(RP->layoutoptions3) { 732 if (RP->layoutoptions3)
733 {
617 sprintf(small_buf,"layoutoptions3 %d\n",RP->layoutoptions3); 734 sprintf (small_buf, "layoutoptions3 %d\n", RP->layoutoptions3);
618 strcat(buf,small_buf); 735 strcat (buf, small_buf);
619 } 736 }
620 737
621 if(RP->symmetry) { 738 if (RP->symmetry)
739 {
622 sprintf(small_buf,"symmetry %d\n",RP->symmetry); 740 sprintf (small_buf, "symmetry %d\n", RP->symmetry);
623 strcat(buf,small_buf); 741 strcat (buf, small_buf);
624 } 742 }
625 743
626
627 if(RP->difficulty && RP->difficulty_given ) { 744 if (RP->difficulty && RP->difficulty_given)
745 {
628 sprintf(small_buf,"difficulty %d\n",RP->difficulty); 746 sprintf (small_buf, "difficulty %d\n", RP->difficulty);
629 strcat(buf,small_buf); 747 strcat (buf, small_buf);
630 } 748 }
631 749
632 if(RP->difficulty_increase != 1.0 ) { 750 if (RP->difficulty_increase != 1.0)
751 {
633 sprintf(small_buf,"difficulty_increase %f\n",RP->difficulty_increase); 752 sprintf (small_buf, "difficulty_increase %f\n", RP->difficulty_increase);
634 strcat(buf,small_buf); 753 strcat (buf, small_buf);
635 } 754 }
636 755
637 sprintf(small_buf,"dungeon_level %d\n",RP->dungeon_level); 756 sprintf (small_buf, "dungeon_level %d\n", RP->dungeon_level);
638 strcat(buf,small_buf); 757 strcat (buf, small_buf);
639 758
640 if(RP->dungeon_depth) { 759 if (RP->dungeon_depth)
760 {
641 sprintf(small_buf,"dungeon_depth %d\n",RP->dungeon_depth); 761 sprintf (small_buf, "dungeon_depth %d\n", RP->dungeon_depth);
642 strcat(buf,small_buf); 762 strcat (buf, small_buf);
643 } 763 }
644 764
645 if(RP->decoroptions) { 765 if (RP->decoroptions)
766 {
646 sprintf(small_buf,"decoroptions %d\n",RP->decoroptions); 767 sprintf (small_buf, "decoroptions %d\n", RP->decoroptions);
647 strcat(buf,small_buf); 768 strcat (buf, small_buf);
648 } 769 }
649 770
650 if(RP->orientation) { 771 if (RP->orientation)
772 {
651 sprintf(small_buf,"orientation %d\n",RP->orientation); 773 sprintf (small_buf, "orientation %d\n", RP->orientation);
652 strcat(buf,small_buf); 774 strcat (buf, small_buf);
653 } 775 }
654 776
655 if(RP->origin_x) { 777 if (RP->origin_x)
778 {
656 sprintf(small_buf,"origin_x %d\n",RP->origin_x); 779 sprintf (small_buf, "origin_x %d\n", RP->origin_x);
657 strcat(buf,small_buf); 780 strcat (buf, small_buf);
658 } 781 }
659 782
660 if(RP->origin_y) { 783 if (RP->origin_y)
784 {
661 sprintf(small_buf,"origin_y %d\n",RP->origin_y); 785 sprintf (small_buf, "origin_y %d\n", RP->origin_y);
662 strcat(buf,small_buf); 786 strcat (buf, small_buf);
663 } 787 }
788
789 if (RP->treasureoptions)
790 {
791 sprintf (small_buf, "treasureoptions %d\n", RP->treasureoptions);
792 strcat (buf, small_buf);
793 }
794
664 if(RP->random_seed) { 795 if (RP->random_seed)
796 {
797 sprintf (small_buf, "random_seed %d\n", RP->random_seed);
798 strcat (buf, small_buf);
799 }
800
801 if (RP->custom)
802 {
803 sprintf (small_buf, "custom %s\n", RP->custom);
804 strcat (buf, small_buf);
805 }
806}
807
808void
809write_parameters_to_string (char *buf,
810 int xsize_n,
811 int ysize_n,
812 char *wallstyle_n,
813 char *floorstyle_n,
814 char *monsterstyle_n,
815 char *treasurestyle_n,
816 char *layoutstyle_n,
817 char *decorstyle_n,
818 char *doorstyle_n,
819 char *exitstyle_n,
820 char *final_map_n,
821 char *exit_on_final_map_n,
822 char *this_map_n,
823 int layoutoptions1_n,
824 int layoutoptions2_n,
825 int layoutoptions3_n,
826 int symmetry_n,
827 int dungeon_depth_n,
828 int dungeon_level_n,
829 int difficulty_n,
830 int difficulty_given_n,
831 int decoroptions_n,
832 int orientation_n,
833 int origin_x_n, int origin_y_n, int random_seed_n, int treasureoptions_n, float difficulty_increase)
834{
835 char small_buf[16384];
836
837 sprintf (buf, "xsize %d\nysize %d\n", xsize_n, ysize_n);
838
839 if (wallstyle_n && wallstyle_n[0])
840 {
841 sprintf (small_buf, "wallstyle %s\n", wallstyle_n);
842 strcat (buf, small_buf);
843 }
844
845 if (floorstyle_n && floorstyle_n[0])
846 {
847 sprintf (small_buf, "floorstyle %s\n", floorstyle_n);
848 strcat (buf, small_buf);
849 }
850
851 if (monsterstyle_n && monsterstyle_n[0])
852 {
853 sprintf (small_buf, "monsterstyle %s\n", monsterstyle_n);
854 strcat (buf, small_buf);
855 }
856
857 if (treasurestyle_n && treasurestyle_n[0])
858 {
859 sprintf (small_buf, "treasurestyle %s\n", treasurestyle_n);
860 strcat (buf, small_buf);
861 }
862
863 if (layoutstyle_n && layoutstyle_n[0])
864 {
865 sprintf (small_buf, "layoutstyle %s\n", layoutstyle_n);
866 strcat (buf, small_buf);
867 }
868
869 if (decorstyle_n && decorstyle_n[0])
870 {
871 sprintf (small_buf, "decorstyle %s\n", decorstyle_n);
872 strcat (buf, small_buf);
873 }
874
875 if (doorstyle_n && doorstyle_n[0])
876 {
877 sprintf (small_buf, "doorstyle %s\n", doorstyle_n);
878 strcat (buf, small_buf);
879 }
880
881 if (exitstyle_n && exitstyle_n[0])
882 {
883 sprintf (small_buf, "exitstyle %s\n", exitstyle_n);
884 strcat (buf, small_buf);
885 }
886
887 if (final_map_n && final_map_n[0])
888 {
889 sprintf (small_buf, "final_map %s\n", final_map_n);
890 strcat (buf, small_buf);
891 }
892
893 if (exit_on_final_map_n && exit_on_final_map_n[0])
894 {
895 sprintf (small_buf, "exit_on_final_map %s\n", exit_on_final_map_n);
896 strcat (buf, small_buf);
897 }
898
899 if (this_map_n && this_map_n[0])
900 {
901 sprintf (small_buf, "origin_map %s\n", this_map_n);
902 strcat (buf, small_buf);
903 }
904
905 if (layoutoptions1_n)
906 {
907 sprintf (small_buf, "layoutoptions1 %d\n", layoutoptions1_n);
908 strcat (buf, small_buf);
909 }
910
911 if (layoutoptions2_n)
912 {
913 sprintf (small_buf, "layoutoptions2 %d\n", layoutoptions2_n);
914 strcat (buf, small_buf);
915 }
916
917
918 if (layoutoptions3_n)
919 {
920 sprintf (small_buf, "layoutoptions3 %d\n", layoutoptions3_n);
921 strcat (buf, small_buf);
922 }
923
924 if (symmetry_n)
925 {
926 sprintf (small_buf, "symmetry %d\n", symmetry_n);
927 strcat (buf, small_buf);
928 }
929
930
931 if (difficulty_n && difficulty_given_n)
932 {
933 sprintf (small_buf, "difficulty %d\n", difficulty_n);
934 strcat (buf, small_buf);
935 }
936
937 if (difficulty_increase > 0.001)
938 {
939 sprintf (small_buf, "difficulty_increase %f\n", difficulty_increase);
940 strcat (buf, small_buf);
941 }
942
943 sprintf (small_buf, "dungeon_level %d\n", dungeon_level_n);
944 strcat (buf, small_buf);
945
946 if (dungeon_depth_n)
947 {
948 sprintf (small_buf, "dungeon_depth %d\n", dungeon_depth_n);
949 strcat (buf, small_buf);
950 }
951
952 if (decoroptions_n)
953 {
954 sprintf (small_buf, "decoroptions %d\n", decoroptions_n);
955 strcat (buf, small_buf);
956 }
957
958 if (orientation_n)
959 {
960 sprintf (small_buf, "orientation %d\n", orientation_n);
961 strcat (buf, small_buf);
962 }
963
964 if (origin_x_n)
965 {
966 sprintf (small_buf, "origin_x %d\n", origin_x_n);
967 strcat (buf, small_buf);
968 }
969
970 if (origin_y_n)
971 {
972 sprintf (small_buf, "origin_y %d\n", origin_y_n);
973 strcat (buf, small_buf);
974 }
975
976 if (random_seed_n)
977 {
665 /* Add one so that the next map is a bit different */ 978 /* Add one so that the next map is a bit different */
666 sprintf(small_buf,"random_seed %d\n",RP->random_seed + 1);
667 strcat(buf,small_buf);
668 }
669
670 if(RP->treasureoptions) {
671 sprintf(small_buf,"treasureoptions %d\n",RP->treasureoptions);
672 strcat(buf,small_buf);
673 }
674
675
676}
677
678void write_parameters_to_string(char *buf,
679 int xsize_n,
680 int ysize_n,
681 char *wallstyle_n,
682 char *floorstyle_n,
683 char *monsterstyle_n,
684 char *treasurestyle_n,
685 char *layoutstyle_n,
686 char *decorstyle_n,
687 char *doorstyle_n,
688 char *exitstyle_n,
689 char *final_map_n,
690 char *exit_on_final_map_n,
691 char *this_map_n,
692 int layoutoptions1_n,
693 int layoutoptions2_n,
694 int layoutoptions3_n,
695 int symmetry_n,
696 int dungeon_depth_n,
697 int dungeon_level_n,
698 int difficulty_n,
699 int difficulty_given_n,
700 int decoroptions_n,
701 int orientation_n,
702 int origin_x_n,
703 int origin_y_n,
704 int random_seed_n,
705 int treasureoptions_n,
706 float difficulty_increase)
707{
708
709 char small_buf[256];
710 sprintf(buf,"xsize %d\nysize %d\n",xsize_n,ysize_n);
711
712 if(wallstyle_n && wallstyle_n[0]) {
713 sprintf(small_buf,"wallstyle %s\n",wallstyle_n);
714 strcat(buf,small_buf);
715 }
716
717 if(floorstyle_n && floorstyle_n[0]) {
718 sprintf(small_buf,"floorstyle %s\n",floorstyle_n);
719 strcat(buf,small_buf);
720 }
721
722 if(monsterstyle_n && monsterstyle_n[0]) {
723 sprintf(small_buf,"monsterstyle %s\n",monsterstyle_n);
724 strcat(buf,small_buf);
725 }
726
727 if(treasurestyle_n && treasurestyle_n[0]) {
728 sprintf(small_buf,"treasurestyle %s\n",treasurestyle_n);
729 strcat(buf,small_buf);
730 }
731
732 if(layoutstyle_n &&layoutstyle_n[0]) {
733 sprintf(small_buf,"layoutstyle %s\n",layoutstyle_n);
734 strcat(buf,small_buf);
735 }
736
737 if(decorstyle_n && decorstyle_n[0]) {
738 sprintf(small_buf,"decorstyle %s\n",decorstyle_n);
739 strcat(buf,small_buf);
740 }
741
742 if(doorstyle_n && doorstyle_n[0]) {
743 sprintf(small_buf,"doorstyle %s\n",doorstyle_n);
744 strcat(buf,small_buf);
745 }
746
747 if(exitstyle_n && exitstyle_n[0]) {
748 sprintf(small_buf,"exitstyle %s\n",exitstyle_n);
749 strcat(buf,small_buf);
750 }
751
752 if(final_map_n && final_map_n[0]) {
753 sprintf(small_buf,"final_map %s\n",final_map_n);
754 strcat(buf,small_buf);
755 }
756
757 if(exit_on_final_map_n && exit_on_final_map_n[0]) {
758 sprintf(small_buf,"exit_on_final_map %s\n",exit_on_final_map_n);
759 strcat(buf,small_buf);
760 }
761
762 if(this_map_n && this_map_n[0]) {
763 sprintf(small_buf,"origin_map %s\n",this_map_n);
764 strcat(buf,small_buf);
765 }
766
767 if(layoutoptions1_n) {
768 sprintf(small_buf,"layoutoptions1 %d\n",layoutoptions1_n);
769 strcat(buf,small_buf);
770 }
771
772
773 if(layoutoptions2_n) {
774 sprintf(small_buf,"layoutoptions2 %d\n",layoutoptions2_n);
775 strcat(buf,small_buf);
776 }
777
778
779 if(layoutoptions3_n) {
780 sprintf(small_buf,"layoutoptions3 %d\n",layoutoptions3_n);
781 strcat(buf,small_buf);
782 }
783
784 if(symmetry_n) {
785 sprintf(small_buf,"symmetry %d\n",symmetry_n);
786 strcat(buf,small_buf);
787 }
788
789
790 if(difficulty_n && difficulty_given_n ) {
791 sprintf(small_buf,"difficulty %d\n",difficulty_n);
792 strcat(buf,small_buf);
793 }
794
795 if(difficulty_increase > 0.001 ) {
796 sprintf(small_buf,"difficulty_increase %f\n",difficulty_increase);
797 strcat(buf,small_buf);
798 }
799
800 sprintf(small_buf,"dungeon_level %d\n",dungeon_level_n);
801 strcat(buf,small_buf);
802
803 if(dungeon_depth_n) {
804 sprintf(small_buf,"dungeon_depth %d\n",dungeon_depth_n);
805 strcat(buf,small_buf);
806 }
807
808 if(decoroptions_n) {
809 sprintf(small_buf,"decoroptions %d\n",decoroptions_n);
810 strcat(buf,small_buf);
811 }
812
813 if(orientation_n) {
814 sprintf(small_buf,"orientation %d\n",orientation_n);
815 strcat(buf,small_buf);
816 }
817
818 if(origin_x_n) {
819 sprintf(small_buf,"origin_x %d\n",origin_x_n);
820 strcat(buf,small_buf);
821 }
822
823 if(origin_y_n) {
824 sprintf(small_buf,"origin_y %d\n",origin_y_n);
825 strcat(buf,small_buf);
826 }
827 if(random_seed_n) {
828 /* Add one so that the next map is a bit different */
829 sprintf(small_buf,"random_seed %d\n",random_seed_n + 1); 979 sprintf (small_buf, "random_seed %d\n", random_seed_n + 1);
830 strcat(buf,small_buf); 980 strcat (buf, small_buf);
831 } 981 }
832 982
833 if(treasureoptions_n) { 983 if (treasureoptions_n)
984 {
834 sprintf(small_buf,"treasureoptions %d\n",treasureoptions_n); 985 sprintf (small_buf, "treasureoptions %d\n", treasureoptions_n);
835 strcat(buf,small_buf); 986 strcat (buf, small_buf);
836 } 987 }
837
838
839} 988}
840 989
841/* copy an object with an inventory... i.e., duplicate the inv too. */ 990/* copy an object with an inventory... i.e., duplicate the inv too. */
991void
842void copy_object_with_inv(object *src_ob, object *dest_ob) { 992copy_object_with_inv (object *src_ob, object *dest_ob)
993{
843 object *walk,*tmp; 994 object *walk, *tmp;
844 995
845 copy_object(src_ob,dest_ob); 996 src_ob->copy_to (dest_ob);
846 997
847 for(walk=src_ob->inv;walk!=NULL;walk=walk->below) { 998 for (walk = src_ob->inv; walk; walk = walk->below)
848 tmp=get_object(); 999 {
849 copy_object(walk,tmp); 1000 tmp = object::create ();
1001
1002 walk->copy_to (tmp);
850 insert_ob_in_ob(tmp,dest_ob); 1003 insert_ob_in_ob (tmp, dest_ob);
851 } 1004 }
852} 1005}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines