| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
#include <global.h> |
| 29 |
#include <ob_methods.h> |
| 30 |
#include <ob_types.h> |
| 31 |
#include <sounds.h> |
| 32 |
#include <sproto.h> |
| 33 |
|
| 34 |
static method_ret lamp_type_apply(ob_methods *context, object *lighter, object *applier, int aflags); |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
void init_type_lamp(void) { |
| 40 |
register_apply(LAMP, lamp_type_apply); |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
static void do_turn(object *op, object *who, int aflags, const char *onoff) { |
| 55 |
object *tmp2; |
| 56 |
|
| 57 |
if (!(aflags&AP_NOPRINT)) |
| 58 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 59 |
"You turn %s your %s.", |
| 60 |
onoff, op->name); |
| 61 |
|
| 62 |
tmp2 = arch_to_object(op->other_arch); |
| 63 |
tmp2->stats.food = op->stats.food; |
| 64 |
if (QUERY_FLAG(op, FLAG_APPLIED)) |
| 65 |
CLEAR_FLAG(tmp2, FLAG_APPLIED); |
| 66 |
else |
| 67 |
SET_FLAG(tmp2, FLAG_APPLIED); |
| 68 |
if (QUERY_FLAG(op, FLAG_INV_LOCKED)) |
| 69 |
SET_FLAG(tmp2, FLAG_INV_LOCKED); |
| 70 |
object_insert_in_ob(tmp2, who); |
| 71 |
|
| 72 |
object_remove(op); |
| 73 |
object_free_drop_inventory(op); |
| 74 |
|
| 75 |
fix_object(who); |
| 76 |
|
| 77 |
if (QUERY_FLAG(op, FLAG_CURSED) || QUERY_FLAG(op, FLAG_DAMNED)) { |
| 78 |
if (who->type == PLAYER) { |
| 79 |
if (!(aflags&AP_NOPRINT)) |
| 80 |
draw_ext_info(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_CURSED, |
| 81 |
"Oops, it feels deadly cold!"); |
| 82 |
SET_FLAG(tmp2, FLAG_KNOWN_CURSED); |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
if (who->map) { |
| 87 |
SET_MAP_FLAGS(who->map, who->x, who->y, P_NEED_UPDATE); |
| 88 |
update_position(who->map, who->x, who->y); |
| 89 |
update_all_los(who->map, who->x, who->y); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
static method_ret lamp_type_apply(ob_methods *context, object *lamp, object *applier, int aflags) { |
| 108 |
object *tmp; |
| 109 |
|
| 110 |
if (object_get_player_container(lamp) != applier) { |
| 111 |
draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 112 |
"You must get it first!\n"); |
| 113 |
return METHOD_ERROR; |
| 114 |
} |
| 115 |
|
| 116 |
if (lamp->nrof > 1) |
| 117 |
tmp = object_split(lamp, lamp->nrof-1, NULL, 0); |
| 118 |
else |
| 119 |
tmp = NULL; |
| 120 |
|
| 121 |
if (QUERY_FLAG(lamp, FLAG_APPLIED)) |
| 122 |
do_turn(lamp, applier, aflags, "off"); |
| 123 |
else { |
| 124 |
if (lamp->stats.food < 1) { |
| 125 |
if (!(aflags&AP_NOPRINT)) |
| 126 |
draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, |
| 127 |
"Your %s is out of fuel!", |
| 128 |
lamp->name); |
| 129 |
return METHOD_OK; |
| 130 |
} |
| 131 |
do_turn(lamp, applier, aflags, "on"); |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
if (tmp != NULL) { |
| 136 |
object_insert_in_ob(tmp, applier); |
| 137 |
} |
| 138 |
|
| 139 |
return METHOD_OK; |
| 140 |
} |