Crossfire Server, Trunk  R213250
ob_methods.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 #include <ob_methods.h>
21 #include <ob_types.h>
22 #include <sproto.h>
23 
24 /*
25  * The following functions are meant for calling methods. No actual behavoir
26  * logic should be contained in this code. Code in the common/ directory should
27  * be used for logic common to all types, and should always be called by
28  * individual method code (i.e. all apply methods should call 'can_apply' from
29  * common/). Defaults for all types should not be put here either, as that code
30  * belongs in the common/ directory also, referenced to by base_type.
31  */
32 
44 method_ret ob_apply(object *op, object *applier, int aflags) {
45  method_ret ret;
46  ob_methods *methods;
47 
48  /* Lauwenmark: Handle for plugin apply event */
49  if (execute_event(op, EVENT_APPLY, applier, NULL, NULL, SCRIPT_FIX_ALL) != 0)
50  return METHOD_OK;
51 
52  for (methods = &type_methods[op->type]; methods; methods = methods->fallback) {
53  if (methods->apply) {
54  ret = methods->apply(methods, op, applier, aflags);
55  if (ret != METHOD_UNHANDLED)
56  return ret;
57  }
58  }
59  return METHOD_UNHANDLED;
60 }
61 
68 method_ret ob_process(object *op) {
69  method_ret ret;
70  ob_methods *methods;
71 
72  for (methods = &type_methods[op->type]; methods; methods = methods->fallback) {
73  if (methods->process) {
74  ret = methods->process(methods, op);
75  if (ret != METHOD_UNHANDLED)
76  return ret;
77  }
78  }
79  return METHOD_UNHANDLED;
80 }
81 
91 char *ob_describe(const object *op, const object *observer, char *buf, size_t size) {
92  ob_methods *methods;
93 
94  for (methods = &type_methods[op->type]; methods; methods = methods->fallback) {
95  if (methods->describe) {
96  methods->describe(methods, op, observer, buf, size);
97  return buf;
98  }
99  }
100  buf[0] = '\0';
101  return buf;
102 }
103 
111 method_ret ob_move_on(object *op, object *victim, object *originator) {
112  method_ret ret;
113  ob_methods *methods;
114 
115  for (methods = &type_methods[op->type]; methods; methods = methods->fallback) {
116  if (methods->move_on) {
117  ret = methods->move_on(methods, op, victim, originator);
118  if (ret != METHOD_UNHANDLED)
119  return ret;
120  }
121  }
122  return METHOD_UNHANDLED;
123 }
124 
133 method_ret ob_trigger(object *op, object *cause, int state) {
134  method_ret ret;
135  ob_methods *methods;
136 
137  for (methods = &type_methods[op->type]; methods; methods = methods->fallback) {
138  if (methods->trigger) {
139  ret = methods->trigger(methods, op, cause, state);
140  if (ret != METHOD_UNHANDLED)
141  return ret;
142  }
143  }
144  return METHOD_UNHANDLED;
145 }
ob_methods type_methods[OBJECT_TYPE_MAX]
Definition: ob_types.c:25
struct ob_methods * fallback
Definition: ob_methods.h:51
apply_func apply
Definition: ob_methods.h:46
method_ret ob_process(object *op)
Definition: ob_methods.c:68
method_ret ob_apply(object *op, object *applier, int aflags)
Definition: ob_methods.c:44
#define SCRIPT_FIX_ALL
Definition: global.h:367
char method_ret
Definition: ob_methods.h:14
#define METHOD_OK
Definition: ob_methods.h:15
move_on_func move_on
Definition: ob_methods.h:49
#define METHOD_UNHANDLED
Definition: ob_methods.h:16
char * ob_describe(const object *op, const object *observer, char *buf, size_t size)
Definition: ob_methods.c:91
method_ret ob_move_on(object *op, object *victim, object *originator)
Definition: ob_methods.c:111
trigger_func trigger
Definition: ob_methods.h:50
process_func process
Definition: ob_methods.h:47
#define EVENT_APPLY
Definition: plugin.h:64
uint8_t type
Definition: object.h:339
int execute_event(object *op, int eventcode, object *activator, object *third, const char *message, int fix)
Definition: main.c:365
describe_func describe
Definition: ob_methods.h:48
method_ret ob_trigger(object *op, object *cause, int state)
Definition: ob_methods.c:133