--- deliantra/server/random_maps/treasure.C 2006/12/31 19:02:24 1.12 +++ deliantra/server/random_maps/treasure.C 2007/01/15 21:06:19 1.18 @@ -1,26 +1,26 @@ - /* - CrossFire, A Multiplayer game for X-windows - - 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 -*/ + * 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 + */ /* placing treasure in maps, where appropriate. */ @@ -72,8 +72,8 @@ void place_treasure (maptile *map, char **layout, char *treasure_style, int treasureoptions, random_map_params *RP) { - char styledirname[256]; - char stylefilepath[256]; + char styledirname[1024]; + char stylefilepath[1024]; maptile *style_map = 0; int num_treasures; @@ -213,6 +213,7 @@ the_chest->destroy (); return NULL; } + xl = x + freearr_x[i]; yl = y + freearr_y[i]; @@ -278,7 +279,7 @@ if ((treasureoptions & KEYREQUIRED) && n_treasures > 1) { - char keybuf[256]; + char keybuf[1024]; sprintf (keybuf, "%d", (int) RANDOM ()); the_chest->slaying = keybuf; @@ -368,8 +369,9 @@ { kx = (RANDOM () % (RP->Xsize - 2)) + 1; ky = (RANDOM () % (RP->Ysize - 2)) + 1; - freeindex = find_first_free_spot (the_key, map, kx, ky); + freeindex = find_free_spot (the_key, map, kx, ky, 1, SIZEOFFREE1 + 1); } + if (freeindex != -1) { kx += freearr_x[freeindex]; @@ -385,6 +387,7 @@ { if (wall_blocked (map, x, y)) return 0; + the_keymaster = find_monster_in_room (map, x, y, RP); if (the_keymaster == NULL) /* if fail, find a spot to drop the key. */ find_spot_in_room (map, x, y, &kx, &ky, RP); @@ -655,15 +658,19 @@ } } /* give up and return the closest free spot. */ - i = find_first_free_spot (&archetype::find ("chest")->clone, map, x, y); - if (i != -1 && i <= SIZEOFFREE1) + i = find_free_spot (&archetype::find ("chest")->clone, map, x, y, 1, SIZEOFFREE1 + 1); + + if (i != -1) { *cx = x + freearr_x[i]; *cy = y + freearr_y[i]; - return; } - /* indicate failure */ - *cx = *cy = -1; + else + { + /* indicate failure */ + *cx = -1; + *cy = -1; + } } @@ -765,14 +772,15 @@ { /* there could be a door here */ layout[x][y] = 1; door = door_in_square (map, x, y); - if (door != NULL) + if (door) { doorlist[*ndoors] = door; - if (*ndoors > 254) /* eek! out of memory */ + if (*ndoors > 1022) /* eek! out of memory */ { LOG (llevError, "find_doors_in_room_recursive:Too many doors for memory allocated!\n"); return; } + *ndoors = *ndoors + 1; } } @@ -781,9 +789,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++) - { - find_doors_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], doorlist, ndoors, RP); - } + find_doors_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], doorlist, ndoors, RP); } } @@ -796,8 +802,7 @@ int i, j; int ndoors = 0; - doorlist = (object **) calloc (sizeof (int), 256); - + doorlist = (object **) calloc (sizeof (int), 1024); layout2 = (char **) calloc (sizeof (char *), RP->Xsize); /* allocate and copy the layout, converting C to 0. */ @@ -816,9 +821,8 @@ /* deallocate the temp. layout */ for (i = 0; i < RP->Xsize; i++) - { - free (layout2[i]); - } + free (layout2[i]); + free (layout2); return doorlist; } @@ -841,7 +845,7 @@ for (i = 0, door = doorlist[0]; doorlist[i] != NULL; i++) { object *new_door = get_archetype ("locked_door1"); - char keybuf[256]; + char keybuf[1024]; door = doorlist[i]; new_door->face = door->face;