--- deliantra/server/common/button.C 2007/04/24 12:32:14 1.29 +++ deliantra/server/common/button.C 2008/04/21 06:35:26 1.43 @@ -1,25 +1,24 @@ /* - * CrossFire, A Multiplayer game + * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team - * Copyright (C) 2002 Mark Wedel & Crossfire Development Team - * Copyright (C) 1992 Frank Tore Johansen + * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team + * Copyright (©) 1992,2007 Frank Tore Johansen * - * This program is free software; you can redistribute it and/or modify + * Deliantra is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * 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 + * along with this program. If not, see . + * + * The authors can be reached via e-mail to */ #include @@ -62,6 +61,7 @@ /* if the criteria isn't appropriate, don't do anything */ if (state && !QUERY_FLAG (tmp, FLAG_ACTIVATE_ON_PUSH)) continue; + if (!state && !QUERY_FLAG (tmp, FLAG_ACTIVATE_ON_RELEASE)) continue; @@ -69,6 +69,10 @@ { case GATE: case HOLE: + if (!tmp->active) + tmp->play_sound (tmp->sound + ? tmp->sound + : sound_find (tmp->type == GATE ? "trigger_gate" : "trigger_hole")); tmp->value = tmp->stats.maxsp ? !state : state; tmp->set_speed (0.5); break; @@ -81,6 +85,7 @@ case SIGN: if (!tmp->stats.food || tmp->last_eat < tmp->stats.food) { + tmp->play_sound (tmp->sound ? tmp->sound : sound_find ("trigger_sign")); new_info_map (NDI_UNIQUE | NDI_NAVY, tmp->map, tmp->msg); if (tmp->stats.food) tmp->last_eat++; @@ -88,6 +93,7 @@ break; case ALTAR: + tmp->play_sound (tmp->sound ? tmp->sound : sound_find ("trigger_altar")); tmp->value = 1; SET_ANIMATION (tmp, tmp->value); update_object (tmp, UP_OBJ_FACE); @@ -95,6 +101,7 @@ case BUTTON: case PEDESTAL: + tmp->play_sound (tmp->sound ? tmp->sound : sound_find ("trigger_button")); tmp->value = state; SET_ANIMATION (tmp, tmp->value); update_object (tmp, UP_OBJ_FACE); @@ -105,19 +112,21 @@ break; case TIMED_GATE: - tmp->set_speed (tmp->arch->clone.speed); - tmp->value = tmp->arch->clone.value; + if (!tmp->active) + tmp->play_sound (tmp->sound ? tmp->sound : sound_find ("trigger_gate")); + tmp->set_speed (tmp->arch->speed); + tmp->value = tmp->arch->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) + for (object *part = tmp->more; part; part = part->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); + part->value = tmp->value; + part->stats.sp = tmp->stats.sp; + part->stats.hp = tmp->stats.hp; + part->set_speed (tmp->speed); } break; @@ -129,6 +138,7 @@ { if ((tmp->stats.sp += tmp->stats.maxsp) > 8) /* next direction */ tmp->stats.sp = ((tmp->stats.sp - 1) % 8) + 1; + animate_turning (tmp); } break; @@ -142,6 +152,7 @@ break; case TRIGGER_MARKER: + //tmp->play_sound (tmp->sound ? tmp->sound : sound_find ("trigger_marker")); move_marker (tmp); break; @@ -226,33 +237,30 @@ 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? - */ + for (ab = tmp->above, tot = 0; ab; ab = ab->above) + { + head = ab->head_ (); - /* 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 - * 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; + /* Basically, if the move_type matches that on what the + * 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 ((head->move_type & tmp->move_on) || head->move_type == 0) + tot += head->total_weight (); + } - tmp->value = (tot >= tmp->weight) ? 1 : 0; - if (tmp->value) - any_down = 1; + tmp->value = tot >= tmp->weight ? 1 : 0; } else if (tmp->type == PEDESTAL) { tmp->value = 0; - for (ab = tmp->above; ab != NULL; ab = ab->above) + + for (ab = tmp->above; ab; ab = ab->above) { - head = ab->head ? ab->head : ab; + 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 || @@ -260,10 +268,11 @@ (!strcmp (tmp->slaying, "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; @@ -314,17 +323,20 @@ int check_altar_sacrifice (const object *altar, const object *sacrifice) { - if (!QUERY_FLAG (sacrifice, FLAG_ALIVE) && !QUERY_FLAG (sacrifice, FLAG_IS_LINKED) && sacrifice->type != PLAYER) - { - if ((ARCH_SACRIFICE (altar) == sacrifice->arch->name || - ARCH_SACRIFICE (altar) == sacrifice->name || - ARCH_SACRIFICE (altar) == sacrifice->slaying || - (!strcmp (ARCH_SACRIFICE (altar), query_base_name (sacrifice, 0)))) - && NROF_SACRIFICE (altar) <= (sacrifice->nrof ? sacrifice->nrof : 1)) + if (!QUERY_FLAG (sacrifice, FLAG_ALIVE) + && !QUERY_FLAG (sacrifice, FLAG_IS_LINKED) + && sacrifice->type != PLAYER) + { + if (ARCH_SACRIFICE (altar) == shstr_money + && sacrifice->type == MONEY + && sacrifice->nrof * sacrifice->value >= NROF_SACRIFICE (altar)) return 1; - if (strcmp (ARCH_SACRIFICE (altar), "money") == 0 - && sacrifice->type == MONEY && sacrifice->nrof * sacrifice->value >= NROF_SACRIFICE (altar)) + if ((ARCH_SACRIFICE (altar) == sacrifice->arch->archname + || ARCH_SACRIFICE (altar) == sacrifice->name + || ARCH_SACRIFICE (altar) == sacrifice->slaying + || strstr (query_base_name (sacrifice, 0), ARCH_SACRIFICE (altar))) + && NROF_SACRIFICE (altar) <= sacrifice->number_of ()) return 1; } @@ -358,7 +370,7 @@ /* check_altar_sacrifice should have already verified that enough money * has been dropped. */ - if (!strcmp (ARCH_SACRIFICE (altar), "money")) + if (ARCH_SACRIFICE (altar) == shstr_money) { int number = NROF_SACRIFICE (altar) / (*sacrifice)->value; @@ -366,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); @@ -429,26 +443,28 @@ * 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->weight * (tmp->nrof ? tmp->nrof : 1) + tmp->carrying; - } + 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; case TRIGGER_PEDESTAL: @@ -456,7 +472,7 @@ { for (tmp = op->above; tmp; tmp = tmp->above) { - object *head = tmp->head ? tmp->head : tmp; + object *head = tmp->head_ (); /* See comment in TRIGGER_BUTTON about move_types */ if (((head->move_type & op->move_on) || head->move_type == 0) @@ -466,18 +482,24 @@ 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; @@ -486,6 +508,7 @@ { if (in_movement) return 0; + if (operate_altar (op, &cause)) { if (NUM_ANIMATIONS (op) > 1) @@ -493,6 +516,7 @@ SET_ANIMATION (op, 1); update_object (op, UP_OBJ_FACE); } + if (op->last_sp >= 0) { trigger_move (op, 1); @@ -509,12 +533,11 @@ op->last_sp = -op->last_sp; op->value = !op->value; } + return cause == NULL; } else - { - return 0; - } + return 0; } else { @@ -743,8 +766,8 @@ if (tmp->type == GOLEM && tmp->owner && tmp->owner->type == PLAYER - && tmp->owner->contr->ranges[range_golem] == tmp) - tmp->owner->contr->ranges[range_golem] = 0; + && tmp->owner->contr->golem == tmp) + tmp->owner->contr->golem = 0; tmp->owner = 0; @@ -781,14 +804,17 @@ } break; - case 6: + case 6: // kill monsters if (!QUERY_FLAG (tmp, FLAG_FRIENDLY)) break; // FALL THROUGH - case 5: - get_archetype ("burnout")->insert_at (tmp, source); - tmp->destroy (); + case 5: // kill all alives + if (!tmp->flag [FLAG_PRECIOUS]) + { + get_archetype ("burnout")->insert_at (tmp, source); + tmp->destroy (); + } break; default: @@ -810,7 +836,7 @@ /* 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->race && (op->arch->archname == trig->race))) return op; for (tmp = op->inv; tmp; tmp = tmp->below) @@ -823,7 +849,7 @@ } else if ((trig->stats.hp && (tmp->type == trig->stats.hp)) || (trig->slaying && (tmp->slaying == trig->slaying)) - || (trig->race && (tmp->arch->name == trig->race))) + || (trig->race && (tmp->arch->archname == trig->race))) return tmp; } return NULL; @@ -871,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);