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.50 by root, Sun May 16 13:48:08 2010 UTC vs.
Revision 1.51 by root, Sat Jun 26 22:10:18 2010 UTC

32#define CEDE coroapi::cede_to_tick () 32#define CEDE coroapi::cede_to_tick ()
33 33
34static void symmetrize_layout (Layout maze, random_map_params *RP); 34static void symmetrize_layout (Layout maze, random_map_params *RP);
35static void rotate_layout (Layout maze, int rotation); 35static void rotate_layout (Layout maze, int rotation);
36 36
37const_utf8_string
38random_map_params::get_str (const_utf8_string option, const_utf8_string fallback) const
39{
40 SV **he = hv_fetch (hv, option, strlen (option), 0);
41
42 return he ? cfSvPVutf8_nolen (*he) : fallback;
43}
44
45IV
46random_map_params::get_iv (const char *option, IV fallback) const
47{
48 SV **he = hv_fetch (hv, option, strlen (option), 0);
49
50 return he ? SvIV (*he) : fallback;
51}
52
53random_map_params::~random_map_params ()
54{
55 SvREFCNT_dec (hv);
56}
57
37void 58void
38dump_layout (Layout layout) 59dump_layout (Layout layout)
39{ 60{
40 for (int j = 0; j < layout->h; j++) 61 for (int j = 0; j < layout->h; j++)
41 { 62 {
338 sfree (doorlist_x, RP->Xsize * RP->Ysize); 359 sfree (doorlist_x, RP->Xsize * RP->Ysize);
339 sfree (doorlist_y, RP->Xsize * RP->Ysize); 360 sfree (doorlist_y, RP->Xsize * RP->Ysize);
340} 361}
341 362
342void 363void
343write_map_parameters_to_string (char *buf, random_map_params *RP) 364write_map_parameters_to_string (dynbuf_text &buf, random_map_params *RP)
344{ 365{
345 char small_buf[16384]; 366 hv_iterinit (RP->hv);
346 367
368 while (HE *he = hv_iternext (RP->hv))
369 buf << HePV (he, PL_na) << ' ' << cfSvPVutf8_nolen (HeVAL (he)) << '\n';
370
347 sprintf (buf, "xsize %d\nysize %d\n", RP->xsize, RP->ysize); 371 buf.printf ("xsize %d\nysize %d\n", RP->xsize, RP->ysize);
348 372
349 if (RP->wallstyle[0]) 373 if (RP->monsterstyle[0] ) buf.printf ("monsterstyle %s\n", RP->monsterstyle);
350 { 374 if (RP->treasurestyle[0] ) buf.printf ("treasurestyle %s\n", RP->treasurestyle);
351 sprintf (small_buf, "wallstyle %s\n", RP->wallstyle); 375 if (RP->layoutstyle[0] ) buf.printf ("layoutstyle %s\n", RP->layoutstyle);
352 strcat (buf, small_buf); 376 if (RP->decorstyle[0] ) buf.printf ("decorstyle %s\n", RP->decorstyle);
353 } 377 if (RP->doorstyle[0] ) buf.printf ("doorstyle %s\n", RP->doorstyle);
354 378 if (RP->final_map.length () ) buf.printf ("final_map %s\n", &RP->final_map);
355 if (RP->miningstyle[0]) 379 if (RP->exit_on_final_map[0]) buf.printf ("exit_on_final_map %s\n", RP->exit_on_final_map);
356 { 380 if (RP->this_map.length () ) buf.printf ("origin_map %s\n", &RP->this_map);
357 sprintf (small_buf, "miningstyle %s\n", RP->miningstyle); 381 if (RP->expand2x ) buf.printf ("expand2x %d\n", RP->expand2x);
358 strcat (buf, small_buf); 382 if (RP->layoutoptions1 ) buf.printf ("layoutoptions1 %d\n", RP->layoutoptions1);
359 } 383 if (RP->layoutoptions2 ) buf.printf ("layoutoptions2 %d\n", RP->layoutoptions2);
360 384 if (RP->layoutoptions3 ) buf.printf ("layoutoptions3 %d\n", RP->layoutoptions3);
361 if (RP->floorstyle[0]) 385 if (RP->symmetry ) buf.printf ("symmetry %d\n", RP->symmetry);
362 {
363 sprintf (small_buf, "floorstyle %s\n", RP->floorstyle);
364 strcat (buf, small_buf);
365 }
366
367 if (RP->monsterstyle[0])
368 {
369 sprintf (small_buf, "monsterstyle %s\n", RP->monsterstyle);
370 strcat (buf, small_buf);
371 }
372
373 if (RP->treasurestyle[0])
374 {
375 sprintf (small_buf, "treasurestyle %s\n", RP->treasurestyle);
376 strcat (buf, small_buf);
377 }
378
379 if (RP->layoutstyle[0])
380 {
381 sprintf (small_buf, "layoutstyle %s\n", RP->layoutstyle);
382 strcat (buf, small_buf);
383 }
384
385 if (RP->decorstyle[0])
386 {
387 sprintf (small_buf, "decorstyle %s\n", RP->decorstyle);
388 strcat (buf, small_buf);
389 }
390
391 if (RP->doorstyle[0])
392 {
393 sprintf (small_buf, "doorstyle %s\n", RP->doorstyle);
394 strcat (buf, small_buf);
395 }
396
397 if (RP->exitstyle[0])
398 {
399 sprintf (small_buf, "exitstyle %s\n", RP->exitstyle);
400 strcat (buf, small_buf);
401 }
402
403 if (RP->final_map.length ())
404 {
405 sprintf (small_buf, "final_map %s\n", &RP->final_map);
406 strcat (buf, small_buf);
407 }
408
409 if (RP->exit_on_final_map[0])
410 {
411 sprintf (small_buf, "exit_on_final_map %s\n", RP->exit_on_final_map);
412 strcat (buf, small_buf);
413 }
414
415 if (RP->this_map.length ())
416 {
417 sprintf (small_buf, "origin_map %s\n", &RP->this_map);
418 strcat (buf, small_buf);
419 }
420
421 if (RP->expand2x)
422 {
423 sprintf (small_buf, "expand2x %d\n", RP->expand2x);
424 strcat (buf, small_buf);
425 }
426
427 if (RP->layoutoptions1)
428 {
429 sprintf (small_buf, "layoutoptions1 %d\n", RP->layoutoptions1);
430 strcat (buf, small_buf);
431 }
432
433 if (RP->layoutoptions2)
434 {
435 sprintf (small_buf, "layoutoptions2 %d\n", RP->layoutoptions2);
436 strcat (buf, small_buf);
437 }
438
439 if (RP->layoutoptions3)
440 {
441 sprintf (small_buf, "layoutoptions3 %d\n", RP->layoutoptions3);
442 strcat (buf, small_buf);
443 }
444
445 if (RP->symmetry)
446 {
447 sprintf (small_buf, "symmetry %d\n", RP->symmetry);
448 strcat (buf, small_buf);
449 }
450 386
451 if (RP->difficulty && RP->difficulty_given) 387 if (RP->difficulty && RP->difficulty_given)
452 {
453 sprintf (small_buf, "difficulty %d\n", RP->difficulty); 388 buf.printf ("difficulty %d\n", RP->difficulty);
454 strcat (buf, small_buf);
455 }
456 389
457 if (fabs (RP->difficulty_increase - 1.f) >= (1.f / 1024.f)) 390 if (fabs (RP->difficulty_increase - 1.f) >= (1.f / 1024.f))
458 {
459 sprintf (small_buf, "difficulty_increase %f\n", RP->difficulty_increase); 391 buf.printf ("difficulty_increase %f\n", RP->difficulty_increase);
460 strcat (buf, small_buf);
461 }
462 392
463 sprintf (small_buf, "dungeon_level %d\n", RP->dungeon_level); 393 buf.printf ("dungeon_level %d\n", RP->dungeon_level);
464 strcat (buf, small_buf);
465 394
466 if (RP->dungeon_depth) 395 if (RP->dungeon_depth ) buf.printf ("dungeon_depth %d\n", RP->dungeon_depth);
467 { 396 if (RP->decoroptions ) buf.printf ("decoroptions %d\n", RP->decoroptions);
468 sprintf (small_buf, "dungeon_depth %d\n", RP->dungeon_depth); 397 if (RP->orientation ) buf.printf ("orientation %d\n", RP->orientation);
469 strcat (buf, small_buf); 398 if (RP->origin_x ) buf.printf ("origin_x %d\n", RP->origin_x);
470 } 399 if (RP->origin_y ) buf.printf ("origin_y %d\n", RP->origin_y);
471 400 if (RP->treasureoptions ) buf.printf ("treasureoptions %d\n", RP->treasureoptions);
472 if (RP->decoroptions) 401 if (RP->random_seed ) buf.printf ("random_seed %u\n", RP->random_seed);
473 {
474 sprintf (small_buf, "decoroptions %d\n", RP->decoroptions);
475 strcat (buf, small_buf);
476 }
477
478 if (RP->orientation)
479 {
480 sprintf (small_buf, "orientation %d\n", RP->orientation);
481 strcat (buf, small_buf);
482 }
483
484 if (RP->origin_x)
485 {
486 sprintf (small_buf, "origin_x %d\n", RP->origin_x);
487 strcat (buf, small_buf);
488 }
489
490 if (RP->origin_y)
491 {
492 sprintf (small_buf, "origin_y %d\n", RP->origin_y);
493 strcat (buf, small_buf);
494 }
495
496 if (RP->treasureoptions)
497 {
498 sprintf (small_buf, "treasureoptions %d\n", RP->treasureoptions);
499 strcat (buf, small_buf);
500 }
501
502 if (RP->random_seed)
503 {
504 sprintf (small_buf, "random_seed %u\n", RP->random_seed);
505 strcat (buf, small_buf);
506 }
507
508 if (RP->custom)
509 {
510 sprintf (small_buf, "custom %s\n", RP->custom);
511 strcat (buf, small_buf);
512 }
513} 402}
514 403
515///////////////////////////////////////////////////////////////////////////// 404/////////////////////////////////////////////////////////////////////////////
516 405
517LayoutData::LayoutData (int w, int h) 406LayoutData::LayoutData (int w, int h)
627} 516}
628 517
629bool 518bool
630maptile::generate_random_map (random_map_params *RP) 519maptile::generate_random_map (random_map_params *RP)
631{ 520{
632 char buf[16384];
633 int i; 521 int i;
634 522
635 RP->Xsize = RP->xsize; 523 RP->Xsize = RP->xsize;
636 RP->Ysize = RP->ysize; 524 RP->Ysize = RP->ysize;
637 525
641 : time (0); 529 : time (0);
642 530
643 // we run "single-threaded" 531 // we run "single-threaded"
644 rmg_rndm.seed (RP->random_seed); 532 rmg_rndm.seed (RP->random_seed);
645 533
534 dynbuf_text buf;
646 write_map_parameters_to_string (buf, RP); 535 write_map_parameters_to_string (buf, RP);
647 536
648 if (RP->difficulty == 0) 537 if (RP->difficulty == 0)
649 { 538 {
650 RP->difficulty = RP->dungeon_level; /* use this instead of a map difficulty */ 539 RP->difficulty = RP->dungeon_level; /* use this instead of a map difficulty */
717 // need to patch RP becasue following code doesn't use the Layout object 606 // need to patch RP becasue following code doesn't use the Layout object
718 RP->Xsize = layout->w; 607 RP->Xsize = layout->w;
719 RP->Ysize = layout->h; 608 RP->Ysize = layout->h;
720 609
721 /* allocate the map and set the floor */ 610 /* allocate the map and set the floor */
722 make_map_floor (layout, RP->floorstyle, RP); 611 make_map_floor (layout, RP->get_str ("floorstyle", ""), RP);
723 612
724 /* set region */ 613 /* set region */
725 default_region = RP->region; 614 default_region = RP->region;
726 615
727 CEDE; 616 CEDE;
728 617
729 place_specials_in_map (this, layout, RP); 618 place_specials_in_map (this, layout, RP);
730 619
731 CEDE; 620 CEDE;
732 621
622 const char *wallstyle = RP->get_str ("wallstyle", 0);
623
733 /* create walls unless the wallstyle is "none" */ 624 /* create walls unless the wallstyle is "none" */
734 if (strcmp (RP->wallstyle, "none")) 625 if (strcmp (wallstyle, "none"))
735 { 626 {
736 make_map_walls (this, layout, RP->wallstyle, RP->miningstyle, RP); 627 make_map_walls (this, layout, wallstyle, RP->get_str ("miningstyle", ""), RP);
737 628
738 /* place doors unless doorstyle or wallstyle is "none" */ 629 /* place doors unless doorstyle or wallstyle is "none" */
739 if (strcmp (RP->doorstyle, "none")) 630 if (strcmp (RP->doorstyle, "none"))
740 put_doors (this, layout, RP->doorstyle, RP); 631 put_doors (this, layout, RP->doorstyle, RP);
741 } 632 }
742 633
743 CEDE; 634 CEDE;
744 635
636 const char *exitstyle = RP->get_str ("exitstyle", "");
637
745 /* create exits unless the exitstyle is "none" */ 638 /* create exits unless the exitstyle is "none" */
746 if (strcmp (RP->exitstyle, "none")) 639 if (strcmp (exitstyle, "none"))
747 place_exits (this, layout, RP->exitstyle, RP->orientation, RP); 640 place_exits (this, layout, exitstyle, RP->orientation, RP);
748 641
749 CEDE; 642 CEDE;
750 643
751 /* create monsters unless the monsterstyle is "none" */ 644 /* create monsters unless the monsterstyle is "none" */
752 if (strcmp (RP->monsterstyle, "none")) 645 if (strcmp (RP->monsterstyle, "none"))
775 668
776 CEDE; 669 CEDE;
777 670
778 unblock_exits (this, layout, RP); 671 unblock_exits (this, layout, RP);
779 672
780 msg = strdup (buf); 673 msg = buf;
781 in_memory = MAP_ACTIVE; 674 in_memory = MAP_ACTIVE;
782 675
783 CEDE; 676 CEDE;
784 677
785 return 1; 678 return 1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines