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.51 by root, Sat Jun 26 22:10:18 2010 UTC vs.
Revision 1.55 by root, Wed Jun 30 01:32:57 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 37noinline SV *
38random_map_params::get_str (const_utf8_string option, const_utf8_string fallback) const 38random_map_params::get_sv (const char *option) const
39{ 39{
40 SV **he = hv_fetch (hv, option, strlen (option), 0); 40 SV **he = hv_fetch (hv, option, strlen (option), 0);
41 41
42 return he ? *he : 0;
43}
44
45noinline const_utf8_string
46random_map_params::get_str (const char *option, const_utf8_string fallback) const
47{
48 SV *sv = get_sv (option);
42 return he ? cfSvPVutf8_nolen (*he) : fallback; 49 return sv ? cfSvPVutf8_nolen (sv) : fallback;
43} 50}
44 51
45IV 52noinline IV
46random_map_params::get_iv (const char *option, IV fallback) const 53random_map_params::get_iv (const char *option, IV fallback) const
47{ 54{
48 SV **he = hv_fetch (hv, option, strlen (option), 0); 55 SV *sv = get_sv (option);
49
50 return he ? SvIV (*he) : fallback; 56 return sv ? SvIV (sv) : fallback;
57}
58
59noinline UV
60random_map_params::get_uv (const char *option, UV fallback) const
61{
62 SV *sv = get_sv (option);
63 return sv ? SvUV (sv) : fallback;
64}
65
66noinline NV
67random_map_params::get_nv (const char *option, NV fallback) const
68{
69 SV *sv = get_sv (option);
70 return sv ? SvNV (sv) : fallback;
71}
72
73noinline void
74random_map_params::set (const char *option, SV *value) const
75{
76 int len = strlen (option);
77
78 if (value)
79 hv_store (hv, option, len, value, 0);
80 else
81 hv_delete (hv, option, len, G_DISCARD);
82}
83
84noinline void
85random_map_params::set (const char *option, const_utf8_string value) const
86{
87 set (option, value && *value ? newSVpvn_utf8 (value, strlen (value), 1) : 0);
88}
89
90void
91random_map_params::set (const char *option, IV value) const
92{
93 set (option, newSViv (value));
94}
95
96void
97random_map_params::set (const char *option, UV value) const
98{
99 set (option, newSVuv (value));
100}
101
102void
103random_map_params::set (const char *option, NV value) const
104{
105 set (option, newSVnv (value));
106}
107
108void
109random_map_params::hv_clone ()
110{
111 HV *copy = newHV ();
112
113 hv_iterinit (hv);
114
115 // does not work for utf-8 keys
116 while (HE *he = hv_iternext (hv))
117 {
118 STRLEN klen; const char *key = HePV (he, klen);
119 hv_store (copy, key, klen, newSVsv (HeVAL (he)), HeHASH (he));
120 }
121
122 SvREFCNT_dec (hv);
123 hv = copy;
124}
125
126shstr_tmp
127random_map_params::as_shstr () const
128{
129 set ("xsize" , xsize);
130 set ("ysize" , ysize);
131 set ("monsterstyle" , monsterstyle);
132 set ("exit_on_final_map" , exit_on_final_map);
133 set ("layoutstyle" , layoutstyle);
134 set ("doorstyle" , doorstyle);
135 set ("final_map" , final_map);
136 set ("this_map" , this_map);
137 set ("expand2x" , expand2x);
138 set ("layoutoptions1" , layoutoptions1);
139 set ("layoutoptions2" , layoutoptions2);
140 set ("layoutoptions3" , layoutoptions3);
141 set ("symmetry" , symmetry);
142 set ("dungeon_depth" , dungeon_depth);
143 set ("orientation" , orientation);
144 set ("origin_x" , origin_x);
145 set ("origin_y" , origin_y);
146 set ("random_seed" , (UV)random_seed);
147 set ("difficulty" , difficulty && difficulty_given ? difficulty : 0);
148 set ("difficulty_increase", difficulty_increase);
149 set ("dungeon_level" , dungeon_level);
150
151 dynbuf_text buf;
152 hv_iterinit (hv);
153
154 // does not work for utf-8 keys
155 while (HE *he = hv_iternext (hv))
156 {
157 STRLEN klen; const char *key = HePV (he, klen);
158 STRLEN vlen; const char *value = SvPVutf8 (HeVAL (he), vlen);
159
160 buf.fadd (key, klen);
161 buf << ' ';
162 buf.fadd (value, vlen);
163 buf << '\n';
164 }
165
166 return shstr (buf);
51} 167}
52 168
53random_map_params::~random_map_params () 169random_map_params::~random_map_params ()
54{ 170{
55 SvREFCNT_dec (hv); 171 SvREFCNT_dec (hv);
56} 172}
57 173
58void 174void
59dump_layout (Layout layout) 175Layout::print ()
60{ 176{
61 for (int j = 0; j < layout->h; j++) 177 for (int j = 0; j < ptr->h; j++)
62 { 178 {
63 for (int i = 0; i < layout->w; i++) 179 for (int i = 0; i < ptr->w; i++)
64 putc (layout[i][j] ? layout[i][j] : ' ', stdout); 180 putc (ptr->col[i][j] ? ptr->col[i][j] : ' ', stdout);
65 181
66 putc ('\n', stdout); 182 putc ('\n', stdout);
67 } 183 }
68 184
69 putc ('\n', stdout); 185 putc ('\n', stdout);
358 474
359 sfree (doorlist_x, RP->Xsize * RP->Ysize); 475 sfree (doorlist_x, RP->Xsize * RP->Ysize);
360 sfree (doorlist_y, RP->Xsize * RP->Ysize); 476 sfree (doorlist_y, RP->Xsize * RP->Ysize);
361} 477}
362 478
363void
364write_map_parameters_to_string (dynbuf_text &buf, random_map_params *RP)
365{
366 hv_iterinit (RP->hv);
367
368 while (HE *he = hv_iternext (RP->hv))
369 buf << HePV (he, PL_na) << ' ' << cfSvPVutf8_nolen (HeVAL (he)) << '\n';
370
371 buf.printf ("xsize %d\nysize %d\n", RP->xsize, RP->ysize);
372
373 if (RP->monsterstyle[0] ) buf.printf ("monsterstyle %s\n", RP->monsterstyle);
374 if (RP->treasurestyle[0] ) buf.printf ("treasurestyle %s\n", RP->treasurestyle);
375 if (RP->layoutstyle[0] ) buf.printf ("layoutstyle %s\n", RP->layoutstyle);
376 if (RP->decorstyle[0] ) buf.printf ("decorstyle %s\n", RP->decorstyle);
377 if (RP->doorstyle[0] ) buf.printf ("doorstyle %s\n", RP->doorstyle);
378 if (RP->final_map.length () ) buf.printf ("final_map %s\n", &RP->final_map);
379 if (RP->exit_on_final_map[0]) buf.printf ("exit_on_final_map %s\n", RP->exit_on_final_map);
380 if (RP->this_map.length () ) buf.printf ("origin_map %s\n", &RP->this_map);
381 if (RP->expand2x ) buf.printf ("expand2x %d\n", RP->expand2x);
382 if (RP->layoutoptions1 ) buf.printf ("layoutoptions1 %d\n", RP->layoutoptions1);
383 if (RP->layoutoptions2 ) buf.printf ("layoutoptions2 %d\n", RP->layoutoptions2);
384 if (RP->layoutoptions3 ) buf.printf ("layoutoptions3 %d\n", RP->layoutoptions3);
385 if (RP->symmetry ) buf.printf ("symmetry %d\n", RP->symmetry);
386
387 if (RP->difficulty && RP->difficulty_given)
388 buf.printf ("difficulty %d\n", RP->difficulty);
389
390 if (fabs (RP->difficulty_increase - 1.f) >= (1.f / 1024.f))
391 buf.printf ("difficulty_increase %f\n", RP->difficulty_increase);
392
393 buf.printf ("dungeon_level %d\n", RP->dungeon_level);
394
395 if (RP->dungeon_depth ) buf.printf ("dungeon_depth %d\n", RP->dungeon_depth);
396 if (RP->decoroptions ) buf.printf ("decoroptions %d\n", RP->decoroptions);
397 if (RP->orientation ) buf.printf ("orientation %d\n", RP->orientation);
398 if (RP->origin_x ) buf.printf ("origin_x %d\n", RP->origin_x);
399 if (RP->origin_y ) buf.printf ("origin_y %d\n", RP->origin_y);
400 if (RP->treasureoptions ) buf.printf ("treasureoptions %d\n", RP->treasureoptions);
401 if (RP->random_seed ) buf.printf ("random_seed %u\n", RP->random_seed);
402}
403
404///////////////////////////////////////////////////////////////////////////// 479/////////////////////////////////////////////////////////////////////////////
405 480
406LayoutData::LayoutData (int w, int h) 481LayoutData::LayoutData (int w, int h)
407: w(w), h(h) 482: w(w), h(h)
408{ 483{
450 roomify_layout (layout, RP); 525 roomify_layout (layout, RP);
451 526
452 break; 527 break;
453 528
454 case LAYOUT_MAZE: 529 case LAYOUT_MAZE:
455 maze_gen (layout, rmg_rndm (2)); 530 maze_gen (layout, RP->get_iv ("maze_type", rmg_rndm (4)));
456 531
457 if (!(rmg_rndm (2))) 532 if (!(rmg_rndm (2)))
458 doorify_layout (layout, RP); 533 doorify_layout (layout, RP);
459 534
460 break; 535 break;
516} 591}
517 592
518bool 593bool
519maptile::generate_random_map (random_map_params *RP) 594maptile::generate_random_map (random_map_params *RP)
520{ 595{
521 int i;
522
523 RP->Xsize = RP->xsize; 596 RP->Xsize = RP->xsize;
524 RP->Ysize = RP->ysize; 597 RP->Ysize = RP->ysize;
525 598
526 /* pick a random seed, or use the one from the input file */ 599 /* pick a random seed, or use the one from the input file */
527 RP->random_seed = RP->random_seed 600 RP->random_seed = RP->random_seed
529 : time (0); 602 : time (0);
530 603
531 // we run "single-threaded" 604 // we run "single-threaded"
532 rmg_rndm.seed (RP->random_seed); 605 rmg_rndm.seed (RP->random_seed);
533 606
534 dynbuf_text buf; 607 shstr buf = RP->as_shstr ();
535 write_map_parameters_to_string (buf, RP);
536 608
537 if (RP->difficulty == 0) 609 if (RP->difficulty == 0)
538 { 610 {
539 RP->difficulty = RP->dungeon_level; /* use this instead of a map difficulty */ 611 RP->difficulty = RP->dungeon_level; /* use this instead of a map difficulty */
540 612
650 /* treasures needs to have a proper difficulty set for the map. */ 722 /* treasures needs to have a proper difficulty set for the map. */
651 difficulty = estimate_difficulty (); 723 difficulty = estimate_difficulty ();
652 724
653 CEDE; 725 CEDE;
654 726
727 const char *treasurestyle = RP->get_str ("treasurestyle", "");
728
655 /* create treasure unless the treasurestyle is "none" */ 729 /* create treasure unless the treasurestyle is "none" */
656 place_treasure (this, layout, RP->treasurestyle, RP->treasureoptions, RP); 730 place_treasure (this, layout, treasurestyle, RP->get_iv ("treasureoptions"), RP);
657 731
658 CEDE; 732 CEDE;
733
734 const char *decorstyle = RP->get_str ("treasurestyle", "");
659 735
660 /* create decor unless the decorstyle is "none" */ 736 /* create decor unless the decorstyle is "none" */
661 if (strcmp (RP->decorstyle, "none")) 737 if (strcmp (decorstyle, "none"))
662 put_decor (this, layout, RP->decorstyle, RP->decoroptions, RP); 738 put_decor (this, layout, decorstyle, RP->get_iv ("decoroptions"), RP);
663 739
664 CEDE; 740 CEDE;
665 741
666 /* generate treasures, etc. */ 742 /* generate treasures, etc. */
667 fix_auto_apply (); 743 fix_auto_apply ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines