--- deliantra/server/common/button.C 2006/09/11 20:28:37 1.8 +++ deliantra/server/common/button.C 2006/12/21 01:33:49 1.18 @@ -1,9 +1,3 @@ - -/* - * static char *rcsid_button_c = - * "$Id: button.C,v 1.8 2006/09/11 20:28:37 root Exp $"; - */ - /* CrossFire, A Multiplayer game for X-windows @@ -24,7 +18,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - The authors can be reached via e-mail at crossfire-devel@real-time.com + The authors can be reached via e-mail at */ #include @@ -47,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 @@ -195,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; @@ -212,7 +207,6 @@ * to make sure that all gates and other buttons connected to the * button reacts to the (eventual) change of state. */ - void update_button (object *op) { @@ -226,11 +220,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) { @@ -289,7 +284,7 @@ */ void -update_buttons (mapstruct *m) +update_buttons (maptile *m) { objectlink *ol; oblinkpt *obp; @@ -297,12 +292,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); @@ -359,14 +355,15 @@ (!strcmp (ARCH_SACRIFICE (altar), query_base_name (sacrifice, 0)))) && NROF_SACRIFICE (altar) <= (sacrifice->nrof ? sacrifice->nrof : 1)) return 1; + if (strcmp (ARCH_SACRIFICE (altar), "money") == 0 && sacrifice->type == MONEY && sacrifice->nrof * sacrifice->value >= NROF_SACRIFICE (altar)) return 1; } + return 0; } - /* * operate_altar checks if sacrifice was accepted and removes sacrificed * objects. If sacrifice was succeed return 1 else 0. Might be better to @@ -376,11 +373,9 @@ * If this function returns 1, '*sacrifice' is modified to point to the * remaining sacrifice, or is set to NULL if the sacrifice was used up. */ - int operate_altar (object *altar, object **sacrifice) { - if (!altar->map) { LOG (llevError, "BUG: operate_altar(): altar has no map\n"); @@ -403,6 +398,7 @@ /* Round up any sacrifices. Altars don't make change either */ if (NROF_SACRIFICE (altar) % (*sacrifice)->value) number++; + *sacrifice = decrease_ob_nr (*sacrifice, number); } else @@ -410,6 +406,7 @@ if (altar->msg) new_info_map (NDI_BLACK, altar->map, altar->msg); + return 1; } @@ -604,7 +601,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 (); @@ -623,7 +620,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); @@ -659,11 +655,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) @@ -673,9 +671,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); } @@ -684,11 +683,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; } @@ -704,10 +704,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; } @@ -725,7 +727,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; } @@ -772,10 +774,8 @@ * dereference a null value */ if (tmp->type == GOLEM && tmp->owner && tmp->owner->type == PLAYER && tmp->owner->contr->ranges[range_golem] == tmp) - { - tmp->owner->contr->ranges[range_golem] = NULL; - tmp->owner->contr->golem_count = 0; - } + tmp->owner->contr->ranges[range_golem] = 0; + tmp->owner = 0; } break; @@ -795,17 +795,20 @@ if (op == source) break; /* only if 'connected' */ - for (tmp2 = get_map_ob (source->map, source->x, source->y); /* finding an owner */ + for (tmp2 = GET_MAP_OB (source->map, source->x, source->y); /* finding an owner */ tmp2->type != PLAYER; tmp2 = tmp2->above) if (tmp2->above == NULL) break; if (tmp2->type != PLAYER) break; - set_owner (tmp, tmp2); + + tmp->set_owner (tmp2); SET_FLAG (tmp, FLAG_MONSTER); + tmp->stats.exp = 0; SET_FLAG (tmp, FLAG_FRIENDLY); + add_friendly_object (tmp); tmp->attack_movement = PETMOVE; break; @@ -821,7 +824,6 @@ * race = match object archetype name flag * hp = match object type (excpt type '0'== PLAYER) */ - object * check_inv_recursive (object *op, const object *trig) { @@ -829,7 +831,8 @@ /* First check the object itself. */ if ((trig->stats.hp && (op->type == trig->stats.hp)) - || (trig->slaying && (op->slaying == trig->slaying)) || (trig->race && (op->arch->name == trig->race))) + || (trig->slaying && (op->slaying == trig->slaying)) + || (trig->race && (op->arch->name == trig->race))) return op; for (tmp = op->inv; tmp; tmp = tmp->below) @@ -841,7 +844,8 @@ return ret; } else if ((trig->stats.hp && (tmp->type == trig->stats.hp)) - || (trig->slaying && (tmp->slaying == trig->slaying)) || (trig->race && (tmp->arch->name == trig->race))) + || (trig->slaying && (tmp->slaying == trig->slaying)) + || (trig->race && (tmp->arch->name == trig->race))) return tmp; } return NULL; @@ -854,46 +858,37 @@ * Values are: last_sp = 1/0 obj/no obj triggers * last_heal = 1/0 remove/dont remove obj if triggered * -b.t. (thomas@nomad.astro.psu.edu + * + * Tue Dec 19 15:34:00 CET 2006 elmex: changed the function to ignore op + * because the check-inventory semantic essentially only applies when + * something is above the inventory checker. + * The semantic prior this change was: trigger if something has moved on or off + * and has a matching item. Imagine what happens if someone steps on the inventory + * checker with a matching item, has it, activates the connection, throws the item + * away, and then leaves the inventory checker. That would've caused an always-enabled + * state in the inventory checker. This won't happen anymore now. + * */ - void check_inv (object *op, object *trig) { - object *match; + trig->value = 0; // deactivate if none of the following conditions apply - if (op->type != PLAYER) - return; - match = check_inv_recursive (op, trig); - if (match && trig->last_sp) + if (object *pl = trig->ms ().player ()) { - if (trig->last_heal) - decrease_ob (match); - use_trigger (trig); - } - else if (!match && !trig->last_sp) - 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; + object *match = check_inv_recursive (pl, trig); - for (obp = map->buttons; obp; obp = obp->next) - { - for (ol = obp->link; ol; ol = ol->next) + if (match && trig->last_sp) // match == having { - 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); + if (trig->last_heal) + decrease_ob (match); + + trig->value = 1; } + else if (!match && !trig->last_sp) // match == not having + trig->value = 1; } + + push_button (trig); } +