Debian Codegraph @

types/lamp/lamp.c

raw symbols SCIP
1 /*
2 CrossFire, A Multiplayer game for X-windows
3
4 Copyright (C) 2007 Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 The authors can be reached via e-mail at [email protected]
22 */
23
24 /**
25 * @file lamp.c
26 * Lamps.
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 lamp_type_apply(ob_methods *context, object *lighter, object *applier, int aflags);
35
36 /**
37 * Initializer for the LAMP object type.
38 */
39 void init_type_lamp(void) {
40 register_apply(LAMP, lamp_type_apply);
41 }
42
43 /**
44 * Turn on/off the lamp, based on op's APPLIED status.
45 * @param op
46 * lamp.
47 * @param who
48 * player or monster.
49 * @param aflags
50 * flags.
51 * @param onoff
52 * string that will be appended to the 'turn' verb in the message.
53 */
54 static void do_turn(object *op, object *who, int aflags, const char *onoff) {
55 object *tmp2;
56
57 if (!(aflags&AP_NOPRINT))
58 draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS,
59 "You turn %s your %s.",
60 onoff, op->name);
61
62 tmp2 = arch_to_object(op->other_arch);
63 tmp2->stats.food = op->stats.food;
64 if (QUERY_FLAG(op, FLAG_APPLIED))
65 CLEAR_FLAG(tmp2, FLAG_APPLIED);
66 else
67 SET_FLAG(tmp2, FLAG_APPLIED);
68 if (QUERY_FLAG(op, FLAG_INV_LOCKED))
69 SET_FLAG(tmp2, FLAG_INV_LOCKED);
70 object_insert_in_ob(tmp2, who);
71
72 object_remove(op);
73 object_free_drop_inventory(op);
74
75 fix_object(who);
76
77 if (QUERY_FLAG(op, FLAG_CURSED) || QUERY_FLAG(op, FLAG_DAMNED)) {
78 if (who->type == PLAYER) {
79 if (!(aflags&AP_NOPRINT))
80 draw_ext_info(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_CURSED,
81 "Oops, it feels deadly cold!");
82 SET_FLAG(tmp2, FLAG_KNOWN_CURSED);
83 }
84 }
85
86 if (who->map) {
87 SET_MAP_FLAGS(who->map, who->x, who->y, P_NEED_UPDATE);
88 update_position(who->map, who->x, who->y);
89 update_all_los(who->map, who->x, who->y);
90 }
91 }
92
93 /**
94 * Applies a lamp.
95 *
96 * @param context
97 * method context.
98 * @param lamp
99 * lamp to turn on/off.
100 * @param applier
101 * object attempting to apply the scroll. Should be a player.
102 * @param aflags
103 * special flags (always apply/unapply).
104 * @return
105 * METHOD_ERROR if lamp can't be applied, METHOD_OK else.
106 */
107 static method_ret lamp_type_apply(ob_methods *context, object *lamp, object *applier, int aflags) {
108 object *tmp;
109
110 if (object_get_player_container(lamp) != applier) {
111 draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR,
112 "You must get it first!\n");
113 return METHOD_ERROR;
114 }
115
116 if (lamp->nrof > 1)
117 tmp = object_split(lamp, lamp->nrof-1, NULL, 0);
118 else
119 tmp = NULL;
120
121 if (QUERY_FLAG(lamp, FLAG_APPLIED))
122 do_turn(lamp, applier, aflags, "off");
123 else {
124 if (lamp->stats.food < 1) {
125 if (!(aflags&AP_NOPRINT))
126 draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE,
127 "Your %s is out of fuel!",
128 lamp->name);
129 return METHOD_OK;
130 }
131 do_turn(lamp, applier, aflags, "on");
132 }
133
134 /* insert the portion that was split off. */
135 if (tmp != NULL) {
136 object_insert_in_ob(tmp, applier);
137 }
138
139 return METHOD_OK;
140 }