| 1 | /** |
| 2 | * @file |
| 3 | * Object type functions and variables. |
| 4 | */ |
| 5 | |
| 6 | #ifndef OB_METHODS_H |
| 7 | #define OB_METHODS_H |
| 8 | |
| 9 | /** |
| 10 | * Define some standard return values for callbacks which don't need to return |
| 11 | * any other results. Later this might be expanded into a more complex return |
| 12 | * value system if necessary |
| 13 | */ |
| 14 | typedef char method_ret; |
| 15 | #define METHOD_OK 0 |
| 16 | #define METHOD_UNHANDLED 1 |
| 17 | #define METHOD_ERROR 2 |
| 18 | #define METHOD_SILENT_ERROR 3 /**< Player was warned she can't use the item for now. */ |
| 19 | |
| 20 | /** |
| 21 | * Typedefs for ob_methods. Also used in ob_types.c for storing the pointers |
| 22 | * temporarily. As a convention, callbacks parameters should begin with |
| 23 | * "ob_methods *context, object *ob", and return method_ret unless it needs to |
| 24 | * return something else. |
| 25 | */ |
| 26 | /* Example: |
| 27 | * typedef method_ret (apply_func)(ob_methods *context, object *ob); |
| 28 | */ |
| 29 | |
| 30 | /** |
| 31 | * @struct ob_methods |
| 32 | * This struct stores function pointers for actions that can be done to objects. |
| 33 | * It is currently just used for type-specific object code. Add new function |
| 34 | * pointers here when moving type specific code into the server/types/ *.c area. |
| 35 | * When adding function pointers here, be sure to add to init_ob_methods() in |
| 36 | * ob_types.c as necessary. |
| 37 | */ |
| 38 | typedef struct ob_methods ob_methods; |
| 39 | typedef method_ret (*apply_func)(ob_methods *, object *, object *, int); |
| 40 | typedef method_ret (*process_func)(ob_methods *, object *); |
| 41 | typedef void (*describe_func)(const ob_methods *, const object *, const object *, int use_media_tags, char *buf, size_t size); |
| 42 | typedef method_ret (*move_on_func)(ob_methods *, object *, object *, object *); |
| 43 | typedef method_ret (*trigger_func)(ob_methods *, object *, object *, int); |
| 44 | |
| 45 | struct ob_methods { |
| 46 | apply_func apply; /**< The apply method */ |
| 47 | process_func process; /**< The process method */ |
| 48 | describe_func describe; /**< The describe method */ |
| 49 | move_on_func move_on; /**< The move_on method */ |
| 50 | trigger_func trigger; /**< When something is triggered via a button. */ |
| 51 | struct ob_methods *fallback; /**< ob_method structure to fallback to */ |
| 52 | /* Example: |
| 53 | * apply_func *apply; |
| 54 | */ |
| 55 | }; |
| 56 | |
| 57 | #endif /* OB_METHODS_H */ |