… | |
… | |
45 | /* a macro to get a strongly centered random distribution, |
45 | /* a macro to get a strongly centered random distribution, |
46 | from 0 to x, centered at x/2 */ |
46 | from 0 to x, centered at x/2 */ |
47 | static int |
47 | static int |
48 | bc_random (int x) |
48 | bc_random (int x) |
49 | { |
49 | { |
50 | return (rndm (x) + rndm (x) + rndm (x)) / 3; |
50 | return (rmg_rndm (x) + rmg_rndm (x) + rmg_rndm (x)) / 3; |
51 | } |
51 | } |
52 | |
52 | |
53 | /* returns true if square x,y has P_NO_PASS set, which is true for walls |
53 | /* returns true if square x,y has P_NO_PASS set, which is true for walls |
54 | * and doors but not monsters. |
54 | * and doors but not monsters. |
55 | * This function is not map tile aware. |
55 | * This function is not map tile aware. |
… | |
… | |
82 | if (treasure_style) |
82 | if (treasure_style) |
83 | if (!strcmp (treasure_style, "none")) |
83 | if (!strcmp (treasure_style, "none")) |
84 | return; |
84 | return; |
85 | |
85 | |
86 | if (treasureoptions <= 0) |
86 | if (treasureoptions <= 0) |
87 | treasureoptions = rndm (2 * LAST_OPTION); |
87 | treasureoptions = rmg_rndm (2 * LAST_OPTION); |
88 | |
88 | |
89 | /* filter out the mutually exclusive options */ |
89 | /* filter out the mutually exclusive options */ |
90 | if ((treasureoptions & RICH) && (treasureoptions & SPARSE)) |
90 | if ((treasureoptions & RICH) && (treasureoptions & SPARSE)) |
91 | { |
91 | { |
92 | if (rndm (2)) |
92 | if (rmg_rndm (2)) |
93 | treasureoptions -= 1; |
93 | treasureoptions -= 1; |
94 | else |
94 | else |
95 | treasureoptions -= 2; |
95 | treasureoptions -= 2; |
96 | } |
96 | } |
97 | |
97 | |
… | |
… | |
168 | |
168 | |
169 | i = j = -1; |
169 | i = j = -1; |
170 | tries = 0; |
170 | tries = 0; |
171 | while (i == -1 && tries < 100) |
171 | while (i == -1 && tries < 100) |
172 | { |
172 | { |
173 | i = rndm (RP->Xsize - 2) + 1; |
173 | i = rmg_rndm (RP->Xsize - 2) + 1; |
174 | j = rndm (RP->Ysize - 2) + 1; |
174 | j = rmg_rndm (RP->Ysize - 2) + 1; |
175 | find_enclosed_spot (map, &i, &j, RP); |
175 | find_enclosed_spot (map, &i, &j, RP); |
176 | |
176 | |
177 | if (wall_blocked (map, i, j)) |
177 | if (wall_blocked (map, i, j)) |
178 | i = -1; |
178 | i = -1; |
179 | |
179 | |
… | |
… | |
200 | { /* DIFFUSE treasure layout */ |
200 | { /* DIFFUSE treasure layout */ |
201 | int ti, i, j; |
201 | int ti, i, j; |
202 | |
202 | |
203 | for (ti = 0; ti < num_treasures; ti++) |
203 | for (ti = 0; ti < num_treasures; ti++) |
204 | { |
204 | { |
205 | i = rndm (RP->Xsize - 2) + 1; |
205 | i = rmg_rndm (RP->Xsize - 2) + 1; |
206 | j = rndm (RP->Ysize - 2) + 1; |
206 | j = rmg_rndm (RP->Ysize - 2) + 1; |
207 | place_chest (treasureoptions, i, j, map, style_map, 1, RP); |
207 | place_chest (treasureoptions, i, j, map, style_map, 1, RP); |
208 | } |
208 | } |
209 | } |
209 | } |
210 | } |
210 | } |
211 | |
211 | |
… | |
… | |
213 | determined (may be null, or may be a treasure list from lib/treasures, |
213 | determined (may be null, or may be a treasure list from lib/treasures, |
214 | if the global variable "treasurestyle" is set to that treasure list's name */ |
214 | if the global variable "treasurestyle" is set to that treasure list's name */ |
215 | object * |
215 | object * |
216 | place_chest (int treasureoptions, int x, int y, maptile *map, maptile *style_map, int n_treasures, random_map_params *RP) |
216 | place_chest (int treasureoptions, int x, int y, maptile *map, maptile *style_map, int n_treasures, random_map_params *RP) |
217 | { |
217 | { |
218 | object *the_chest; |
|
|
219 | int i, xl, yl; |
|
|
220 | |
|
|
221 | the_chest = get_archetype ("chest"); /* was "chest_2" */ |
218 | object *the_chest = archetype::get (shstr_chest); /* was "chest_2" */ |
222 | |
219 | |
223 | /* first, find a place to put the chest. */ |
220 | /* first, find a place to put the chest. */ |
224 | i = find_first_free_spot (the_chest, map, x, y); |
221 | int i = find_first_free_spot (the_chest, map, x, y); // this call uses the main rng |
225 | if (i == -1) |
222 | if (i == -1) |
226 | { |
223 | { |
227 | the_chest->destroy (); |
224 | the_chest->destroy (); |
228 | return NULL; |
225 | return NULL; |
229 | } |
226 | } |
230 | |
227 | |
231 | xl = x + freearr_x[i]; |
228 | int xl = x + freearr_x[i]; |
232 | yl = y + freearr_y[i]; |
229 | int yl = y + freearr_y[i]; |
233 | |
230 | |
234 | /* if the placement is blocked, return a fail. */ |
231 | /* if the placement is blocked, return a fail. */ |
235 | if (wall_blocked (map, xl, yl)) |
232 | if (wall_blocked (map, xl, yl)) |
236 | return 0; |
233 | return 0; |
237 | |
234 | |
… | |
… | |
244 | treasurelist *tlist = find_treasurelist (RP->treasurestyle); |
241 | treasurelist *tlist = find_treasurelist (RP->treasurestyle); |
245 | |
242 | |
246 | if (tlist != NULL) |
243 | if (tlist != NULL) |
247 | for (ti = 0; ti < n_treasures; ti++) |
244 | for (ti = 0; ti < n_treasures; ti++) |
248 | { /* use the treasure list */ |
245 | { /* use the treasure list */ |
249 | object *new_treasure = style_map->pick_random_object (); |
246 | object *new_treasure = style_map->pick_random_object (rmg_rndm); |
250 | |
247 | |
251 | insert_ob_in_ob (arch_to_object (new_treasure->arch), the_chest); |
248 | insert_ob_in_ob (arch_to_object (new_treasure->arch), the_chest); |
252 | } |
249 | } |
253 | else |
250 | else |
254 | { /* use the style map */ |
251 | { /* use the style map */ |
… | |
… | |
268 | { |
265 | { |
269 | maptile *trap_map = find_style ("/styles/trapstyles", "traps", -1); |
266 | maptile *trap_map = find_style ("/styles/trapstyles", "traps", -1); |
270 | |
267 | |
271 | if (trap_map) |
268 | if (trap_map) |
272 | { |
269 | { |
273 | object *the_trap = trap_map->pick_random_object (); |
270 | object *the_trap = trap_map->pick_random_object (rmg_rndm); |
274 | |
271 | |
275 | the_trap->stats.Cha = 10 + RP->difficulty; |
272 | the_trap->stats.Cha = 10 + RP->difficulty; |
276 | the_trap->level = bc_random ((3 * RP->difficulty) / 2); |
273 | the_trap->level = bc_random ((3 * RP->difficulty) / 2); |
277 | |
274 | |
278 | if (the_trap) |
275 | if (the_trap) |
… | |
… | |
291 | there's only 1 treasure.... */ |
288 | there's only 1 treasure.... */ |
292 | if ((treasureoptions & KEYREQUIRED) && n_treasures > 1) |
289 | if ((treasureoptions & KEYREQUIRED) && n_treasures > 1) |
293 | { |
290 | { |
294 | char keybuf[1024]; |
291 | char keybuf[1024]; |
295 | |
292 | |
296 | sprintf (keybuf, "%d", rndm (1000000000)); |
293 | sprintf (keybuf, "%d", rmg_rndm (1000000000)); |
297 | the_chest->slaying = keybuf; |
294 | the_chest->slaying = keybuf; |
298 | keyplace (map, x, y, keybuf, PASS_DOORS, 1, RP); |
295 | keyplace (map, x, y, keybuf, PASS_DOORS, 1, RP); |
299 | } |
296 | } |
300 | |
297 | |
301 | /* actually place the chest. */ |
298 | /* actually place the chest. */ |
… | |
… | |
350 | keyplace (maptile *map, int x, int y, char *keycode, int door_flag, int n_keys, random_map_params *RP) |
347 | keyplace (maptile *map, int x, int y, char *keycode, int door_flag, int n_keys, random_map_params *RP) |
351 | { |
348 | { |
352 | int i, j; |
349 | int i, j; |
353 | int kx = 0, ky = 0; |
350 | int kx = 0, ky = 0; |
354 | object *the_keymaster; /* the monster that gets the key. */ |
351 | object *the_keymaster; /* the monster that gets the key. */ |
355 | object *the_key; |
|
|
356 | |
352 | |
357 | /* get a key and set its keycode */ |
353 | /* get a key and set its keycode */ |
358 | the_key = get_archetype ("key2"); |
354 | object *the_key = archetype::get (shstr_key2); |
359 | the_key->slaying = keycode; |
355 | the_key->slaying = keycode; |
360 | |
356 | |
361 | if (door_flag == PASS_DOORS) |
357 | if (door_flag == PASS_DOORS) |
362 | { |
358 | { |
363 | int tries = 0; |
359 | int tries = 0; |
364 | |
360 | |
365 | the_keymaster = 0; |
361 | the_keymaster = 0; |
366 | while (tries < 15 && !the_keymaster) |
362 | while (tries < 15 && !the_keymaster) |
367 | { |
363 | { |
368 | i = rndm (RP->Xsize - 2) + 1; |
364 | i = rmg_rndm (RP->Xsize - 2) + 1; |
369 | j = rndm (RP->Ysize - 2) + 1; |
365 | j = rmg_rndm (RP->Ysize - 2) + 1; |
370 | tries++; |
366 | tries++; |
371 | the_keymaster = find_closest_monster (map, i, j, RP); |
367 | the_keymaster = find_closest_monster (map, i, j, RP); |
372 | } |
368 | } |
373 | |
369 | |
374 | /* if we don't find a good keymaster, drop the key on the ground. */ |
370 | /* if we don't find a good keymaster, drop the key on the ground. */ |
… | |
… | |
377 | int freeindex; |
373 | int freeindex; |
378 | |
374 | |
379 | freeindex = -1; |
375 | freeindex = -1; |
380 | for (tries = 0; tries < 15 && freeindex == -1; tries++) |
376 | for (tries = 0; tries < 15 && freeindex == -1; tries++) |
381 | { |
377 | { |
382 | kx = rndm (RP->Xsize - 2) + 1; |
378 | kx = rmg_rndm (RP->Xsize - 2) + 1; |
383 | ky = rndm (RP->Ysize - 2) + 1; |
379 | ky = rmg_rndm (RP->Ysize - 2) + 1; |
384 | freeindex = find_free_spot (the_key, map, kx, ky, 1, SIZEOFFREE1 + 1); |
380 | freeindex = find_free_spot (the_key, map, kx, ky, 1, SIZEOFFREE1 + 1); |
385 | } |
381 | } |
386 | |
382 | |
387 | // can freeindex ever be < 0? |
383 | // can freeindex ever be < 0? |
388 | if (freeindex >= 0) |
384 | if (freeindex >= 0) |
… | |
… | |
480 | return theMonsterToFind; |
476 | return theMonsterToFind; |
481 | } |
477 | } |
482 | } |
478 | } |
483 | |
479 | |
484 | /* now search all the 8 squares around recursively for a monster,in random order */ |
480 | /* now search all the 8 squares around recursively for a monster,in random order */ |
485 | for (i = rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) |
481 | for (i = rmg_rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) |
486 | { |
482 | { |
487 | theMonsterToFind = find_monster_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); |
483 | theMonsterToFind = find_monster_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); |
488 | if (theMonsterToFind != NULL) |
484 | if (theMonsterToFind != NULL) |
489 | return theMonsterToFind; |
485 | return theMonsterToFind; |
490 | } |
486 | } |
… | |
… | |
543 | room_free_spots_x[number_of_free_spots_in_room] = x; |
539 | room_free_spots_x[number_of_free_spots_in_room] = x; |
544 | room_free_spots_y[number_of_free_spots_in_room] = y; |
540 | room_free_spots_y[number_of_free_spots_in_room] = y; |
545 | number_of_free_spots_in_room++; |
541 | number_of_free_spots_in_room++; |
546 | |
542 | |
547 | /* now search all the 8 squares around recursively for free spots,in random order */ |
543 | /* now search all the 8 squares around recursively for free spots,in random order */ |
548 | for (i = rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) |
544 | for (i = rmg_rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) |
549 | find_spot_in_room_recursive (layout, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); |
545 | find_spot_in_room_recursive (layout, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); |
550 | |
546 | |
551 | } |
547 | } |
552 | |
548 | |
553 | /* find a random non-blocked spot in this room to drop a key. */ |
549 | /* find a random non-blocked spot in this room to drop a key. */ |
… | |
… | |
574 | /* setup num_free_spots and room_free_spots */ |
570 | /* setup num_free_spots and room_free_spots */ |
575 | find_spot_in_room_recursive (layout2, x, y, RP); |
571 | find_spot_in_room_recursive (layout2, x, y, RP); |
576 | |
572 | |
577 | if (number_of_free_spots_in_room > 0) |
573 | if (number_of_free_spots_in_room > 0) |
578 | { |
574 | { |
579 | i = rndm (number_of_free_spots_in_room); |
575 | i = rmg_rndm (number_of_free_spots_in_room); |
580 | *kx = room_free_spots_x[i]; |
576 | *kx = room_free_spots_x[i]; |
581 | *ky = room_free_spots_y[i]; |
577 | *ky = room_free_spots_y[i]; |
582 | } |
578 | } |
583 | |
579 | |
584 | /* deallocate the temp. layout */ |
580 | /* deallocate the temp. layout */ |
… | |
… | |
652 | *cy = ly; |
648 | *cy = ly; |
653 | return; |
649 | return; |
654 | } |
650 | } |
655 | } |
651 | } |
656 | /* give up and return the closest free spot. */ |
652 | /* give up and return the closest free spot. */ |
657 | i = find_free_spot (archetype::find ("chest"), map, x, y, 1, SIZEOFFREE1 + 1); |
653 | i = find_free_spot (archetype::find (shstr_chest), map, x, y, 1, SIZEOFFREE1 + 1); |
658 | |
654 | |
659 | if (i != -1) |
655 | if (i != -1) |
660 | { |
656 | { |
661 | *cx = x + freearr_x[i]; |
657 | *cx = x + freearr_x[i]; |
662 | *cy = y + freearr_y[i]; |
658 | *cy = y + freearr_y[i]; |
… | |
… | |
779 | else |
775 | else |
780 | { |
776 | { |
781 | layout[x][y] = 1; |
777 | layout[x][y] = 1; |
782 | |
778 | |
783 | /* now search all the 8 squares around recursively for free spots,in random order */ |
779 | /* now search all the 8 squares around recursively for free spots,in random order */ |
784 | for (i = rndm (8), j = 0; j < 8 && !theMonsterToFind; i++, j++) |
780 | for (i = rmg_rndm (8), j = 0; j < 8 && !theMonsterToFind; i++, j++) |
785 | find_doors_in_room_recursive (layout, map, |
781 | find_doors_in_room_recursive (layout, map, |
786 | x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], |
782 | x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], |
787 | doorlist, ndoors, RP); |
783 | doorlist, ndoors, RP); |
788 | } |
784 | } |
789 | } |
785 | } |
… | |
… | |
834 | new_door->y = door->y; |
830 | new_door->y = door->y; |
835 | door->remove (); |
831 | door->remove (); |
836 | door->destroy (); |
832 | door->destroy (); |
837 | doorlist[i] = new_door; |
833 | doorlist[i] = new_door; |
838 | insert_ob_in_map (new_door, map, NULL, 0); |
834 | insert_ob_in_map (new_door, map, NULL, 0); |
839 | sprintf (keybuf, "%d", rndm (1000000000)); |
835 | sprintf (keybuf, "%d", rmg_rndm (1000000000)); |
840 | new_door->slaying = keybuf; |
836 | new_door->slaying = keybuf; |
841 | keyplace (map, new_door->x, new_door->y, keybuf, NO_PASS_DOORS, 2, RP); |
837 | keyplace (map, new_door->x, new_door->y, keybuf, NO_PASS_DOORS, 2, RP); |
842 | } |
838 | } |
843 | } |
839 | } |
844 | |
840 | |