--- deliantra/server/random_maps/treasure.C 2007/01/17 12:36:31 1.19 +++ deliantra/server/random_maps/treasure.C 2007/02/17 23:32:11 1.25 @@ -1,5 +1,4 @@ /* -<<<<<<< treasure.C * CrossFire, A Multiplayer game * * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team @@ -22,30 +21,6 @@ * * The authors can be reached via e-mail at */ -======= - * CrossFire, A Multiplayer game for X-windows - * - * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team - * Copyright (C) 2001 Mark Wedel & Crossfire Development Team - * Copyright (C) 1992 Frank Tore Johansen - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * The authors can be reached via e-mail at - */ ->>>>>>> 1.18 /* placing treasure in maps, where appropriate. */ @@ -68,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. @@ -101,13 +83,14 @@ if (treasure_style) if (!strcmp (treasure_style, "none")) 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)) { - if (RANDOM () % 2) + if (rndm (2)) treasureoptions -= 1; else treasureoptions -= 2; @@ -115,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; @@ -129,6 +112,12 @@ sprintf (stylefilepath, "%s/%s", styledirname, treasure_style); style_map = find_style (styledirname, treasure_style, -1); + if (!style_map) + { + LOG (llevError, "unable to load style map %s %s.\n", styledirname, treasure_style); + return; + } + /* all the treasure at one spot in the map. */ if (treasureoptions & CONCENTRATED) { @@ -180,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; @@ -207,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); } } @@ -252,7 +241,7 @@ if (tlist != NULL) for (ti = 0; ti < n_treasures; ti++) { /* use the treasure list */ - object *new_treasure = pick_random_object (style_map); + object *new_treasure = style_map->pick_random_object (); insert_ob_in_ob (arch_to_object (new_treasure->arch), the_chest); } @@ -277,9 +266,9 @@ if (trap_map) { - the_trap = pick_random_object (trap_map); + the_trap = trap_map->pick_random_object (); 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; @@ -296,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); } @@ -373,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); } @@ -387,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); } @@ -490,7 +478,7 @@ } /* now search all the 8 squares around recursively for a monster,in random order */ - for (i = RANDOM () % 8, j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) + for (i = rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) { theMonsterToFind = find_monster_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); if (theMonsterToFind != NULL) @@ -563,7 +551,7 @@ number_of_free_spots_in_room++; /* now search all the 8 squares around recursively for free spots,in random order */ - for (i = RANDOM () % 8, j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) + for (i = rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) find_spot_in_room_recursive (layout, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); } @@ -594,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]; } @@ -687,13 +675,12 @@ } } - void remove_monsters (int x, int y, maptile *map) { object *tmp; - for (tmp = GET_MAP_OB (map, x, y); tmp != NULL; tmp = tmp->above) + for (tmp = GET_MAP_OB (map, x, y); tmp; tmp = tmp->above) if (QUERY_FLAG (tmp, FLAG_ALIVE)) { if (tmp->head) @@ -706,11 +693,9 @@ }; } - /* surrounds the point x,y by doors, so as to enclose something, like a chest. It only goes as far as the 8 squares surrounding, and it'll remove any monsters it finds.*/ - object ** surround_by_doors (maptile *map, char **layout, int x, int y, int opts) { @@ -737,18 +722,17 @@ { int x1 = x + freearr_x[i], y1 = y + freearr_y[i]; - if (!wall_blocked (map, x1, y1) || layout[x1][y1] == '>') + if (!wall_blocked (map, x1, y1) && layout[x1][y1] == '>') { /* place a door */ - object *new_door = get_archetype ((freearr_x[i] == 0) ? doors[1] : doors[0]); + remove_monsters (x1, y1, map); - new_door->x = x + freearr_x[i]; - new_door->y = y + freearr_y[i]; - remove_monsters (new_door->x, new_door->y, map); - insert_ob_in_map (new_door, map, NULL, 0); + object *new_door = get_archetype (freearr_x[i] == 0 ? doors[1] : doors[0]); + map->insert (new_door, x1, y1); doorlist[ndoors_made] = new_door; ndoors_made++; } } + return doorlist; } @@ -801,9 +785,12 @@ else { layout[x][y] = 1; + /* now search all the 8 squares around recursively for free spots,in random order */ - for (i = RANDOM () % 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); } } @@ -869,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); }