--- deliantra/server/random_maps/treasure.C 2007/01/18 00:06:56 1.20 +++ deliantra/server/random_maps/treasure.C 2007/01/19 21:49:58 1.22 @@ -76,13 +76,14 @@ if (treasure_style) if (!strcmp (treasure_style, "none")) return; + if (treasureoptions <= 0) treasureoptions = RANDOM () % (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; @@ -465,7 +466,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) @@ -538,7 +539,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); } @@ -662,13 +663,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) @@ -681,11 +681,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) { @@ -712,18 +710,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; } @@ -777,7 +774,7 @@ { 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++) + 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); } }