--- deliantra/server/common/button.C 2006/12/21 01:33:49 1.18 +++ deliantra/server/common/button.C 2007/01/29 15:36:25 1.28 @@ -1,25 +1,26 @@ /* - CrossFire, A Multiplayer game for X-windows - - Copyright (C) 2002 Mark Wedel & Crossfire Development Team - Copyright (C) 1992 Frank Tore Johansen - - This program 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 - (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 - 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 -*/ + * 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 + * + * This program 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 + * (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 + * 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 + */ #include #include @@ -37,8 +38,6 @@ void activate_connection_link (objectlink * ol, bool state, object *source = 0) { - object *tmp = 0; - for (; ol; ol = ol->next) { if (!ol->ob) @@ -57,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)) @@ -67,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; } } } @@ -279,38 +276,9 @@ } } -/* - * Updates every button on the map (by calling update_button() for them). - */ - -void -update_buttons (maptile *m) -{ - objectlink *ol; - oblinkpt *obp; - - for (obp = m->buttons; obp; obp = obp->next) - for (ol = obp->link; ol; ol = ol->next) - { - if (!ol->ob) - { - 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); - break; - } - } -} - void use_trigger (object *op) { - /* Toggle value */ op->value = !op->value; push_button (op); @@ -320,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 */ { @@ -417,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); } } @@ -573,8 +535,7 @@ { op->stats.wc = 0; op->value = !op->value; - op->speed = 0; - update_ob_speed (op); + op->set_speed (0); } } return 0; @@ -584,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; @@ -611,17 +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; - for (obp = map->buttons; obp && obp->value != connected; obp = obp->next); + for (obp = map->buttons; obp && obp->value != connected; obp = obp->next) + ; if (obp) { @@ -744,19 +707,24 @@ void do_mood_floor (object *op, object *source) { - object *tmp; - object *tmp2; - if (!source) source = op; - for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = tmp->above) + mapspace &ms = op->ms (); + + if (!(ms.flags () & P_IS_ALIVE)) + return; + + object *tmp; + + for (tmp = ms.top; tmp; tmp = tmp->below) if (QUERY_FLAG (tmp, FLAG_MONSTER)) break; /* doesn't effect players, and if there is a player on this space, won't also * be a monster here. */ + //TODO: have players really FLAG_MONSTER? kept it for safety if (!tmp || tmp->type == PLAYER) return; @@ -765,10 +733,11 @@ case 0: /* furious--make all monsters mad */ if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE)) CLEAR_FLAG (tmp, FLAG_UNAGGRESSIVE); + if (QUERY_FLAG (tmp, FLAG_FRIENDLY)) { - CLEAR_FLAG (tmp, FLAG_FRIENDLY); remove_friendly_object (tmp); + tmp->attack_movement = 0; /* lots of checks here, but want to make sure we don't * dereference a null value @@ -779,38 +748,44 @@ tmp->owner = 0; } break; + case 1: /* angry -- get neutral monsters mad */ if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE) && !QUERY_FLAG (tmp, FLAG_FRIENDLY)) CLEAR_FLAG (tmp, FLAG_UNAGGRESSIVE); break; + case 2: /* calm -- pacify unfriendly monsters */ - if (!QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE)) - SET_FLAG (tmp, FLAG_UNAGGRESSIVE); + SET_FLAG (tmp, FLAG_UNAGGRESSIVE); break; + case 3: /* make all monsters fall asleep */ - if (!QUERY_FLAG (tmp, FLAG_SLEEP)) - SET_FLAG (tmp, FLAG_SLEEP); + SET_FLAG (tmp, FLAG_SLEEP); break; + case 4: /* charm all monsters */ if (op == source) break; /* only if 'connected' */ - 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 (object *pl = source->ms ().player ()) + { + tmp->set_owner (pl); + SET_FLAG (tmp, FLAG_MONSTER); - if (tmp2->type != PLAYER) - break; + tmp->stats.exp = 0; - tmp->set_owner (tmp2); - SET_FLAG (tmp, FLAG_MONSTER); + add_friendly_object (tmp); + tmp->attack_movement = PETMOVE; + } + break; - tmp->stats.exp = 0; - SET_FLAG (tmp, FLAG_FRIENDLY); + case 6: + if (!QUERY_FLAG (tmp, FLAG_FRIENDLY)) + break; - add_friendly_object (tmp); - tmp->attack_movement = PETMOVE; + // FALL THROUGH + case 5: + get_archetype ("burnout")->insert_at (tmp, source); + tmp->destroy (); break; default: @@ -868,27 +843,40 @@ * 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. * + * Wed Jan 10 11:34:26 CET 2007 elmex: fixed this function, we now check + * whether op is on this mapspace or not, because the value (1|0) depends + * on this information. also make sure to only push_button if op has + * a matching item (because when we do a push_button with value=0 timed gates + * will still open)! (i hope i got the semantics right this time) + * */ void check_inv (object *op, object *trig) { trig->value = 0; // deactivate if none of the following conditions apply - if (object *pl = trig->ms ().player ()) - { - object *match = check_inv_recursive (pl, trig); + object *pl = trig->ms ().player (); + object *match = check_inv_recursive (op, trig); - if (match && trig->last_sp) // match == having - { - if (trig->last_heal) - decrease_ob (match); + // elmex: a note about (pl == op): + // if pl == 0 then the player has left this space + // if pl != 0 then a player is on this mapspace, but then + // we still have to check whether it's the player that triggered + // this inv-checker, because if not, then the op left this inv-checker + // and we have to set the value to 0 - trig->value = 1; - } - else if (!match && !trig->last_sp) // match == not having - trig->value = 1; - } + if (match && trig->last_sp) // match == having + { + if (trig->last_heal) + decrease_ob (match); - push_button (trig); + trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left + push_button (trig); + } + else if (!match && !trig->last_sp) // match == not having + { + trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left + push_button (trig); + } }