… | |
… | |
41 | #define LAST_OPTION 64 /* set this to the last real option, for random */ |
41 | #define LAST_OPTION 64 /* set this to the last real option, for random */ |
42 | |
42 | |
43 | #define NO_PASS_DOORS 0 |
43 | #define NO_PASS_DOORS 0 |
44 | #define PASS_DOORS 1 |
44 | #define PASS_DOORS 1 |
45 | |
45 | |
|
|
46 | /* a macro to get a strongly centered random distribution, |
|
|
47 | from 0 to x, centered at x/2 */ |
|
|
48 | static int |
|
|
49 | bc_random (int x) |
|
|
50 | { |
|
|
51 | return (rndm (x) + rndm (x) + rndm (x)) / 3; |
|
|
52 | } |
46 | |
53 | |
47 | /* returns true if square x,y has P_NO_PASS set, which is true for walls |
54 | /* returns true if square x,y has P_NO_PASS set, which is true for walls |
48 | * and doors but not monsters. |
55 | * and doors but not monsters. |
49 | * This function is not map tile aware. |
56 | * This function is not map tile aware. |
50 | */ |
57 | */ |
… | |
… | |
76 | if (treasure_style) |
83 | if (treasure_style) |
77 | if (!strcmp (treasure_style, "none")) |
84 | if (!strcmp (treasure_style, "none")) |
78 | return; |
85 | return; |
79 | |
86 | |
80 | if (treasureoptions <= 0) |
87 | if (treasureoptions <= 0) |
81 | treasureoptions = RANDOM () % (2 * LAST_OPTION); |
88 | treasureoptions = rndm (2 * LAST_OPTION); |
82 | |
89 | |
83 | /* filter out the mutually exclusive options */ |
90 | /* filter out the mutually exclusive options */ |
84 | if ((treasureoptions & RICH) && (treasureoptions & SPARSE)) |
91 | if ((treasureoptions & RICH) && (treasureoptions & SPARSE)) |
85 | { |
92 | { |
86 | if (rndm (2)) |
93 | if (rndm (2)) |
… | |
… | |
89 | treasureoptions -= 2; |
96 | treasureoptions -= 2; |
90 | } |
97 | } |
91 | |
98 | |
92 | /* pick the number of treasures */ |
99 | /* pick the number of treasures */ |
93 | if (treasureoptions & SPARSE) |
100 | if (treasureoptions & SPARSE) |
94 | num_treasures = BC_RANDOM (RP->total_map_hp / 600 + RP->difficulty / 2 + 1); |
101 | num_treasures = bc_random (RP->total_map_hp / 600 + RP->difficulty / 2 + 1); |
95 | else if (treasureoptions & RICH) |
102 | else if (treasureoptions & RICH) |
96 | num_treasures = BC_RANDOM (RP->total_map_hp / 150 + 2 * RP->difficulty + 1); |
103 | num_treasures = bc_random (RP->total_map_hp / 150 + 2 * RP->difficulty + 1); |
97 | else |
104 | else |
98 | num_treasures = BC_RANDOM (RP->total_map_hp / 300 + RP->difficulty + 1); |
105 | num_treasures = bc_random (RP->total_map_hp / 300 + RP->difficulty + 1); |
99 | |
106 | |
100 | if (num_treasures <= 0) |
107 | if (num_treasures <= 0) |
101 | return; |
108 | return; |
102 | |
109 | |
103 | /* get the style map */ |
110 | /* get the style map */ |
104 | sprintf (styledirname, "%s", "/styles/treasurestyles"); |
111 | sprintf (styledirname, "%s", "/styles/treasurestyles"); |
105 | sprintf (stylefilepath, "%s/%s", styledirname, treasure_style); |
112 | sprintf (stylefilepath, "%s/%s", styledirname, treasure_style); |
106 | style_map = find_style (styledirname, treasure_style, -1); |
113 | style_map = find_style (styledirname, treasure_style, -1); |
|
|
114 | |
|
|
115 | if (!style_map) |
|
|
116 | { |
|
|
117 | LOG (llevError, "unable to load style map %s %s.\n", styledirname, treasure_style); |
|
|
118 | return; |
|
|
119 | } |
107 | |
120 | |
108 | /* all the treasure at one spot in the map. */ |
121 | /* all the treasure at one spot in the map. */ |
109 | if (treasureoptions & CONCENTRATED) |
122 | if (treasureoptions & CONCENTRATED) |
110 | { |
123 | { |
111 | |
124 | |
… | |
… | |
154 | |
167 | |
155 | i = j = -1; |
168 | i = j = -1; |
156 | tries = 0; |
169 | tries = 0; |
157 | while (i == -1 && tries < 100) |
170 | while (i == -1 && tries < 100) |
158 | { |
171 | { |
159 | i = RANDOM () % (RP->Xsize - 2) + 1; |
172 | i = rndm (RP->Xsize - 2) + 1; |
160 | j = RANDOM () % (RP->Ysize - 2) + 1; |
173 | j = rndm (RP->Ysize - 2) + 1; |
161 | find_enclosed_spot (map, &i, &j, RP); |
174 | find_enclosed_spot (map, &i, &j, RP); |
162 | if (wall_blocked (map, i, j)) |
175 | if (wall_blocked (map, i, j)) |
163 | i = -1; |
176 | i = -1; |
164 | tries++; |
177 | tries++; |
165 | } |
178 | } |
… | |
… | |
181 | { /* DIFFUSE treasure layout */ |
194 | { /* DIFFUSE treasure layout */ |
182 | int ti, i, j; |
195 | int ti, i, j; |
183 | |
196 | |
184 | for (ti = 0; ti < num_treasures; ti++) |
197 | for (ti = 0; ti < num_treasures; ti++) |
185 | { |
198 | { |
186 | i = RANDOM () % (RP->Xsize - 2) + 1; |
199 | i = rndm (RP->Xsize - 2) + 1; |
187 | j = RANDOM () % (RP->Ysize - 2) + 1; |
200 | j = rndm (RP->Ysize - 2) + 1; |
188 | place_chest (treasureoptions, i, j, map, style_map, 1, RP); |
201 | place_chest (treasureoptions, i, j, map, style_map, 1, RP); |
189 | } |
202 | } |
190 | } |
203 | } |
191 | } |
204 | } |
192 | |
205 | |
… | |
… | |
253 | |
266 | |
254 | if (trap_map) |
267 | if (trap_map) |
255 | { |
268 | { |
256 | the_trap = pick_random_object (trap_map); |
269 | the_trap = pick_random_object (trap_map); |
257 | the_trap->stats.Cha = 10 + RP->difficulty; |
270 | the_trap->stats.Cha = 10 + RP->difficulty; |
258 | the_trap->level = BC_RANDOM ((3 * RP->difficulty) / 2); |
271 | the_trap->level = bc_random ((3 * RP->difficulty) / 2); |
259 | if (the_trap) |
272 | if (the_trap) |
260 | { |
273 | { |
261 | object *new_trap; |
274 | object *new_trap; |
262 | |
275 | |
263 | new_trap = arch_to_object (the_trap->arch); |
276 | new_trap = arch_to_object (the_trap->arch); |
… | |
… | |
270 | } |
283 | } |
271 | |
284 | |
272 | /* set the chest lock code, and call the keyplacer routine with |
285 | /* set the chest lock code, and call the keyplacer routine with |
273 | the lockcode. It's not worth bothering to lock the chest if |
286 | the lockcode. It's not worth bothering to lock the chest if |
274 | there's only 1 treasure.... */ |
287 | there's only 1 treasure.... */ |
275 | |
|
|
276 | if ((treasureoptions & KEYREQUIRED) && n_treasures > 1) |
288 | if ((treasureoptions & KEYREQUIRED) && n_treasures > 1) |
277 | { |
289 | { |
278 | char keybuf[1024]; |
290 | char keybuf[1024]; |
279 | |
291 | |
280 | sprintf (keybuf, "%d", (int) RANDOM ()); |
292 | sprintf (keybuf, "%d", rndm (1000000000)); |
281 | the_chest->slaying = keybuf; |
293 | the_chest->slaying = keybuf; |
282 | keyplace (map, x, y, keybuf, PASS_DOORS, 1, RP); |
294 | keyplace (map, x, y, keybuf, PASS_DOORS, 1, RP); |
283 | } |
295 | } |
284 | |
296 | |
285 | /* actually place the chest. */ |
297 | /* actually place the chest. */ |
… | |
… | |
347 | int tries = 0; |
359 | int tries = 0; |
348 | |
360 | |
349 | the_keymaster = 0; |
361 | the_keymaster = 0; |
350 | while (tries < 15 && !the_keymaster) |
362 | while (tries < 15 && !the_keymaster) |
351 | { |
363 | { |
352 | i = (RANDOM () % (RP->Xsize - 2)) + 1; |
364 | i = rndm (RP->Xsize - 2) + 1; |
353 | j = (RANDOM () % (RP->Ysize - 2)) + 1; |
365 | j = rndm (RP->Ysize - 2) + 1; |
354 | tries++; |
366 | tries++; |
355 | the_keymaster = find_closest_monster (map, i, j, RP); |
367 | the_keymaster = find_closest_monster (map, i, j, RP); |
356 | } |
368 | } |
357 | |
369 | |
358 | /* 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. */ |
… | |
… | |
361 | int freeindex; |
373 | int freeindex; |
362 | |
374 | |
363 | freeindex = -1; |
375 | freeindex = -1; |
364 | for (tries = 0; tries < 15 && freeindex == -1; tries++) |
376 | for (tries = 0; tries < 15 && freeindex == -1; tries++) |
365 | { |
377 | { |
366 | kx = (RANDOM () % (RP->Xsize - 2)) + 1; |
378 | kx = rndm (RP->Xsize - 2) + 1; |
367 | ky = (RANDOM () % (RP->Ysize - 2)) + 1; |
379 | ky = rndm (RP->Ysize - 2) + 1; |
368 | 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); |
369 | } |
381 | } |
370 | |
382 | |
371 | // can freeindex ever be < 0? |
383 | // can freeindex ever be < 0? |
372 | if (freeindex >= 0) |
384 | if (freeindex >= 0) |
… | |
… | |
568 | /* setup num_free_spots and room_free_spots */ |
580 | /* setup num_free_spots and room_free_spots */ |
569 | find_spot_in_room_recursive (layout2, x, y, RP); |
581 | find_spot_in_room_recursive (layout2, x, y, RP); |
570 | |
582 | |
571 | if (number_of_free_spots_in_room > 0) |
583 | if (number_of_free_spots_in_room > 0) |
572 | { |
584 | { |
573 | i = RANDOM () % number_of_free_spots_in_room; |
585 | i = rndm (number_of_free_spots_in_room); |
574 | *kx = room_free_spots_x[i]; |
586 | *kx = room_free_spots_x[i]; |
575 | *ky = room_free_spots_y[i]; |
587 | *ky = room_free_spots_y[i]; |
576 | } |
588 | } |
577 | |
589 | |
578 | /* deallocate the temp. layout */ |
590 | /* deallocate the temp. layout */ |
… | |
… | |
771 | } |
783 | } |
772 | } |
784 | } |
773 | else |
785 | else |
774 | { |
786 | { |
775 | layout[x][y] = 1; |
787 | layout[x][y] = 1; |
|
|
788 | |
776 | /* now search all the 8 squares around recursively for free spots,in random order */ |
789 | /* now search all the 8 squares around recursively for free spots,in random order */ |
777 | for (i = rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) |
790 | for (i = rndm (8), j = 0; j < 8 && !theMonsterToFind; i++, j++) |
778 | find_doors_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], doorlist, ndoors, RP); |
791 | find_doors_in_room_recursive (layout, map, |
|
|
792 | x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], |
|
|
793 | doorlist, ndoors, RP); |
779 | } |
794 | } |
780 | } |
795 | } |
781 | |
796 | |
782 | /* find a random non-blocked spot in this room to drop a key. */ |
797 | /* find a random non-blocked spot in this room to drop a key. */ |
783 | object ** |
798 | object ** |
… | |
… | |
839 | new_door->y = door->y; |
854 | new_door->y = door->y; |
840 | door->remove (); |
855 | door->remove (); |
841 | door->destroy (); |
856 | door->destroy (); |
842 | doorlist[i] = new_door; |
857 | doorlist[i] = new_door; |
843 | insert_ob_in_map (new_door, map, NULL, 0); |
858 | insert_ob_in_map (new_door, map, NULL, 0); |
844 | sprintf (keybuf, "%d", (int) RANDOM ()); |
859 | sprintf (keybuf, "%d", rndm (1000000000)); |
845 | new_door->slaying = keybuf; |
860 | new_door->slaying = keybuf; |
846 | keyplace (map, new_door->x, new_door->y, keybuf, NO_PASS_DOORS, 2, RP); |
861 | keyplace (map, new_door->x, new_door->y, keybuf, NO_PASS_DOORS, 2, RP); |
847 | } |
862 | } |
848 | } |
863 | } |
849 | |
864 | |