Crossfire Server, Branch 1.12  R12190
identify_altar.c
Go to the documentation of this file.
00001 /*
00002     CrossFire, A Multiplayer game for X-windows
00003 
00004     Copyright (C) 2007 Mark Wedel & Crossfire Development Team
00005     Copyright (C) 1992 Frank Tore Johansen
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020 
00021     The authors can be reached via e-mail at crossfire-devel@real-time.com
00022 */
00023 
00027 #include <global.h>
00028 #include <ob_methods.h>
00029 #include <ob_types.h>
00030 #include <sounds.h>
00031 #include <sproto.h>
00032 
00033 static method_ret identify_altar_type_move_on(ob_methods *context, object *altar, object *money, object *originator);
00034 
00038 void init_type_identify_altar(void) {
00039     register_move_on(IDENTIFY_ALTAR, identify_altar_type_move_on);
00040 }
00041 
00050 static method_ret identify_altar_type_move_on(ob_methods *context, object *altar, object *money, object *originator) {
00051     object *id;
00052     object *marked;
00053     int success = 0;
00054     char desc[MAX_BUF];
00055 
00056     if (common_pre_ob_move_on(altar, money, originator) == METHOD_ERROR)
00057         return METHOD_OK;
00058 
00059     if (originator == NULL || originator->type != PLAYER) {
00060         common_post_ob_move_on(altar, money, originator);
00061         return METHOD_OK;
00062     }
00063     /* Check for MONEY type is a special hack - it prevents 'nothing needs
00064      * identifying' from being printed out more than it needs to be.
00065      */
00066     if (money->type != MONEY || !check_altar_sacrifice(altar, money, 0, NULL)) {
00067         common_post_ob_move_on(altar, money, originator);
00068         return METHOD_OK;
00069     }
00070     marked = find_marked_object(originator);
00071     /* if the player has a marked item, identify that if it needs to be
00072      * identified.  IF it doesn't, then go through the player inventory.
00073      */
00074     if (marked
00075     && !QUERY_FLAG(marked, FLAG_IDENTIFIED)
00076     && need_identify(marked)) {
00077         if (operate_altar(altar, &money)) {
00078             identify(marked);
00079             draw_ext_info_format(NDI_UNIQUE, 0, originator, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS,
00080                 "You have %s.",
00081                 NULL,
00082                 ob_describe(marked, originator, desc, sizeof(desc)));
00083 
00084             if (marked->msg) {
00085                 draw_ext_info(NDI_UNIQUE, 0, originator, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS,
00086                     "The item has a story:", NULL);
00087                 draw_ext_info(NDI_UNIQUE, 0, originator, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS,
00088                     marked->msg, NULL);
00089             }
00090             common_post_ob_move_on(altar, money, originator);
00091             return METHOD_OK;
00092         }
00093     }
00094 
00095     for (id = originator->inv; id; id = id->below) {
00096         if (!QUERY_FLAG(id, FLAG_IDENTIFIED)
00097         && !id->invisible
00098         && need_identify(id)) {
00099             if (operate_altar(altar, &money)) {
00100                 identify(id);
00101                 draw_ext_info_format(NDI_UNIQUE, 0, originator, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS,
00102                     "You have %s.", "You have %s.", ob_describe(id, originator, desc, sizeof(desc)));
00103                 if (id->msg) {
00104                     draw_ext_info(NDI_UNIQUE, 0, originator, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS,
00105                         "The item has a story:", NULL);
00106                     draw_ext_info(NDI_UNIQUE, 0, originator, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS,
00107                         id->msg, NULL);
00108                 }
00109                 success = 1;
00110                 /* If no more money, might as well quit now */
00111                 if (money == NULL || !check_altar_sacrifice(altar, money, 0, NULL))
00112                     break;
00113             } else {
00114                 LOG(llevError, "check_id_altar:  Couldn't do sacrifice when we should have been able to\n");
00115                 break;
00116             }
00117         }
00118     }
00119     if (!success)
00120         draw_ext_info(NDI_UNIQUE, 0, originator, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE,
00121             "You have nothing that needs identifying", NULL);
00122     common_post_ob_move_on(altar, money, originator);
00123     return METHOD_OK;
00124 }