… | |
… | |
933 | * what the converter wants, this will not do anything. |
933 | * what the converter wants, this will not do anything. |
934 | */ |
934 | */ |
935 | int |
935 | int |
936 | convert_item (object *item, object *converter) |
936 | convert_item (object *item, object *converter) |
937 | { |
937 | { |
938 | int nr = 0; |
|
|
939 | uint32 price_in; |
938 | sint64 nr, price_in; |
940 | |
939 | |
941 | /* We make some assumptions - we assume if it takes money as it type, |
940 | /* We make some assumptions - we assume if it takes money as it type, |
942 | * it wants some amount. We don't make change (ie, if something costs |
941 | * it wants some amount. We don't make change (ie, if something costs |
943 | * 3 gp and player drops a platinum, tough luck) |
942 | * 3 gp and player drops a platinum, tough luck) |
944 | */ |
943 | */ |
945 | if (CONV_FROM (converter) == shstr_money) |
944 | if (CONV_FROM (converter) == shstr_money) |
946 | { |
945 | { |
947 | if (item->type != MONEY) |
946 | if (item->type != MONEY) |
948 | return 0; |
947 | return 0; |
949 | |
948 | |
950 | nr = (item->nrof * item->value) / CONV_NEED (converter); |
949 | nr = sint64 (item->nrof) * item->value / CONV_NEED (converter); |
951 | if (!nr) |
950 | if (!nr) |
952 | return 0; |
951 | return 0; |
953 | |
952 | |
954 | converter->play_sound (sound_find ("shop_buy")); |
953 | converter->play_sound (sound_find ("shop_buy")); |
955 | |
954 | |
956 | int cost = nr * CONV_NEED (converter) / item->value; |
955 | sint64 cost = (nr * CONV_NEED (converter) + item->value - 1) / item->value; |
957 | /* take into account rounding errors */ |
|
|
958 | if (nr * CONV_NEED (converter) % item->value) |
|
|
959 | cost++; |
|
|
960 | |
956 | |
961 | decrease_ob_nr (item, cost); |
957 | decrease_ob_nr (item, cost); |
962 | |
958 | |
963 | price_in = cost * item->value; |
959 | price_in = cost * item->value; |
964 | } |
960 | } |
… | |
… | |
970 | |
966 | |
971 | converter->play_sound (sound_find ("convert_item")); |
967 | converter->play_sound (sound_find ("convert_item")); |
972 | |
968 | |
973 | if (CONV_NEED (converter)) |
969 | if (CONV_NEED (converter)) |
974 | { |
970 | { |
975 | nr = item->nrof / CONV_NEED (converter); |
971 | nr = sint64 (item->nrof) / CONV_NEED (converter); |
976 | decrease_ob_nr (item, nr * CONV_NEED (converter)); |
972 | decrease_ob_nr (item, nr * CONV_NEED (converter)); |
977 | price_in = nr * CONV_NEED (converter) * item->value; |
973 | price_in = nr * CONV_NEED (converter) * item->value; |
978 | } |
974 | } |
979 | else |
975 | else |
980 | { |
976 | { |
981 | price_in = item->value; |
977 | price_in = item->value; |
982 | item->destroy (); |
978 | item->destroy (); |
983 | } |
979 | } |
984 | } |
980 | } |
|
|
981 | |
|
|
982 | fprintf (stderr, "price_in %lld nr %lld\n", price_in, nr);//D |
985 | |
983 | |
986 | if (converter->inv) |
984 | if (converter->inv) |
987 | { |
985 | { |
988 | object *ob; |
986 | object *ob; |
989 | int i; |
987 | int i; |
… | |
… | |
999 | CLEAR_FLAG (item, FLAG_IS_A_TEMPLATE); |
997 | CLEAR_FLAG (item, FLAG_IS_A_TEMPLATE); |
1000 | unflag_inv (item, FLAG_IS_A_TEMPLATE); |
998 | unflag_inv (item, FLAG_IS_A_TEMPLATE); |
1001 | } |
999 | } |
1002 | else |
1000 | else |
1003 | { |
1001 | { |
1004 | if (converter->other_arch == NULL) |
1002 | if (!converter->other_arch) |
1005 | { |
1003 | { |
1006 | LOG (llevError, "move_creator: Converter doesn't have other arch set: %s (%s, %d, %d)\n", |
1004 | LOG (llevError, "move_creator: Converter doesn't have other arch set: %s (%s, %d, %d)\n", |
1007 | &converter->name, &converter->map->path, converter->x, converter->y); |
1005 | &converter->name, &converter->map->path, converter->x, converter->y); |
1008 | return -1; |
1006 | return -1; |
1009 | } |
1007 | } |
… | |
… | |
1016 | item->nrof = CONV_NR (converter); |
1014 | item->nrof = CONV_NR (converter); |
1017 | |
1015 | |
1018 | if (nr) |
1016 | if (nr) |
1019 | item->nrof *= nr; |
1017 | item->nrof *= nr; |
1020 | |
1018 | |
|
|
1019 | fprintf (stderr, "outnrof %lld\n", sint64(item->nrof));//D |
|
|
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 < item->nrof * item->value) |
1023 | else if (price_in < sint64 (item->nrof) * item->value) |
1024 | { |
1024 | { |
1025 | LOG (llevDebug, "converter output price higher than input: %s at %s (%d, %d) in value %d, out value %d for %s\n", |
1025 | LOG (llevDebug, "converter output price higher than input: %s at %s (%d, %d) in value %d, out value %d for %s\n", |
1026 | &converter->name, &converter->map->path, converter->x, converter->y, price_in, item->nrof * item->value, &item->name); |
1026 | &converter->name, &converter->map->path, converter->x, converter->y, price_in, item->nrof * item->value, &item->name); |
1027 | /** |
1027 | /** |
1028 | * elmex: we are going to let the game continue, as the mapcreator |
1028 | * elmex: we are going to let the game continue, as the mapcreator |