Crossfire Server, Trunk
detector.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5  * Copyright (c) 1992 Frank Tore Johansen
6  *
7  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8  * welcome to redistribute it under certain conditions. For details, please
9  * see COPYING and LICENSE.
10  *
11  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
12  */
13 
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(object *op);
29 
33 void init_type_detector(void) {
35 }
36 
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;
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
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  /* the detector sets the button if detection is found */
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 { /* in this case, we unset buttons */
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 
117  move_detector(op);
118  return METHOD_OK;
119 }
GET_MAP_OB
#define GET_MAP_OB(M, X, Y)
Definition: map.h:170
PLAYER
@ PLAYER
Definition: object.h:112
global.h
llevError
@ llevError
Definition: logger.h:11
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.cpp:58
METHOD_OK
#define METHOD_OK
Definition: ob_methods.h:15
Ice.tmp
int tmp
Definition: Ice.py:207
register_process
void register_process(int ob_type, process_func method)
Definition: ob_types.cpp:71
object_find_by_name
object * object_find_by_name(const object *who, const char *name)
Definition: object.cpp:3956
detector_type_process
static method_ret detector_type_process(object *op)
Definition: detector.cpp:116
SPECIAL_KEY
@ SPECIAL_KEY
Definition: object.h:129
object_update_speed
void object_update_speed(object *op)
Definition: object.cpp:1349
sproto.h
method_ret
char method_ret
Definition: ob_methods.h:14
ob_types.h
sounds.h
object_find_by_type_and_slaying
object * object_find_by_type_and_slaying(const object *who, int type, const char *slaying)
Definition: object.cpp:4158
init_type_detector
void init_type_detector(void)
Definition: detector.cpp:33
give.op
op
Definition: give.py:33
push_button
void push_button(object *op)
Definition: button.cpp:149
ob_methods.h
move_detector
static void move_detector(object *op)
Definition: detector.cpp:49
FORCE
@ FORCE
Definition: object.h:229
DETECTOR
@ DETECTOR
Definition: object.h:154