Crossfire Server, Trunk  R21466
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 *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);
77  "You have %s.",
78  ob_describe(marked, originator, 1, desc, sizeof(desc)));
79 
80  if (marked->msg) {
82  "The item has a story:");
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);
96  "You have %s.", ob_describe(id, originator, 1, desc, sizeof(desc)));
97  if (id->msg) {
99  "The item has a story:");
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)
115  "You have nothing that needs identifying");
116  common_post_ob_move_on(altar, money, originator);
117  return METHOD_OK;
118 }
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...)
Definition: main.c:316
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:599
#define METHOD_ERROR
Definition: ob_methods.h:17
Definition: object.h:137
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Definition: main.c:311
#define MSG_TYPE_APPLY
Definition: newclient.h:384
char method_ret
Definition: ob_methods.h:14
int is_identified(const object *op)
Definition: item.c:1359
void register_move_on(int ob_type, move_on_func method)
Definition: ob_types.c:89
#define METHOD_OK
Definition: ob_methods.h:15
int check_altar_sacrifice(const object *altar, const object *sacrifice, int remove_others, int *toremove)
Definition: button.c:352
#define FOR_INV_FINISH()
Definition: define.h:715
int operate_altar(object *altar, object **sacrifice)
Definition: button.c:468
object * find_marked_object(object *op)
Definition: c_object.c:1270
#define MAX_BUF
Definition: define.h:35
void common_post_ob_move_on(object *trap, object *victim, object *originator)
Definition: common_apply.c:87
Definition: object.h:107
char * ob_describe(const object *op, const object *observer, int use_media_tags, char *buf, size_t size)
Definition: ob_methods.c:92
void init_type_identify_altar(void)
uint8_t type
Definition: object.h:339
#define MSG_TYPE_APPLY_SUCCESS
Definition: newclient.h:598
const char * msg
Definition: object.h:322
object * identify(object *op)
Definition: item.c:1429
#define NDI_UNIQUE
Definition: newclient.h:245
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:51
#define FOR_INV_PREPARE(op_, it_)
Definition: define.h:708