Crossfire Server, Branches 1.12  R18729
ob_methods.c
Go to the documentation of this file.
1 /*
2  * static char *rcsid_ob_methods =
3  * "$Id: build_map.c 5057 2006-10-29 07:50:09Z mwedel $";
4  */
5 /*
6  CrossFire, A Multiplayer game for X-windows
7 
8  Copyright (C) 2006 Mark Wedel & Crossfire Development Team
9  Copyright (C) 1992 Frank Tore Johansen
10 
11  This program is free software; you can redistribute it and/or modify
12  it under the terms of the GNU General Public License as published by
13  the Free Software Foundation; either version 2 of the License, or
14  (at your option) any later version.
15 
16  This program is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  GNU General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, write to the Free Software
23  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 
25  The authors can be reached via e-mail to crossfire-devel@real-time.com
26 */
27 
33 #include <global.h>
34 #include <ob_methods.h>
35 #include <ob_types.h>
36 
37 #ifndef __CEXTRACT__
38 #include <sproto.h>
39 #endif
40 
41 /*
42  * The following functions are meant for calling methods. No actual behavoir
43  * logic should be contained in this code. Code in the common/ directory should
44  * be used for logic common to all types, and should always be called by
45  * individual method code (i.e. all apply methods should call 'can_apply' from
46  * common/). Defaults for all types should not be put here either, as that code
47  * belongs in the common/ directory also, referenced to by base_type.
48  */
49 
59 method_ret ob_apply(object *op, object *applier, int aflags) {
60  method_ret ret;
61  ob_methods *methods;
62 
63  for (methods = &type_methods[op->type]; methods; methods = methods->fallback) {
64  if (methods->apply) {
65  ret = methods->apply(methods, op, applier, aflags);
66  if (ret != METHOD_UNHANDLED)
67  return ret;
68  }
69  }
70  return METHOD_UNHANDLED;
71 }
72 
79 method_ret ob_process(object *op) {
80  method_ret ret;
81  ob_methods *methods;
82 
83  for (methods = &type_methods[op->type]; methods; methods = methods->fallback) {
84  if (methods->process) {
85  ret = methods->process(methods, op);
86  if (ret != METHOD_UNHANDLED)
87  return ret;
88  }
89  }
90  return METHOD_UNHANDLED;
91 }
92 
102 char *ob_describe(const object *op, const object *observer, char *buf, size_t size) {
103  ob_methods *methods;
104 
105  for (methods = &type_methods[op->type]; methods; methods = methods->fallback) {
106  if (methods->describe) {
107  methods->describe(methods, op, observer, buf, size);
108  return buf;
109  }
110  }
111  buf[0] = '\0';
112  return buf;
113 }
114 
122 method_ret ob_move_on(object *op, object *victim, object *originator) {
123  method_ret ret;
124  ob_methods *methods;
125 
126  for (methods = &type_methods[op->type]; methods; methods = methods->fallback) {
127  if (methods->move_on) {
128  ret = methods->move_on(methods, op, victim, originator);
129  if (ret != METHOD_UNHANDLED)
130  return ret;
131  }
132  }
133  return METHOD_UNHANDLED;
134 }
135 
144 method_ret ob_trigger(object *op, object *cause, int state) {
145  method_ret ret;
146  ob_methods *methods;
147 
148  for (methods = &type_methods[op->type]; methods; methods = methods->fallback) {
149  if (methods->trigger) {
150  ret = methods->trigger(methods, op, cause, state);
151  if (ret != METHOD_UNHANDLED)
152  return ret;
153  }
154  }
155  return METHOD_UNHANDLED;
156 }
ob_methods type_methods[OBJECT_TYPE_MAX]
Definition: ob_types.c:42
struct ob_methods * fallback
Definition: ob_methods.h:78
apply_func apply
Definition: ob_methods.h:73
method_ret ob_process(object *op)
Definition: ob_methods.c:79
method_ret ob_apply(object *op, object *applier, int aflags)
Definition: ob_methods.c:59
char method_ret
Definition: ob_methods.h:41
move_on_func move_on
Definition: ob_methods.h:76
#define METHOD_UNHANDLED
Definition: ob_methods.h:43
char * ob_describe(const object *op, const object *observer, char *buf, size_t size)
Definition: ob_methods.c:102
method_ret ob_move_on(object *op, object *victim, object *originator)
Definition: ob_methods.c:122
trigger_func trigger
Definition: ob_methods.h:77
process_func process
Definition: ob_methods.h:74
describe_func describe
Definition: ob_methods.h:75
method_ret ob_trigger(object *op, object *cause, int state)
Definition: ob_methods.c:144
uint8 type
Definition: object.h:189