--- deliantra/server/common/button.C 2006/09/14 22:33:58 1.10 +++ deliantra/server/common/button.C 2006/10/15 02:16:34 1.12 @@ -41,11 +41,12 @@ for (; ol; ol = ol->next) { - if (!ol->ob || ol->ob->count != ol->id) + if (!ol->ob) { - LOG (llevError, "Internal error in activate_connection_link (%ld).\n", ol->id); + LOG (llevError, "Internal error in activate_connection_link.\n"); continue; } + /* a button link object can become freed when the map is saving. As * a map is saved, objects are removed and freed, and if an object is * on top of a button, this function is eventually called. If a map @@ -189,7 +190,7 @@ * */ void -activate_connection (mapstruct *map, long connection, bool state) +activate_connection (maptile *map, long connection, bool state) { if (INVOKE_MAP (TRIGGER, map, ARG_INT64 (connection), ARG_INT (state))) return; @@ -220,11 +221,12 @@ if (obp) for (ol = obp->link; ol; ol = ol->next) { - if (!ol->ob || ol->ob->count != ol->id) + if (!ol->ob) { LOG (llevDebug, "Internal error in update_button (%s).\n", &op->name); continue; } + tmp = ol->ob; if (tmp->type == BUTTON) { @@ -283,7 +285,7 @@ */ void -update_buttons (mapstruct *m) +update_buttons (maptile *m) { objectlink *ol; oblinkpt *obp; @@ -291,12 +293,13 @@ for (obp = m->buttons; obp; obp = obp->next) for (ol = obp->link; ol; ol = ol->next) { - if (!ol->ob || ol->ob->count != ol->id) + if (!ol->ob) { - LOG (llevError, "Internal error in update_button (%s (%dx%d):%d, connected %ld).\n", - ol->ob ? (const char *) ol->ob->name : "null", ol->ob ? ol->ob->x : -1, ol->ob ? ol->ob->y : -1, ol->id, obp->value); + LOG (llevError, "Internal error in update_button (%s (%dx%d), connected %ld).\n", + ol->ob ? (const char *) ol->ob->name : "null", ol->ob ? ol->ob->x : -1, ol->ob ? ol->ob->y : -1, obp->value); continue; } + if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL) { update_button (ol->ob); @@ -597,7 +600,7 @@ } void -add_button_link (object *button, mapstruct *map, int connected) +add_button_link (object *button, maptile *map, int connected) { oblinkpt *obp; objectlink *ol = get_objectlink (); @@ -616,7 +619,6 @@ SET_FLAG (button, FLAG_IS_LINKED); ol->ob = button; - ol->id = button->count; for (obp = map->buttons; obp && obp->value != connected; obp = obp->next); @@ -652,11 +654,13 @@ LOG (llevError, "remove_button_link() in object without map.\n"); return; } + if (!QUERY_FLAG (op, FLAG_IS_LINKED)) { LOG (llevError, "remove_button_linked() in unlinked object.\n"); return; } + for (obp = op->map->buttons; obp; obp = obp->next) for (olp = &obp->link; (ol = *olp); olp = &ol->next) if (ol->ob == op) @@ -666,9 +670,10 @@ obp->value, op->name, op->map->path); */ *olp = ol->next; - free (ol); + delete ol; return; } + LOG (llevError, "remove_button_linked(): couldn't find object.\n"); CLEAR_FLAG (op, FLAG_IS_LINKED); } @@ -677,11 +682,12 @@ * Gets the objectlink for this connection from the map. */ oblinkpt * -get_connection_links (mapstruct *map, long connection) +get_connection_links (maptile *map, long connection) { for (oblinkpt * obp = map->buttons; obp; obp = obp->next) if (obp->value == connection) return obp; + return 0; } @@ -697,10 +703,12 @@ if (!button->map) return NULL; + for (obp = button->map->buttons; obp; obp = obp->next) for (ol = obp->link; ol; ol = ol->next) - if (ol->ob == button && ol->id == button->count) + if (ol->ob == button) return obp; + return NULL; } @@ -718,7 +726,7 @@ return 0; for (obp = button->map->buttons; obp; obp = obp->next) for (ol = obp->link; ol; ol = ol->next) - if (ol->ob == button && ol->id == button->count) + if (ol->ob == button) return obp->value; return 0; } @@ -867,26 +875,3 @@ use_trigger (trig); } - -/* This does a minimal check of the button link consistency for object - * map. All it really does it much sure the object id link that is set - * matches what the object has. - */ -void -verify_button_links (const mapstruct *map) -{ - oblinkpt *obp; - objectlink *ol; - - if (!map) - return; - - for (obp = map->buttons; obp; obp = obp->next) - { - for (ol = obp->link; ol; ol = ol->next) - { - if (ol->id != ol->ob->count) - LOG (llevError, "verify_button_links: object %s on list is corrupt (%d!=%d)\n", &ol->ob->name, ol->id, ol->ob->count); - } - } -}