Crossfire Server, Branches 1.12  R18729
identify_altar.c
Go to the documentation of this file.
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 crossfire-devel@real-time.com
22 */
23 
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 
40 }
41 
50 static method_ret identify_altar_type_move_on(ob_methods *context, object *altar, object *money, object *originator) {
51  object *id;
52  object *marked;
53  int success = 0;
54  char desc[MAX_BUF];
55 
56  if (common_pre_ob_move_on(altar, money, originator) == METHOD_ERROR)
57  return METHOD_OK;
58 
59  if (originator == NULL || originator->type != PLAYER) {
60  common_post_ob_move_on(altar, money, originator);
61  return METHOD_OK;
62  }
63  /* Check for MONEY type is a special hack - it prevents 'nothing needs
64  * identifying' from being printed out more than it needs to be.
65  */
66  if (money->type != MONEY || !check_altar_sacrifice(altar, money, 0, NULL)) {
67  common_post_ob_move_on(altar, money, originator);
68  return METHOD_OK;
69  }
70  marked = find_marked_object(originator);
71  /* if the player has a marked item, identify that if it needs to be
72  * identified. IF it doesn't, then go through the player inventory.
73  */
74  if (marked
75  && !QUERY_FLAG(marked, FLAG_IDENTIFIED)
76  && need_identify(marked)) {
77  if (operate_altar(altar, &money)) {
78  identify(marked);
80  "You have %s.",
81  NULL,
82  ob_describe(marked, originator, desc, sizeof(desc)));
83 
84  if (marked->msg) {
86  "The item has a story:", NULL);
88  marked->msg, NULL);
89  }
90  common_post_ob_move_on(altar, money, originator);
91  return METHOD_OK;
92  }
93  }
94 
95  for (id = originator->inv; id; id = id->below) {
96  if (!QUERY_FLAG(id, FLAG_IDENTIFIED)
97  && !id->invisible
98  && need_identify(id)) {
99  if (operate_altar(altar, &money)) {
100  identify(id);
102  "You have %s.", "You have %s.", ob_describe(id, originator, desc, sizeof(desc)));
103  if (id->msg) {
105  "The item has a story:", NULL);
107  id->msg, NULL);
108  }
109  success = 1;
110  /* If no more money, might as well quit now */
111  if (money == NULL || !check_altar_sacrifice(altar, money, 0, NULL))
112  break;
113  } else {
114  LOG(llevError, "check_id_altar: Couldn't do sacrifice when we should have been able to\n");
115  break;
116  }
117  }
118  }
119  if (!success)
121  "You have nothing that needs identifying", NULL);
122  common_post_ob_move_on(altar, money, originator);
123  return METHOD_OK;
124 }
static method_ret identify_altar_type_move_on(ob_methods *context, object *altar, object *money, object *originator)
method_ret common_pre_ob_move_on(object *trap, object *victim, object *originator)
Definition: common_apply.c:51
#define MSG_TYPE_APPLY_FAILURE
Definition: newclient.h:519
#define METHOD_ERROR
Definition: ob_methods.h:44
#define MONEY
Definition: define.h:148
sint16 invisible
Definition: object.h:211
void draw_ext_info(int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *message, const char *oldmessage)
Definition: standalone.c:171
void draw_ext_info_format(int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *new_format, const char *old_format,...)
Definition: standalone.c:175
#define PLAYER
Definition: define.h:113
char method_ret
Definition: ob_methods.h:41
void register_move_on(int ob_type, move_on_func method)
Definition: ob_types.c:106
#define METHOD_OK
Definition: ob_methods.h:42
int check_altar_sacrifice(const object *altar, const object *sacrifice, int remove_others, int *toremove)
Definition: button.c:355
#define FLAG_IDENTIFIED
Definition: define.h:557
void identify(object *op)
Definition: item.c:1447
struct obj * below
Definition: object.h:145
int operate_altar(object *altar, object **sacrifice)
Definition: button.c:470
object * find_marked_object(object *op)
Definition: c_object.c:1339
#define QUERY_FLAG(xyz, p)
Definition: define.h:514
#define MSG_TYPE_APPLY
Definition: newclient.h:330
#define MAX_BUF
Definition: define.h:81
char * ob_describe(const object *op, const object *observer, char *buf, size_t size)
Definition: ob_methods.c:102
int need_identify(const object *op)
Definition: item.c:1401
void common_post_ob_move_on(object *trap, object *victim, object *originator)
Definition: common_apply.c:88
#define MSG_TYPE_APPLY_SUCCESS
Definition: newclient.h:518
void init_type_identify_altar(void)
const char * msg
Definition: object.h:175
struct obj * inv
Definition: object.h:148
#define NDI_UNIQUE
Definition: newclient.h:219
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:63
#define IDENTIFY_ALTAR
Definition: define.h:317
uint8 type
Definition: object.h:189