ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/apply.C
(Generate patch)

Comparing deliantra/server/server/apply.C (file contents):
Revision 1.141 by root, Sun Apr 13 01:36:06 2008 UTC vs.
Revision 1.142 by root, Sun Apr 13 20:21:50 2008 UTC

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 */
935int 930static int
936convert_item (object *item, object *converter) 931convert_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 ();
995 CLEAR_FLAG (item, FLAG_IS_A_TEMPLATE); 999 CLEAR_FLAG (item, FLAG_IS_A_TEMPLATE);
996 unflag_inv (item, FLAG_IS_A_TEMPLATE); 1000 unflag_inv (item, FLAG_IS_A_TEMPLATE);
997 } 1001 }
998 else 1002 else
999 { 1003 {
1000 if (!converter->other_arch) 1004 if (!conv_to)
1001 { 1005 {
1002 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",
1003 &converter->name, &converter->map->path, converter->x, converter->y); 1007 &converter->name, &converter->map->path, converter->x, converter->y);
1004 return -1; 1008 return -1;
1005 } 1009 }
1006 1010
1007 item = object_create_arch (converter->other_arch); 1011 item = object_create_arch (conv_to);
1008 fix_generated_item (item, converter, 0, 0, GT_MINIMAL); 1012 fix_generated_item (item, converter, 0, 0, GT_MINIMAL);
1009 } 1013 }
1010 1014
1011 if (CONV_NR (converter)) 1015 if (give)
1012 item->nrof = CONV_NR (converter); 1016 item->nrof = give;
1013 1017
1014 if (nr) 1018 if (nr)
1015 item->nrof *= nr; 1019 item->nrof *= nr;
1016 1020
1017 if (is_in_shop (converter)) 1021 if (is_in_shop (converter))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines