Debian Codegraph @

types/marker/marker.c

raw symbols SCIP
1 /*
2 CrossFire, A Multiplayer game for X-windows
3
4 Copyright (C) 2008 Crossfire Development Team
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20 The authors can be reached via e-mail at [email protected]
21 */
22
23 /**
24 * @file
25 * The implementation of @ref page_type_55 "marker" objects.
26 */
27
28 #include <global.h>
29 #include <ob_methods.h>
30 #include <ob_types.h>
31 #include <sounds.h>
32 #include <sproto.h>
33
34 static method_ret marker_type_process(ob_methods *context, object *op);
35 static method_ret marker_type_trigger(ob_methods *context, object *op, object *cause, int state);
36
37 /**
38 * Initializer for the @ref page_type_55 "marker" object type.
39 */
40 void init_type_marker(void) {
41 register_process(MARKER, marker_type_process);
42 register_trigger(TRIGGER_MARKER, marker_type_trigger);
43 }
44
45 /**
46 * Move function for @ref page_type_55 "marker" objects.
47 *
48 * When moved, a marker will search for a player sitting above
49 * it, and insert an invisible, weightless force into him
50 * with a specific code as the slaying field.
51 *
52 * At that time, it writes the contents of its own message
53 * field to the player. The marker will decrement hp to
54 * 0 and then delete itself every time it grants a mark.
55 * unless hp was zero to start with, in which case it is infinite.
56 * @author [email protected]
57 *
58 * @param op
59 * marker to move. Can be removed if it reached its marking limit.
60 */
61 static void move_marker(object *op) {
62 object *tmp, *tmp2;
63
64 /*
65 * markers not on a map for any reason should not crash server
66 */
67 if (!op->map) {
68 return;
69 }
70
71 for (tmp = GET_MAP_OB(op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) {
72 if (tmp->type == PLAYER) { /* we've got someone to MARK */
73 /* cycle through his inventory to look for the MARK we want to
74 * place
75 */
76 tmp2 = object_find_by_type_and_slaying(tmp, FORCE, op->slaying);
77 /* if we didn't find our own MARK */
78 if (tmp2 == NULL) {
79 object *force = create_archetype(FORCE_NAME);
80
81 force->speed = 0;
82 if (op->stats.food) {
83 force->speed = 0.01;
84 force->speed_left = -op->stats.food;
85 }
86 object_update_speed(force);
87 /* put in the lock code */
88 force->slaying = add_string(op->slaying);
89
90 if (op->lore)
91 force->lore = add_string(op->lore);
92
93 object_insert_in_ob(force, tmp);
94 if (op->msg)
95 draw_ext_info(NDI_UNIQUE|NDI_NAVY, 0, tmp, MSG_TYPE_MISC, MSG_SUBTYPE_NONE,
96 op->msg);
97
98 if (op->stats.hp > 0) {
99 op->stats.hp--;
100 if (op->stats.hp == 0) {
101 /* marker expires--granted mark number limit */
102 object_remove(op);
103 object_free_drop_inventory(op);
104 return;
105 }
106 }
107 } /* if tmp2 == NULL */
108 } /* if tmp->type == PLAYER */
109 } /* For all objects on this space */
110 }
111
112 /**
113 * Processes a @ref page_type_55 "marker".
114 * @param context The method context
115 * @param op The marker to process
116 * @retval METHOD_OK
117 */
118 static method_ret marker_type_process(ob_methods *context, object *op) {
119 move_marker(op);
120 return METHOD_OK;
121 }
122
123 /**
124 * A @ref page_type_55 "marker" is triggered.
125 * @param context Ignored.
126 * @param op The object being triggered
127 * @param cause Ignored.
128 * @param state Ignored.
129 * @retval METHOD_OK
130 */
131 static method_ret marker_type_trigger(ob_methods *context, object *op, object *cause, int state) {
132 move_marker(op);
133 return METHOD_OK;
134 }