--- deliantra/server/random_maps/treasure.C 2008/04/11 21:09:53 1.33 +++ deliantra/server/random_maps/treasure.C 2008/05/04 14:12:38 1.38 @@ -47,7 +47,7 @@ static int bc_random (int x) { - return (rndm (x) + rndm (x) + rndm (x)) / 3; + return (rmg_rndm (x) + rmg_rndm (x) + rmg_rndm (x)) / 3; } /* returns true if square x,y has P_NO_PASS set, which is true for walls @@ -84,12 +84,12 @@ return; if (treasureoptions <= 0) - treasureoptions = rndm (2 * LAST_OPTION); + treasureoptions = rmg_rndm (2 * LAST_OPTION); /* filter out the mutually exclusive options */ if ((treasureoptions & RICH) && (treasureoptions & SPARSE)) { - if (rndm (2)) + if (rmg_rndm (2)) treasureoptions -= 1; else treasureoptions -= 2; @@ -120,7 +120,6 @@ /* all the treasure at one spot in the map. */ if (treasureoptions & CONCENTRATED) { - /* map_layout_style global, and is previously set */ switch (RP->map_layout_style) { @@ -142,6 +141,7 @@ if (tdiv == 3) tdiv = 2; /* this symmetry uses a divisor of 2 */ + /* don't put a chest on an exit. */ chest = place_chest (treasureoptions, i, j, map, style_map, num_treasures / tdiv, RP); @@ -159,6 +159,7 @@ } break; } + default: { int i, j, tries; @@ -169,16 +170,21 @@ tries = 0; while (i == -1 && tries < 100) { - i = rndm (RP->Xsize - 2) + 1; - j = rndm (RP->Ysize - 2) + 1; + i = rmg_rndm (RP->Xsize - 2) + 1; + j = rmg_rndm (RP->Ysize - 2) + 1; find_enclosed_spot (map, &i, &j, RP); + if (wall_blocked (map, i, j)) i = -1; + tries++; } + chest = place_chest (treasureoptions, i, j, map, style_map, num_treasures, RP); + if (!chest) return; + i = chest->x; j = chest->y; if (treasureoptions & (DOORED | HIDDEN)) @@ -196,8 +202,8 @@ for (ti = 0; ti < num_treasures; ti++) { - i = rndm (RP->Xsize - 2) + 1; - j = rndm (RP->Ysize - 2) + 1; + i = rmg_rndm (RP->Xsize - 2) + 1; + j = rmg_rndm (RP->Ysize - 2) + 1; place_chest (treasureoptions, i, j, map, style_map, 1, RP); } } @@ -206,25 +212,21 @@ /* put a chest into the map, near x and y, with the treasure style determined (may be null, or may be a treasure list from lib/treasures, if the global variable "treasurestyle" is set to that treasure list's name */ - object * place_chest (int treasureoptions, int x, int y, maptile *map, maptile *style_map, int n_treasures, random_map_params *RP) { - object *the_chest; - int i, xl, yl; - - the_chest = get_archetype ("chest"); /* was "chest_2" */ + object *the_chest = archetype::get (shstr_chest); /* was "chest_2" */ /* first, find a place to put the chest. */ - i = find_first_free_spot (the_chest, map, x, y); + int i = find_first_free_spot (the_chest, map, x, y); // this call uses the main rng if (i == -1) { the_chest->destroy (); return NULL; } - xl = x + freearr_x[i]; - yl = y + freearr_y[i]; + int xl = x + freearr_x[i]; + int yl = y + freearr_y[i]; /* if the placement is blocked, return a fail. */ if (wall_blocked (map, xl, yl)) @@ -241,7 +243,7 @@ if (tlist != NULL) for (ti = 0; ti < n_treasures; ti++) { /* use the treasure list */ - object *new_treasure = style_map->pick_random_object (); + object *new_treasure = style_map->pick_random_object (rmg_rndm); insert_ob_in_ob (arch_to_object (new_treasure->arch), the_chest); } @@ -262,19 +264,18 @@ if (treasureoptions & TRAPPED) { maptile *trap_map = find_style ("/styles/trapstyles", "traps", -1); - object *the_trap; if (trap_map) { - the_trap = trap_map->pick_random_object (); + object *the_trap = trap_map->pick_random_object (rmg_rndm); + the_trap->stats.Cha = 10 + RP->difficulty; the_trap->level = bc_random ((3 * RP->difficulty) / 2); + if (the_trap) { - object *new_trap; + object *new_trap = the_trap->arch->instance ();//TODO: why not clone? - new_trap = arch_to_object (the_trap->arch); - new_trap->copy_to (the_trap); new_trap->x = x; new_trap->y = y; insert_ob_in_ob (new_trap, the_chest); @@ -289,7 +290,7 @@ { char keybuf[1024]; - sprintf (keybuf, "%d", rndm (1000000000)); + sprintf (keybuf, "%d", rmg_rndm (1000000000)); the_chest->slaying = keybuf; keyplace (map, x, y, keybuf, PASS_DOORS, 1, RP); } @@ -348,10 +349,9 @@ int i, j; int kx = 0, ky = 0; object *the_keymaster; /* the monster that gets the key. */ - object *the_key; /* get a key and set its keycode */ - the_key = get_archetype ("key2"); + object *the_key = archetype::get (shstr_key2); the_key->slaying = keycode; if (door_flag == PASS_DOORS) @@ -361,8 +361,8 @@ the_keymaster = 0; while (tries < 15 && !the_keymaster) { - i = rndm (RP->Xsize - 2) + 1; - j = rndm (RP->Ysize - 2) + 1; + i = rmg_rndm (RP->Xsize - 2) + 1; + j = rmg_rndm (RP->Ysize - 2) + 1; tries++; the_keymaster = find_closest_monster (map, i, j, RP); } @@ -375,8 +375,8 @@ freeindex = -1; for (tries = 0; tries < 15 && freeindex == -1; tries++) { - kx = rndm (RP->Xsize - 2) + 1; - ky = rndm (RP->Ysize - 2) + 1; + kx = rmg_rndm (RP->Xsize - 2) + 1; + ky = rmg_rndm (RP->Ysize - 2) + 1; freeindex = find_free_spot (the_key, map, kx, ky, 1, SIZEOFFREE1 + 1); } @@ -478,43 +478,35 @@ } /* now search all the 8 squares around recursively for a monster,in random order */ - for (i = rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) + for (i = rmg_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) return theMonsterToFind; } + return theMonsterToFind; } - /* sets up some data structures: the _recursive form does the real work. */ - object * find_monster_in_room (maptile *map, int x, int y, random_map_params *RP) { - char **layout2; - int i, j; + Layout layout2 (RP); + + layout2->clear (); - theMonsterToFind = 0; - layout2 = (char **) calloc (sizeof (char *), RP->Xsize); /* allocate and copy the layout, converting C to 0. */ - for (i = 0; i < RP->Xsize; i++) - { - layout2[i] = (char *) calloc (sizeof (char), RP->Ysize); - for (j = 0; j < RP->Ysize; j++) - if (wall_blocked (map, i, j)) - layout2[i][j] = '#'; - } + for (int i = 0; i < layout2->w; i++) + for (int j = 0; j < layout2->h; j++) + if (wall_blocked (map, i, j)) + layout2[i][j] = '#'; + theMonsterToFind = 0; theMonsterToFind = find_monster_in_room_recursive (layout2, map, x, y, RP); - /* deallocate the temp. layout */ - for (i = 0; i < RP->Xsize; i++) - free (layout2[i]); - - free (layout2); + layout2.free (); return theMonsterToFind; } @@ -549,7 +541,7 @@ number_of_free_spots_in_room++; /* 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++) + for (i = rmg_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); } @@ -580,7 +572,7 @@ if (number_of_free_spots_in_room > 0) { - i = rndm (number_of_free_spots_in_room); + i = rmg_rndm (number_of_free_spots_in_room); *kx = room_free_spots_x[i]; *ky = room_free_spots_y[i]; } @@ -658,7 +650,7 @@ } } /* give up and return the closest free spot. */ - i = find_free_spot (archetype::find ("chest"), map, x, y, 1, SIZEOFFREE1 + 1); + i = find_free_spot (archetype::find (shstr_chest), map, x, y, 1, SIZEOFFREE1 + 1); if (i != -1) { @@ -785,7 +777,7 @@ 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; i++, j++) + for (i = rmg_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); @@ -799,15 +791,15 @@ int i, j; int ndoors = 0; - object **doorlist = (object **) calloc (sizeof (int), 1024); + object **doorlist = (object **)calloc (sizeof (int), 1024); - MazeData layout2 (RP->Xsize, RP->Ysize); + LayoutData layout2 (RP->Xsize, RP->Ysize); + layout2.clear (); /* allocate and copy the layout, converting C to 0. */ for (i = 0; i < RP->Xsize; i++) for (j = 0; j < RP->Ysize; j++) - if (wall_blocked (map, i, j)) - layout2[i][j] = '#'; + layout2[i][j] = wall_blocked (map, i, j) ? '#' : 0; /* setup num_free_spots and room_free_spots */ find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP); @@ -840,7 +832,7 @@ door->destroy (); doorlist[i] = new_door; insert_ob_in_map (new_door, map, NULL, 0); - sprintf (keybuf, "%d", rndm (1000000000)); + sprintf (keybuf, "%d", rmg_rndm (1000000000)); new_door->slaying = keybuf; keyplace (map, new_door->x, new_door->y, keybuf, NO_PASS_DOORS, 2, RP); } @@ -861,9 +853,12 @@ retrofit_joined_wall (map, door->x + 1, door->y, 0, RP); retrofit_joined_wall (map, door->x, door->y - 1, 0, RP); retrofit_joined_wall (map, door->x, door->y + 1, 0, RP); + door->face = wallface->face; + if (!QUERY_FLAG (wallface, FLAG_REMOVED)) wallface->remove (); + wallface->destroy (); } }