| 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 <[email protected]>. |
| 12 | */ |
| 13 | |
| 14 | /** |
| 15 | * @file |
| 16 | * Those functions deal with the object/type system. |
| 17 | */ |
| 18 | |
| 19 | #include <global.h> |
| 20 | #include <ob_types.h> |
| 21 | #include <ob_methods.h> |
| 22 | #include <sproto.h> |
| 23 | |
| 24 | /** Registered method handlers. */ |
| 25 | ob_methods type_methods[OBJECT_TYPE_MAX]; |
| 26 | |
| 27 | /** |
| 28 | * Initializes a ob_methods struct. Make sure this always matches ob_methods.h |
| 29 | * @param methods ob_method structure to initialize |
| 30 | * @param fallback Default fallback for the ob_method |
| 31 | */ |
| 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 | |
| 41 | /** |
| 42 | * Initializes the object system. |
| 43 | * |
| 44 | * @param base_type |
| 45 | * base type to use as a base for all types. |
| 46 | * @todo when migration is complete, the parameter should go, and this function should be called from |
| 47 | * init_library() instead of init_ob_methods() in server/ob_methods.c. |
| 48 | */ |
| 49 | void init_ob_types(ob_methods *base_type) { |
| 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 */ |
| 57 | /** |
| 58 | * Registers the apply method for the given type. |
| 59 | * @param ob_type The type of object to register this method to |
| 60 | * @param method The method to link |
| 61 | */ |
| 62 | void register_apply(int ob_type, apply_func method) { |
| 63 | type_methods[ob_type].apply = method; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Registers the process method for the given type. |
| 68 | * @param ob_type The type of object to register this method to |
| 69 | * @param method The method to link |
| 70 | */ |
| 71 | void register_process(int ob_type, process_func method) { |
| 72 | type_methods[ob_type].process = method; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Registers the describe method for the given type. |
| 77 | * @param ob_type The type of object to register this method to |
| 78 | * @param method The method to link |
| 79 | */ |
| 80 | void register_describe(int ob_type, describe_func method) { |
| 81 | type_methods[ob_type].describe = method; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Registers the move_on method for the given type. |
| 86 | * @param ob_type The type of object to register this method to |
| 87 | * @param method The method to link |
| 88 | */ |
| 89 | void register_move_on(int ob_type, move_on_func method) { |
| 90 | type_methods[ob_type].move_on = method; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Registers the trigger method for the given type. |
| 95 | * @param ob_type The type of object to register this method to |
| 96 | * @param method The method to link |
| 97 | */ |
| 98 | void register_trigger(int ob_type, trigger_func method) { |
| 99 | type_methods[ob_type].trigger = method; |
| 100 | } |