| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#include "global.h" |
| 19 |
|
| 20 |
#include <string.h> |
| 21 |
|
| 22 |
#include "ob_methods.h" |
| 23 |
#include "ob_types.h" |
| 24 |
#include "sounds.h" |
| 25 |
#include "sproto.h" |
| 26 |
|
| 27 |
static method_ret lighter_type_apply(ob_methods *context, object *lighter, object *applier, int aflags); |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
void init_type_lighter(void) { |
| 33 |
register_apply(LIGHTER, lighter_type_apply); |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
static method_ret lighter_type_apply(ob_methods *context, object *lighter, object *applier, int aflags) { |
| 55 |
object *item; |
| 56 |
int is_player_env = 0; |
| 57 |
uint32_t nrof; |
| 58 |
tag_t count; |
| 59 |
char item_name[MAX_BUF]; |
| 60 |
|
| 61 |
if (applier->type != PLAYER) |
| 62 |
return METHOD_UNHANDLED; |
| 63 |
|
| 64 |
item = find_marked_object(applier); |
| 65 |
if (!item) { |
| 66 |
draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 67 |
"You need to mark a lightable object."); |
| 68 |
return METHOD_OK; |
| 69 |
} |
| 70 |
|
| 71 |
if (lighter->last_eat && lighter->stats.food) { |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
if (lighter->nrof > 1) { |
| 76 |
object *oneLighter = object_split(lighter, 1, NULL, 0); |
| 77 |
|
| 78 |
oneLighter->stats.food--; |
| 79 |
oneLighter = object_insert_in_ob(oneLighter, applier); |
| 80 |
} else { |
| 81 |
lighter->stats.food--; |
| 82 |
} |
| 83 |
} else if (lighter->last_eat) { |
| 84 |
draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, |
| 85 |
"You fail to light the %s with a used up %s.", |
| 86 |
item->name, lighter->name); |
| 87 |
return METHOD_OK; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
nrof = item->nrof; |
| 94 |
count = item->count; |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
safe_strncpy(item_name, item->name, sizeof(item_name)); |
| 99 |
if (applier == object_get_player_container(item)) |
| 100 |
is_player_env = 1; |
| 101 |
|
| 102 |
save_throw_object(item, AT_FIRE, applier); |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
if ((nrof != item->nrof) || (count != item->count)) { |
| 107 |
draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 108 |
"You light the %s with the %s.", |
| 109 |
item_name, lighter->name); |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
if (is_player_env) |
| 114 |
fix_object(applier); |
| 115 |
} else { |
| 116 |
draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, |
| 117 |
"You attempt to light the %s with the %s and fail.", |
| 118 |
item->name, lighter->name); |
| 119 |
} |
| 120 |
|
| 121 |
return METHOD_OK; |
| 122 |
} |