Crossfire Server, Branch 1.12
R12190
|
00001 /* 00002 CrossFire, A Multiplayer game for X-windows 00003 00004 Copyright (C) 2007 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 lighter_type_apply(ob_methods *context, object *lighter, object *applier, int aflags); 00034 00038 void init_type_lighter(void) { 00039 register_apply(LIGHTER, lighter_type_apply); 00040 } 00041 00060 static method_ret lighter_type_apply(ob_methods *context, object *lighter, object *applier, int aflags) { 00061 object *item; 00062 int is_player_env = 0; 00063 uint32 nrof; 00064 tag_t count; 00065 char item_name[MAX_BUF]; 00066 00067 if (applier->type != PLAYER) 00068 return METHOD_UNHANDLED; 00069 00070 item = find_marked_object(applier); 00071 if (!item) { 00072 draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, 00073 "You need to mark a lightable object.", NULL); 00074 return METHOD_OK; 00075 } 00076 00077 if (lighter->last_eat && lighter->stats.food) { 00078 /* Split multiple lighters if they're being used up. Otherwise 00079 * one charge from each would be used up. --DAMN 00080 */ 00081 if (lighter->nrof > 1) { 00082 object *oneLighter = get_split_ob(lighter, 1, NULL, 0); 00083 00084 oneLighter->stats.food--; 00085 oneLighter = insert_ob_in_ob(oneLighter, applier); 00086 } else { 00087 lighter->stats.food--; 00088 } 00089 } else if (lighter->last_eat) { /* no charges left in lighter */ 00090 draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, 00091 "You fail to light the %s with a used up %s.", 00092 NULL, 00093 item->name, lighter->name); 00094 return METHOD_OK; 00095 } 00096 00097 /* Perhaps we should split what we are trying to light on fire? 00098 * I can't see many times when you would want to light multiple 00099 * objects at once. */ 00100 nrof = item->nrof; 00101 count = item->count; 00102 /* If the item is destroyed, we don't have a valid pointer to the 00103 * name object, so make a copy so the message we print out makes 00104 * some sense. */ 00105 strncpy(item_name, item->name, sizeof(item_name)); 00106 if (applier == get_player_container(item)) 00107 is_player_env = 1; 00108 00109 save_throw_object(item, AT_FIRE, applier); 00110 00111 /* Change to check count and not freed, since the object pointer 00112 * may have gotten recycled */ 00113 if ((nrof != item->nrof) || (count != item->count)) { 00114 draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, 00115 "You light the %s with the %s.", 00116 NULL, 00117 item_name, lighter->name); 00118 00119 /* Need to update the player so that the players glow radius 00120 * gets changed. */ 00121 if (is_player_env) 00122 fix_object(applier); 00123 } else { 00124 draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, 00125 "You attempt to light the %s with the %s and fail.", 00126 NULL, 00127 item->name, lighter->name); 00128 } 00129 00130 return METHOD_OK; 00131 }