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.20 by pippijn, Mon Jan 15 21:06:19 2007 UTC vs.
Revision 1.22 by root, Fri Jan 19 15:29:52 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines