1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
… | |
… | |
206 | * AND Cha = 30 will get optimal price. |
206 | * AND Cha = 30 will get optimal price. |
207 | * Thus charisma will never get useless. |
207 | * Thus charisma will never get useless. |
208 | * -b.e. edler@heydernet.de |
208 | * -b.e. edler@heydernet.de |
209 | */ |
209 | */ |
210 | |
210 | |
211 | if (who != NULL && who->type == PLAYER) |
211 | if (who && who->type == PLAYER) |
212 | { |
212 | { |
213 | int lev_bargain = 0; |
213 | int lev_bargain = 0; |
214 | int lev_identify = 0; |
214 | int lev_identify = 0; |
215 | int idskill1 = 0; |
|
|
216 | int idskill2 = 0; |
|
|
217 | const typedata *tmptype; |
|
|
218 | |
|
|
219 | tmptype = get_typedata (tmp->type); |
|
|
220 | |
215 | |
221 | if (find_skill_by_number (who, SK_BARGAINING)) |
216 | if (find_skill_by_number (who, SK_BARGAINING)) |
222 | lev_bargain = find_skill_by_number (who, SK_BARGAINING)->level; |
217 | lev_bargain = find_skill_by_number (who, SK_BARGAINING)->level; |
223 | |
218 | |
224 | if (tmptype) |
219 | if (const typedata *tmptype = get_typedata (tmp->type)) |
225 | { |
220 | { |
226 | idskill1 = tmptype->identifyskill; |
221 | if (int idskill1 = tmptype->identifyskill) |
227 | |
|
|
228 | if (idskill1) |
|
|
229 | { |
222 | { |
230 | idskill2 = tmptype->identifyskill2; |
223 | int idskill2 = tmptype->identifyskill2; |
231 | |
224 | |
232 | if (find_skill_by_number (who, idskill1)) |
225 | if (find_skill_by_number (who, idskill1)) |
233 | lev_identify = find_skill_by_number (who, idskill1)->level; |
226 | lev_identify = find_skill_by_number (who, idskill1)->level; |
234 | |
227 | |
235 | if (idskill2 && find_skill_by_number (who, idskill2)) |
228 | if (idskill2 && find_skill_by_number (who, idskill2)) |
236 | lev_identify += find_skill_by_number (who, idskill2)->level; |
229 | lev_identify += find_skill_by_number (who, idskill2)->level; |
237 | } |
230 | } |
238 | } |
231 | } |
239 | else |
|
|
240 | LOG (llevError, "Query_cost: item %s hasn't got a valid type\n", tmp->debug_desc ()); |
|
|
241 | |
232 | |
242 | /* ratio determines how much of the price modification |
233 | /* ratio determines how much of the price modification |
243 | * will come from the basic stat charisma |
234 | * will come from the basic stat charisma |
244 | * the rest will come from the level in bargaining skill |
235 | * the rest will come from the level in bargaining skill |
245 | */ |
236 | */ |
… | |
… | |
418 | |
409 | |
419 | if (coin == NULL) |
410 | if (coin == NULL) |
420 | return "nothing"; |
411 | return "nothing"; |
421 | |
412 | |
422 | num = real_value / coin->value; |
413 | num = real_value / coin->value; |
|
|
414 | |
423 | if (num == 1) |
415 | if (num == 1) |
424 | sprintf (buf, "about one %s", &coin->object::name); |
416 | sprintf (buf, "about one %s", &coin->object::name); |
425 | else if (num < 5) |
417 | else if (num < 5) |
426 | sprintf (buf, "a few %s", &coin->object::name_pl); |
418 | sprintf (buf, "a few %s", &coin->object::name_pl); |
427 | else if (num < 10) |
419 | else if (num < 10) |
… | |
… | |
432 | sprintf (buf, "lots of %s", &coin->object::name_pl); |
424 | sprintf (buf, "lots of %s", &coin->object::name_pl); |
433 | else if (num < 1000) |
425 | else if (num < 1000) |
434 | sprintf (buf, "a great many %s", &coin->object::name_pl); |
426 | sprintf (buf, "a great many %s", &coin->object::name_pl); |
435 | else |
427 | else |
436 | sprintf (buf, "a vast quantity of %s", &coin->object::name_pl); |
428 | sprintf (buf, "a vast quantity of %s", &coin->object::name_pl); |
|
|
429 | |
437 | return buf; |
430 | return buf; |
438 | } |
431 | } |
439 | } |
432 | } |
440 | } |
433 | } |
441 | |
434 | |
… | |
… | |
583 | { |
576 | { |
584 | // This should not happen, but if it does, just merge the two. |
577 | // This should not happen, but if it does, just merge the two. |
585 | if (coin_objs [i]) |
578 | if (coin_objs [i]) |
586 | { |
579 | { |
587 | LOG (llevError, "%s has two money entries of (%s)\n", &pouch->name, coins[NUM_COINS - 1 - i]); |
580 | LOG (llevError, "%s has two money entries of (%s)\n", &pouch->name, coins[NUM_COINS - 1 - i]); |
588 | tmp->remove (); |
|
|
589 | coin_objs[i]->nrof += tmp->nrof; |
581 | coin_objs[i]->nrof += tmp->nrof; |
590 | esrv_del_item (pl->contr, tmp->count); |
|
|
591 | tmp->destroy (); |
582 | tmp->destroy (); |
592 | } |
583 | } |
593 | else |
584 | else |
594 | { |
585 | { |
595 | tmp->remove (); |
586 | tmp->remove (); |
596 | |
|
|
597 | if (pouch->type == PLAYER) |
|
|
598 | esrv_del_item (pl->contr, tmp->count); |
|
|
599 | |
|
|
600 | coin_objs[i] = tmp; |
587 | coin_objs[i] = tmp; |
601 | } |
588 | } |
602 | |
589 | |
603 | break; |
590 | break; |
604 | } |
591 | } |
… | |
… | |
646 | } |
633 | } |
647 | |
634 | |
648 | for (i = 0; i < NUM_COINS; i++) |
635 | for (i = 0; i < NUM_COINS; i++) |
649 | { |
636 | { |
650 | if (coin_objs[i]->nrof) |
637 | if (coin_objs[i]->nrof) |
651 | { |
|
|
652 | object *tmp = insert_ob_in_ob (coin_objs[i], pouch); |
638 | insert_ob_in_ob (coin_objs [i], pouch); |
653 | |
|
|
654 | esrv_send_item (pl, tmp); |
|
|
655 | esrv_send_item (pl, pouch); |
|
|
656 | |
|
|
657 | if (pl != pouch) |
|
|
658 | esrv_update_item (UPD_WEIGHT, pl, pouch); |
|
|
659 | |
|
|
660 | if (pl->type != PLAYER) |
|
|
661 | esrv_send_item (pl, pl); |
|
|
662 | } |
|
|
663 | else |
639 | else |
664 | coin_objs[i]->destroy (); |
640 | coin_objs[i]->destroy (); |
665 | } |
641 | } |
666 | } |
642 | } |
667 | |
643 | |
… | |
… | |
738 | SET_FLAG (op, FLAG_UNPAID); |
714 | SET_FLAG (op, FLAG_UNPAID); |
739 | return 0; |
715 | return 0; |
740 | } |
716 | } |
741 | else |
717 | else |
742 | { |
718 | { |
743 | object *tmp; |
|
|
744 | |
|
|
745 | CLEAR_FLAG (op, FLAG_UNPAID); |
719 | CLEAR_FLAG (op, FLAG_UNPAID); |
746 | CLEAR_FLAG (op, FLAG_PLAYER_SOLD); |
720 | CLEAR_FLAG (op, FLAG_PLAYER_SOLD); |
747 | new_draw_info_format (NDI_UNIQUE, 0, op, "You paid %s for %s.", buf, query_name (op)); |
721 | new_draw_info_format (NDI_UNIQUE, 0, op, "You paid %s for %s.", buf, query_name (op)); |
748 | tmp = merge_ob (op, NULL); |
|
|
749 | |
722 | |
750 | if (pl->type == PLAYER) |
723 | if (!merge_ob (op, op->env->inv)) |
751 | { |
|
|
752 | if (tmp) |
|
|
753 | { /* it was merged */ |
|
|
754 | esrv_del_item (pl->contr, op->count); |
|
|
755 | op = tmp; |
|
|
756 | } |
|
|
757 | |
|
|
758 | esrv_send_item (pl, op); |
724 | esrv_update_item (UPD_FLAGS, pl, op); |
759 | } |
|
|
760 | |
725 | |
761 | goto next_item; |
726 | goto next_item; |
762 | } |
727 | } |
763 | } |
728 | } |
764 | } |
729 | } |
… | |
… | |
806 | if (n > 0 && (!pouch->weight_limit || pouch->carrying + w <= pouch->weight_limit)) |
771 | if (n > 0 && (!pouch->weight_limit || pouch->carrying + w <= pouch->weight_limit)) |
807 | { |
772 | { |
808 | if (pouch->weight_limit && (pouch->weight_limit - pouch->carrying) / w < n) |
773 | if (pouch->weight_limit && (pouch->weight_limit - pouch->carrying) / w < n) |
809 | n = (pouch->weight_limit - pouch->carrying) / w; |
774 | n = (pouch->weight_limit - pouch->carrying) / w; |
810 | |
775 | |
811 | tmp = arch_to_object (at); |
776 | object *tmp = arch_to_object (at); |
812 | tmp->nrof = n; |
777 | tmp->nrof = n; |
813 | amount -= tmp->nrof * tmp->value; |
778 | amount -= tmp->nrof * tmp->value; |
814 | tmp = insert_ob_in_ob (tmp, pouch); |
779 | pouch->insert (tmp); |
815 | esrv_send_item (pl, tmp); |
|
|
816 | esrv_send_item (pl, pouch); |
|
|
817 | esrv_update_item (UPD_WEIGHT, pl, pouch); |
|
|
818 | esrv_send_item (pl, pl); |
|
|
819 | } |
780 | } |
820 | } |
781 | } |
821 | } |
782 | } |
822 | |
783 | |
823 | if (amount / at->value > 0) |
784 | if (amount / at->value > 0) |
824 | { |
785 | { |
825 | tmp = arch_to_object (at); |
786 | object *tmp = arch_to_object (at); |
826 | tmp->nrof = amount / tmp->value; |
787 | tmp->nrof = amount / tmp->value; |
827 | amount -= tmp->nrof * tmp->value; |
788 | amount -= tmp->nrof * tmp->value; |
828 | tmp = insert_ob_in_ob (tmp, pl); |
789 | pl->insert (tmp); |
829 | esrv_send_item (pl, tmp); |
|
|
830 | esrv_send_item (pl, pl); |
|
|
831 | } |
790 | } |
832 | } |
791 | } |
833 | } |
792 | } |
834 | |
793 | |
835 | if (amount != 0) |
794 | if (amount != 0) |
… | |
… | |
839 | /* elmex: this is for the bank plugin :( */ |
798 | /* elmex: this is for the bank plugin :( */ |
840 | sint64 |
799 | sint64 |
841 | pay_player_arch (object *pl, const char *arch, sint64 amount) |
800 | pay_player_arch (object *pl, const char *arch, sint64 amount) |
842 | { |
801 | { |
843 | archetype *at = archetype::find (arch); |
802 | archetype *at = archetype::find (arch); |
844 | object *tmp = NULL; |
|
|
845 | |
803 | |
846 | if (at == NULL) |
804 | if (!at) |
847 | return 0; |
805 | return 0; |
848 | |
806 | |
849 | if (amount > 0) |
807 | if (amount > 0) |
850 | { |
808 | { |
851 | tmp = arch_to_object (at); |
809 | object *tmp = arch_to_object (at); |
852 | tmp->nrof = amount; |
810 | tmp->nrof = amount; |
853 | tmp = insert_ob_in_ob (tmp, pl); |
811 | insert_ob_in_ob (tmp, pl); |
854 | esrv_send_item (pl, tmp); |
|
|
855 | esrv_send_item (pl, pl); |
|
|
856 | } |
812 | } |
857 | |
813 | |
858 | return 1; |
814 | return 1; |
859 | } |
815 | } |
860 | |
816 | |
… | |
… | |
863 | * buy item. |
819 | * buy item. |
864 | * |
820 | * |
865 | * Modified to fill available race: gold containers before dumping |
821 | * Modified to fill available race: gold containers before dumping |
866 | * remaining coins in character's inventory. |
822 | * remaining coins in character's inventory. |
867 | */ |
823 | */ |
868 | void |
824 | bool |
869 | sell_item (object *op, object *pl) |
825 | sell_item (object *op, object *pl) |
870 | { |
826 | { |
871 | sint64 amount = query_cost (op, pl, F_SELL | F_SHOP), extra_gain; |
827 | sint64 amount = query_cost (op, pl, F_SELL | F_SHOP), extra_gain; |
872 | |
828 | |
873 | if (pl == NULL || pl->type != PLAYER) |
829 | if (pl == NULL || pl->type != PLAYER) |
874 | { |
830 | { |
875 | LOG (llevDebug, "Object other than player tried to sell something.\n"); |
831 | LOG (llevDebug, "Object other than player tried to sell something.\n"); |
876 | return; |
832 | return false; |
877 | } |
833 | } |
878 | |
834 | |
879 | op->custom_name = 0; |
835 | op->custom_name = 0; |
880 | |
836 | |
881 | if (!amount) |
837 | if (!amount) |
882 | { |
838 | { |
883 | new_draw_info_format (NDI_UNIQUE, 0, pl, "We're not interested in %s.", query_name (op)); |
839 | new_draw_info_format (NDI_UNIQUE, 0, pl, "We're not interested in %s.", |
884 | |
840 | query_name (op)); |
885 | /* Even if the character doesn't get anything for it, it may still be |
841 | // elmex: change: the player now gets the item back if the shop is not |
886 | * worth something. If so, make it unpaid |
842 | // interested in it. |
887 | */ |
|
|
888 | if (op->value) |
|
|
889 | { |
|
|
890 | SET_FLAG (op, FLAG_UNPAID); |
|
|
891 | SET_FLAG (op, FLAG_PLAYER_SOLD); |
|
|
892 | } |
|
|
893 | |
|
|
894 | identify (op); |
|
|
895 | return; |
843 | return false; |
896 | } |
844 | } |
897 | |
845 | |
898 | /* We compare the price with the one for a player |
846 | /* We compare the price with the one for a player |
899 | * without bargaining skill. |
847 | * without bargaining skill. |
900 | * This determins the amount of exp (if any) gained for bargaining. |
848 | * This determins the amount of exp (if any) gained for bargaining. |
… | |
… | |
905 | if (extra_gain > 0) |
853 | if (extra_gain > 0) |
906 | change_exp (pl, extra_gain / 10, "bargaining", SK_EXP_NONE); |
854 | change_exp (pl, extra_gain / 10, "bargaining", SK_EXP_NONE); |
907 | |
855 | |
908 | pay_player (pl, amount); |
856 | pay_player (pl, amount); |
909 | |
857 | |
910 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You receive %s for %s.", query_cost_string (op, pl, F_SELL | F_SHOP), query_name (op)); |
858 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You receive %s for %s.", |
|
|
859 | query_cost_string (op, pl, F_SELL | F_SHOP), query_name (op)); |
911 | pl->play_sound (sound_find ("shop_sell")); |
860 | pl->play_sound (sound_find ("shop_sell")); |
912 | |
861 | |
913 | SET_FLAG (op, FLAG_UNPAID); |
862 | SET_FLAG (op, FLAG_UNPAID); |
914 | identify (op); |
863 | identify (op); |
|
|
864 | |
|
|
865 | return true; |
915 | } |
866 | } |
916 | |
867 | |
917 | /* returns a double that is the ratio of the price that a shop will offer for |
868 | /* returns a double that is the ratio of the price that a shop will offer for |
918 | * item based on the shops specialisation. Does not take account of greed, |
869 | * item based on the shops specialisation. Does not take account of greed, |
919 | * returned value is between SPECIALISATION_EFFECT and 1. |
870 | * returned value is between SPECIALISATION_EFFECT and 1. |
… | |
… | |
1117 | { |
1068 | { |
1118 | shopinv *s1 = (shopinv *) a1, *s2 = (shopinv *) a2; |
1069 | shopinv *s1 = (shopinv *) a1, *s2 = (shopinv *) a2; |
1119 | |
1070 | |
1120 | if (s1->type < s2->type) |
1071 | if (s1->type < s2->type) |
1121 | return -1; |
1072 | return -1; |
|
|
1073 | |
1122 | if (s1->type > s2->type) |
1074 | if (s1->type > s2->type) |
1123 | return 1; |
1075 | return 1; |
1124 | |
1076 | |
1125 | /* the type is the same (what atoi gets), so do a strcasecmp to sort |
1077 | /* the type is the same (what atoi gets), so do a strcasecmp to sort |
1126 | * via alphabetical order |
1078 | * via alphabetical order |
… | |
… | |
1176 | |
1128 | |
1177 | void |
1129 | void |
1178 | shop_listing (object *sign, object *op) |
1130 | shop_listing (object *sign, object *op) |
1179 | { |
1131 | { |
1180 | int i, j, numitems = 0, numallocated = 0, x1, x2, y1, y2; |
1132 | int i, j, numitems = 0, numallocated = 0, x1, x2, y1, y2; |
1181 | const char *shop_coords = get_ob_key_value (sign, "shop_coords"); |
1133 | const char *shop_coords = sign->kv (shstr_shop_coords); |
1182 | object *stack; |
1134 | object *stack; |
1183 | shopinv *items; |
1135 | shopinv *items; |
1184 | |
1136 | |
1185 | /* Should never happen, but just in case a monster does apply a sign */ |
1137 | /* Should never happen, but just in case a monster does apply a sign */ |
1186 | if (op->type != PLAYER) |
1138 | if (op->type != PLAYER) |
… | |
… | |
1259 | |
1211 | |
1260 | /* elmex: this function checks whether the object is in a shop */ |
1212 | /* elmex: this function checks whether the object is in a shop */ |
1261 | bool |
1213 | bool |
1262 | is_in_shop (object *o) |
1214 | is_in_shop (object *o) |
1263 | { |
1215 | { |
1264 | if (!o->map) |
1216 | if (!o->is_on_map ()) |
1265 | return false; |
1217 | return false; |
1266 | |
1218 | |
1267 | return is_in_shop (o->map, o->x, o->y); |
1219 | return is_in_shop (o->map, o->x, o->y); |
1268 | } |
1220 | } |
1269 | |
1221 | |
… | |
… | |
1277 | is_in_shop (maptile *map, int x, int y) |
1229 | is_in_shop (maptile *map, int x, int y) |
1278 | { |
1230 | { |
1279 | for (object *floor = GET_MAP_OB (map, x, y); floor; floor = floor->above) |
1231 | for (object *floor = GET_MAP_OB (map, x, y); floor; floor = floor->above) |
1280 | if (QUERY_FLAG (floor, FLAG_IS_FLOOR)) |
1232 | if (QUERY_FLAG (floor, FLAG_IS_FLOOR)) |
1281 | return floor->type == SHOP_FLOOR; |
1233 | return floor->type == SHOP_FLOOR; |
|
|
1234 | |
1282 | return false; |
1235 | return false; |
1283 | } |
1236 | } |
1284 | |
1237 | |