| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include "global.h" |
| 20 |
|
| 21 |
#include <string.h> |
| 22 |
|
| 23 |
#include "ob_methods.h" |
| 24 |
#include "ob_types.h" |
| 25 |
#include "sounds.h" |
| 26 |
#include "sproto.h" |
| 27 |
|
| 28 |
static method_ret detector_type_process(ob_methods *context, object *op); |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
void init_type_detector(void) { |
| 34 |
register_process(DETECTOR, detector_type_process); |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
static void move_detector(object *op) { |
| 50 |
object *tmp; |
| 51 |
int last = op->value; |
| 52 |
int detected; |
| 53 |
detected = 0; |
| 54 |
|
| 55 |
if (!op->slaying) { |
| 56 |
if (op->map) |
| 57 |
LOG(llevError, "Detector with no slaying set at %s (%d,%d)\n", op->map->path, op->x, op->y); |
| 58 |
else if (op->env) |
| 59 |
LOG(llevError, "Detector with no slaying in %s\n", op->env->name); |
| 60 |
else |
| 61 |
LOG(llevError, "Detector with no slaying nowhere?\n"); |
| 62 |
op->speed = 0; |
| 63 |
object_update_speed(op); |
| 64 |
return; |
| 65 |
} |
| 66 |
|
| 67 |
for (tmp = GET_MAP_OB(op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) { |
| 68 |
if (op->stats.hp) { |
| 69 |
if (object_find_by_name(tmp, op->slaying) != NULL |
| 70 |
|| object_find_by_type_and_slaying(tmp, FORCE, op->slaying)) { |
| 71 |
detected = 1; |
| 72 |
break; |
| 73 |
} |
| 74 |
} |
| 75 |
if (op->slaying == tmp->name) { |
| 76 |
detected = 1; |
| 77 |
break; |
| 78 |
} |
| 79 |
if (tmp->type == PLAYER && !strcmp(op->slaying, "player")) { |
| 80 |
detected = 1; |
| 81 |
break; |
| 82 |
} |
| 83 |
if (tmp->type == SPECIAL_KEY && tmp->slaying == op->slaying) { |
| 84 |
detected = 1; |
| 85 |
break; |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
if (op->stats.sp == 1) { |
| 91 |
if (detected && last == 0) { |
| 92 |
op->value = 1; |
| 93 |
push_button(op); |
| 94 |
} |
| 95 |
if (!detected && last == 1) { |
| 96 |
op->value = 0; |
| 97 |
push_button(op); |
| 98 |
} |
| 99 |
} else { |
| 100 |
if (detected && last == 1) { |
| 101 |
op->value = 0; |
| 102 |
push_button(op); |
| 103 |
} |
| 104 |
if (!detected && last == 0) { |
| 105 |
op->value = 1; |
| 106 |
push_button(op); |
| 107 |
} |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
static method_ret detector_type_process(ob_methods *context, object *op) { |
| 118 |
move_detector(op); |
| 119 |
return METHOD_OK; |
| 120 |
} |