--- deliantra/server/common/map.C 2006/09/16 22:24:12 1.31 +++ deliantra/server/common/map.C 2006/12/11 14:28:12 1.37 @@ -33,8 +33,6 @@ #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. @@ -277,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 @@ -290,7 +287,6 @@ * the coordinates & map passed in should have been updated for tiling * by the caller. */ - int blocked_link (object *ob, maptile *m, int sx, int sy) { @@ -649,37 +645,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; } @@ -688,24 +687,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); } @@ -720,7 +720,8 @@ m->width = sizex; m->height = sizey; m->in_memory = MAP_SWAPPED; - allocate_map (m); + m->allocate (); + return m; } @@ -857,31 +858,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. */ @@ -914,7 +918,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; @@ -935,7 +939,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; @@ -1188,7 +1192,7 @@ return NULL; } - allocate_map (m); + m->allocate (); m->in_memory = MAP_LOADING; load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); @@ -1244,7 +1248,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); @@ -1279,7 +1284,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);