Debian Codegraph @

types/identify_altar/identify_altar.c

raw symbols SCIP
1 /*
2 CrossFire, A Multiplayer game for X-windows
3
4 Copyright (C) 2007 Mark Wedel & 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 /** @file identify_altar.c
25 * The implementation of the Identify Altar class of objects.
26 */
27 #include <global.h>
28 #include <ob_methods.h>
29 #include <ob_types.h>
30 #include <sounds.h>
31 #include <sproto.h>
32
33 static method_ret identify_altar_type_move_on(ob_methods *context, object *altar, object *money, object *originator);
34
35 /**
36 * Initializer for the IDENTIFY_ALTAR object type.
37 */
38 void init_type_identify_altar(void) {
39 register_move_on(IDENTIFY_ALTAR, identify_altar_type_move_on);
40 }
41
42 /**
43 * Move on this Altar Identifier object.
44 * @param context The method context
45 * @param altar The Altar Identifier we're moving on
46 * @param money The object moving over this one
47 * @param originator The object that caused the move_on event
48 * @return METHOD_OK
49 */
50 static method_ret identify_altar_type_move_on(ob_methods *context, object *altar, object *money, object *originator) {
51 object *marked;
52 int success = 0;
53 char desc[MAX_BUF];
54
55 if (common_pre_ob_move_on(altar, money, originator) == METHOD_ERROR)
56 return METHOD_OK;
57
58 if (originator == NULL || originator->type != PLAYER) {
59 common_post_ob_move_on(altar, money, originator);
60 return METHOD_OK;
61 }
62 /* Check for MONEY type is a special hack - it prevents 'nothing needs
63 * identifying' from being printed out more than it needs to be.
64 */
65 if (money->type != MONEY || !check_altar_sacrifice(altar, money, 0, NULL)) {
66 common_post_ob_move_on(altar, money, originator);
67 return METHOD_OK;
68 }
69 marked = find_marked_object(originator);
70 /* if the player has a marked item, identify that if it needs to be
71 * identified. IF it doesn't, then go through the player inventory.
72 */
73 if (marked && !is_identified(marked)) {
74 if (operate_altar(altar, &money)) {
75 marked = identify(marked);
76 draw_ext_info_format(NDI_UNIQUE, 0, originator, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS,
77 "You have %s.",
78 ob_describe(marked, originator, 1, desc, sizeof(desc)));
79
80 if (marked->msg) {
81 draw_ext_info(NDI_UNIQUE, 0, originator, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS,
82 "The item has a story:");
83 draw_ext_info(NDI_UNIQUE, 0, originator, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS,
84 marked->msg);
85 }
86 common_post_ob_move_on(altar, money, originator);
87 return METHOD_OK;
88 }
89 }
90
91 FOR_INV_PREPARE(originator, id) {
92 if (!id->invisible && !is_identified(id)) {
93 if (operate_altar(altar, &money)) {
94 id = identify(id);
95 draw_ext_info_format(NDI_UNIQUE, 0, originator, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS,
96 "You have %s.", ob_describe(id, originator, 1, desc, sizeof(desc)));
97 if (id->msg) {
98 draw_ext_info(NDI_UNIQUE, 0, originator, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS,
99 "The item has a story:");
100 draw_ext_info(NDI_UNIQUE, 0, originator, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS,
101 id->msg);
102 }
103 success = 1;
104 /* If no more money, might as well quit now */
105 if (money == NULL || !check_altar_sacrifice(altar, money, 0, NULL))
106 break;
107 } else {
108 LOG(llevError, "check_id_altar: Couldn't do sacrifice when we should have been able to\n");
109 break;
110 }
111 }
112 } FOR_INV_FINISH();
113 if (!success)
114 draw_ext_info(NDI_UNIQUE, 0, originator, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE,
115 "You have nothing that needs identifying");
116 common_post_ob_move_on(altar, money, originator);
117 return METHOD_OK;
118 }