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 treasure_type_apply(ob_methods *context, object *op, object *applier, int aflags);
00034
00038 void init_type_treasure(void) {
00039 register_apply(TREASURE, treasure_type_apply);
00040 }
00041
00051 static method_ret treasure_type_apply(ob_methods *context, object *op, object *applier, int aflags) {
00052 object *treas;
00053 tag_t op_tag = op->count, applier_tag = applier->count;
00054 char name[MAX_BUF];
00055
00056 if (applier->type == PLAYER) {
00057
00058
00059
00060
00061
00062
00063
00064 treas = op->inv;
00065 if (treas == NULL) {
00066 draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE,
00067 "The chest was empty.", NULL);
00068 decrease_ob(op);
00069 return METHOD_OK;
00070 }
00071 while (op->inv) {
00072 treas = op->inv;
00073
00074 remove_ob(treas);
00075 query_name(treas, name, MAX_BUF);
00076 draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS,
00077 "You find %s in the chest.",
00078 "You find %s in the chest.",
00079 name);
00080
00081 treas->x = applier->x;
00082 treas->y = applier->y;
00083 treas = insert_ob_in_map(treas, applier->map, applier, INS_BELOW_ORIGINATOR);
00084
00085 if (treas
00086 && (treas->type == RUNE || treas->type == TRAP)
00087 && treas->level && QUERY_FLAG(applier, FLAG_ALIVE))
00088 spring_trap(treas, applier);
00089
00090
00091
00092
00093
00094 if (was_destroyed(applier, applier_tag) || was_destroyed(op, op_tag))
00095 break;
00096 }
00097
00098 if (!was_destroyed(op, op_tag) && op->inv == NULL)
00099 decrease_ob(op);
00100 }
00101 return METHOD_OK;
00102 }