Crossfire Server, Trunk  R20513
ob_types.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_types.h>
21 #include <ob_methods.h>
22 #include <sproto.h>
23 
26 
32 void init_ob_method_struct(ob_methods *methods, ob_methods *fallback) {
33  methods->fallback = fallback;
34  methods->apply = NULL;
35  methods->process = NULL;
36  methods->describe = NULL;
37  methods->move_on = NULL;
38  methods->trigger = NULL;
39 }
40 
50  int tmp;
51 
52  for (tmp = 0; tmp < OBJECT_TYPE_MAX; tmp++)
53  init_ob_method_struct(&type_methods[tmp], base_type);
54 }
55 
56 /* Functions for registering methods for types */
62 void register_apply(int ob_type, apply_func method) {
63  type_methods[ob_type].apply = method;
64 }
65 
71 void register_process(int ob_type, process_func method) {
72  type_methods[ob_type].process = method;
73 }
74 
80 void register_describe(int ob_type, describe_func method) {
81  type_methods[ob_type].describe = method;
82 }
83 
89 void register_move_on(int ob_type, move_on_func method) {
90  type_methods[ob_type].move_on = method;
91 }
92 
98 void register_trigger(int ob_type, trigger_func method) {
99  type_methods[ob_type].trigger = method;
100 }
void init_ob_types(ob_methods *base_type)
Initializes the object system.
Definition: ob_types.c:49
ob_methods type_methods[OBJECT_TYPE_MAX]
Registered method handlers.
Definition: ob_types.c:25
void init_ob_method_struct(ob_methods *methods, ob_methods *fallback)
Initializes a ob_methods struct.
Definition: ob_types.c:32
void(* describe_func)(const ob_methods *, const object *, const object *, char *buf, size_t size)
Definition: ob_methods.h:41
Typedefs for ob_methods.
Definition: ob_methods.h:45
void register_describe(int ob_type, describe_func method)
Registers the describe method for the given type.
Definition: ob_types.c:80
Update if you add new types.
Definition: object.h:250
struct ob_methods * fallback
ob_method structure to fallback to
Definition: ob_methods.h:51
apply_func apply
The apply method.
Definition: ob_methods.h:46
Global type definitions and header inclusions.
void register_move_on(int ob_type, move_on_func method)
Registers the move_on method for the given type.
Definition: ob_types.c:89
move_on_func move_on
The move_on method.
Definition: ob_methods.h:49
void register_apply(int ob_type, apply_func method)
Registers the apply method for the given type.
Definition: ob_types.c:62
void register_trigger(int ob_type, trigger_func method)
Registers the trigger method for the given type.
Definition: ob_types.c:98
method_ret(* process_func)(ob_methods *, object *)
Definition: ob_methods.h:40
trigger_func trigger
When something is triggered via a button.
Definition: ob_methods.h:50
Object type variables.
process_func process
The process method.
Definition: ob_methods.h:47
method_ret(* apply_func)(ob_methods *, object *, object *, int)
Definition: ob_methods.h:39
method_ret(* trigger_func)(ob_methods *, object *, object *, int)
Definition: ob_methods.h:43
void register_process(int ob_type, process_func method)
Registers the process method for the given type.
Definition: ob_types.c:71
describe_func describe
The describe method.
Definition: ob_methods.h:48
Object type functions and variables.
static ob_methods base_type
Definition: ob_methods.c:27
method_ret(* move_on_func)(ob_methods *, object *, object *, object *)
Definition: ob_methods.h:42