Crossfire Server, Trunk  R20513
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
74  && !QUERY_FLAG(marked, FLAG_IDENTIFIED)
75  && need_identify(marked)) {
76  if (operate_altar(altar, &money)) {
77  marked = identify(marked);
79  "You have %s.",
80  ob_describe(marked, originator, desc, sizeof(desc)));
81 
82  if (marked->msg) {
84  "The item has a story:");
86  marked->msg);
87  }
88  common_post_ob_move_on(altar, money, originator);
89  return METHOD_OK;
90  }
91  }
92 
93  FOR_INV_PREPARE(originator, id) {
94  if (!QUERY_FLAG(id, FLAG_IDENTIFIED)
95  && !id->invisible
96  && need_identify(id)) {
97  if (operate_altar(altar, &money)) {
98  id = identify(id);
100  "You have %s.", ob_describe(id, originator, desc, sizeof(desc)));
101  if (id->msg) {
103  "The item has a story:");
105  id->msg);
106  }
107  success = 1;
108  /* If no more money, might as well quit now */
109  if (money == NULL || !check_altar_sacrifice(altar, money, 0, NULL))
110  break;
111  } else {
112  LOG(llevError, "check_id_altar: Couldn't do sacrifice when we should have been able to\n");
113  break;
114  }
115  }
116  } FOR_INV_FINISH();
117  if (!success)
119  "You have nothing that needs identifying");
120  common_post_ob_move_on(altar, money, originator);
121  return METHOD_OK;
122 }
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...)
Sends message to player(s).
Definition: main.c:315
Error, serious thing.
Definition: logger.h:11
Sound-related defines.
static method_ret identify_altar_type_move_on(ob_methods *context, object *altar, object *money, object *originator)
Move on this Altar Identifier object.
Typedefs for ob_methods.
Definition: ob_methods.h:45
method_ret common_pre_ob_move_on(object *trap, object *victim, object *originator)
Definition: common_apply.c:51
#define MSG_TYPE_APPLY_FAILURE
Apply OK, but no/bad result.
Definition: newclient.h:599
#define METHOD_ERROR
Definition: ob_methods.h:17
See Money.
Definition: object.h:137
Global type definitions and header inclusions.
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Sends message to player(s).
Definition: main.c:310
#define MSG_TYPE_APPLY
Applying objects.
Definition: newclient.h:384
char method_ret
Define some standard return values for callbacks which don&#39;t need to return any other results...
Definition: ob_methods.h:14
void register_move_on(int ob_type, move_on_func method)
Registers the move_on method for the given type.
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)
Checks whether the altar has enough to sacrifice.
Definition: button.c:352
#define FLAG_IDENTIFIED
Player knows full info about item.
Definition: define.h:261
#define FOR_INV_FINISH()
Finishes FOR_INV_PREPARE().
Definition: define.h:712
int operate_altar(object *altar, object **sacrifice)
Checks if sacrifice was accepted and removes sacrificed objects.
Definition: button.c:468
object * find_marked_object(object *op)
Return the object the player has marked with the &#39;mark&#39; command below.
Definition: c_object.c:1256
#define QUERY_FLAG(xyz, p)
Definition: define.h:225
#define MAX_BUF
Used for all kinds of things.
Definition: define.h:35
char * ob_describe(const object *op, const object *observer, char *buf, size_t size)
Returns the description of an object, as seen by the given observer.
Definition: ob_methods.c:85
Object type variables.
int need_identify(const object *op)
This function really should not exist - by default, any item not identified should need it...
Definition: item.c:1331
void common_post_ob_move_on(object *trap, object *victim, object *originator)
Definition: common_apply.c:87
See Player.
Definition: object.h:107
void init_type_identify_altar(void)
Initializer for the IDENTIFY_ALTAR object type.
uint8_t type
PLAYER, BULLET, etc.
Definition: object.h:338
#define MSG_TYPE_APPLY_SUCCESS
Was able to apply object.
Definition: newclient.h:598
const char * msg
If this is a book/sign/magic mouth/etc.
Definition: object.h:322
object * identify(object *op)
Identifies an item.
Definition: item.c:1437
#define NDI_UNIQUE
Print immediately, don&#39;t buffer.
Definition: newclient.h:245
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
Definition: logger.c:51
Object type functions and variables.
#define FOR_INV_PREPARE(op_, it_)
Constructs a loop iterating over the inventory of an object.
Definition: define.h:705