Crossfire Server, Trunk  1.75.0
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 
116 static method_ret detector_type_process(object *op) {
117  move_detector(op);
118  return METHOD_OK;
119 }
GET_MAP_OB
#define GET_MAP_OB(M, X, Y)
Gets the bottom object on a map.
Definition: map.h:170
PLAYER
@ PLAYER
Definition: object.h:112
global.h
llevError
@ llevError
Error, serious thing.
Definition: logger.h:11
LOG
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
Definition: logger.cpp:58
object::speed
float speed
Frequency of object 'moves' relative to server tick rate.
Definition: object.h:337
METHOD_OK
#define METHOD_OK
Definition: ob_methods.h:15
object::x
int16_t x
Definition: object.h:335
object::map
struct mapstruct * map
Pointer to the map in which this object is present.
Definition: object.h:305
register_process
void register_process(int ob_type, process_func method)
Registers the process method for the given type.
Definition: ob_types.cpp:71
mapstruct::path
char path[HUGE_BUF]
Filename of the map.
Definition: map.h:355
object::above
object * above
Pointer to the object stacked above this one.
Definition: object.h:296
object::y
int16_t y
Position in the map for this object.
Definition: object.h:335
object_find_by_name
object * object_find_by_name(const object *who, const char *name)
Finds an object in inventory name.
Definition: object.cpp:3956
detector_type_process
static method_ret detector_type_process(object *op)
Processes a detector.
Definition: detector.cpp:116
object::value
int32_t value
How much money it is worth (or contains)
Definition: object.h:360
SPECIAL_KEY
@ SPECIAL_KEY
Definition: object.h:129
object_update_speed
void object_update_speed(object *op)
Updates the speed of an object.
Definition: object.cpp:1349
object::type
uint8_t type
PLAYER, BULLET, etc.
Definition: object.h:348
sproto.h
living::sp
int16_t sp
Spell points.
Definition: living.h:42
method_ret
char method_ret
Define some standard return values for callbacks which don't need to return any other results.
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)
Find object in inventory by type and slaying.
Definition: object.cpp:4158
init_type_detector
void init_type_detector(void)
Initializer for the detector object type.
Definition: detector.cpp:33
object::slaying
sstring slaying
Which race to do double damage to.
Definition: object.h:327
object::name
sstring name
The name of the object, obviously...
Definition: object.h:319
object::env
object * env
Pointer to the object which is the environment.
Definition: object.h:301
push_button
void push_button(object *op)
Push the specified object.
Definition: button.cpp:149
ob_methods.h
object::stats
living stats
Str, Con, Dex, etc.
Definition: object.h:378
move_detector
static void move_detector(object *op)
Move a detector.
Definition: detector.cpp:49
living::hp
int16_t hp
Hit Points.
Definition: living.h:40
FORCE
@ FORCE
Definition: object.h:229
DETECTOR
@ DETECTOR
peterm: detector is an object which notices the presense of another object and is triggered like butt...
Definition: object.h:154