--- deliantra/server/common/map.C 2006/10/05 16:50:06 1.32 +++ deliantra/server/common/map.C 2006/12/12 21:39:56 1.40 @@ -26,15 +26,11 @@ #include #include -#ifndef WIN32 /* ---win32 exclude header */ -# include -#endif /* win32 */ +#include #include "path.h" -extern int nrofallocobjects, nroffreeobjects; - /* * Returns the maptile which has a name matching the given argument. * return NULL if no match is found. @@ -161,19 +157,14 @@ { char buf[MAX_BUF]; -#ifndef WIN32 char *endbuf; struct stat statbuf; int mode = 0; -#endif if (prepend_dir) strcpy (buf, create_pathname (name)); else strcpy (buf, name); -#ifdef WIN32 /* ***win32: check this sucker in windows style. */ - return (_access (buf, 0)); -#else /* old method (strchr(buf, '\0')) seemd very odd to me - * this method should be equivalant and is clearer. @@ -196,7 +187,6 @@ mode |= 2; return (mode); -#endif } /* @@ -544,7 +534,7 @@ int unique; object *op, *prev = NULL, *last_more = NULL, *otmp; - op = get_object (); + op = object::create (); op->map = m; /* To handle buttons correctly */ while ((i = load_object (fp, op, mapflags))) @@ -584,7 +574,7 @@ if (mapflags & MAP_STYLE) remove_from_active_list (op); - op = get_object (); + op = object::create (); op->map = m; } @@ -604,7 +594,7 @@ } } - free_object (op); + op->destroy (); link_multipart_objects (m); } @@ -647,37 +637,40 @@ } /* 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 maptile. * Modified to no longer take a path option which was not being * used anyways. MSW 2001-07-01 */ - maptile * get_linked_map (void) { - maptile *map = new maptile; - maptile *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; } @@ -686,24 +679,25 @@ * This basically allocates the dynamic array of spaces for the * map. */ - void -allocate_map (maptile *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); } @@ -718,7 +712,8 @@ m->width = sizex; m->height = sizey; m->in_memory = MAP_SWAPPED; - allocate_map (m); + m->allocate (); + return m; } @@ -855,31 +850,34 @@ 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; + while (isspace (*key)) key++; + if (*key == 0) continue; /* empty line */ + value = strchr (key, ' '); + if (!value) { - end = strchr (key, '\n'); - if (end != NULL) - { - *end = 0; - } + if ((end = strchr (key, '\n'))) + *end = 0; } else { *value = 0; value++; end = strchr (value, '\n'); + while (isspace (*value)) { value++; + if (*value == '\0' || value == end) { /* Nothing but spaces. */ @@ -912,7 +910,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; @@ -933,7 +931,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; @@ -1186,7 +1184,7 @@ return NULL; } - allocate_map (m); + m->allocate (); m->in_memory = MAP_LOADING; load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); @@ -1242,7 +1240,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); @@ -1277,7 +1276,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); @@ -1301,18 +1300,22 @@ for (j = 0; j < MAP_HEIGHT (m); j++) { unique = 0; + for (op = get_map_ob (m, i, j); op; op = next) { next = op->above; + if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) unique = 1; + if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) { clean_object (op); + if (QUERY_FLAG (op, FLAG_IS_LINKED)) remove_button_link (op); - remove_ob (op); - free_object (op); + + op->destroy (); } } } @@ -1425,17 +1428,10 @@ } if (m->shopgreed) fprintf (freezer, "shopgreed %f\n", m->shopgreed); -#ifndef WIN32 if (m->shopmin) fprintf (freezer, "shopmin %llu\n", m->shopmin); if (m->shopmax) fprintf (freezer, "shopmax %llu\n", m->shopmax); -#else - if (m->shopmin) - fprintf (freezer, "shopmin %I64u\n", m->shopmin); - if (m->shopmax) - fprintf (freezer, "shopmax %I64u\n", m->shopmax); -#endif if (m->shoprace) fprintf (freezer, "shoprace %s\n", m->shoprace); if (m->darkness) @@ -1524,11 +1520,12 @@ for (tmp = op->inv; tmp; tmp = next) { next = tmp->below; + clean_object (tmp); if (QUERY_FLAG (tmp, FLAG_IS_LINKED)) remove_button_link (tmp); - remove_ob (tmp); - free_object (tmp); + + tmp->destroy (); } } @@ -1554,7 +1551,9 @@ LOG (llevDebug, "free_all_objects: Link error, bailing out.\n"); break; } + previous_obj = op; + if (op->head != NULL) op = op->head; @@ -1563,8 +1562,8 @@ */ if (m->in_memory == MAP_IN_MEMORY) clean_object (op); - remove_ob (op); - free_object (op); + + op->destroy (); } } }