--- deliantra/server/common/map.C 2006/12/25 17:11:16 1.51 +++ deliantra/server/common/map.C 2006/12/27 13:13:46 1.54 @@ -21,7 +21,6 @@ The authors can be reached via e-mail at */ - #include #include @@ -37,16 +36,14 @@ maptile * has_been_loaded (const char *name) { - maptile *map; - if (!name || !*name) return 0; - for (map = first_map; map; map = map->next) + for_all_maps (map) if (!strcmp (name, map->path)) - break; + return map; - return (map); + return 0; } /* @@ -223,9 +220,7 @@ void dump_all_maps (void) { - maptile *m; - - for (m = first_map; m; m = m->next) + for_all_maps (m) dump_map (m); } @@ -478,7 +473,6 @@ * they are saved). We do have to look for the old maps that did save * the more sections and not re-add sections for them. */ - static void link_multipart_objects (maptile *m) { @@ -619,10 +613,7 @@ if (op->flag [FLAG_UNIQUE] && op->flag [FLAG_IS_FLOOR]) unique = 1; - if (op->type == PLAYER) - continue; - - if (op->head || op->owner) + if (!op->can_map_save ()) continue; if (unique || op->flag [FLAG_UNIQUE]) @@ -636,18 +627,40 @@ maptile::maptile () { in_memory = MAP_SWAPPED; + /* The maps used to pick up default x and y values from the * map archetype. Mimic that behaviour. */ - this->width = 16; - this->height = 16; - this->reset_timeout = 0; - this->timeout = 300; - this->enter_x = 0; - this->enter_y = 0; + width = 16; + height = 16; + reset_timeout = 0; + timeout = 300; + enter_x = 0; + enter_y = 0; /*set part to -1 indicating conversion to weather map not yet done */ - this->worldpartx = -1; - this->worldparty = -1; + worldpartx = -1; + worldparty = -1; +} + +void +maptile::link () +{ + next = first_map; + first_map = this; +} + +void +maptile::unlink () +{ + if (first_map == this) + first_map = next; + else + for_all_maps (m) + if (m->next = this) + { + m->next = next; + break; + } } /* @@ -658,15 +671,8 @@ maptile * get_linked_map (void) { - maptile *mp, *map = new maptile; - - for (mp = first_map; mp && mp->next; mp = mp->next); - - if (mp == NULL) - first_map = map; - else - mp->next = map; - + maptile *map = new maptile; + map->link (); return map; } @@ -687,14 +693,10 @@ if (spaces) { LOG (llevError, "allocate_map called with already allocated map (%s)\n", path); - free (spaces); + sfree (spaces, size ()); } - spaces = (mapspace *) - calloc (1, width * height * sizeof (mapspace)); - - if (!spaces) - fatal (OUT_OF_MEMORY); + spaces = salloc0 (size ()); } /* Create and returns a map of the specific size. Used @@ -737,6 +739,7 @@ if (p) p++; } + p = shop_string; strip_endline (p); items = new shopitems[number_of_entries + 1]; @@ -747,6 +750,7 @@ LOG (llevError, "parse_shop_string: I seem to have run out of string, that shouldn't happen.\n"); break; } + next_semicolon = strchr (p, ';'); next_colon = strchr (p, ':'); /* if there is a stregth specified, figure out what it is, we'll need it soon. */ @@ -783,12 +787,14 @@ LOG (llevError, "invalid type %s defined in shopitems in string %s\n", p, input_string); } } + items[i].index = number_of_entries; if (next_semicolon) p = ++next_semicolon; else p = NULL; } + free (shop_string); return items; } @@ -807,21 +813,18 @@ if (m->shopitems[i].typenum) { if (m->shopitems[i].strength) - { - sprintf (tmp, "%s:%d;", m->shopitems[i].name, m->shopitems[i].strength); - } + sprintf (tmp, "%s:%d;", m->shopitems[i].name, m->shopitems[i].strength); else sprintf (tmp, "%s;", m->shopitems[i].name); } else { if (m->shopitems[i].strength) - { - sprintf (tmp, "*:%d;", m->shopitems[i].strength); - } + sprintf (tmp, "*:%d;", m->shopitems[i].strength); else sprintf (tmp, "*"); } + strcat (output_string, tmp); } } @@ -1099,7 +1102,6 @@ * MAP_STYLE: style map - don't add active objects, don't add to server * managed map list. */ - maptile * load_original_map (const char *filename, int flags) { @@ -1148,7 +1150,6 @@ * Return the map object we load into (this can change from the passed * option if we can't find the original map) */ - static maptile * load_temporary_map (maptile *m) { @@ -1202,7 +1203,6 @@ * Return the map object we load into (this can change from the passed * option if we can't find the original map) */ - maptile * load_overlay_map (const char *filename, maptile *m) { @@ -1263,7 +1263,6 @@ } } - /* * Loads unique objects from file(s) into the map which is in memory * m is the map to load unique items into. @@ -1489,8 +1488,9 @@ if (flag && m->spaces) free_all_objects (m); + sfree (m->spaces, m->size ()), m->spaces = 0; + free (m->name), m->name = 0; - free (m->spaces), m->spaces = 0; free (m->msg), m->msg = 0; free (m->maplore), m->maplore = 0; free (m->shoprace), m->shoprace = 0; @@ -1500,20 +1500,14 @@ free_objectlinkpt (m->buttons), m->buttons = 0; for (int i = 0; i < 4; i++) - { - if (m->tile_path[i]) - free (m->tile_path[i]), m->tile_path[i] = 0; - - m->tile_map[i] = 0; - } + free (m->tile_path[i]), m->tile_path[i] = 0; m->in_memory = MAP_SWAPPED; } maptile::~maptile () { - free_map (this, 1); - free (tmpname); + assert (destroyed ()); } void @@ -1521,7 +1515,10 @@ { attachable::do_destroy (); - free_all_objects (this); + unlink (); + + free_map (this, 1); + free (tmpname), tmpname = 0; /* We need to look through all the maps and see if any maps * are pointing at this one for tiling information. Since @@ -1529,20 +1526,10 @@ * maps this map tiles with and clears those. */ //TODO: non-euclidean-tiling MUST GO - for (maptile *m = first_map; m; m = m->next) + for_all_maps (m) for (int i = 0; i < 4; i++) if (m->tile_map[i] == this) m->tile_map[i] = 0; - - if (first_map == this) - first_map = next; - else - for (maptile *m = first_map; m; m = m->next) - if (m->next = this) - { - m->next = next; - break; - } } //TODO: must go @@ -1600,10 +1587,8 @@ else LOG (llevDebug, "Trying to load map %s.\n", create_pathname (name)); - //eval_pv ("$x = Event::time", 1);//D if (!(m = load_original_map (name, (flags & MAP_PLAYER_UNIQUE)))) return (NULL); - //eval_pv ("warn \"LOAD \", Event::time - $x", 1);//D fix_auto_apply (m); /* Chests which open as default */ @@ -1749,6 +1734,7 @@ delete_map (first_map); real_maps++; } + LOG (llevDebug, "free_all_maps: Freed %d maps\n", real_maps); } @@ -2353,3 +2339,13 @@ return adjacent_map (op1->map, op2->map, &dx, &dy); } + +object * +maptile::insert (object *op, int x, int y, object *originator, int flags) +{ + if (!op->flag [FLAG_REMOVED]) + op->remove (); + + return insert_ob_in_map_at (op, this, originator, flags, x, y); +} +