--- deliantra/server/common/button.C 2008/04/09 14:36:47 1.41 +++ deliantra/server/common/button.C 2008/05/04 18:24:11 1.46 @@ -22,7 +22,6 @@ */ #include -#include /* * This code is no longer highly inefficient 8) @@ -218,13 +217,11 @@ void update_button (object *op) { - object *ab, *tmp, *head; - int tot, any_down = 0, old_value = op->value; + int any_down = 0, old_value = op->value; oblinkpt *obp = 0; objectlink *ol; obp = get_button_links (op); - /* LOG(llevDebug, "update_button: %s (%d)\n", op->name, op->count); */ if (obp) for (ol = obp->link; ol; ol = ol->next) { @@ -234,51 +231,51 @@ continue; } - tmp = ol->ob; + object *tmp = ol->ob; + if (tmp->type == BUTTON) { - for (ab = tmp->above, tot = 0; ab != NULL; ab = ab->above) - /* Bug? The pedestal code below looks for the head of - * the object, this bit doesn't. I'd think we should check - * for head here also. Maybe it also makese sense to - * make the for ab=tmp->above loop common, and alter - * behaviour based on object within that loop? - */ + sint32 total = 0; + for (object *ab = tmp->above; ab; ab = ab->above) /* Basically, if the move_type matches that on what the - * button wants, we count it. The second check is so that - * objects don't move (swords, etc) will count. Note that + * button wants, we count it. The second check is so that + * objects who don't move (swords, etc) will count. Note that * this means that more work is needed to make buttons * that are only triggered by flying objects. */ if ((ab->move_type & tmp->move_on) || ab->move_type == 0) - tot += ab->weight * (ab->nrof ? ab->nrof : 1) + ab->carrying; + total += ab->head_ ()->total_weight (); - tmp->value = (tot >= tmp->weight) ? 1 : 0; - if (tmp->value) - any_down = 1; + tmp->value = total >= tmp->weight; + + any_down = any_down || tmp->value; } else if (tmp->type == PEDESTAL) { tmp->value = 0; - for (ab = tmp->above; ab != NULL; ab = ab->above) + + for (object *ab = tmp->above; ab; ab = ab->above) { - head = ab->head_ (); + object *head = ab->head_ (); + /* Same note regarding move_type for buttons above apply here. */ - if (((head->move_type & tmp->move_on) || ab->move_type == 0) && - (head->race == tmp->slaying || - ((head->type == SPECIAL_KEY) && (head->slaying == tmp->slaying)) || - (!strcmp (tmp->slaying, "player") && head->type == PLAYER))) + if (((ab->move_type & tmp->move_on) || ab->move_type == 0) + && (head->race == tmp->slaying + || (head->type == SPECIAL_KEY && head->slaying == tmp->slaying) + || (tmp->slaying == shstr_player && head->type == PLAYER))) tmp->value = 1; } - if (tmp->value) - any_down = 1; + any_down = any_down || tmp->value; } } + if (any_down) /* If any other buttons were down, force this to remain down */ op->value = 1; + //LOG(llevDebug, "update_button: %s (%d, %d=%d)\n", &op->name, op->count, op->value, old_value); + /* If this button hasn't changed, don't do anything */ if (op->value != old_value) { @@ -339,7 +336,7 @@ || ARCH_SACRIFICE (altar) == sacrifice->name || ARCH_SACRIFICE (altar) == sacrifice->slaying || strstr (query_base_name (sacrifice, 0), ARCH_SACRIFICE (altar))) - && NROF_SACRIFICE (altar) <= (sacrifice->nrof ? sacrifice->nrof : 1)) + && NROF_SACRIFICE (altar) <= sacrifice->number_of ()) return 1; } @@ -381,10 +378,12 @@ if (NROF_SACRIFICE (altar) % (*sacrifice)->value) number++; - *sacrifice = decrease_ob_nr (*sacrifice, number); + if (!(*sacrifice)->decrease (number)) + *sacrifice = 0; } else - *sacrifice = decrease_ob_nr (*sacrifice, NROF_SACRIFICE (altar)); + if (!(*sacrifice)->decrease (NROF_SACRIFICE (altar))) + *sacrifice = 0; if (altar->msg) new_info_map (NDI_BLACK, altar->map, altar->msg); @@ -431,158 +430,160 @@ switch (op->type) { - case TRIGGER_BUTTON: - if (op->weight > 0) - { - if (cause) - { - for (tmp = op->above; tmp; tmp = tmp->above) - /* Comment reproduced from update_buttons(): */ - /* Basically, if the move_type matches that on what the - * button wants, we count it. The second check is so that - * objects that don't move (swords, etc) will count. Note that - * this means that more work is needed to make buttons - * that are only triggered by flying objects. - */ + case TRIGGER_BUTTON: + if (op->weight > 0) + { + if (cause) + { + for (tmp = op->above; tmp; tmp = tmp->above) + /* Comment reproduced from update_buttons(): */ + /* Basically, if the move_type matches that on what the + * button wants, we count it. The second check is so that + * objects that don't move (swords, etc) will count. Note that + * this means that more work is needed to make buttons + * that are only triggered by flying objects. + */ + if ((tmp->move_type & op->move_on) || tmp->move_type == 0) + tot += tmp->head_ ()->total_weight (); + + if (tot >= op->weight) + push = 1; + + if (op->stats.ac == push) + return 0; + + op->stats.ac = push; + if (NUM_ANIMATIONS (op) > 1) + { + SET_ANIMATION (op, push); + update_object (op, UP_OBJ_FACE); + } + + if (in_movement || !push) + return 0; + } + trigger_move (op, push); + } + + return 0; - if ((tmp->move_type & op->move_on) || tmp->move_type == 0) - { - tot += tmp->weight * (tmp->nrof ? tmp->nrof : 1) + tmp->carrying; - } - if (tot >= op->weight) + case TRIGGER_PEDESTAL: + if (cause) + { + for (tmp = op->above; tmp; tmp = tmp->above) + { + object *head = tmp->head_ (); + + /* See comment in TRIGGER_BUTTON about move_types */ + if (((head->move_type & op->move_on) || head->move_type == 0) + && (head->race == op->slaying || (!strcmp (op->slaying, "player") && head->type == PLAYER))) + { push = 1; - if (op->stats.ac == push) - return 0; - op->stats.ac = push; - if (NUM_ANIMATIONS (op) > 1) - { - SET_ANIMATION (op, push); - update_object (op, UP_OBJ_FACE); - } - if (in_movement || !push) - return 0; - } - trigger_move (op, push); - } - return 0; - - case TRIGGER_PEDESTAL: - if (cause) - { - for (tmp = op->above; tmp; tmp = tmp->above) - { - object *head = tmp->head_ (); - - /* See comment in TRIGGER_BUTTON about move_types */ - if (((head->move_type & op->move_on) || head->move_type == 0) - && (head->race == op->slaying || (!strcmp (op->slaying, "player") && head->type == PLAYER))) - { - push = 1; - break; - } - } - - if (op->stats.ac == push) - return 0; - - op->stats.ac = push; - - if (NUM_ANIMATIONS (op) > 1) - { - SET_ANIMATION (op, push); - update_object (op, UP_OBJ_FACE); - } - - update_object (op, UP_OBJ_FACE); - - if (in_movement || !push) - return 0; - } - - trigger_move (op, push); - return 0; - - case TRIGGER_ALTAR: - if (cause) - { - if (in_movement) - return 0; - - if (operate_altar (op, &cause)) - { - if (NUM_ANIMATIONS (op) > 1) - { - SET_ANIMATION (op, 1); - update_object (op, UP_OBJ_FACE); - } - - if (op->last_sp >= 0) - { - trigger_move (op, 1); - if (op->last_sp > 0) - op->last_sp = -op->last_sp; - } - else - { - /* for trigger altar with last_sp, the ON/OFF - * status (-> +/- value) is "simulated": - */ - op->value = !op->value; - trigger_move (op, 1); + break; + } + } + + if (op->stats.ac == push) + return 0; + + op->stats.ac = push; + + if (NUM_ANIMATIONS (op) > 1) + { + SET_ANIMATION (op, push); + update_object (op, UP_OBJ_FACE); + } + + update_object (op, UP_OBJ_FACE); + + if (in_movement || !push) + return 0; + } + + trigger_move (op, push); + return 0; + + case TRIGGER_ALTAR: + if (cause) + { + if (in_movement) + return 0; + + if (operate_altar (op, &cause)) + { + if (NUM_ANIMATIONS (op) > 1) + { + SET_ANIMATION (op, 1); + update_object (op, UP_OBJ_FACE); + } + + if (op->last_sp >= 0) + { + trigger_move (op, 1); + if (op->last_sp > 0) op->last_sp = -op->last_sp; - op->value = !op->value; - } + } + else + { + /* for trigger altar with last_sp, the ON/OFF + * status (-> +/- value) is "simulated": + */ + op->value = !op->value; + trigger_move (op, 1); + op->last_sp = -op->last_sp; + op->value = !op->value; + } - return cause == NULL; - } - else - return 0; - } - else - { - if (NUM_ANIMATIONS (op) > 1) - { - SET_ANIMATION (op, 0); - update_object (op, UP_OBJ_FACE); - } - - /* If trigger_altar has "last_sp > 0" set on the map, - * it will push the connected value only once per sacrifice. - * Otherwise (default), the connected value will be - * pushed twice: First by sacrifice, second by reset! -AV - */ - if (!op->last_sp) - trigger_move (op, 0); - else - { - op->stats.wc = 0; - op->value = !op->value; - op->set_speed (0); - } - } - return 0; - - case TRIGGER: - if (cause) - { - 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; - - default: - LOG (llevDebug, "Unknown trigger type: %s (%d)\n", &op->name, op->type); - return 0; + return cause == NULL; + } + else + return 0; + } + else + { + if (NUM_ANIMATIONS (op) > 1) + { + SET_ANIMATION (op, 0); + update_object (op, UP_OBJ_FACE); + } + + /* If trigger_altar has "last_sp > 0" set on the map, + * it will push the connected value only once per sacrifice. + * Otherwise (default), the connected value will be + * pushed twice: First by sacrifice, second by reset! -AV + */ + if (!op->last_sp) + trigger_move (op, 0); + else + { + op->stats.wc = 0; + op->value = !op->value; + op->set_speed (0); + } + } + return 0; + + case TRIGGER: + if (cause) + { + 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; + + default: + LOG (llevDebug, "Unknown trigger type: %s (%d)\n", &op->name, op->type); + return 0; } } @@ -811,7 +812,7 @@ case 5: // kill all alives if (!tmp->flag [FLAG_PRECIOUS]) { - get_archetype ("burnout")->insert_at (tmp, source); + archetype::get (shstr_burnout)->insert_at (tmp, source); tmp->destroy (); } break; @@ -896,7 +897,7 @@ if (match && trig->last_sp) // match == having { if (trig->last_heal) - decrease_ob (match); + match->decrease (); trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left push_button (trig);