ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/room_gen_onion.C
(Generate patch)

Comparing deliantra/server/random_maps/room_gen_onion.C (file contents):
Revision 1.9 by root, Thu Jan 18 19:42:10 2007 UTC vs.
Revision 1.10 by root, Sat Jan 27 02:19:37 2007 UTC

130 float *ylocations; 130 float *ylocations;
131 131
132 maxlayers = (MIN (xsize, ysize) - 2) / 5; 132 maxlayers = (MIN (xsize, ysize) - 2) / 5;
133 if (!maxlayers) 133 if (!maxlayers)
134 return; /* map too small to onionize */ 134 return; /* map too small to onionize */
135
135 if (layers > maxlayers) 136 if (layers > maxlayers)
136 layers = maxlayers; 137 layers = maxlayers;
138
137 if (layers == 0) 139 if (layers == 0)
138 layers = (RANDOM () % maxlayers) + 1; 140 layers = rndm (maxlayers) + 1;
141
139 xlocations = (float *) calloc (sizeof (float), 2 * layers); 142 xlocations = (float *) calloc (sizeof (float), 2 * layers);
140 ylocations = (float *) calloc (sizeof (float), 2 * layers); 143 ylocations = (float *) calloc (sizeof (float), 2 * layers);
141
142 144
143 /* place all the walls */ 145 /* place all the walls */
144 if (option & RMOPT_IRR_SPACE) /* randomly spaced */ 146 if (option & RMOPT_IRR_SPACE) /* randomly spaced */
145 { 147 {
146 int x_spaces_available, y_spaces_available; 148 int x_spaces_available, y_spaces_available;
154 for (i = 0; i < 2 * layers; i++) 156 for (i = 0; i < 2 * layers; i++)
155 { 157 {
156 float xpitch = 2, ypitch = 2; 158 float xpitch = 2, ypitch = 2;
157 159
158 if (x_spaces_available > 0) 160 if (x_spaces_available > 0)
159 xpitch = 2 + (RANDOM () % x_spaces_available + RANDOM () % x_spaces_available + RANDOM () % x_spaces_available) / 3; 161 xpitch = 2 + (rndm (x_spaces_available) + rndm (x_spaces_available) + rndm (x_spaces_available)) / 3;
160 162
161 if (y_spaces_available > 0) 163 if (y_spaces_available > 0)
162 ypitch = 2 + (RANDOM () % y_spaces_available + RANDOM () % y_spaces_available + RANDOM () % y_spaces_available) / 3; 164 ypitch = 2 + (rndm (y_spaces_available) + rndm (y_spaces_available) + rndm (y_spaces_available)) / 3;
165
163 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; 166 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch;
164 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; 167 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch;
165 x_spaces_available -= (int) (xpitch - 2); 168 x_spaces_available -= (int) (xpitch - 2);
166 y_spaces_available -= (int) (ypitch - 2); 169 y_spaces_available -= (int) (ypitch - 2);
167 } 170 }
200 if (!maxlayers) 203 if (!maxlayers)
201 return; /* map too small to onionize */ 204 return; /* map too small to onionize */
202 if (layers > maxlayers) 205 if (layers > maxlayers)
203 layers = maxlayers; 206 layers = maxlayers;
204 if (layers == 0) 207 if (layers == 0)
205 layers = (RANDOM () % maxlayers) + 1; 208 layers = rndm (maxlayers) + 1;
206 xlocations = (float *) calloc (sizeof (float), 2 * layers); 209 xlocations = (float *) calloc (sizeof (float), 2 * layers);
207 ylocations = (float *) calloc (sizeof (float), 2 * layers); 210 ylocations = (float *) calloc (sizeof (float), 2 * layers);
208 211
209 212
210 /* place all the walls */ 213 /* place all the walls */
221 for (i = 0; i < 2 * layers; i++) 224 for (i = 0; i < 2 * layers; i++)
222 { 225 {
223 float xpitch = 2, ypitch = 2; 226 float xpitch = 2, ypitch = 2;
224 227
225 if (x_spaces_available > 0) 228 if (x_spaces_available > 0)
226 xpitch = 2 + (RANDOM () % x_spaces_available + RANDOM () % x_spaces_available + RANDOM () % x_spaces_available) / 3; 229 xpitch = 2 + (rndm (x_spaces_available) + rndm (x_spaces_available) + rndm (x_spaces_available)) / 3;
227 230
228 if (y_spaces_available > 0) 231 if (y_spaces_available > 0)
229 ypitch = 2 + (RANDOM () % y_spaces_available + RANDOM () % y_spaces_available + RANDOM () % y_spaces_available) / 3; 232 ypitch = 2 + (rndm (y_spaces_available) + rndm (y_spaces_available) + rndm (y_spaces_available)) / 3;
233
230 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; 234 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch;
231 if (i < layers) 235 if (i < layers)
232 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; 236 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch;
233 else 237 else
234 ylocations[i] = ysize - 1; 238 ylocations[i] = ysize - 1;
239
235 x_spaces_available -= (int) (xpitch - 2); 240 x_spaces_available -= (int) (xpitch - 2);
236 y_spaces_available -= (int) (ypitch - 2); 241 y_spaces_available -= (int) (ypitch - 2);
237 } 242 }
238 243
239 } 244 }
307 freedoms = 3; 312 freedoms = 3;
308 if (options & RMOPT_BOTTOM_R) 313 if (options & RMOPT_BOTTOM_R)
309 freedoms = 2; 314 freedoms = 2;
310 if (layers <= 0) 315 if (layers <= 0)
311 return; 316 return;
317
312 /* pick which wall will have a door. */ 318 /* pick which wall will have a door. */
313 which_wall = RANDOM () % freedoms + 1; 319 which_wall = rndm (freedoms) + 1;
314 for (l = 0; l < layers; l++) 320 for (l = 0; l < layers; l++)
315 { 321 {
316 if (options & RMOPT_LINEAR) 322 if (options & RMOPT_LINEAR)
317 { /* linear door placement. */ 323 { /* linear door placement. */
318 switch (which_wall) 324 switch (which_wall)
343 } 349 }
344 } 350 }
345 } 351 }
346 else 352 else
347 { /* random door placement. */ 353 { /* random door placement. */
348 which_wall = RANDOM () % freedoms + 1; 354 which_wall = rndm (freedoms) + 1;
349 switch (which_wall) 355 switch (which_wall)
350 { 356 {
351 case 1: 357 case 1:
352 { /* left hand wall */ 358 { /* left hand wall */
353 x1 = (int) xlocations[l]; 359 x1 = (int) xlocations[l];
354 y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1); 360 y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1);
355 if (y2 > 0) 361 if (y2 > 0)
356 y1 = (int) (ylocations[l] + RANDOM () % y2 + 1); 362 y1 = (int) (ylocations[l] + rndm (y2) + 1);
357 else 363 else
358 y1 = (int) (ylocations[l] + 1); 364 y1 = (int) (ylocations[l] + 1);
359 break; 365 break;
360 } 366 }
361 case 2: 367 case 2:
362 { /* top wall placement */ 368 { /* top wall placement */
363 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; 369 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1;
364 if (x2 > 0) 370 if (x2 > 0)
365 x1 = (int) (xlocations[l] + RANDOM () % x2 + 1); 371 x1 = (int) (xlocations[l] + rndm (x2) + 1);
366 else 372 else
367 x1 = (int) (xlocations[l] + 1); 373 x1 = (int) (xlocations[l] + 1);
368 y1 = (int) ylocations[l]; 374 y1 = (int) ylocations[l];
369 break; 375 break;
370 } 376 }
371 case 3: 377 case 3:
372 { /* right wall placement */ 378 { /* right wall placement */
373 x1 = (int) xlocations[2 * layers - l - 1]; 379 x1 = (int) xlocations[2 * layers - l - 1];
374 y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1; 380 y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1;
375 if (y2 > 0) 381 if (y2 > 0)
376 y1 = (int) (ylocations[l] + RANDOM () % y2 + 1); 382 y1 = (int) (ylocations[l] + rndm (y2) + 1);
377 else 383 else
378 y1 = (int) (ylocations[l] + 1); 384 y1 = (int) (ylocations[l] + 1);
379 385
380 break; 386 break;
381 } 387 }
382 case 4: 388 case 4:
383 { /* bottom wall placement */ 389 { /* bottom wall placement */
384 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; 390 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1;
385 if (x2 > 0) 391 if (x2 > 0)
386 x1 = (int) (xlocations[l] + RANDOM () % x2 + 1); 392 x1 = (int) (xlocations[l] + rndm (x2) + 1);
387 else 393 else
388 x1 = (int) (xlocations[l] + 1); 394 x1 = (int) (xlocations[l] + 1);
389 y1 = (int) ylocations[2 * layers - l - 1]; 395 y1 = (int) ylocations[2 * layers - l - 1];
390 break; 396 break;
391 } 397 }
421 if (!maxlayers) 427 if (!maxlayers)
422 return; /* map too small to onionize */ 428 return; /* map too small to onionize */
423 if (layers > maxlayers) 429 if (layers > maxlayers)
424 layers = maxlayers; 430 layers = maxlayers;
425 if (layers == 0) 431 if (layers == 0)
426 layers = (RANDOM () % maxlayers) + 1; 432 layers = rndm (maxlayers) + 1;
433
427 xlocations = (float *) calloc (sizeof (float), 2 * layers); 434 xlocations = (float *) calloc (sizeof (float), 2 * layers);
428 ylocations = (float *) calloc (sizeof (float), 2 * layers); 435 ylocations = (float *) calloc (sizeof (float), 2 * layers);
429
430 436
431 /* place all the walls */ 437 /* place all the walls */
432 if (option & RMOPT_IRR_SPACE) /* randomly spaced */ 438 if (option & RMOPT_IRR_SPACE) /* randomly spaced */
433 { 439 {
434 int x_spaces_available, y_spaces_available; 440 int x_spaces_available, y_spaces_available;
442 for (i = 0; i < 2 * layers; i++) 448 for (i = 0; i < 2 * layers; i++)
443 { 449 {
444 float xpitch = 2, ypitch = 2; 450 float xpitch = 2, ypitch = 2;
445 451
446 if (x_spaces_available > 0) 452 if (x_spaces_available > 0)
447 xpitch = 2 + (RANDOM () % x_spaces_available + RANDOM () % x_spaces_available + RANDOM () % x_spaces_available) / 3; 453 xpitch = 2 + (rndm (x_spaces_available) + rndm (x_spaces_available) + rndm (x_spaces_available)) / 3;
448 454
449 if (y_spaces_available > 0) 455 if (y_spaces_available > 0)
450 ypitch = 2 + (RANDOM () % y_spaces_available + RANDOM () % y_spaces_available + RANDOM () % y_spaces_available) / 3; 456 ypitch = 2 + (rndm (y_spaces_available) + rndm (y_spaces_available) + rndm (y_spaces_available)) / 3;
457
451 if (i < layers) 458 if (i < layers)
452 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; 459 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch;
453 else 460 else
454 xlocations[i] = xsize - 1; 461 xlocations[i] = xsize - 1;
455 462

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines