--- deliantra/server/random_maps/treasure.C 2007/01/27 00:56:48 1.23 +++ deliantra/server/random_maps/treasure.C 2007/01/27 02:19:37 1.24 @@ -43,6 +43,13 @@ #define NO_PASS_DOORS 0 #define PASS_DOORS 1 +/* a macro to get a strongly centered random distribution, + from 0 to x, centered at x/2 */ +static int +bc_random (int x) +{ + return (rndm (x) + rndm (x) + rndm (x)) / 3; +} /* returns true if square x,y has P_NO_PASS set, which is true for walls * and doors but not monsters. @@ -78,7 +85,7 @@ return; if (treasureoptions <= 0) - treasureoptions = RANDOM () % (2 * LAST_OPTION); + treasureoptions = rndm (2 * LAST_OPTION); /* filter out the mutually exclusive options */ if ((treasureoptions & RICH) && (treasureoptions & SPARSE)) @@ -91,11 +98,11 @@ /* pick the number of treasures */ if (treasureoptions & SPARSE) - num_treasures = BC_RANDOM (RP->total_map_hp / 600 + RP->difficulty / 2 + 1); + num_treasures = bc_random (RP->total_map_hp / 600 + RP->difficulty / 2 + 1); else if (treasureoptions & RICH) - num_treasures = BC_RANDOM (RP->total_map_hp / 150 + 2 * RP->difficulty + 1); + num_treasures = bc_random (RP->total_map_hp / 150 + 2 * RP->difficulty + 1); else - num_treasures = BC_RANDOM (RP->total_map_hp / 300 + RP->difficulty + 1); + num_treasures = bc_random (RP->total_map_hp / 300 + RP->difficulty + 1); if (num_treasures <= 0) return; @@ -162,8 +169,8 @@ tries = 0; while (i == -1 && tries < 100) { - i = RANDOM () % (RP->Xsize - 2) + 1; - j = RANDOM () % (RP->Ysize - 2) + 1; + i = rndm (RP->Xsize - 2) + 1; + j = rndm (RP->Ysize - 2) + 1; find_enclosed_spot (map, &i, &j, RP); if (wall_blocked (map, i, j)) i = -1; @@ -189,8 +196,8 @@ for (ti = 0; ti < num_treasures; ti++) { - i = RANDOM () % (RP->Xsize - 2) + 1; - j = RANDOM () % (RP->Ysize - 2) + 1; + i = rndm (RP->Xsize - 2) + 1; + j = rndm (RP->Ysize - 2) + 1; place_chest (treasureoptions, i, j, map, style_map, 1, RP); } } @@ -261,7 +268,7 @@ { the_trap = pick_random_object (trap_map); the_trap->stats.Cha = 10 + RP->difficulty; - the_trap->level = BC_RANDOM ((3 * RP->difficulty) / 2); + the_trap->level = bc_random ((3 * RP->difficulty) / 2); if (the_trap) { object *new_trap; @@ -278,12 +285,11 @@ /* set the chest lock code, and call the keyplacer routine with the lockcode. It's not worth bothering to lock the chest if there's only 1 treasure.... */ - if ((treasureoptions & KEYREQUIRED) && n_treasures > 1) { char keybuf[1024]; - sprintf (keybuf, "%d", (int) RANDOM ()); + sprintf (keybuf, "%d", rndm (1000000000)); the_chest->slaying = keybuf; keyplace (map, x, y, keybuf, PASS_DOORS, 1, RP); } @@ -355,8 +361,8 @@ the_keymaster = 0; while (tries < 15 && !the_keymaster) { - i = (RANDOM () % (RP->Xsize - 2)) + 1; - j = (RANDOM () % (RP->Ysize - 2)) + 1; + i = rndm (RP->Xsize - 2) + 1; + j = rndm (RP->Ysize - 2) + 1; tries++; the_keymaster = find_closest_monster (map, i, j, RP); } @@ -369,8 +375,8 @@ freeindex = -1; for (tries = 0; tries < 15 && freeindex == -1; tries++) { - kx = (RANDOM () % (RP->Xsize - 2)) + 1; - ky = (RANDOM () % (RP->Ysize - 2)) + 1; + kx = rndm (RP->Xsize - 2) + 1; + ky = rndm (RP->Ysize - 2) + 1; freeindex = find_free_spot (the_key, map, kx, ky, 1, SIZEOFFREE1 + 1); } @@ -576,7 +582,7 @@ if (number_of_free_spots_in_room > 0) { - i = RANDOM () % number_of_free_spots_in_room; + i = rndm (number_of_free_spots_in_room); *kx = room_free_spots_x[i]; *ky = room_free_spots_y[i]; } @@ -779,9 +785,12 @@ else { layout[x][y] = 1; + /* now search all the 8 squares around recursively for free spots,in random order */ - for (i = rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) - find_doors_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], doorlist, ndoors, RP); + for (i = rndm (8), j = 0; j < 8 && !theMonsterToFind; i++, j++) + find_doors_in_room_recursive (layout, map, + x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], + doorlist, ndoors, RP); } } @@ -847,7 +856,7 @@ door->destroy (); doorlist[i] = new_door; insert_ob_in_map (new_door, map, NULL, 0); - sprintf (keybuf, "%d", (int) RANDOM ()); + sprintf (keybuf, "%d", rndm (1000000000)); new_door->slaying = keybuf; keyplace (map, new_door->x, new_door->y, keybuf, NO_PASS_DOORS, 2, RP); }