Crossfire Server, Branch 1.12
R12190
|
00001 /* 00002 CrossFire, A Multiplayer game for X-windows 00003 00004 Copyright (C) 2008 Crossfire Development Team 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00019 00020 The authors can be reached via e-mail at crossfire-devel@real-time.com 00021 */ 00022 00028 #include <global.h> 00029 #include <ob_methods.h> 00030 #include <ob_types.h> 00031 #include <sounds.h> 00032 #include <sproto.h> 00033 00034 static method_ret detector_type_process(ob_methods *context, object *op); 00035 00039 void init_type_detector(void) { 00040 register_process(DETECTOR, detector_type_process); 00041 } 00042 00055 static void move_detector(object *op) { 00056 object *tmp, *tmp2; 00057 int last = op->value; 00058 int detected; 00059 detected = 0; 00060 00061 if (!op->slaying) { 00062 if (op->map) 00063 LOG(llevError, "Detector with no slaying set at %s (%d,%d)\n", op->map->path, op->x, op->y); 00064 else if (op->env) 00065 LOG(llevError, "Detector with no slaying in %s\n", op->env->name); 00066 else 00067 LOG(llevError, "Detector with no slaying nowhere?\n"); 00068 op->speed = 0; 00069 update_ob_speed(op); 00070 return; 00071 } 00072 00073 for (tmp = GET_MAP_OB(op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) { 00074 if (op->stats.hp) { 00075 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) { 00076 if (op->slaying == tmp2->name) { 00077 detected = 1; 00078 break; 00079 } 00080 if (tmp2->type == FORCE && tmp2->slaying == op->slaying) { 00081 detected = 1; 00082 break; 00083 } 00084 } 00085 } 00086 if (op->slaying == tmp->name) { 00087 detected = 1; 00088 break; 00089 } 00090 if (tmp->type == PLAYER && !strcmp(op->slaying, "player")) { 00091 detected = 1; 00092 break; 00093 } 00094 if (tmp->type == SPECIAL_KEY && tmp->slaying == op->slaying) { 00095 detected = 1; 00096 break; 00097 } 00098 } 00099 00100 /* the detector sets the button if detection is found */ 00101 if (op->stats.sp == 1) { 00102 if (detected && last == 0) { 00103 op->value = 1; 00104 push_button(op); 00105 } 00106 if (!detected && last == 1) { 00107 op->value = 0; 00108 push_button(op); 00109 } 00110 } else { /* in this case, we unset buttons */ 00111 if (detected && last == 1) { 00112 op->value = 0; 00113 push_button(op); 00114 } 00115 if (!detected && last == 0) { 00116 op->value = 1; 00117 push_button(op); 00118 } 00119 } 00120 } 00121 00128 static method_ret detector_type_process(ob_methods *context, object *op) { 00129 move_detector(op); 00130 return METHOD_OK; 00131 }