… | |
… | |
34 | random_map_params::random_map_params () |
34 | random_map_params::random_map_params () |
35 | { |
35 | { |
36 | hv = newHV (); |
36 | hv = newHV (); |
37 | } |
37 | } |
38 | |
38 | |
|
|
39 | random_map_params::random_map_params (random_map_params *RP) |
|
|
40 | { |
|
|
41 | *this = *RP; |
|
|
42 | |
|
|
43 | HV *copy = newHV (); |
|
|
44 | |
|
|
45 | hv_iterinit (hv); |
|
|
46 | |
|
|
47 | // does not work for utf-8 keys |
|
|
48 | while (HE *he = hv_iternext (hv)) |
|
|
49 | { |
|
|
50 | STRLEN klen; const char *key = HePV (he, klen); |
|
|
51 | hv_store (copy, key, klen, newSVsv (HeVAL (he)), HeHASH (he)); |
|
|
52 | } |
|
|
53 | |
|
|
54 | hv = copy; |
|
|
55 | } |
|
|
56 | |
39 | random_map_params::random_map_params (HV *hv) |
57 | random_map_params::random_map_params (HV *hv) |
40 | { |
58 | { |
41 | this->hv = (HV *)SvREFCNT_inc_NN ((SV *)hv); |
59 | this->hv = (HV *)SvREFCNT_inc_NN ((SV *)hv); |
42 | |
60 | |
43 | assign (wall_name, get_str ("wall_name")); |
61 | assign (wall_name, get_str ("wall_name")); |
… | |
… | |
46 | ysize = get_iv ("ysize"); |
64 | ysize = get_iv ("ysize"); |
47 | expand2x = get_iv ("expand2x"); |
65 | expand2x = get_iv ("expand2x"); |
48 | layoutoptions1 = get_iv ("layoutoptions1"); |
66 | layoutoptions1 = get_iv ("layoutoptions1"); |
49 | layoutoptions2 = get_iv ("layoutoptions2"); |
67 | layoutoptions2 = get_iv ("layoutoptions2"); |
50 | layoutoptions3 = get_iv ("layoutoptions3"); |
68 | layoutoptions3 = get_iv ("layoutoptions3"); |
51 | symmetry = get_iv ("symmetry"); |
|
|
52 | difficulty = get_iv ("difficulty"); |
69 | difficulty = get_iv ("difficulty"); |
53 | difficulty_given = get_iv ("difficulty_given"); |
70 | difficulty_given = get_iv ("difficulty_given"); |
54 | difficulty_increase = get_nv ("difficulty_increase"); |
71 | difficulty_increase = get_nv ("difficulty_increase"); |
55 | dungeon_level = get_iv ("dungeon_level"); |
72 | dungeon_level = get_iv ("dungeon_level"); |
56 | dungeon_depth = get_iv ("dungeon_depth"); |
73 | dungeon_depth = get_iv ("dungeon_depth"); |
57 | orientation = get_iv ("orientation"); |
|
|
58 | random_seed = get_uv ("random_seed"); |
74 | random_seed = get_uv ("random_seed"); |
59 | total_map_hp = get_nv ("total_map_hp"); // actually val64, but I am too lazy |
75 | total_map_hp = get_nv ("total_map_hp"); // actually val64, but I am too lazy |
60 | map_layout_style = get_iv ("map_layout_style"); |
|
|
61 | symmetry_used = get_iv ("symmetry_used"); |
76 | symmetry_used = get_iv ("symmetry_used"); |
62 | } |
77 | } |
63 | |
78 | |
64 | random_map_params::~random_map_params () |
79 | random_map_params::~random_map_params () |
65 | { |
80 | { |
… | |
… | |
72 | set ("xsize" , xsize); |
87 | set ("xsize" , xsize); |
73 | set ("ysize" , ysize); |
88 | set ("ysize" , ysize); |
74 | set ("layoutoptions1" , layoutoptions1); |
89 | set ("layoutoptions1" , layoutoptions1); |
75 | set ("layoutoptions2" , layoutoptions2); |
90 | set ("layoutoptions2" , layoutoptions2); |
76 | set ("layoutoptions3" , layoutoptions3); |
91 | set ("layoutoptions3" , layoutoptions3); |
77 | set ("symmetry" , symmetry); |
|
|
78 | set ("dungeon_depth" , dungeon_depth); |
92 | set ("dungeon_depth" , dungeon_depth); |
79 | set ("orientation" , orientation); |
|
|
80 | set ("random_seed" , (UV)random_seed); |
93 | set ("random_seed" , (UV)random_seed); |
81 | set ("difficulty" , difficulty && difficulty_given ? difficulty : 0); |
94 | set ("difficulty" , difficulty && difficulty_given ? difficulty : 0); |
82 | set ("difficulty_increase", difficulty_increase); |
95 | set ("difficulty_increase", difficulty_increase); |
83 | set ("dungeon_level" , dungeon_level); |
96 | set ("dungeon_level" , dungeon_level); |
84 | |
97 | |
… | |
… | |
169 | random_map_params::set (const char *option, NV value) const |
182 | random_map_params::set (const char *option, NV value) const |
170 | { |
183 | { |
171 | set (option, newSVnv (value)); |
184 | set (option, newSVnv (value)); |
172 | } |
185 | } |
173 | |
186 | |
174 | void |
|
|
175 | random_map_params::hv_clone () |
|
|
176 | { |
|
|
177 | HV *copy = newHV (); |
|
|
178 | |
|
|
179 | hv_iterinit (hv); |
|
|
180 | |
|
|
181 | // does not work for utf-8 keys |
|
|
182 | while (HE *he = hv_iternext (hv)) |
|
|
183 | { |
|
|
184 | STRLEN klen; const char *key = HePV (he, klen); |
|
|
185 | hv_store (copy, key, klen, newSVsv (HeVAL (he)), HeHASH (he)); |
|
|
186 | } |
|
|
187 | |
|
|
188 | SvREFCNT_dec (hv); |
|
|
189 | hv = copy; |
|
|
190 | } |
|
|
191 | |
|
|
192 | bool |
187 | bool |
193 | maptile::generate_random_map (random_map_params *RP) |
188 | maptile::generate_random_map (random_map_params *RP) |
194 | { |
189 | { |
195 | RP->Xsize = RP->xsize; |
190 | RP->Xsize = RP->xsize; |
196 | RP->Ysize = RP->ysize; |
191 | RP->Ysize = RP->ysize; |
|
|
192 | |
|
|
193 | max_it (RP->dungeon_level, 1); |
197 | |
194 | |
198 | /* pick a random seed, or use the one from the input file */ |
195 | /* pick a random seed, or use the one from the input file */ |
199 | RP->random_seed = RP->random_seed |
196 | RP->random_seed = RP->random_seed |
200 | ? RP->random_seed + RP->dungeon_level |
197 | ? RP->random_seed + RP->dungeon_level |
201 | : time (0); |
198 | : pticks; |
202 | |
199 | |
203 | // we run "single-threaded" |
200 | // we run "single-threaded" |
204 | rmg_rndm.seed (RP->random_seed); |
201 | rmg_rndm.seed (RP->random_seed); |
|
|
202 | rmg_rndm.seed (RP->random_seed + pticks);//D |
205 | |
203 | |
206 | shstr buf = RP->as_shstr (); |
204 | shstr buf = RP->as_shstr (); |
207 | |
205 | |
208 | if (RP->difficulty == 0) |
206 | if (RP->difficulty == 0) |
209 | { |
207 | { |
210 | RP->difficulty = RP->dungeon_level; /* use this instead of a map difficulty */ |
208 | RP->difficulty = RP->dungeon_level; /* use this instead of a map difficulty */ |
211 | |
209 | |
212 | if (RP->difficulty_increase > 0.001) |
210 | if (RP->difficulty_increase > 0.001f) |
213 | RP->difficulty = (int) ((float) RP->dungeon_level * RP->difficulty_increase); |
211 | RP->difficulty = RP->dungeon_level * RP->difficulty_increase; |
214 | |
212 | |
215 | if (RP->difficulty < 1) |
213 | if (RP->difficulty < 1) |
216 | RP->difficulty = 1; |
214 | RP->difficulty = 1; |
217 | } |
215 | } |
218 | else |
216 | else |
… | |
… | |
225 | RP->Ysize = MIN_RANDOM_MAP_SIZE + rmg_rndm (25) + 5; |
223 | RP->Ysize = MIN_RANDOM_MAP_SIZE + rmg_rndm (25) + 5; |
226 | |
224 | |
227 | min_it (RP->Xsize, MAX_RANDOM_MAP_SIZE); |
225 | min_it (RP->Xsize, MAX_RANDOM_MAP_SIZE); |
228 | min_it (RP->Ysize, MAX_RANDOM_MAP_SIZE); |
226 | min_it (RP->Ysize, MAX_RANDOM_MAP_SIZE); |
229 | |
227 | |
|
|
228 | int symmetry = RP->get_iv ("symmetry", SYMMETRY_NONE); |
|
|
229 | |
230 | if (RP->symmetry == SYMMETRY_RANDOM) |
230 | if (symmetry == SYMMETRY_RANDOM) |
231 | RP->symmetry_used = rmg_rndm (SYMMETRY_XY) + 1; |
231 | RP->symmetry_used = rmg_rndm (SYMMETRY_XY) + 1; |
232 | else |
232 | else |
233 | RP->symmetry_used = RP->symmetry; |
233 | RP->symmetry_used = symmetry; |
234 | |
234 | |
235 | if (RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY) |
235 | if (RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY) |
236 | RP->Ysize = RP->Ysize / 2 + 1; |
236 | RP->Ysize = RP->Ysize / 2 + 1; |
237 | |
237 | |
238 | if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY) |
238 | if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY) |
… | |
… | |
258 | RP->map_layout_style = LAYOUT_SNAKE; |
258 | RP->map_layout_style = LAYOUT_SNAKE; |
259 | else if (strstr (layoutstyle, "squarespiral")) |
259 | else if (strstr (layoutstyle, "squarespiral")) |
260 | RP->map_layout_style = LAYOUT_SQUARE_SPIRAL; |
260 | RP->map_layout_style = LAYOUT_SQUARE_SPIRAL; |
261 | else if (strstr (layoutstyle, "cave")) |
261 | else if (strstr (layoutstyle, "cave")) |
262 | RP->map_layout_style = LAYOUT_CAVE; |
262 | RP->map_layout_style = LAYOUT_CAVE; |
|
|
263 | else if (strstr (layoutstyle, "castle")) |
|
|
264 | RP->map_layout_style = LAYOUT_CASTLE; |
|
|
265 | else if (strstr (layoutstyle, "multiple")) |
|
|
266 | RP->map_layout_style = LAYOUT_MULTIPLE; |
263 | else |
267 | else |
264 | RP->map_layout_style = rmg_rndm (NROFLAYOUTS - 1) + 1; /* No style found - choose one randomly */ |
268 | RP->map_layout_style = rmg_rndm (NROFLAYOUTS - 1) + 1; /* No style found - choose one randomly */ |
265 | |
269 | |
266 | layout maze (RP->Xsize, RP->Ysize); |
270 | layout maze (RP->Xsize, RP->Ysize); |
267 | maze.generate (RP); |
271 | maze.generate (RP); |
|
|
272 | |
|
|
273 | if (RP->get_iv ("rotate", 1)) |
|
|
274 | maze.rotate (rmg_rndm (4)); |
|
|
275 | |
|
|
276 | maze.symmetrize (RP->symmetry_used); |
|
|
277 | |
|
|
278 | if (RP->expand2x) |
|
|
279 | maze.expand2x (); |
|
|
280 | |
|
|
281 | #if 0 |
|
|
282 | maze.print ();//D |
|
|
283 | #endif |
268 | |
284 | |
269 | /* increment these for the current map */ |
285 | /* increment these for the current map */ |
270 | ++RP->dungeon_level; |
286 | ++RP->dungeon_level; |
271 | |
287 | |
272 | // need to patch RP becasue following code doesn't use the layout object |
288 | // need to patch RP becasue following code doesn't use the layout object |
… | |
… | |
303 | |
319 | |
304 | const char *exitstyle = RP->get_str ("exitstyle", ""); |
320 | const char *exitstyle = RP->get_str ("exitstyle", ""); |
305 | |
321 | |
306 | /* create exits unless the exitstyle is "none" */ |
322 | /* create exits unless the exitstyle is "none" */ |
307 | if (strcmp (exitstyle, "none")) |
323 | if (strcmp (exitstyle, "none")) |
308 | place_exits (this, maze, exitstyle, RP->orientation, RP); |
324 | place_exits (this, maze, exitstyle, RP->get_iv ("orientation", 0), RP); |
309 | |
325 | |
310 | CEDE; |
326 | CEDE; |
311 | |
327 | |
312 | const char *monsterstyle = RP->get_str ("monsterstyle", ""); |
328 | const char *monsterstyle = RP->get_str ("monsterstyle", ""); |
313 | |
329 | |
… | |
… | |
340 | /* generate treasures, etc. */ |
356 | /* generate treasures, etc. */ |
341 | fix_auto_apply (); |
357 | fix_auto_apply (); |
342 | |
358 | |
343 | CEDE; |
359 | CEDE; |
344 | |
360 | |
345 | unblock_exits (this, maze, RP); |
361 | unblock_exits (this, maze); |
346 | |
362 | |
347 | msg = buf; |
363 | msg = buf; |
348 | in_memory = MAP_ACTIVE; |
364 | in_memory = MAP_ACTIVE; |
349 | |
365 | |
350 | CEDE; |
366 | CEDE; |