--- deliantra/server/common/button.C 2006/09/14 22:33:58 1.10 +++ deliantra/server/common/button.C 2007/01/09 16:38:23 1.24 @@ -1,6 +1,7 @@ /* CrossFire, A Multiplayer game for X-windows + Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team Copyright (C) 2002 Mark Wedel & Crossfire Development Team Copyright (C) 1992 Frank Tore Johansen @@ -37,15 +38,14 @@ void activate_connection_link (objectlink * ol, bool state, object *source = 0) { - object *tmp = 0; - 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 @@ -56,7 +56,8 @@ if (QUERY_FLAG (ol->ob, FLAG_FREED)) return; - tmp = ol->ob; + + object *tmp = ol->ob; /* if the criteria isn't appropriate, don't do anything */ if (state && !QUERY_FLAG (tmp, FLAG_ACTIVATE_ON_PUSH)) @@ -66,90 +67,87 @@ switch (tmp->type) { - case GATE: - case HOLE: - tmp->value = tmp->stats.maxsp ? !state : state; - tmp->speed = 0.5; - update_ob_speed (tmp); - break; - - case CF_HANDLE: - SET_ANIMATION (tmp, (tmp->value = tmp->stats.maxsp ? !state : state)); - update_object (tmp, UP_OBJ_FACE); - break; + case GATE: + case HOLE: + tmp->value = tmp->stats.maxsp ? !state : state; + tmp->set_speed (0.5); + break; - case SIGN: - if (!tmp->stats.food || tmp->last_eat < tmp->stats.food) - { - new_info_map (NDI_UNIQUE | NDI_NAVY, tmp->map, tmp->msg); - if (tmp->stats.food) - tmp->last_eat++; - } - break; + case CF_HANDLE: + SET_ANIMATION (tmp, (tmp->value = tmp->stats.maxsp ? !state : state)); + update_object (tmp, UP_OBJ_FACE); + break; - case ALTAR: - tmp->value = 1; - SET_ANIMATION (tmp, tmp->value); - update_object (tmp, UP_OBJ_FACE); - break; - - case BUTTON: - case PEDESTAL: - tmp->value = state; - SET_ANIMATION (tmp, tmp->value); - update_object (tmp, UP_OBJ_FACE); - break; - - case MOOD_FLOOR: - do_mood_floor (tmp, source); - break; - - case TIMED_GATE: - tmp->speed = tmp->arch->clone.speed; - update_ob_speed (tmp); /* original values */ - tmp->value = tmp->arch->clone.value; - tmp->stats.sp = 1; - tmp->stats.hp = tmp->stats.maxhp; - /* Handle multipart gates. We copy the value for the other parts - * from the head - this ensures that the data will consistent - */ - for (tmp = tmp->more; tmp != NULL; tmp = tmp->more) - { - tmp->speed = tmp->head->speed; - tmp->value = tmp->head->value; - tmp->stats.sp = tmp->head->stats.sp; - tmp->stats.hp = tmp->head->stats.hp; - update_ob_speed (tmp); - } - break; + case SIGN: + if (!tmp->stats.food || tmp->last_eat < tmp->stats.food) + { + new_info_map (NDI_UNIQUE | NDI_NAVY, tmp->map, tmp->msg); + if (tmp->stats.food) + tmp->last_eat++; + } + break; - case DIRECTOR: - case FIREWALL: - if (!QUERY_FLAG (tmp, FLAG_ANIMATE) && tmp->type == FIREWALL) - move_firewall (tmp); - else - { - if ((tmp->stats.sp += tmp->stats.maxsp) > 8) /* next direction */ - tmp->stats.sp = ((tmp->stats.sp - 1) % 8) + 1; - animate_turning (tmp); - } - break; + case ALTAR: + tmp->value = 1; + SET_ANIMATION (tmp, tmp->value); + update_object (tmp, UP_OBJ_FACE); + break; + + case BUTTON: + case PEDESTAL: + tmp->value = state; + SET_ANIMATION (tmp, tmp->value); + update_object (tmp, UP_OBJ_FACE); + break; - case TELEPORTER: - move_teleporter (tmp); - break; - - case CREATOR: - move_creator (tmp); - break; - - case TRIGGER_MARKER: - move_marker (tmp); - break; - - case DUPLICATOR: - move_duplicator (tmp); - break; + case MOOD_FLOOR: + do_mood_floor (tmp, source); + break; + + case TIMED_GATE: + tmp->set_speed (tmp->arch->clone.speed); + tmp->value = tmp->arch->clone.value; + tmp->stats.sp = 1; + tmp->stats.hp = tmp->stats.maxhp; + /* Handle multipart gates. We copy the value for the other parts + * from the head - this ensures that the data will consistent + */ + for (tmp = tmp->more; tmp; tmp = tmp->more) + { + tmp->value = tmp->head->value; + tmp->stats.sp = tmp->head->stats.sp; + tmp->stats.hp = tmp->head->stats.hp; + tmp->set_speed (tmp->head->speed); + } + break; + + case DIRECTOR: + case FIREWALL: + if (!QUERY_FLAG (tmp, FLAG_ANIMATE) && tmp->type == FIREWALL) + move_firewall (tmp); + else + { + if ((tmp->stats.sp += tmp->stats.maxsp) > 8) /* next direction */ + tmp->stats.sp = ((tmp->stats.sp - 1) % 8) + 1; + animate_turning (tmp); + } + break; + + case TELEPORTER: + move_teleporter (tmp); + break; + + case CREATOR: + move_creator (tmp); + break; + + case TRIGGER_MARKER: + move_marker (tmp); + break; + + case DUPLICATOR: + move_duplicator (tmp); + break; } } } @@ -189,7 +187,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; @@ -206,7 +204,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) { @@ -220,11 +217,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) { @@ -278,37 +276,9 @@ } } -/* - * Updates every button on the map (by calling update_button() for them). - */ - -void -update_buttons (mapstruct *m) -{ - objectlink *ol; - oblinkpt *obp; - - for (obp = m->buttons; obp; obp = obp->next) - for (ol = obp->link; ol; ol = ol->next) - { - if (!ol->ob || ol->ob->count != ol->id) - { - 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); - continue; - } - if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL) - { - update_button (ol->ob); - break; - } - } -} - void use_trigger (object *op) { - /* Toggle value */ op->value = !op->value; push_button (op); @@ -318,7 +288,6 @@ * Note: animate_object should be used instead of this, * but it can't handle animations in the 8 directions */ - void animate_turning (object *op) /* only one part objects */ { @@ -353,10 +322,12 @@ (!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; } @@ -413,18 +384,13 @@ if (state) { use_trigger (op); - if (op->stats.exp > 0) /* check sanity */ - op->speed = 1.0 / op->stats.exp; - else - op->speed = 1.0; - update_ob_speed (op); + op->set_speed (op->stats.exp > 0 ? 1. / op->stats.exp : 1.); op->speed_left = -1; } else { use_trigger (op); - op->speed = 0; - update_ob_speed (op); + op->set_speed (0); } } @@ -569,8 +535,7 @@ { op->stats.wc = 0; op->value = !op->value; - op->speed = 0; - update_ob_speed (op); + op->set_speed (0); } } return 0; @@ -580,13 +545,16 @@ { if (in_movement) return 0; + push = 1; } + if (NUM_ANIMATIONS (op) > 1) { SET_ANIMATION (op, push); update_object (op, UP_OBJ_FACE); } + trigger_move (op, push); return 1; @@ -597,7 +565,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 (); @@ -607,18 +575,16 @@ LOG (llevError, "Tried to add button-link without map.\n"); return; } - if (!editor) - button->path_attuned = connected; /* peterm: I need this so I can rebuild - a connected map from a template map. */ -/* LOG(llevDebug,"adding button %s (%d)\n", button->name, connected);*/ + button->path_attuned = connected; /* peterm: I need this so I can rebuild + a connected map from a template map. */ SET_FLAG (button, FLAG_IS_LINKED); ol->ob = button; - ol->id = button->count; - for (obp = map->buttons; obp && obp->value != connected; obp = obp->next); + for (obp = map->buttons; obp && obp->value != connected; obp = obp->next) + ; if (obp) { @@ -652,11 +618,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 +634,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 +646,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 +667,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 +690,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; } @@ -765,10 +737,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; @@ -788,17 +758,19 @@ 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; @@ -814,7 +786,6 @@ * race = match object archetype name flag * hp = match object type (excpt type '0'== PLAYER) */ - object * check_inv_recursive (object *op, const object *trig) { @@ -822,7 +793,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) @@ -834,7 +806,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; @@ -847,46 +820,39 @@ * 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; + sint32 prev_state = trig->value; + 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; } + + if (prev_state != trig->value) + push_button (trig); } +