00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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 {
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 }