Crossfire Server, Trunk
ob_methods.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 #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  if (events_execute_object_event(op, EVENT_APPLY, applier, NULL, NULL, SCRIPT_FIX_ALL) != 0)
49  return METHOD_OK;
50 
51  for (methods = &type_methods[op->type]; methods; methods = methods->fallback) {
52  if (methods->apply) {
53  ret = methods->apply(op, applier, aflags);
54  if (ret != METHOD_UNHANDLED)
55  return ret;
56  }
57  }
58  return METHOD_UNHANDLED;
59 }
60 
68  method_ret ret;
69  ob_methods *methods;
70 
71  for (methods = &type_methods[op->type]; methods; methods = methods->fallback) {
72  if (methods->process) {
73  ret = methods->process(op);
74  if (ret != METHOD_UNHANDLED)
75  return ret;
76  }
77  }
78  return METHOD_UNHANDLED;
79 }
80 
91 char *ob_describe(const object *op, const object *observer, int use_media_tags, 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(op, observer, use_media_tags, 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(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(op, cause, state);
140  if (ret != METHOD_UNHANDLED)
141  return ret;
142  }
143  }
144  return METHOD_UNHANDLED;
145 }
global.h
ob_trigger
method_ret ob_trigger(object *op, object *cause, int state)
Definition: ob_methods.cpp:133
ob_methods::move_on
move_on_func move_on
Definition: ob_methods.h:47
METHOD_OK
#define METHOD_OK
Definition: ob_methods.h:15
type_methods
ob_methods type_methods[OBJECT_TYPE_MAX]
Definition: ob_types.cpp:25
events_execute_object_event
int events_execute_object_event(object *op, int eventcode, object *activator, object *third, const char *message, int fix)
Definition: events.cpp:299
buf
StringBuffer * buf
Definition: readable.cpp:1565
ob_move_on
method_ret ob_move_on(object *op, object *victim, object *originator)
Definition: ob_methods.cpp:111
ob_methods::fallback
ob_methods * fallback
Definition: ob_methods.h:49
METHOD_UNHANDLED
#define METHOD_UNHANDLED
Definition: ob_methods.h:16
sword_of_souls.victim
victim
Definition: sword_of_souls.py:12
ob_methods::apply
apply_func apply
Definition: ob_methods.h:44
ob_methods
Definition: ob_methods.h:43
SCRIPT_FIX_ALL
#define SCRIPT_FIX_ALL
Definition: global.h:389
ob_describe
char * ob_describe(const object *op, const object *observer, int use_media_tags, char *buf, size_t size)
Definition: ob_methods.cpp:91
sproto.h
ob_methods::describe
describe_func describe
Definition: ob_methods.h:46
method_ret
char method_ret
Definition: ob_methods.h:14
ob_types.h
ob_methods::process
process_func process
Definition: ob_methods.h:45
ob_methods::trigger
trigger_func trigger
Definition: ob_methods.h:48
ob_process
method_ret ob_process(object *op)
Definition: ob_methods.cpp:67
give.op
op
Definition: give.py:33
ob_apply
method_ret ob_apply(object *op, object *applier, int aflags)
Definition: ob_methods.cpp:44
ob_methods.h
dragon.state
state
Definition: dragon.py:84
EVENT_APPLY
#define EVENT_APPLY
Definition: events.h:20