… | |
… | |
919 | } |
919 | } |
920 | |
920 | |
921 | /* |
921 | /* |
922 | * convert_item() returns 1 if anything was converted, 0 if the item was not |
922 | * convert_item() returns 1 if anything was converted, 0 if the item was not |
923 | * what the converter wants, -1 if the converter is broken. |
923 | * what the converter wants, -1 if the converter is broken. |
924 | */ |
924 | * |
925 | #define CONV_FROM(xyz) xyz->slaying |
|
|
926 | #define CONV_TO(xyz) xyz->other_arch |
|
|
927 | #define CONV_NR(xyz) xyz->stats.sp |
|
|
928 | #define CONV_NEED(xyz) xyz->stats.food |
|
|
929 | |
|
|
930 | /* Takes one items and makes another. |
925 | * Takes one type of items and makes another. |
931 | * converter is the object that is doing the conversion. |
926 | * converter is the object that is doing the conversion. |
932 | * item is the object that triggered the converter - if it is not |
927 | * item is the object that triggered the converter - if it is not |
933 | * what the converter wants, this will not do anything. |
928 | * what the converter wants, this will not do anything. |
934 | */ |
929 | */ |
935 | int |
930 | static int |
936 | convert_item (object *item, object *converter) |
931 | convert_item (object *item, object *converter) |
937 | { |
932 | { |
938 | sint64 nr, price_in; |
933 | sint64 nr, price_in; |
|
|
934 | |
|
|
935 | if (item->flag [FLAG_UNPAID]) |
|
|
936 | return 0; |
|
|
937 | |
|
|
938 | shstr conv_from = converter->slaying; |
|
|
939 | archetype *conv_to = converter->other_arch; |
|
|
940 | sint64 need = converter->stats.food; |
|
|
941 | sint64 give = converter->stats.sp; |
939 | |
942 | |
940 | /* We make some assumptions - we assume if it takes money as it type, |
943 | /* We make some assumptions - we assume if it takes money as it type, |
941 | * it wants some amount. We don't make change (ie, if something costs |
944 | * it wants some amount. We don't make change (ie, if something costs |
942 | * 3 gp and player drops a platinum, tough luck) |
945 | * 3 gp and player drops a platinum, tough luck) |
943 | */ |
946 | */ |
944 | if (CONV_FROM (converter) == shstr_money) |
947 | if (conv_from == shstr_money) |
945 | { |
948 | { |
946 | if (item->type != MONEY) |
949 | if (item->type != MONEY) |
947 | return 0; |
950 | return 0; |
948 | |
951 | |
949 | nr = sint64 (item->nrof) * item->value / CONV_NEED (converter); |
952 | nr = sint64 (item->nrof) * item->value / need; |
950 | if (!nr) |
953 | if (!nr) |
951 | return 0; |
954 | return 0; |
952 | |
955 | |
953 | converter->play_sound (sound_find ("shop_buy")); |
956 | converter->play_sound (sound_find ("shop_buy")); |
954 | |
957 | |
955 | sint64 cost = (nr * CONV_NEED (converter) + item->value - 1) / item->value; |
958 | sint64 cost = (nr * need + item->value - 1) / item->value; |
956 | |
959 | |
957 | decrease_ob_nr (item, cost); |
960 | decrease_ob_nr (item, cost); |
958 | |
961 | |
959 | price_in = cost * item->value; |
962 | price_in = cost * item->value; |
960 | } |
963 | } |
961 | else |
964 | else |
962 | { |
965 | { |
963 | if (item->type == PLAYER || CONV_FROM (converter) != item->arch->archname || |
966 | if (item->type == PLAYER |
964 | (CONV_NEED (converter) && CONV_NEED (converter) > (uint16) item->nrof)) |
967 | || conv_from != item->arch->archname |
|
|
968 | || (need && need > (uint16) item->nrof)) |
965 | return 0; |
969 | return 0; |
966 | |
970 | |
967 | converter->play_sound (sound_find ("convert_item")); |
971 | converter->play_sound (sound_find ("convert_item")); |
968 | |
972 | |
969 | if (CONV_NEED (converter)) |
973 | if (need) |
970 | { |
974 | { |
971 | nr = sint64 (item->nrof) / CONV_NEED (converter); |
975 | nr = sint64 (item->nrof) / need; |
972 | decrease_ob_nr (item, nr * CONV_NEED (converter)); |
976 | decrease_ob_nr (item, nr * need); |
973 | price_in = nr * CONV_NEED (converter) * item->value; |
977 | price_in = nr * need * item->value; |
974 | } |
978 | } |
975 | else |
979 | else |
976 | { |
980 | { |
977 | price_in = item->value; |
981 | price_in = item->value; |
978 | item->destroy (); |
982 | item->destroy (); |
979 | } |
983 | } |
980 | } |
984 | } |
981 | |
|
|
982 | fprintf (stderr, "price_in %lld nr %lld\n", price_in, nr);//D |
|
|
983 | |
985 | |
984 | if (converter->inv) |
986 | if (converter->inv) |
985 | { |
987 | { |
986 | object *ob; |
988 | object *ob; |
987 | int i; |
989 | int i; |
… | |
… | |
997 | CLEAR_FLAG (item, FLAG_IS_A_TEMPLATE); |
999 | CLEAR_FLAG (item, FLAG_IS_A_TEMPLATE); |
998 | unflag_inv (item, FLAG_IS_A_TEMPLATE); |
1000 | unflag_inv (item, FLAG_IS_A_TEMPLATE); |
999 | } |
1001 | } |
1000 | else |
1002 | else |
1001 | { |
1003 | { |
1002 | if (!converter->other_arch) |
1004 | if (!conv_to) |
1003 | { |
1005 | { |
1004 | LOG (llevError, "move_creator: Converter doesn't have other arch set: %s (%s, %d, %d)\n", |
1006 | LOG (llevError, "move_creator: Converter doesn't have other arch set: %s (%s, %d, %d)\n", |
1005 | &converter->name, &converter->map->path, converter->x, converter->y); |
1007 | &converter->name, &converter->map->path, converter->x, converter->y); |
1006 | return -1; |
1008 | return -1; |
1007 | } |
1009 | } |
1008 | |
1010 | |
1009 | item = object_create_arch (converter->other_arch); |
1011 | item = object_create_arch (conv_to); |
1010 | fix_generated_item (item, converter, 0, 0, GT_MINIMAL); |
1012 | fix_generated_item (item, converter, 0, 0, GT_MINIMAL); |
1011 | } |
1013 | } |
1012 | |
1014 | |
1013 | if (CONV_NR (converter)) |
1015 | if (give) |
1014 | item->nrof = CONV_NR (converter); |
1016 | item->nrof = give; |
1015 | |
1017 | |
1016 | if (nr) |
1018 | if (nr) |
1017 | item->nrof *= nr; |
1019 | item->nrof *= nr; |
1018 | |
|
|
1019 | fprintf (stderr, "outnrof %lld\n", sint64(item->nrof));//D |
|
|
1020 | |
1020 | |
1021 | if (is_in_shop (converter)) |
1021 | if (is_in_shop (converter)) |
1022 | SET_FLAG (item, FLAG_UNPAID); |
1022 | SET_FLAG (item, FLAG_UNPAID); |
1023 | else if (price_in < sint64 (item->nrof) * item->value) |
1023 | else if (price_in < sint64 (item->nrof) * item->value) |
1024 | { |
1024 | { |