--- deliantra/server/random_maps/treasure.C 2007/01/15 21:06:19 1.18 +++ deliantra/server/random_maps/treasure.C 2007/01/17 12:36:31 1.19 @@ -1,4 +1,28 @@ /* +<<<<<<< treasure.C + * 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 + * 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 @@ -21,11 +45,10 @@ * * The authors can be reached via e-mail at */ +>>>>>>> 1.18 /* placing treasure in maps, where appropriate. */ - - #include #include #include @@ -50,15 +73,13 @@ * and doors but not monsters. * This function is not map tile aware. */ - int wall_blocked (maptile *m, int x, int y) { - int r; - if (OUT_OF_REAL_MAP (m, x, y)) return 1; - r = GET_MAP_MOVE_BLOCK (m, x, y) & ~MOVE_BLOCK_DEFAULT; + + int r = GET_MAP_MOVE_BLOCK (m, x, y) & ~MOVE_BLOCK_DEFAULT; return r; } @@ -68,7 +89,6 @@ treasure style (may be empty or NULL, or "none" to cause no treasure.) treasureoptions (may be 0 for random choices or positive) */ - void place_treasure (maptile *map, char **layout, char *treasure_style, int treasureoptions, random_map_params *RP) { @@ -334,12 +354,11 @@ The idea is that you call keyplace on x,y where a door is, and it'll make sure a key is placed on both sides of the door. */ - int keyplace (maptile *map, int x, int y, char *keycode, int door_flag, int n_keys, random_map_params *RP) { int i, j; - int kx, ky; + int kx = 0, ky = 0; object *the_keymaster; /* the monster that gets the key. */ object *the_key; @@ -351,16 +370,17 @@ { int tries = 0; - the_keymaster = NULL; - while (tries < 15 && the_keymaster == NULL) + the_keymaster = 0; + while (tries < 15 && !the_keymaster) { i = (RANDOM () % (RP->Xsize - 2)) + 1; j = (RANDOM () % (RP->Ysize - 2)) + 1; tries++; the_keymaster = find_closest_monster (map, i, j, RP); } + /* if we don't find a good keymaster, drop the key on the ground. */ - if (the_keymaster == NULL) + if (!the_keymaster) { int freeindex; @@ -372,10 +392,11 @@ freeindex = find_free_spot (the_key, map, kx, ky, 1, SIZEOFFREE1 + 1); } - if (freeindex != -1) + // can freeindex ever be < 0? + if (freeindex >= 0) { - kx += freearr_x[freeindex]; - ky += freearr_y[freeindex]; + kx += freearr_x [freeindex]; + ky += freearr_y [freeindex]; } } } @@ -389,7 +410,7 @@ 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. */ + if (!the_keymaster) /* if fail, find a spot to drop the key. */ find_spot_in_room (map, x, y, &kx, &ky, RP); } else @@ -401,18 +422,20 @@ sum += keyplace (map, x, y + 1, keycode, NO_PASS_DOORS, 1, RP); sum += keyplace (map, x - 1, y, keycode, NO_PASS_DOORS, 1, RP); sum += keyplace (map, x, y - 1, keycode, NO_PASS_DOORS, 1, RP); + if (sum < 2) /* we might have made a disconnected map-place more keys. */ - { /* diagnoally this time. */ + { /* diagonally this time. */ keyplace (map, x + 1, y + 1, keycode, NO_PASS_DOORS, 1, RP); keyplace (map, x + 1, y - 1, keycode, NO_PASS_DOORS, 1, RP); keyplace (map, x - 1, y + 1, keycode, NO_PASS_DOORS, 1, RP); keyplace (map, x - 1, y - 1, keycode, NO_PASS_DOORS, 1, RP); } + return 1; } } - if (the_keymaster == NULL) + if (!the_keymaster) { the_key->x = kx; the_key->y = ky; @@ -510,9 +533,6 @@ return theMonsterToFind; } - - - /* a datastructure needed by find_spot_in_room and find_spot_in_room_recursive */ int *room_free_spots_x; int *room_free_spots_y; @@ -521,7 +541,6 @@ /* the workhorse routine, which finds the free spots in a room: a datastructure of free points is set up, and a position chosen from that datastructure. */ - void find_spot_in_room_recursive (char **layout, int x, int y, random_map_params *RP) { @@ -542,11 +561,10 @@ room_free_spots_x[number_of_free_spots_in_room] = x; room_free_spots_y[number_of_free_spots_in_room] = y; 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++) - { - find_spot_in_room_recursive (layout, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); - } + find_spot_in_room_recursive (layout, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); } @@ -567,10 +585,8 @@ { 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] = '#'; } /* setup num_free_spots and room_free_spots */ @@ -585,9 +601,8 @@ /* deallocate the temp. layout */ for (i = 0; i < RP->Xsize; i++) - { - free (layout2[i]); - } + free (layout2[i]); + free (layout2); free (room_free_spots_x); free (room_free_spots_y); @@ -597,7 +612,6 @@ /* searches the map for a spot with walls around it. The more walls the better, but it'll settle for 1 wall, or even 0, but it'll return 0 if no FREE spots are found.*/ - void find_enclosed_spot (maptile *map, int *cx, int *cy, random_map_params *RP) {