--- deliantra/server/random_maps/treasure.C 2006/12/12 20:53:03 1.8 +++ deliantra/server/random_maps/treasure.C 2006/12/31 20:46:17 1.13 @@ -1,3 +1,4 @@ + /* CrossFire, A Multiplayer game for X-windows @@ -69,10 +70,10 @@ */ void -place_treasure (maptile *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]; + char styledirname[1024]; + char stylefilepath[1024]; maptile *style_map = 0; int num_treasures; @@ -115,69 +116,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 +194,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, maptile *map, maptile *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 +210,7 @@ i = find_first_free_spot (the_chest, map, x, y); if (i == -1) { - the_chest->destroy (0); + the_chest->destroy (); return NULL; } xl = x + freearr_x[i]; @@ -221,7 +220,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 +241,6 @@ the_chest->stats.hp = n_treasures; } #endif - else { /* neither style_map no treasure list given */ treasurelist *tlist = find_treasurelist ("chest"); @@ -267,7 +264,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 +278,7 @@ if ((treasureoptions & KEYREQUIRED) && n_treasures > 1) { - char keybuf[256]; + char keybuf[1024]; sprintf (keybuf, "%d", (int) RANDOM ()); the_chest->slaying = keybuf; @@ -299,7 +296,7 @@ /* finds the closest monster and returns him, regardless of doors or walls */ object * -find_closest_monster (maptile *map, int x, int y, RMParms * RP) +find_closest_monster (maptile *map, int x, int y, random_map_params *RP) { int i; @@ -314,7 +311,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 +335,7 @@ */ int -keyplace (maptile *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 +431,7 @@ it does a check-off on the layout, converting 0's to 1's */ object * -find_monster_in_room_recursive (char **layout, maptile *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 +452,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 +478,7 @@ real work. */ object * -find_monster_in_room (maptile *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 +520,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 +549,7 @@ /* find a random non-blocked spot in this room to drop a key. */ void -find_spot_in_room (maptile *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 +596,7 @@ it'll return 0 if no FREE spots are found.*/ void -find_enclosed_spot (maptile *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; @@ -675,14 +672,14 @@ { 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; tmp->remove (); - tmp->destroy (0); - tmp = get_map_ob (map, x, y); + tmp->destroy (); + tmp = GET_MAP_OB (map, x, y); if (tmp == NULL) break; }; @@ -741,7 +738,7 @@ { 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 +747,7 @@ /* 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, 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 +765,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 +782,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 (maptile *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 +814,8 @@ /* deallocate the temp. layout */ for (i = 0; i < RP->Xsize; i++) - { - free (layout2[i]); - } + free (layout2[i]); + free (layout2); return doorlist; } @@ -832,7 +826,7 @@ opts doesn't say to lock/hide doors. */ void -lock_and_hide_doors (object **doorlist, maptile *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 +838,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; door->remove (); - door->destroy (0); + door->destroy (); doorlist[i] = new_door; insert_ob_in_map (new_door, map, NULL, 0); sprintf (keybuf, "%d", (int) RANDOM ()); @@ -878,7 +872,7 @@ door->face = wallface->face; if (!QUERY_FLAG (wallface, FLAG_REMOVED)) wallface->remove (); - wallface->destroy (0); + wallface->destroy (); } } }