--- deliantra/server/common/map.C 2006/12/20 11:36:38 1.46 +++ deliantra/server/common/map.C 2006/12/25 11:25:49 1.47 @@ -411,10 +411,10 @@ return P_OUT_OF_MAP; /* don't have object, so don't know what types would block */ - return (GET_MAP_MOVE_BLOCK (m1, sx, sy)); + return m1->at (sx, sy).move_block; } - for (tmp = ob->arch; tmp != NULL; tmp = tmp->more) + for (tmp = ob->arch; tmp; tmp = tmp->more) { flag = get_map_flags (m, &m1, x + tmp->clone.x, y + tmp->clone.y, &sx, &sy); @@ -423,18 +423,21 @@ if (flag & P_IS_ALIVE) return P_IS_ALIVE; + mapspace &ms = m1->at (sx, sy); + + /* find_first_free_spot() calls this function. However, often * ob doesn't have any move type (when used to place exits) * so the AND operation in OB_TYPE_MOVE_BLOCK doesn't work. */ - if (ob->move_type == 0 && GET_MAP_MOVE_BLOCK (m1, sx, sy) != MOVE_ALL) + if (ob->move_type == 0 && ms.move_block != MOVE_ALL) continue; /* Note it is intentional that we check ob - the movement type of the * head of the object should correspond for the entire object. */ - if (OB_TYPE_MOVE_BLOCK (ob, GET_MAP_MOVE_BLOCK (m1, sx, sy))) + if (OB_TYPE_MOVE_BLOCK (ob, ms.move_block)) return P_NO_PASS; } @@ -544,7 +547,6 @@ continue; } - switch (i) { case LL_NORMAL: @@ -1123,7 +1125,7 @@ { LOG (llevError, "Error loading map header for %s, flags=%d\n", filename, flags); delete_map (m); - return NULL; + return 0; } m->allocate (); @@ -1216,7 +1218,7 @@ LOG (llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname); delete_map (m); m = load_original_map (m->path, 0); - return NULL; + return 0; } /*m->allocate ();*/ @@ -1252,11 +1254,7 @@ if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) { - clean_object (op); - - if (QUERY_FLAG (op, FLAG_IS_LINKED)) - remove_button_link (op); - + op->destroy_inv (false); op->destroy (); } } @@ -1448,63 +1446,26 @@ return 0; } - -/* - * Remove and free all objects in the inventory of the given object. - * object.c ? - */ - -void -clean_object (object *op) -{ - object *tmp, *next; - - for (tmp = op->inv; tmp; tmp = next) - { - next = tmp->below; - - clean_object (tmp); - if (QUERY_FLAG (tmp, FLAG_IS_LINKED)) - remove_button_link (tmp); - - tmp->destroy (); - } -} - /* * Remove and free all objects in the given map. */ - void free_all_objects (maptile *m) { - int i, j; - object *op; + if (!m->spaces) + return; - for (i = 0; i < MAP_WIDTH (m); i++) - for (j = 0; j < MAP_HEIGHT (m); j++) + for (int i = 0; i < MAP_WIDTH (m); i++) + for (int j = 0; j < MAP_HEIGHT (m); j++) { - object *previous_obj = NULL; + mapspace &ms = m->at (i, j); - while ((op = GET_MAP_OB (m, i, j)) != NULL) + while (object *op = ms.bottom) { - if (op == previous_obj) - { - LOG (llevDebug, "free_all_objects: Link error, bailing out.\n"); - break; - } - - previous_obj = op; - - if (op->head != NULL) + if (op->head) op = op->head; - /* If the map isn't in memory, free_object will remove and - * free objects in op's inventory. So let it do the job. - */ - if (m->in_memory == MAP_IN_MEMORY) - clean_object (op); - + op->destroy_inv (false); op->destroy (); } } @@ -1514,17 +1475,13 @@ * Frees everything allocated by the given maptileure. * don't free tmpname - our caller is left to do that */ - void free_map (maptile *m, int flag) { - int i; + if (m->in_memory != MAP_IN_MEMORY) + return; - if (!m->in_memory) - { - LOG (llevError, "Trying to free freed map.\n"); - return; - } + m->in_memory = MAP_SAVING; // TODO: use new/delete #define FREE_AND_CLEAR(p) { free (p); p = NULL; } @@ -1551,85 +1508,60 @@ m->buttons = NULL; - for (i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) { if (m->tile_path[i]) FREE_AND_CLEAR (m->tile_path[i]); - m->tile_map[i] = NULL; + + m->tile_map[i] = 0; } m->in_memory = MAP_SWAPPED; #undef FREE_AND_CLEAR - } -/* - * 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. - */ +maptile::~maptile () +{ + free_map (this, 1); + free (tmpname); +} void -delete_map (maptile *m) +maptile::do_destroy () { - maptile *tmp, *last; - int i; + attachable::do_destroy (); - if (!m) - return; + free_all_objects (this); - m->clear (); - - if (m->in_memory == MAP_IN_MEMORY) - { - /* change to MAP_SAVING, even though we are not, - * so that remove_ob doesn't do as much work. - */ - m->in_memory = MAP_SAVING; - free_map (m, 1); - } - /* move this out of free_map, since tmpname can still be needed if - * the map is swapped out. - */ - if (m->tmpname) - { - free (m->tmpname); - m->tmpname = NULL; - } - last = NULL; /* We need to look through all the maps and see if any maps * are pointing at this one for tiling information. Since - * tiling can be assymetric, we just can not look to see which + * tiling can be asymetric, we just can not look to see which * maps this map tiles with and clears those. */ - for (tmp = first_map; tmp != NULL; tmp = tmp->next) - { - if (tmp->next == m) - last = tmp; - - /* This should hopefully get unrolled on a decent compiler */ - for (i = 0; i < 4; i++) - if (tmp->tile_map[i] == m) - tmp->tile_map[i] = NULL; - } + //TODO: non-euclidean-tiling MUST GO + for (maptile *m = first_map; m; m = m->next) + for (int i = 0; i < 4; i++) + if (m->tile_map[i] == this) + m->tile_map[i] = 0; - /* If last is null, then this should be the first map in the list */ - if (!last) - { - if (m == first_map) - first_map = m->next; - else - /* m->path is a static char, so should hopefully still have - * some useful data in it. - */ - LOG (llevError, "delete_map: Unable to find map %s in list\n", m->path); - } + if (first_map == this) + first_map = next; else - last->next = m->next; + for (maptile *m = first_map; m; m = m->next) + if (m->next = this) + { + m->next = next; + break; + } +} - delete m; +//TODO: must go +void +delete_map (maptile *m) +{ + if (m) + m->destroy (); } /* @@ -1646,19 +1578,15 @@ maptile * ready_map_name (const char *name, int flags) { - maptile *m; - if (!name) - return (NULL); + return 0; /* Have we been at this level before? */ - m = has_been_loaded (name); + maptile *m = has_been_loaded (name); /* Map is good to go, so just return it */ if (m && (m->in_memory == MAP_LOADING || m->in_memory == MAP_IN_MEMORY)) - { - return m; - } + return m; /* unique maps always get loaded from their original location, and never * a temp location. Likewise, if map_flush is set, or we have never loaded @@ -1670,7 +1598,6 @@ */ if ((flags & (MAP_FLUSH | MAP_PLAYER_UNIQUE)) || !m) { - /* first visit or time to reset */ if (m) {