Atrinik Server 2.5
types/detector.c
Go to the documentation of this file.
00001 /************************************************************************
00002 *            Atrinik, a Multiplayer Online Role Playing Game            *
00003 *                                                                       *
00004 *    Copyright (C) 2009-2011 Alex Tokar and Atrinik Development Team    *
00005 *                                                                       *
00006 * Fork from Daimonin (Massive Multiplayer Online Role Playing Game)     *
00007 * and Crossfire (Multiplayer game for X-windows).                       *
00008 *                                                                       *
00009 * This program is free software; you can redistribute it and/or modify  *
00010 * it under the terms of the GNU General Public License as published by  *
00011 * the Free Software Foundation; either version 2 of the License, or     *
00012 * (at your option) any later version.                                   *
00013 *                                                                       *
00014 * This program is distributed in the hope that it will be useful,       *
00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00017 * GNU General Public License for more details.                          *
00018 *                                                                       *
00019 * You should have received a copy of the GNU General Public License     *
00020 * along with this program; if not, write to the Free Software           *
00021 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.             *
00022 *                                                                       *
00023 * The author can be reached at admin@atrinik.org                        *
00024 ************************************************************************/
00025 
00030 #include <global.h>
00031 
00035 void move_detector(object *op)
00036 {
00037     object *tmp;
00038     int last = op->value, detected = 0;
00039 
00040     for (tmp = GET_BOTTOM_MAP_OB(op); tmp != NULL && !detected; tmp = tmp->above)
00041     {
00042         object *tmp2;
00043 
00044         if (op->stats.hp)
00045         {
00046             for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below)
00047             {
00048                 if (op->slaying && !strcmp(op->slaying, tmp->name))
00049                 {
00050                     detected = 1;
00051                 }
00052 
00053                 if (tmp2->type == FORCE && tmp->slaying && tmp2->slaying == op->slaying)
00054                 {
00055                     detected = 1;
00056                 }
00057             }
00058         }
00059 
00060         if (op->slaying && op->slaying == tmp->name)
00061         {
00062             detected = 1;
00063         }
00064         else if (tmp->type == KEY && tmp->slaying == op->slaying)
00065         {
00066             detected = 1;
00067         }
00068     }
00069 
00070     /* the detector sets the button if detection is found */
00071     if (op->stats.sp == 1)
00072     {
00073         if (detected && last == 0)
00074         {
00075             op->value = 1;
00076             push_button(op);
00077         }
00078 
00079         if (!detected && last == 1)
00080         {
00081             op->value = 0;
00082             push_button(op);
00083         }
00084     }
00085     /* in this case, we unset buttons */
00086     else
00087     {
00088         if (detected && last == 1)
00089         {
00090             op->value = 0;
00091             push_button(op);
00092         }
00093 
00094         if (!detected && last == 0)
00095         {
00096             op->value = 1;
00097             push_button(op);
00098         }
00099     }
00100 }