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.60 by root, Fri Jul 2 03:40:14 2010 UTC vs.
Revision 1.69 by root, Sat Jul 3 13:14:35 2010 UTC

29#include <rproto.h> 29#include <rproto.h>
30#include <sproto.h> 30#include <sproto.h>
31 31
32#define CEDE coroapi::cede_to_tick () 32#define CEDE coroapi::cede_to_tick ()
33 33
34noinline SV * 34random_map_params::random_map_params ()
35random_map_params::get_sv (const char *option) const
36{ 35{
37 SV **he = hv_fetch (hv, option, strlen (option), 0); 36 hv = newHV ();
38
39 return he ? *he : 0;
40} 37}
41 38
42noinline const_utf8_string 39random_map_params::random_map_params (random_map_params *RP)
43random_map_params::get_str (const char *option, const_utf8_string fallback) const
44{ 40{
45 SV *sv = get_sv (option); 41 *this = *RP;
46 return sv ? cfSvPVutf8_nolen (sv) : fallback;
47}
48 42
49noinline IV
50random_map_params::get_iv (const char *option, IV fallback) const
51{
52 SV *sv = get_sv (option);
53 return sv ? SvIV (sv) : fallback;
54}
55
56noinline UV
57random_map_params::get_uv (const char *option, UV fallback) const
58{
59 SV *sv = get_sv (option);
60 return sv ? SvUV (sv) : fallback;
61}
62
63noinline NV
64random_map_params::get_nv (const char *option, NV fallback) const
65{
66 SV *sv = get_sv (option);
67 return sv ? SvNV (sv) : fallback;
68}
69
70noinline void
71random_map_params::set (const char *option, SV *value) const
72{
73 int len = strlen (option);
74
75 if (value)
76 hv_store (hv, option, len, value, 0);
77 else
78 hv_delete (hv, option, len, G_DISCARD);
79}
80
81noinline void
82random_map_params::set (const char *option, const_utf8_string value) const
83{
84 set (option, value && *value ? newSVpvn_utf8 (value, strlen (value), 1) : 0);
85}
86
87void
88random_map_params::set (const char *option, IV value) const
89{
90 set (option, newSViv (value));
91}
92
93void
94random_map_params::set (const char *option, UV value) const
95{
96 set (option, newSVuv (value));
97}
98
99void
100random_map_params::set (const char *option, NV value) const
101{
102 set (option, newSVnv (value));
103}
104
105void
106random_map_params::hv_clone ()
107{
108 HV *copy = newHV (); 43 HV *copy = newHV ();
109 44
110 hv_iterinit (hv); 45 hv_iterinit (hv);
111 46
112 // does not work for utf-8 keys 47 // does not work for utf-8 keys
114 { 49 {
115 STRLEN klen; const char *key = HePV (he, klen); 50 STRLEN klen; const char *key = HePV (he, klen);
116 hv_store (copy, key, klen, newSVsv (HeVAL (he)), HeHASH (he)); 51 hv_store (copy, key, klen, newSVsv (HeVAL (he)), HeHASH (he));
117 } 52 }
118 53
54 hv = copy;
55}
56
57random_map_params::random_map_params (HV *hv)
58{
59 this->hv = (HV *)SvREFCNT_inc_NN ((SV *)hv);
60
61 assign (wall_name, get_str ("wall_name"));
62
63 xsize = get_iv ("xsize");
64 ysize = get_iv ("ysize");
65 expand2x = get_iv ("expand2x");
66 layoutoptions1 = get_iv ("layoutoptions1");
67 layoutoptions2 = get_iv ("layoutoptions2");
68 layoutoptions3 = get_iv ("layoutoptions3");
69 symmetry = get_iv ("symmetry");
70 difficulty = get_iv ("difficulty");
71 difficulty_given = get_iv ("difficulty_given");
72 difficulty_increase = get_nv ("difficulty_increase");
73 dungeon_level = get_iv ("dungeon_level");
74 dungeon_depth = get_iv ("dungeon_depth");
75 orientation = get_iv ("orientation");
76 random_seed = get_uv ("random_seed");
77 total_map_hp = get_nv ("total_map_hp"); // actually val64, but I am too lazy
78 symmetry_used = get_iv ("symmetry_used");
79}
80
81random_map_params::~random_map_params ()
82{
119 SvREFCNT_dec (hv); 83 SvREFCNT_dec (hv);
120 hv = copy;
121} 84}
122 85
123shstr_tmp 86shstr_tmp
124random_map_params::as_shstr () const 87random_map_params::as_shstr () const
125{ 88{
126 set ("xsize" , xsize); 89 set ("xsize" , xsize);
127 set ("ysize" , ysize); 90 set ("ysize" , ysize);
128 set ("monsterstyle" , monsterstyle);
129 set ("exit_on_final_map" , exit_on_final_map);
130 set ("layoutstyle" , layoutstyle);
131 set ("doorstyle" , doorstyle);
132 set ("final_map" , final_map);
133 set ("this_map" , this_map);
134 set ("expand2x" , expand2x);
135 set ("layoutoptions1" , layoutoptions1); 91 set ("layoutoptions1" , layoutoptions1);
136 set ("layoutoptions2" , layoutoptions2); 92 set ("layoutoptions2" , layoutoptions2);
137 set ("layoutoptions3" , layoutoptions3); 93 set ("layoutoptions3" , layoutoptions3);
138 set ("symmetry" , symmetry); 94 set ("symmetry" , symmetry);
139 set ("dungeon_depth" , dungeon_depth); 95 set ("dungeon_depth" , dungeon_depth);
140 set ("orientation" , orientation); 96 set ("orientation" , orientation);
141 set ("origin_x" , origin_x);
142 set ("origin_y" , origin_y);
143 set ("random_seed" , (UV)random_seed); 97 set ("random_seed" , (UV)random_seed);
144 set ("difficulty" , difficulty && difficulty_given ? difficulty : 0); 98 set ("difficulty" , difficulty && difficulty_given ? difficulty : 0);
145 set ("difficulty_increase", difficulty_increase); 99 set ("difficulty_increase", difficulty_increase);
146 set ("dungeon_level" , dungeon_level); 100 set ("dungeon_level" , dungeon_level);
147 101
161 } 115 }
162 116
163 return shstr (buf); 117 return shstr (buf);
164} 118}
165 119
166random_map_params::~random_map_params () 120noinline SV *
121random_map_params::get_sv (const char *option) const
167{ 122{
168 SvREFCNT_dec (hv); 123 SV **he = hv_fetch (hv, option, strlen (option), 0);
124
125 return he ? *he : 0;
126}
127
128noinline const_utf8_string
129random_map_params::get_str (const char *option, const_utf8_string fallback) const
130{
131 SV *sv = get_sv (option);
132 return sv ? cfSvPVutf8_nolen (sv) : fallback;
133}
134
135noinline IV
136random_map_params::get_iv (const char *option, IV fallback) const
137{
138 SV *sv = get_sv (option);
139 return sv ? SvIV (sv) : fallback;
140}
141
142noinline UV
143random_map_params::get_uv (const char *option, UV fallback) const
144{
145 SV *sv = get_sv (option);
146 return sv ? SvUV (sv) : fallback;
147}
148
149noinline NV
150random_map_params::get_nv (const char *option, NV fallback) const
151{
152 SV *sv = get_sv (option);
153 return sv ? SvNV (sv) : fallback;
154}
155
156noinline void
157random_map_params::set (const char *option, SV *value) const
158{
159 int len = strlen (option);
160
161 if (value)
162 hv_store (hv, option, len, value, 0);
163 else
164 hv_delete (hv, option, len, G_DISCARD);
165}
166
167noinline void
168random_map_params::set (const char *option, const_utf8_string value) const
169{
170 set (option, value && *value ? newSVpvn_utf8 (value, strlen (value), 1) : 0);
171}
172
173void
174random_map_params::set (const char *option, IV value) const
175{
176 set (option, newSViv (value));
177}
178
179void
180random_map_params::set (const char *option, UV value) const
181{
182 set (option, newSVuv (value));
183}
184
185void
186random_map_params::set (const char *option, NV value) const
187{
188 set (option, newSVnv (value));
169} 189}
170 190
171bool 191bool
172maptile::generate_random_map (random_map_params *RP) 192maptile::generate_random_map (random_map_params *RP)
173{ 193{
174 RP->Xsize = RP->xsize; 194 RP->Xsize = RP->xsize;
175 RP->Ysize = RP->ysize; 195 RP->Ysize = RP->ysize;
196
197 max_it (RP->dungeon_level, 1);
176 198
177 /* pick a random seed, or use the one from the input file */ 199 /* pick a random seed, or use the one from the input file */
178 RP->random_seed = RP->random_seed 200 RP->random_seed = RP->random_seed
179 ? RP->random_seed + RP->dungeon_level 201 ? RP->random_seed + RP->dungeon_level
180 : time (0); 202 : pticks;
181 203
182 // we run "single-threaded" 204 // we run "single-threaded"
183 rmg_rndm.seed (RP->random_seed); 205 rmg_rndm.seed (RP->random_seed);
184 206
185 shstr buf = RP->as_shstr (); 207 shstr buf = RP->as_shstr ();
186 208
187 if (RP->difficulty == 0) 209 if (RP->difficulty == 0)
188 { 210 {
189 RP->difficulty = RP->dungeon_level; /* use this instead of a map difficulty */ 211 RP->difficulty = RP->dungeon_level; /* use this instead of a map difficulty */
190 212
191 if (RP->difficulty_increase > 0.001) 213 if (RP->difficulty_increase > 0.001f)
192 RP->difficulty = (int) ((float) RP->dungeon_level * RP->difficulty_increase); 214 RP->difficulty = RP->dungeon_level * RP->difficulty_increase;
193 215
194 if (RP->difficulty < 1) 216 if (RP->difficulty < 1)
195 RP->difficulty = 1; 217 RP->difficulty = 1;
196 } 218 }
197 else 219 else
221 { 243 {
222 RP->Xsize /= 2; 244 RP->Xsize /= 2;
223 RP->Ysize /= 2; 245 RP->Ysize /= 2;
224 } 246 }
225 247
248 const char *layoutstyle = RP->get_str ("layoutstyle", "");
249
226 if (strstr (RP->layoutstyle, "onion")) 250 if (strstr (layoutstyle, "onion"))
227 RP->map_layout_style = LAYOUT_ONION; 251 RP->map_layout_style = LAYOUT_ONION;
228 else if (strstr (RP->layoutstyle, "maze")) 252 else if (strstr (layoutstyle, "maze"))
229 RP->map_layout_style = LAYOUT_MAZE; 253 RP->map_layout_style = LAYOUT_MAZE;
230 else if (strstr (RP->layoutstyle, "spiral")) 254 else if (strstr (layoutstyle, "spiral"))
231 RP->map_layout_style = LAYOUT_SPIRAL; 255 RP->map_layout_style = LAYOUT_SPIRAL;
232 else if (strstr (RP->layoutstyle, "rogue")) 256 else if (strstr (layoutstyle, "rogue"))
233 RP->map_layout_style = LAYOUT_ROGUELIKE; 257 RP->map_layout_style = LAYOUT_ROGUELIKE;
234 else if (strstr (RP->layoutstyle, "snake")) 258 else if (strstr (layoutstyle, "snake"))
235 RP->map_layout_style = LAYOUT_SNAKE; 259 RP->map_layout_style = LAYOUT_SNAKE;
236 else if (strstr (RP->layoutstyle, "squarespiral")) 260 else if (strstr (layoutstyle, "squarespiral"))
237 RP->map_layout_style = LAYOUT_SQUARE_SPIRAL; 261 RP->map_layout_style = LAYOUT_SQUARE_SPIRAL;
238 else if (strstr (RP->layoutstyle, "cave")) 262 else if (strstr (layoutstyle, "cave"))
239 RP->map_layout_style = LAYOUT_CAVE; 263 RP->map_layout_style = LAYOUT_CAVE;
264 else if (strstr (layoutstyle, "castle"))
265 RP->map_layout_style = LAYOUT_CASTLE;
266 else if (strstr (layoutstyle, "multiple"))
267 RP->map_layout_style = LAYOUT_MULTIPLE;
240 else 268 else
241 RP->map_layout_style = rmg_rndm (NROFLAYOUTS - 1) + 1; /* No style found - choose one randomly */ 269 RP->map_layout_style = rmg_rndm (NROFLAYOUTS - 1) + 1; /* No style found - choose one randomly */
242 270
243 Layout layout (RP->Xsize, RP->Ysize); 271 layout maze (RP->Xsize, RP->Ysize);
244 layout.generate (RP); 272 maze.generate (RP);
273 maze.rotate (rmg_rndm (4));
274 maze.symmetrize (RP->symmetry_used);
275
276 if (RP->expand2x)
277 maze.expand2x ();
278
279#if 0
280 maze.print ();//D
281#endif
245 282
246 /* increment these for the current map */ 283 /* increment these for the current map */
247 ++RP->dungeon_level; 284 ++RP->dungeon_level;
248 285
249 // need to patch RP becasue following code doesn't use the Layout object 286 // need to patch RP becasue following code doesn't use the layout object
250 RP->Xsize = layout.w; 287 RP->Xsize = maze.w;
251 RP->Ysize = layout.h; 288 RP->Ysize = maze.h;
252 289
253 /* allocate the map and set the floor */ 290 /* allocate the map and set the floor */
254 make_map_floor (layout, RP->get_str ("floorstyle", ""), RP); 291 make_map_floor (maze, RP->get_str ("floorstyle", ""), RP);
255 292
256 /* set region */ 293 /* set region */
257 default_region = RP->region; 294 default_region = region::find (RP->get_str ("region", 0));
258 295
259 CEDE; 296 CEDE;
260 297
261 place_specials_in_map (this, layout, RP); 298 place_specials_in_map (this, maze, RP);
262 299
263 CEDE; 300 CEDE;
264 301
265 const char *wallstyle = RP->get_str ("wallstyle", 0); 302 const char *wallstyle = RP->get_str ("wallstyle", "");
266 303
267 /* create walls unless the wallstyle is "none" */ 304 /* create walls unless the wallstyle is "none" */
268 if (strcmp (wallstyle, "none")) 305 if (strcmp (wallstyle, "none"))
269 { 306 {
270 make_map_walls (this, layout, wallstyle, RP->get_str ("miningstyle", ""), RP); 307 make_map_walls (this, maze, wallstyle, RP->get_str ("miningstyle", ""), RP);
308
309 const char *doorstyle = RP->get_str ("doorstyle", "");
271 310
272 /* place doors unless doorstyle or wallstyle is "none" */ 311 /* place doors unless doorstyle or wallstyle is "none" */
273 if (strcmp (RP->doorstyle, "none")) 312 if (strcmp (doorstyle, "none"))
274 put_doors (this, layout, RP->doorstyle, RP); 313 put_doors (this, maze, doorstyle, RP);
275 } 314 }
276 315
277 CEDE; 316 CEDE;
278 317
279 const char *exitstyle = RP->get_str ("exitstyle", ""); 318 const char *exitstyle = RP->get_str ("exitstyle", "");
280 319
281 /* create exits unless the exitstyle is "none" */ 320 /* create exits unless the exitstyle is "none" */
282 if (strcmp (exitstyle, "none")) 321 if (strcmp (exitstyle, "none"))
283 place_exits (this, layout, exitstyle, RP->orientation, RP); 322 place_exits (this, maze, exitstyle, RP->orientation, RP);
284 323
285 CEDE; 324 CEDE;
325
326 const char *monsterstyle = RP->get_str ("monsterstyle", "");
286 327
287 /* create monsters unless the monsterstyle is "none" */ 328 /* create monsters unless the monsterstyle is "none" */
288 if (strcmp (RP->monsterstyle, "none")) 329 if (strcmp (monsterstyle, "none"))
289 place_monsters (this, RP->monsterstyle, RP->difficulty, RP); 330 place_monsters (this, monsterstyle, RP->difficulty, RP);
290 331
291 CEDE; 332 CEDE;
292 333
293 /* treasures needs to have a proper difficulty set for the map. */ 334 /* treasures needs to have a proper difficulty set for the map. */
294 difficulty = estimate_difficulty (); 335 difficulty = estimate_difficulty ();
296 CEDE; 337 CEDE;
297 338
298 const char *treasurestyle = RP->get_str ("treasurestyle", ""); 339 const char *treasurestyle = RP->get_str ("treasurestyle", "");
299 340
300 /* create treasure unless the treasurestyle is "none" */ 341 /* create treasure unless the treasurestyle is "none" */
301 place_treasure (this, layout, treasurestyle, RP->get_iv ("treasureoptions"), RP); 342 place_treasure (this, maze, treasurestyle, RP->get_iv ("treasureoptions"), RP);
302 343
303 CEDE; 344 CEDE;
304 345
305 const char *decorstyle = RP->get_str ("treasurestyle", ""); 346 const char *decorstyle = RP->get_str ("treasurestyle", "");
306 347
307 /* create decor unless the decorstyle is "none" */ 348 /* create decor unless the decorstyle is "none" */
308 if (strcmp (decorstyle, "none")) 349 if (strcmp (decorstyle, "none"))
309 put_decor (this, layout, decorstyle, RP->get_iv ("decoroptions"), RP); 350 put_decor (this, maze, decorstyle, RP->get_iv ("decoroptions"), RP);
310 351
311 CEDE; 352 CEDE;
312 353
313 /* generate treasures, etc. */ 354 /* generate treasures, etc. */
314 fix_auto_apply (); 355 fix_auto_apply ();
315 356
316 CEDE; 357 CEDE;
317 358
318 unblock_exits (this, layout, RP); 359 unblock_exits (this, maze, RP);
319 360
320 msg = buf; 361 msg = buf;
321 in_memory = MAP_ACTIVE; 362 in_memory = MAP_ACTIVE;
322 363
323 CEDE; 364 CEDE;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines