--- deliantra/server/random_maps/treasure.C 2006/09/14 22:34:03 1.6 +++ deliantra/server/random_maps/treasure.C 2007/01/06 14:42:30 1.14 @@ -1,6 +1,8 @@ + /* 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 @@ -51,7 +53,7 @@ */ int -wall_blocked (mapstruct *m, int x, int y) +wall_blocked (maptile *m, int x, int y) { int r; @@ -69,11 +71,11 @@ */ void -place_treasure (mapstruct *map, char **layout, char *treasure_style, int treasureoptions, RMParms * RP) +place_treasure (maptile *map, char **layout, char *treasure_style, int treasureoptions, random_map_params *RP) { - char styledirname[256]; - char stylefilepath[256]; - mapstruct *style_map = 0; + char styledirname[1024]; + char stylefilepath[1024]; + maptile *style_map = 0; int num_treasures; /* bail out if treasure isn't wanted. */ @@ -115,69 +117,69 @@ /* map_layout_style global, and is previously set */ switch (RP->map_layout_style) { - case ONION_LAYOUT: - case SPIRAL_LAYOUT: - case SQUARE_SPIRAL_LAYOUT: - { - int i, j; - - /* search the onion for C's or '>', and put treasure there. */ - for (i = 0; i < RP->Xsize; i++) - { - for (j = 0; j < RP->Ysize; j++) - { - 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); - lock_and_hide_doors (doorlist, map, treasureoptions, RP); - free (doorlist); - } - } - } - } - break; - } - default: - { - int i, j, tries; - object *chest; - object **doorlist; - - i = j = -1; - tries = 0; - while (i == -1 && tries < 100) - { - i = RANDOM () % (RP->Xsize - 2) + 1; - j = RANDOM () % (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)) - { - doorlist = surround_by_doors (map, layout, i, j, treasureoptions); - lock_and_hide_doors (doorlist, map, treasureoptions, RP); - free (doorlist); - } - } + case LAYOUT_ONION: + case LAYOUT_SPIRAL: + case LAYOUT_SQUARE_SPIRAL: + { + int i, j; + + /* search the onion for C's or '>', and put treasure there. */ + for (i = 0; i < RP->Xsize; i++) + { + for (j = 0; j < RP->Ysize; j++) + { + 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); + lock_and_hide_doors (doorlist, map, treasureoptions, RP); + free (doorlist); + } + } + } + } + break; + } + default: + { + int i, j, tries; + object *chest; + object **doorlist; + + i = j = -1; + tries = 0; + while (i == -1 && tries < 100) + { + i = RANDOM () % (RP->Xsize - 2) + 1; + j = RANDOM () % (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)) + { + doorlist = surround_by_doors (map, layout, i, j, treasureoptions); + lock_and_hide_doors (doorlist, map, treasureoptions, RP); + free (doorlist); + } + } } } else @@ -193,14 +195,12 @@ } } - - /* 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, mapstruct *map, mapstruct *style_map, int n_treasures, RMParms * RP) +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; @@ -211,7 +211,7 @@ i = find_first_free_spot (the_chest, map, x, y); if (i == -1) { - free_object (the_chest); + the_chest->destroy (); return NULL; } xl = x + freearr_x[i]; @@ -221,7 +221,6 @@ if (wall_blocked (map, xl, yl)) return 0; - /* put the treasures in the chest. */ /* if(style_map) { */ #if 0 /* don't use treasure style maps for now! */ @@ -243,7 +242,6 @@ the_chest->stats.hp = n_treasures; } #endif - else { /* neither style_map no treasure list given */ treasurelist *tlist = find_treasurelist ("chest"); @@ -254,7 +252,7 @@ /* stick a trap in the chest if required */ if (treasureoptions & TRAPPED) { - mapstruct *trap_map = find_style ("/styles/trapstyles", "traps", -1); + maptile *trap_map = find_style ("/styles/trapstyles", "traps", -1); object *the_trap; if (trap_map) @@ -267,7 +265,7 @@ object *new_trap; new_trap = arch_to_object (the_trap->arch); - copy_object (new_trap, the_trap); + new_trap->copy_to (the_trap); new_trap->x = x; new_trap->y = y; insert_ob_in_ob (new_trap, the_chest); @@ -281,7 +279,7 @@ if ((treasureoptions & KEYREQUIRED) && n_treasures > 1) { - char keybuf[256]; + char keybuf[1024]; sprintf (keybuf, "%d", (int) RANDOM ()); the_chest->slaying = keybuf; @@ -299,7 +297,7 @@ /* finds the closest monster and returns him, regardless of doors or walls */ object * -find_closest_monster (mapstruct *map, int x, int y, RMParms * RP) +find_closest_monster (maptile *map, int x, int y, random_map_params *RP) { int i; @@ -314,7 +312,7 @@ /* don't bother searching this square unless the map says life exists. */ if (GET_MAP_FLAGS (map, lx, ly) & P_IS_ALIVE) { - object *the_monster = get_map_ob (map, lx, ly); + object *the_monster = GET_MAP_OB (map, lx, ly); for (; the_monster != NULL && (!QUERY_FLAG (the_monster, FLAG_MONSTER)); the_monster = the_monster->above); if (the_monster && QUERY_FLAG (the_monster, FLAG_MONSTER)) @@ -338,7 +336,7 @@ */ int -keyplace (mapstruct *map, int x, int y, char *keycode, int door_flag, int n_keys, RMParms * RP) +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; @@ -434,7 +432,7 @@ it does a check-off on the layout, converting 0's to 1's */ object * -find_monster_in_room_recursive (char **layout, mapstruct *map, int x, int y, RMParms * RP) +find_monster_in_room_recursive (char **layout, maptile *map, int x, int y, random_map_params *RP) { int i, j; @@ -455,7 +453,7 @@ layout[x][y] = 1; if (GET_MAP_FLAGS (map, x, y) & P_IS_ALIVE) { - object *the_monster = get_map_ob (map, x, y); + object *the_monster = GET_MAP_OB (map, x, y); /* check off this point */ for (; the_monster != NULL && (!QUERY_FLAG (the_monster, FLAG_ALIVE)); the_monster = the_monster->above); @@ -481,7 +479,7 @@ real work. */ object * -find_monster_in_room (mapstruct *map, int x, int y, RMParms * RP) +find_monster_in_room (maptile *map, int x, int y, random_map_params *RP) { char **layout2; int i, j; @@ -523,7 +521,7 @@ that datastructure. */ void -find_spot_in_room_recursive (char **layout, int x, int y, RMParms * RP) +find_spot_in_room_recursive (char **layout, int x, int y, random_map_params *RP) { int i, j; @@ -552,7 +550,7 @@ /* find a random non-blocked spot in this room to drop a key. */ void -find_spot_in_room (mapstruct *map, int x, int y, int *kx, int *ky, RMParms * RP) +find_spot_in_room (maptile *map, int x, int y, int *kx, int *ky, random_map_params *RP) { char **layout2; int i, j; @@ -599,7 +597,7 @@ it'll return 0 if no FREE spots are found.*/ void -find_enclosed_spot (mapstruct *map, int *cx, int *cy, RMParms * RP) +find_enclosed_spot (maptile *map, int *cx, int *cy, random_map_params *RP) { int x, y; int i; @@ -671,18 +669,18 @@ void -remove_monsters (int x, int y, mapstruct *map) +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 != NULL; tmp = tmp->above) if (QUERY_FLAG (tmp, FLAG_ALIVE)) { if (tmp->head) tmp = tmp->head; - remove_ob (tmp); - free_object (tmp); - tmp = get_map_ob (map, x, y); + tmp->remove (); + tmp->destroy (); + tmp = GET_MAP_OB (map, x, y); if (tmp == NULL) break; }; @@ -694,7 +692,7 @@ it'll remove any monsters it finds.*/ object ** -surround_by_doors (mapstruct *map, char **layout, int x, int y, int opts) +surround_by_doors (maptile *map, char **layout, int x, int y, int opts) { int i; char *doors[2]; @@ -737,11 +735,11 @@ /* returns the first door in this square, or NULL if there isn't a door. */ object * -door_in_square (mapstruct *map, int x, int y) +door_in_square (maptile *map, int x, int y) { object *tmp; - for (tmp = get_map_ob (map, x, y); tmp != NULL; tmp = tmp->above) + for (tmp = GET_MAP_OB (map, x, y); tmp != NULL; tmp = tmp->above) if (tmp->type == DOOR || tmp->type == LOCKED_DOOR) return tmp; return NULL; @@ -750,7 +748,7 @@ /* the workhorse routine, which finds the doors in a room */ void -find_doors_in_room_recursive (char **layout, mapstruct *map, int x, int y, object **doorlist, int *ndoors, RMParms * RP) +find_doors_in_room_recursive (char **layout, maptile *map, int x, int y, object **doorlist, int *ndoors, random_map_params *RP) { int i, j; object *door; @@ -768,14 +766,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; } } @@ -784,23 +783,20 @@ 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); } } /* find a random non-blocked spot in this room to drop a key. */ object ** -find_doors_in_room (mapstruct *map, int x, int y, RMParms * RP) +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), 256); - + doorlist = (object **) calloc (sizeof (int), 1024); layout2 = (char **) calloc (sizeof (char *), RP->Xsize); /* allocate and copy the layout, converting C to 0. */ @@ -819,9 +815,8 @@ /* deallocate the temp. layout */ for (i = 0; i < RP->Xsize; i++) - { - free (layout2[i]); - } + free (layout2[i]); + free (layout2); return doorlist; } @@ -832,7 +827,7 @@ opts doesn't say to lock/hide doors. */ void -lock_and_hide_doors (object **doorlist, mapstruct *map, int opts, RMParms * RP) +lock_and_hide_doors (object **doorlist, maptile *map, int opts, random_map_params *RP) { object *door; int i; @@ -844,14 +839,14 @@ 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; new_door->x = door->x; new_door->y = door->y; - remove_ob (door); - free_object (door); + door->remove (); + door->destroy (); doorlist[i] = new_door; insert_ob_in_map (new_door, map, NULL, 0); sprintf (keybuf, "%d", (int) RANDOM ()); @@ -877,8 +872,8 @@ retrofit_joined_wall (map, door->x, door->y + 1, 0, RP); door->face = wallface->face; if (!QUERY_FLAG (wallface, FLAG_REMOVED)) - remove_ob (wallface); - free_object (wallface); + wallface->remove (); + wallface->destroy (); } } }