--- deliantra/server/random_maps/treasure.C 2007/01/27 02:19:37 1.24 +++ deliantra/server/random_maps/treasure.C 2008/04/11 21:09:53 1.33 @@ -1,25 +1,24 @@ /* - * CrossFire, A Multiplayer game - * - * 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 + * This file is part of Deliantra, the Roguelike Realtime MMORPG. + * + * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team + * Copyright (©) 1992,2007 Frank Tore Johansen + * + * Deliantra 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 + * the Free Software Foundation, either version 3 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 + * 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 + * along with this program. If not, see . + * + * The authors can be reached via e-mail to */ /* placing treasure in maps, where appropriate. */ @@ -61,8 +60,8 @@ if (OUT_OF_REAL_MAP (m, x, y)) return 1; - int r = GET_MAP_MOVE_BLOCK (m, x, y) & ~MOVE_BLOCK_DEFAULT; - return r; + m->at (x, y).update (); + return GET_MAP_MOVE_BLOCK (m, x, y) & MOVE_WALK; } /* place treasures in the map, given the @@ -139,18 +138,19 @@ if (layout[i][j] == 'C' || layout[i][j] == '>') { int tdiv = RP->symmetry_used; - object **doorlist; object *chest; 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); + if (!chest) continue; /* if no chest was placed NEXT */ + if (treasureoptions & (DOORED | HIDDEN)) { - doorlist = find_doors_in_room (map, i, j, RP); + object **doorlist = find_doors_in_room (map, i, j, RP); lock_and_hide_doors (doorlist, map, treasureoptions, RP); free (doorlist); } @@ -241,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); } @@ -252,7 +252,7 @@ } #endif { /* neither style_map no treasure list given */ - treasurelist *tlist = find_treasurelist ("chest"); + treasurelist *tlist = treasurelist::find ("chest"); the_chest->randomitems = tlist; the_chest->stats.hp = n_treasures; @@ -266,7 +266,7 @@ 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); if (the_trap) @@ -431,7 +431,7 @@ return 1; } - insert_ob_in_ob (the_key, the_keymaster); + insert_ob_in_ob (the_key, the_keymaster->head_ ()); return 1; } @@ -504,18 +504,16 @@ { layout2[i] = (char *) calloc (sizeof (char), RP->Ysize); for (j = 0; j < RP->Ysize; j++) - { - if (wall_blocked (map, i, j)) - layout2[i][j] = '#'; - } + if (wall_blocked (map, i, j)) + layout2[i][j] = '#'; } + 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[i]); + free (layout2); return theMonsterToFind; @@ -660,7 +658,7 @@ } } /* give up and return the closest free spot. */ - i = find_free_spot (&archetype::find ("chest")->clone, map, x, y, 1, SIZEOFFREE1 + 1); + i = find_free_spot (archetype::find ("chest"), map, x, y, 1, SIZEOFFREE1 + 1); if (i != -1) { @@ -700,7 +698,7 @@ surround_by_doors (maptile *map, char **layout, int x, int y, int opts) { int i; - char *doors[2]; + const char *doors[2]; object **doorlist; int ndoors_made = 0; doorlist = (object **) calloc (9, sizeof (object *)); /* 9 doors so we can hold termination null */ @@ -749,7 +747,6 @@ return NULL; } - /* the workhorse routine, which finds the doors in a room */ void find_doors_in_room_recursive (char **layout, maptile *map, int x, int y, object **doorlist, int *ndoors, random_map_params *RP) @@ -773,6 +770,7 @@ if (door) { doorlist[*ndoors] = door; + if (*ndoors > 1022) /* eek! out of memory */ { LOG (llevError, "find_doors_in_room_recursive:Too many doors for memory allocated!\n"); @@ -798,41 +796,27 @@ object ** find_doors_in_room (maptile *map, int x, int y, random_map_params *RP) { - char **layout2; - object **doorlist; int i, j; int ndoors = 0; - doorlist = (object **) calloc (sizeof (int), 1024); + object **doorlist = (object **) calloc (sizeof (int), 1024); + + MazeData layout2 (RP->Xsize, RP->Ysize); - 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 (j = 0; j < RP->Ysize; j++) + if (wall_blocked (map, i, j)) + layout2[i][j] = '#'; /* setup num_free_spots and room_free_spots */ find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP); - /* deallocate the temp. layout */ - for (i = 0; i < RP->Xsize; i++) - free (layout2[i]); - - free (layout2); return doorlist; } - - /* locks and/or hides all the doors in doorlist, or does nothing if opts doesn't say to lock/hide doors. */ - void lock_and_hide_doors (object **doorlist, maptile *map, int opts, random_map_params *RP) {