00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00079
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) {
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
00098
00099
00100 nrof = item->nrof;
00101 count = item->count;
00102
00103
00104
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
00112
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
00120
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 }