Crossfire Server, Branches 1.12  R18729
detector.c
Go to the documentation of this file.
1 /*
2  CrossFire, A Multiplayer game for X-windows
3 
4  Copyright (C) 2008 Crossfire Development Team
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 
20  The authors can be reached via e-mail at crossfire-devel@real-time.com
21 */
22 
28 #include <global.h>
29 #include <ob_methods.h>
30 #include <ob_types.h>
31 #include <sounds.h>
32 #include <sproto.h>
33 
34 static method_ret detector_type_process(ob_methods *context, object *op);
35 
39 void init_type_detector(void) {
41 }
42 
55 static void move_detector(object *op) {
56  object *tmp, *tmp2;
57  int last = op->value;
58  int detected;
59  detected = 0;
60 
61  if (!op->slaying) {
62  if (op->map)
63  LOG(llevError, "Detector with no slaying set at %s (%d,%d)\n", op->map->path, op->x, op->y);
64  else if (op->env)
65  LOG(llevError, "Detector with no slaying in %s\n", op->env->name);
66  else
67  LOG(llevError, "Detector with no slaying nowhere?\n");
68  op->speed = 0;
69  update_ob_speed(op);
70  return;
71  }
72 
73  for (tmp = GET_MAP_OB(op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) {
74  if (op->stats.hp) {
75  for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) {
76  if (op->slaying == tmp2->name) {
77  detected = 1;
78  break;
79  }
80  if (tmp2->type == FORCE && tmp2->slaying == op->slaying) {
81  detected = 1;
82  break;
83  }
84  }
85  }
86  if (op->slaying == tmp->name) {
87  detected = 1;
88  break;
89  }
90  if (tmp->type == PLAYER && !strcmp(op->slaying, "player")) {
91  detected = 1;
92  break;
93  }
94  if (tmp->type == SPECIAL_KEY && tmp->slaying == op->slaying) {
95  detected = 1;
96  break;
97  }
98  }
99 
100  /* the detector sets the button if detection is found */
101  if (op->stats.sp == 1) {
102  if (detected && last == 0) {
103  op->value = 1;
104  push_button(op);
105  }
106  if (!detected && last == 1) {
107  op->value = 0;
108  push_button(op);
109  }
110  } else { /* in this case, we unset buttons */
111  if (detected && last == 1) {
112  op->value = 0;
113  push_button(op);
114  }
115  if (!detected && last == 0) {
116  op->value = 1;
117  push_button(op);
118  }
119  }
120 }
121 
128 static method_ret detector_type_process(ob_methods *context, object *op) {
129  move_detector(op);
130  return METHOD_OK;
131 }
char path[HUGE_BUF]
Definition: map.h:384
void push_button(object *op)
Definition: button.c:165
const char * slaying
Definition: object.h:172
struct obj * above
Definition: object.h:146
sint16 x
Definition: object.h:179
sint16 sp
Definition: living.h:83
#define PLAYER
Definition: define.h:113
sint16 hp
Definition: living.h:81
#define SPECIAL_KEY
Definition: define.h:133
char method_ret
Definition: ob_methods.h:41
#define METHOD_OK
Definition: ob_methods.h:42
struct mapdef * map
Definition: object.h:155
static void move_detector(object *op)
Definition: detector.c:55
const char * name
Definition: object.h:167
struct obj * env
Definition: object.h:151
void init_type_detector(void)
Definition: detector.c:39
struct obj * below
Definition: object.h:145
sint16 y
Definition: object.h:179
float speed
Definition: object.h:181
#define FORCE
Definition: define.h:296
living stats
Definition: object.h:219
#define DETECTOR
Definition: define.h:174
void register_process(int ob_type, process_func method)
Definition: ob_types.c:88
void update_ob_speed(object *op)
Definition: object.c:1008
#define GET_MAP_OB(M, X, Y)
Definition: map.h:193
struct obj * inv
Definition: object.h:148
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:63
sint32 value
Definition: object.h:201
uint8 type
Definition: object.h:189
static method_ret detector_type_process(ob_methods *context, object *op)
Definition: detector.c:128