File: ob_types.c

package info (click to toggle)
crossfire 1.75.0-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,168 kB
  • sloc: ansic: 83,169; sh: 4,659; perl: 1,736; lex: 1,443; makefile: 1,199; python: 43
file content (100 lines) | stat: -rw-r--r-- 2,965 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
 * Crossfire -- cooperative multi-player graphical RPG and adventure game
 *
 * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
 * Copyright (c) 1992 Frank Tore Johansen
 *
 * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
 * welcome to redistribute it under certain conditions. For details, please
 * see COPYING and LICENSE.
 *
 * The authors can be reached via e-mail at <crossfire@metalforge.org>.
 */

/**
 * @file
 * Those functions deal with the object/type system.
 */

#include <global.h>
#include <ob_types.h>
#include <ob_methods.h>
#include <sproto.h>

/** Registered method handlers. */
ob_methods type_methods[OBJECT_TYPE_MAX];

/**
 * Initializes a ob_methods struct. Make sure this always matches ob_methods.h
 * @param methods ob_method structure to initialize
 * @param fallback Default fallback for the ob_method
 */
void init_ob_method_struct(ob_methods *methods, ob_methods *fallback) {
    methods->fallback = fallback;
    methods->apply = NULL;
    methods->process = NULL;
    methods->describe = NULL;
    methods->move_on = NULL;
    methods->trigger = NULL;
}

/**
 * Initializes the object system.
 *
 * @param base_type
 * base type to use as a base for all types.
 * @todo when migration is complete, the parameter should go, and this function should be called from
 * init_library() instead of init_ob_methods() in server/ob_methods.c.
 */
void init_ob_types(ob_methods *base_type) {
    int tmp;

    for (tmp = 0; tmp < OBJECT_TYPE_MAX; tmp++)
        init_ob_method_struct(&type_methods[tmp], base_type);
}

/* Functions for registering methods for types */
/**
 * Registers the apply method for the given type.
 * @param ob_type The type of object to register this method to
 * @param method The method to link
 */
void register_apply(int ob_type, apply_func method) {
    type_methods[ob_type].apply = method;
}

/**
 * Registers the process method for the given type.
 * @param ob_type The type of object to register this method to
 * @param method The method to link
 */
void register_process(int ob_type, process_func method) {
    type_methods[ob_type].process = method;
}

/**
 * Registers the describe method for the given type.
 * @param ob_type The type of object to register this method to
 * @param method The method to link
 */
void register_describe(int ob_type, describe_func method) {
    type_methods[ob_type].describe = method;
}

/**
 * Registers the move_on method for the given type.
 * @param ob_type The type of object to register this method to
 * @param method The method to link
 */
void register_move_on(int ob_type, move_on_func method) {
    type_methods[ob_type].move_on = method;
}

/**
 * Registers the trigger method for the given type.
 * @param ob_type The type of object to register this method to
 * @param method The method to link
 */
void register_trigger(int ob_type, trigger_func method) {
    type_methods[ob_type].trigger = method;
}