--- deliantra/server/common/map.C 2006/09/10 16:00:23 1.29 +++ deliantra/server/common/map.C 2006/12/10 01:16:27 1.35 @@ -1,9 +1,3 @@ - -/* - * static char *rcsid_map_c = - * "$Id: map.C,v 1.29 2006/09/10 16:00:23 root Exp $"; - */ - /* CrossFire, A Multiplayer game for X-windows @@ -24,7 +18,7 @@ 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-devel@real-time.com + The authors can be reached via e-mail at */ @@ -39,17 +33,15 @@ #include "path.h" -extern int nrofallocobjects, nroffreeobjects; - /* - * Returns the mapstruct which has a name matching the given argument. + * Returns the maptile which has a name matching the given argument. * return NULL if no match is found. */ -mapstruct * +maptile * has_been_loaded (const char *name) { - mapstruct *map; + maptile *map; if (!name || !*name) return 0; @@ -212,7 +204,7 @@ */ void -dump_map (const mapstruct *m) +dump_map (const maptile *m) { LOG (llevError, "Map %s status: %d.\n", m->path, m->in_memory); LOG (llevError, "Size: %dx%d Start: %d,%d\n", MAP_WIDTH (m), MAP_HEIGHT (m), MAP_ENTER_X (m), MAP_ENTER_Y (m)); @@ -239,7 +231,7 @@ void dump_all_maps (void) { - mapstruct *m; + maptile *m; for (m = first_map; m != NULL; m = m->next) { @@ -258,11 +250,11 @@ * don't expect to insert/remove anything from those spaces. */ int -get_map_flags (mapstruct *oldmap, mapstruct **newmap, sint16 x, sint16 y, sint16 * nx, sint16 * ny) +get_map_flags (maptile *oldmap, maptile **newmap, sint16 x, sint16 y, sint16 * nx, sint16 * ny) { sint16 newx, newy; int retval = 0; - mapstruct *mp; + maptile *mp; if (out_of_map (oldmap, x, y)) return P_OUT_OF_MAP; @@ -283,7 +275,6 @@ return retval; } - /* * Returns true if the given coordinate is blocked except by the * object passed is not blocking. This is used with @@ -296,9 +287,8 @@ * the coordinates & map passed in should have been updated for tiling * by the caller. */ - int -blocked_link (object *ob, mapstruct *m, int sx, int sy) +blocked_link (object *ob, maptile *m, int sx, int sy) { object *tmp; int mflags, blocked; @@ -420,11 +410,11 @@ */ int -ob_blocked (const object *ob, mapstruct *m, sint16 x, sint16 y) +ob_blocked (const object *ob, maptile *m, sint16 x, sint16 y) { archetype *tmp; int flag; - mapstruct *m1; + maptile *m1; sint16 sx, sy; if (ob == NULL) @@ -499,7 +489,7 @@ */ static void -link_multipart_objects (mapstruct *m) +link_multipart_objects (maptile *m) { int x, y; object *tmp, *op, *last, *above; @@ -546,7 +536,7 @@ * mapflags is the same as we get with load_original_map */ void -load_objects (mapstruct *m, object_thawer & fp, int mapflags) +load_objects (maptile *m, object_thawer & fp, int mapflags) { int i, j; int unique; @@ -622,7 +612,7 @@ * in order to do map tiling properly. */ void -save_objects (mapstruct *m, object_freezer & fp, object_freezer & fp2, int flag) +save_objects (maptile *m, object_freezer & fp, object_freezer & fp2, int flag) { int i, j = 0, unique = 0; object *op; @@ -655,78 +645,83 @@ } /* for this j */ } +maptile::maptile () +{ + in_memory = MAP_SWAPPED; + /* The maps used to pick up default x and y values from the + * map archetype. Mimic that behaviour. + */ + MAP_WIDTH (this) = 16; + MAP_HEIGHT (this) = 16; + MAP_RESET_TIMEOUT (this) = 0; + MAP_TIMEOUT (this) = 300; + MAP_ENTER_X (this) = 0; + MAP_ENTER_Y (this) = 0; + /*set part to -1 indicating conversion to weather map not yet done */ + MAP_WORLDPARTX (this) = -1; + MAP_WORLDPARTY (this) = -1; +} + /* - * Allocates, initialises, and returns a pointer to a mapstruct. + * Allocates, initialises, and returns a pointer to a maptile. * Modified to no longer take a path option which was not being * used anyways. MSW 2001-07-01 */ - -mapstruct * +maptile * get_linked_map (void) { - mapstruct *map = new mapstruct; - mapstruct *mp; + maptile *mp, *map = new maptile; + + for (mp = first_map; mp && mp->next; mp = mp->next); - for (mp = first_map; mp != NULL && mp->next != NULL; mp = mp->next); if (mp == NULL) first_map = map; else mp->next = map; - map->in_memory = MAP_SWAPPED; - /* The maps used to pick up default x and y values from the - * map archetype. Mimic that behaviour. - */ - MAP_WIDTH (map) = 16; - MAP_HEIGHT (map) = 16; - MAP_RESET_TIMEOUT (map) = 0; - MAP_TIMEOUT (map) = 300; - MAP_ENTER_X (map) = 0; - MAP_ENTER_Y (map) = 0; - /*set part to -1 indicating conversion to weather map not yet done */ - MAP_WORLDPARTX (map) = -1; - MAP_WORLDPARTY (map) = -1; return map; } /* - * Allocates the arrays contained in a mapstruct. + * Allocates the arrays contained in a maptile. * This basically allocates the dynamic array of spaces for the * map. */ - void -allocate_map (mapstruct *m) +maptile::allocate () { - m->in_memory = MAP_IN_MEMORY; + in_memory = MAP_IN_MEMORY; + /* Log this condition and free the storage. We could I suppose * realloc, but if the caller is presuming the data will be intact, * that is their poor assumption. */ - if (m->spaces) + if (spaces) { - LOG (llevError, "allocate_map called with already allocated map (%s)\n", m->path); - free (m->spaces); + LOG (llevError, "allocate_map called with already allocated map (%s)\n", path); + free (spaces); } - m->spaces = (MapSpace *) calloc (1, MAP_WIDTH (m) * MAP_HEIGHT (m) * sizeof (MapSpace)); + spaces = (MapSpace *) + calloc (1, width * height * sizeof (MapSpace)); - if (m->spaces == NULL) + if (!spaces) fatal (OUT_OF_MEMORY); } /* Create and returns a map of the specific size. Used * in random map code and the editor. */ -mapstruct * +maptile * get_empty_map (int sizex, int sizey) { - mapstruct *m = get_linked_map (); + maptile *m = get_linked_map (); m->width = sizex; m->height = sizey; m->in_memory = MAP_SWAPPED; - allocate_map (m); + m->allocate (); + return m; } @@ -813,7 +808,7 @@ /* opposite of parse string, this puts the string that was originally fed in to * the map (or something equivilent) into output_string. */ static void -print_shop_string (mapstruct *m, char *output_string) +print_shop_string (maptile *m, char *output_string) { int i; char tmp[MAX_BUF]; @@ -857,13 +852,13 @@ */ static int -load_map_header (object_thawer & fp, mapstruct *m) +load_map_header (object_thawer & fp, maptile *m) { char buf[HUGE_BUF], msgbuf[HUGE_BUF], maplorebuf[HUGE_BUF], *key = NULL, *value, *end; int msgpos = 0; int maplorepos = 0; - while (fgets (buf, HUGE_BUF - 1, fp) != NULL) + while (fgets (buf, HUGE_BUF, fp) != NULL) { buf[HUGE_BUF - 1] = 0; key = buf; @@ -920,7 +915,7 @@ if (!strcmp (key, "msg")) { - while (fgets (buf, HUGE_BUF - 1, fp) != NULL) + while (fgets (buf, HUGE_BUF, fp) != NULL) { if (!strcmp (buf, "endmsg\n")) break; @@ -941,7 +936,7 @@ } else if (!strcmp (key, "maplore")) { - while (fgets (buf, HUGE_BUF - 1, fp) != NULL) + while (fgets (buf, HUGE_BUF, fp) != NULL) { if (!strcmp (buf, "endmaplore\n")) break; @@ -1155,7 +1150,7 @@ /* * Opens the file "filename" and reads information about the map * from the given file, and stores it in a newly allocated - * mapstruct. A pointer to this structure is returned, or NULL on failure. + * maptile. A pointer to this structure is returned, or NULL on failure. * flags correspond to those in map.h. Main ones used are * MAP_PLAYER_UNIQUE, in which case we don't do any name changes, and * MAP_BLOCK, in which case we block on this load. This happens in all @@ -1164,10 +1159,10 @@ * managed map list. */ -mapstruct * +maptile * load_original_map (const char *filename, int flags) { - mapstruct *m; + maptile *m; char pathname[MAX_BUF]; if (flags & MAP_PLAYER_UNIQUE) @@ -1194,7 +1189,7 @@ return NULL; } - allocate_map (m); + m->allocate (); m->in_memory = MAP_LOADING; load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); @@ -1213,8 +1208,8 @@ * option if we can't find the original map) */ -static mapstruct * -load_temporary_map (mapstruct *m) +static maptile * +load_temporary_map (maptile *m) { char buf[MAX_BUF]; @@ -1250,7 +1245,8 @@ m = load_original_map (m->path, 0); return NULL; } - allocate_map (m); + + m->allocate (); m->in_memory = MAP_LOADING; load_objects (m, thawer, 0); @@ -1266,8 +1262,8 @@ * option if we can't find the original map) */ -mapstruct * -load_overlay_map (const char *filename, mapstruct *m) +maptile * +load_overlay_map (const char *filename, maptile *m) { char pathname[MAX_BUF]; @@ -1285,7 +1281,7 @@ m = load_original_map (m->path, 0); return NULL; } - /*allocate_map(m); */ + /*m->allocate ();*/ m->in_memory = MAP_LOADING; load_objects (m, thawer, MAP_OVERLAY); @@ -1300,7 +1296,7 @@ /* This goes through map 'm' and removed any unique items on the map. */ static void -delete_unique_items (mapstruct *m) +delete_unique_items (maptile *m) { int i, j, unique; object *op, *next; @@ -1332,7 +1328,7 @@ * m is the map to load unique items into. */ static void -load_unique_objects (mapstruct *m) +load_unique_objects (maptile *m) { int count; char firstname[MAX_BUF]; @@ -1365,13 +1361,13 @@ * Saves a map to file. If flag is set, it is saved into the same * file it was (originally) loaded from. Otherwise a temporary * filename will be genarated, and the file will be stored there. - * The temporary filename will be stored in the mapstructure. + * The temporary filename will be stored in the maptileure. * If the map is unique, we also save to the filename in the map * (this should have been updated when first loaded) */ int -new_save_map (mapstruct *m, int flag) +new_save_map (maptile *m, int flag) { char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF]; int i; @@ -1545,7 +1541,7 @@ */ void -free_all_objects (mapstruct *m) +free_all_objects (maptile *m) { int i, j; object *op; @@ -1578,12 +1574,12 @@ } /* - * Frees everything allocated by the given mapstructure. + * Frees everything allocated by the given maptileure. * don't free tmpname - our caller is left to do that */ void -free_map (mapstruct *m, int flag) +free_map (maptile *m, int flag) { int i; @@ -1620,16 +1616,16 @@ } /* - * function: vanish mapstruct - * m : pointer to mapstruct, if NULL no action + * function: vanish maptile + * m : pointer to maptile, if NULL no action * this deletes all the data on the map (freeing pointers) * and then removes this map from the global linked list of maps. */ void -delete_map (mapstruct *m) +delete_map (maptile *m) { - mapstruct *tmp, *last; + maptile *tmp, *last; int i; if (!m) @@ -1701,10 +1697,10 @@ * Returns a pointer to the given map. */ -mapstruct * +maptile * ready_map_name (const char *name, int flags) { - mapstruct *m; + maptile *m; if (!name) return (NULL); @@ -1816,7 +1812,7 @@ */ int -calculate_difficulty (mapstruct *m) +calculate_difficulty (maptile *m) { object *op; archetype *at; @@ -1868,7 +1864,7 @@ } void -clean_tmp_map (mapstruct *m) +clean_tmp_map (maptile *m) { if (m->tmpname == NULL) return; @@ -1903,7 +1899,7 @@ */ int -change_map_light (mapstruct *m, int change) +change_map_light (maptile *m, int change) { int new_level = m->darkness + change; @@ -1944,7 +1940,7 @@ * through, etc) */ void -update_position (mapstruct *m, int x, int y) +update_position (maptile *m, int x, int y) { object *tmp, *last = NULL; uint8 flags = 0, oldflags, light = 0, anywhere = 0; @@ -2147,7 +2143,7 @@ void -set_map_reset_time (mapstruct *map) +set_map_reset_time (maptile *map) { int timeout; @@ -2166,8 +2162,8 @@ * so that it is easier for calling functions to verify success. */ -static mapstruct * -load_and_link_tiled_map (mapstruct *orig_map, int tile_num) +static maptile * +load_and_link_tiled_map (maptile *orig_map, int tile_num) { int dest_tile = (tile_num + 2) % 4; char *path = path_combine_and_normalize (orig_map->path, orig_map->tile_path[tile_num]); @@ -2192,7 +2188,7 @@ * */ int -out_of_map (mapstruct *m, int x, int y) +out_of_map (maptile *m, int x, int y) { /* If we get passed a null map, this is obviously the @@ -2257,8 +2253,8 @@ * Using this is more efficient of calling out_of_map * and then figuring out what the real map is */ -mapstruct * -get_map_from_coord (mapstruct *m, sint16 * x, sint16 * y) +maptile * +get_map_from_coord (maptile *m, sint16 * x, sint16 * y) { if (*x < 0) @@ -2314,7 +2310,7 @@ * map1 to map2 in dx/dy. */ static int -adjacent_map (const mapstruct *map1, const mapstruct *map2, int *dx, int *dy) +adjacent_map (const maptile *map1, const maptile *map2, int *dx, int *dy) { if (!map1 || !map2) return 0; @@ -2482,7 +2478,7 @@ */ void -get_rangevector_from_mapcoord (const mapstruct *m, int x, int y, const object *op2, rv_vector * retval, int flags) +get_rangevector_from_mapcoord (const maptile *m, int x, int y, const object *op2, rv_vector * retval, int flags) { if (!adjacent_map (m, op2->map, &retval->distance_x, &retval->distance_y)) {