Crossfire Server, Trunk  R20513
detector.c
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(ob_methods *context, 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 static method_ret detector_type_process(ob_methods *context, object *op) {
118  move_detector(op);
119  return METHOD_OK;
120 }
Error, serious thing.
Definition: logger.h:11
char path[HUGE_BUF]
Filename of the map.
Definition: map.h:365
Sound-related defines.
void push_button(object *op)
Push the specified object.
Definition: button.c:154
Typedefs for ob_methods.
Definition: ob_methods.h:45
const char * slaying
Which race to do double damage to.
Definition: object.h:319
struct obj * above
Pointer to the object stacked above this one.
Definition: object.h:288
object * object_find_by_type_and_slaying(const object *who, int type, const char *slaying)
Find object in inventory by type and slaying.
Definition: object.c:4049
int16_t sp
Spell points.
Definition: living.h:41
Global type definitions and header inclusions.
object * object_find_by_name(const object *who, const char *name)
Finds an object in inventory name.
Definition: object.c:3879
peterm: detector is an object which notices the presense of another object and is triggered like butt...
Definition: object.h:149
int16_t hp
Hit Points.
Definition: living.h:39
char method_ret
Define some standard return values for callbacks which don&#39;t need to return any other results...
Definition: ob_methods.h:14
int16_t y
Position in the map for this object.
Definition: object.h:326
See Special Key.
Definition: object.h:124
#define METHOD_OK
Definition: ob_methods.h:15
struct mapdef * map
Pointer to the map in which this object is present.
Definition: object.h:297
static void move_detector(object *op)
Move a detector.
Definition: detector.c:49
const char * name
The name of the object, obviously...
Definition: object.h:311
struct obj * env
Pointer to the object which is the environment.
Definition: object.h:293
void init_type_detector(void)
Initializer for the detector object type.
Definition: detector.c:33
float speed
The overall speed of this object.
Definition: object.h:328
int16_t x
Definition: object.h:326
Object type variables.
See Player.
Definition: object.h:107
living stats
Str, Con, Dex, etc.
Definition: object.h:368
uint8_t type
PLAYER, BULLET, etc.
Definition: object.h:338
void register_process(int ob_type, process_func method)
Registers the process method for the given type.
Definition: ob_types.c:71
#define GET_MAP_OB(M, X, Y)
Gets the bottom object on a map.
Definition: map.h:172
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
Definition: logger.c:51
Object type functions and variables.
void object_update_speed(object *op)
Updates the speed of an object.
Definition: object.c:1129
int32_t value
How much money it is worth (or contains)
Definition: object.h:350
Definition: object.h:224
static method_ret detector_type_process(ob_methods *context, object *op)
Processes a detector.
Definition: detector.c:117