ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/treasure.C
(Generate patch)

Comparing deliantra/server/random_maps/treasure.C (file contents):
Revision 1.23 by root, Sat Jan 27 00:56:48 2007 UTC vs.
Revision 1.24 by root, Sat Jan 27 02:19:37 2007 UTC

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 */
48static int
49bc_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 */
160 167
161 i = j = -1; 168 i = j = -1;
162 tries = 0; 169 tries = 0;
163 while (i == -1 && tries < 100) 170 while (i == -1 && tries < 100)
164 { 171 {
165 i = RANDOM () % (RP->Xsize - 2) + 1; 172 i = rndm (RP->Xsize - 2) + 1;
166 j = RANDOM () % (RP->Ysize - 2) + 1; 173 j = rndm (RP->Ysize - 2) + 1;
167 find_enclosed_spot (map, &i, &j, RP); 174 find_enclosed_spot (map, &i, &j, RP);
168 if (wall_blocked (map, i, j)) 175 if (wall_blocked (map, i, j))
169 i = -1; 176 i = -1;
170 tries++; 177 tries++;
171 } 178 }
187 { /* DIFFUSE treasure layout */ 194 { /* DIFFUSE treasure layout */
188 int ti, i, j; 195 int ti, i, j;
189 196
190 for (ti = 0; ti < num_treasures; ti++) 197 for (ti = 0; ti < num_treasures; ti++)
191 { 198 {
192 i = RANDOM () % (RP->Xsize - 2) + 1; 199 i = rndm (RP->Xsize - 2) + 1;
193 j = RANDOM () % (RP->Ysize - 2) + 1; 200 j = rndm (RP->Ysize - 2) + 1;
194 place_chest (treasureoptions, i, j, map, style_map, 1, RP); 201 place_chest (treasureoptions, i, j, map, style_map, 1, RP);
195 } 202 }
196 } 203 }
197} 204}
198 205
259 266
260 if (trap_map) 267 if (trap_map)
261 { 268 {
262 the_trap = pick_random_object (trap_map); 269 the_trap = pick_random_object (trap_map);
263 the_trap->stats.Cha = 10 + RP->difficulty; 270 the_trap->stats.Cha = 10 + RP->difficulty;
264 the_trap->level = BC_RANDOM ((3 * RP->difficulty) / 2); 271 the_trap->level = bc_random ((3 * RP->difficulty) / 2);
265 if (the_trap) 272 if (the_trap)
266 { 273 {
267 object *new_trap; 274 object *new_trap;
268 275
269 new_trap = arch_to_object (the_trap->arch); 276 new_trap = arch_to_object (the_trap->arch);
276 } 283 }
277 284
278 /* set the chest lock code, and call the keyplacer routine with 285 /* set the chest lock code, and call the keyplacer routine with
279 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
280 there's only 1 treasure.... */ 287 there's only 1 treasure.... */
281
282 if ((treasureoptions & KEYREQUIRED) && n_treasures > 1) 288 if ((treasureoptions & KEYREQUIRED) && n_treasures > 1)
283 { 289 {
284 char keybuf[1024]; 290 char keybuf[1024];
285 291
286 sprintf (keybuf, "%d", (int) RANDOM ()); 292 sprintf (keybuf, "%d", rndm (1000000000));
287 the_chest->slaying = keybuf; 293 the_chest->slaying = keybuf;
288 keyplace (map, x, y, keybuf, PASS_DOORS, 1, RP); 294 keyplace (map, x, y, keybuf, PASS_DOORS, 1, RP);
289 } 295 }
290 296
291 /* actually place the chest. */ 297 /* actually place the chest. */
353 int tries = 0; 359 int tries = 0;
354 360
355 the_keymaster = 0; 361 the_keymaster = 0;
356 while (tries < 15 && !the_keymaster) 362 while (tries < 15 && !the_keymaster)
357 { 363 {
358 i = (RANDOM () % (RP->Xsize - 2)) + 1; 364 i = rndm (RP->Xsize - 2) + 1;
359 j = (RANDOM () % (RP->Ysize - 2)) + 1; 365 j = rndm (RP->Ysize - 2) + 1;
360 tries++; 366 tries++;
361 the_keymaster = find_closest_monster (map, i, j, RP); 367 the_keymaster = find_closest_monster (map, i, j, RP);
362 } 368 }
363 369
364 /* 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. */
367 int freeindex; 373 int freeindex;
368 374
369 freeindex = -1; 375 freeindex = -1;
370 for (tries = 0; tries < 15 && freeindex == -1; tries++) 376 for (tries = 0; tries < 15 && freeindex == -1; tries++)
371 { 377 {
372 kx = (RANDOM () % (RP->Xsize - 2)) + 1; 378 kx = rndm (RP->Xsize - 2) + 1;
373 ky = (RANDOM () % (RP->Ysize - 2)) + 1; 379 ky = rndm (RP->Ysize - 2) + 1;
374 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);
375 } 381 }
376 382
377 // can freeindex ever be < 0? 383 // can freeindex ever be < 0?
378 if (freeindex >= 0) 384 if (freeindex >= 0)
574 /* setup num_free_spots and room_free_spots */ 580 /* setup num_free_spots and room_free_spots */
575 find_spot_in_room_recursive (layout2, x, y, RP); 581 find_spot_in_room_recursive (layout2, x, y, RP);
576 582
577 if (number_of_free_spots_in_room > 0) 583 if (number_of_free_spots_in_room > 0)
578 { 584 {
579 i = RANDOM () % number_of_free_spots_in_room; 585 i = rndm (number_of_free_spots_in_room);
580 *kx = room_free_spots_x[i]; 586 *kx = room_free_spots_x[i];
581 *ky = room_free_spots_y[i]; 587 *ky = room_free_spots_y[i];
582 } 588 }
583 589
584 /* deallocate the temp. layout */ 590 /* deallocate the temp. layout */
777 } 783 }
778 } 784 }
779 else 785 else
780 { 786 {
781 layout[x][y] = 1; 787 layout[x][y] = 1;
788
782 /* 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 */
783 for (i = rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) 790 for (i = rndm (8), j = 0; j < 8 && !theMonsterToFind; i++, j++)
784 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);
785 } 794 }
786} 795}
787 796
788/* 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. */
789object ** 798object **
845 new_door->y = door->y; 854 new_door->y = door->y;
846 door->remove (); 855 door->remove ();
847 door->destroy (); 856 door->destroy ();
848 doorlist[i] = new_door; 857 doorlist[i] = new_door;
849 insert_ob_in_map (new_door, map, NULL, 0); 858 insert_ob_in_map (new_door, map, NULL, 0);
850 sprintf (keybuf, "%d", (int) RANDOM ()); 859 sprintf (keybuf, "%d", rndm (1000000000));
851 new_door->slaying = keybuf; 860 new_door->slaying = keybuf;
852 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);
853 } 862 }
854 } 863 }
855 864

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines