1 | /* |
1 | /* |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT 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 | * Crossfire TRT 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 |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
… | |
… | |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * |
20 | * |
21 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
22 | */ |
23 | |
23 | |
24 | #include <global.h> |
24 | #include <global.h> |
25 | #include <spells.h> |
25 | #include <spells.h> |
26 | #include <skills.h> |
26 | #include <skills.h> |
… | |
… | |
42 | |
42 | |
43 | static void pay_from_container (object *pl, object *pouch, sint64 &to_pay); |
43 | static void pay_from_container (object *pl, object *pouch, sint64 &to_pay); |
44 | static sint64 value_limit (sint64 val, int quantity, const object *who, int isshop); |
44 | static sint64 value_limit (sint64 val, int quantity, const object *who, int isshop); |
45 | static double shop_specialisation_ratio (const object *item, const maptile *map); |
45 | static double shop_specialisation_ratio (const object *item, const maptile *map); |
46 | static double shop_greed (const maptile *map); |
46 | static double shop_greed (const maptile *map); |
47 | |
|
|
48 | #define NUM_COINS 4 /* number of coin types */ |
|
|
49 | static const char *const coins[] = { "royalty", "platinacoin", "goldcoin", "silvercoin", NULL }; |
|
|
50 | |
47 | |
51 | /* Added F_TRUE flag to define.h to mean that the price should not |
48 | /* Added F_TRUE flag to define.h to mean that the price should not |
52 | * be adjusted by players charisma. With F_TRUE, it returns the amount |
49 | * be adjusted by players charisma. With F_TRUE, it returns the amount |
53 | * that the item is worth, if it was sold, but unadjusted by charisma. |
50 | * that the item is worth, if it was sold, but unadjusted by charisma. |
54 | * This is needed for alchemy, to to determine what value of gold nuggets |
51 | * This is needed for alchemy, to to determine what value of gold nuggets |
… | |
… | |
586 | { |
583 | { |
587 | // This should not happen, but if it does, just merge the two. |
584 | // This should not happen, but if it does, just merge the two. |
588 | if (coin_objs [i]) |
585 | if (coin_objs [i]) |
589 | { |
586 | { |
590 | LOG (llevError, "%s has two money entries of (%s)\n", &pouch->name, coins[NUM_COINS - 1 - i]); |
587 | LOG (llevError, "%s has two money entries of (%s)\n", &pouch->name, coins[NUM_COINS - 1 - i]); |
591 | tmp->remove (); |
|
|
592 | coin_objs[i]->nrof += tmp->nrof; |
588 | coin_objs[i]->nrof += tmp->nrof; |
593 | esrv_del_item (pl->contr, tmp->count); |
|
|
594 | tmp->destroy (); |
589 | tmp->destroy (); |
595 | } |
590 | } |
596 | else |
591 | else |
597 | { |
592 | { |
598 | tmp->remove (); |
593 | tmp->remove (); |
599 | |
|
|
600 | if (pouch->type == PLAYER) |
|
|
601 | esrv_del_item (pl->contr, tmp->count); |
|
|
602 | |
|
|
603 | coin_objs[i] = tmp; |
594 | coin_objs[i] = tmp; |
604 | } |
595 | } |
605 | |
596 | |
606 | break; |
597 | break; |
607 | } |
598 | } |
… | |
… | |
649 | } |
640 | } |
650 | |
641 | |
651 | for (i = 0; i < NUM_COINS; i++) |
642 | for (i = 0; i < NUM_COINS; i++) |
652 | { |
643 | { |
653 | if (coin_objs[i]->nrof) |
644 | if (coin_objs[i]->nrof) |
654 | { |
|
|
655 | object *tmp = insert_ob_in_ob (coin_objs[i], pouch); |
645 | insert_ob_in_ob (coin_objs [i], pouch); |
656 | |
|
|
657 | esrv_send_item (pl, tmp); |
|
|
658 | esrv_send_item (pl, pouch); |
|
|
659 | |
|
|
660 | if (pl != pouch) |
|
|
661 | esrv_update_item (UPD_WEIGHT, pl, pouch); |
|
|
662 | |
|
|
663 | if (pl->type != PLAYER) |
|
|
664 | esrv_send_item (pl, pl); |
|
|
665 | } |
|
|
666 | else |
646 | else |
667 | coin_objs[i]->destroy (); |
647 | coin_objs[i]->destroy (); |
668 | } |
648 | } |
669 | } |
649 | } |
670 | |
650 | |
… | |
… | |
741 | SET_FLAG (op, FLAG_UNPAID); |
721 | SET_FLAG (op, FLAG_UNPAID); |
742 | return 0; |
722 | return 0; |
743 | } |
723 | } |
744 | else |
724 | else |
745 | { |
725 | { |
746 | object *tmp; |
|
|
747 | |
|
|
748 | CLEAR_FLAG (op, FLAG_UNPAID); |
726 | CLEAR_FLAG (op, FLAG_UNPAID); |
749 | CLEAR_FLAG (op, FLAG_PLAYER_SOLD); |
727 | CLEAR_FLAG (op, FLAG_PLAYER_SOLD); |
750 | new_draw_info_format (NDI_UNIQUE, 0, op, "You paid %s for %s.", buf, query_name (op)); |
728 | new_draw_info_format (NDI_UNIQUE, 0, op, "You paid %s for %s.", buf, query_name (op)); |
751 | tmp = merge_ob (op, NULL); |
|
|
752 | |
729 | |
753 | if (pl->type == PLAYER) |
730 | if (!merge_ob (op, op->env->inv)) |
754 | { |
|
|
755 | if (tmp) |
|
|
756 | { /* it was merged */ |
|
|
757 | esrv_del_item (pl->contr, op->count); |
|
|
758 | op = tmp; |
|
|
759 | } |
|
|
760 | |
|
|
761 | esrv_send_item (pl, op); |
731 | esrv_update_item (UPD_FLAGS, pl, op); |
762 | } |
|
|
763 | |
732 | |
764 | goto next_item; |
733 | goto next_item; |
765 | } |
734 | } |
766 | } |
735 | } |
767 | } |
736 | } |
… | |
… | |
786 | { |
755 | { |
787 | int count = 0; |
756 | int count = 0; |
788 | archetype *at = 0; |
757 | archetype *at = 0; |
789 | object *pouch = 0, *tmp = 0; |
758 | object *pouch = 0, *tmp = 0; |
790 | |
759 | |
791 | for (count = 0; coins[count] != NULL; count++) |
760 | for (count = 0; coins[count]; count++) |
792 | { |
761 | { |
793 | at = archetype::find (coins[count]); |
762 | at = archetype::find (coins[count]); |
794 | |
763 | |
795 | if (at == NULL) |
764 | if (at == NULL) |
796 | LOG (llevError, "Could not find %s archetype\n", coins[count]); |
765 | LOG (llevError, "Could not find %s archetype\n", coins[count]); |
… | |
… | |
809 | if (n > 0 && (!pouch->weight_limit || pouch->carrying + w <= pouch->weight_limit)) |
778 | if (n > 0 && (!pouch->weight_limit || pouch->carrying + w <= pouch->weight_limit)) |
810 | { |
779 | { |
811 | if (pouch->weight_limit && (pouch->weight_limit - pouch->carrying) / w < n) |
780 | if (pouch->weight_limit && (pouch->weight_limit - pouch->carrying) / w < n) |
812 | n = (pouch->weight_limit - pouch->carrying) / w; |
781 | n = (pouch->weight_limit - pouch->carrying) / w; |
813 | |
782 | |
814 | tmp = arch_to_object (at); |
783 | object *tmp = arch_to_object (at); |
815 | tmp->nrof = n; |
784 | tmp->nrof = n; |
816 | amount -= tmp->nrof * tmp->value; |
785 | amount -= tmp->nrof * tmp->value; |
817 | tmp = insert_ob_in_ob (tmp, pouch); |
786 | pouch->insert (tmp); |
818 | esrv_send_item (pl, tmp); |
|
|
819 | esrv_send_item (pl, pouch); |
|
|
820 | esrv_update_item (UPD_WEIGHT, pl, pouch); |
|
|
821 | esrv_send_item (pl, pl); |
|
|
822 | } |
787 | } |
823 | } |
788 | } |
824 | } |
789 | } |
825 | |
790 | |
826 | if (amount / at->value > 0) |
791 | if (amount / at->value > 0) |
827 | { |
792 | { |
828 | tmp = arch_to_object (at); |
793 | object *tmp = arch_to_object (at); |
829 | tmp->nrof = amount / tmp->value; |
794 | tmp->nrof = amount / tmp->value; |
830 | amount -= tmp->nrof * tmp->value; |
795 | amount -= tmp->nrof * tmp->value; |
831 | tmp = insert_ob_in_ob (tmp, pl); |
796 | pl->insert (tmp); |
832 | esrv_send_item (pl, tmp); |
|
|
833 | esrv_send_item (pl, pl); |
|
|
834 | } |
797 | } |
835 | } |
798 | } |
836 | } |
799 | } |
837 | |
800 | |
838 | if (amount != 0) |
801 | if (amount != 0) |
… | |
… | |
842 | /* elmex: this is for the bank plugin :( */ |
805 | /* elmex: this is for the bank plugin :( */ |
843 | sint64 |
806 | sint64 |
844 | pay_player_arch (object *pl, const char *arch, sint64 amount) |
807 | pay_player_arch (object *pl, const char *arch, sint64 amount) |
845 | { |
808 | { |
846 | archetype *at = archetype::find (arch); |
809 | archetype *at = archetype::find (arch); |
847 | object *tmp = NULL; |
|
|
848 | |
810 | |
849 | if (at == NULL) |
811 | if (!at) |
850 | return 0; |
812 | return 0; |
851 | |
813 | |
852 | if (amount > 0) |
814 | if (amount > 0) |
853 | { |
815 | { |
854 | tmp = arch_to_object (at); |
816 | object *tmp = arch_to_object (at); |
855 | tmp->nrof = amount; |
817 | tmp->nrof = amount; |
856 | tmp = insert_ob_in_ob (tmp, pl); |
818 | insert_ob_in_ob (tmp, pl); |
857 | esrv_send_item (pl, tmp); |
|
|
858 | esrv_send_item (pl, pl); |
|
|
859 | } |
819 | } |
860 | |
820 | |
861 | return 1; |
821 | return 1; |
862 | } |
822 | } |
863 | |
823 | |
… | |
… | |
909 | change_exp (pl, extra_gain / 10, "bargaining", SK_EXP_NONE); |
869 | change_exp (pl, extra_gain / 10, "bargaining", SK_EXP_NONE); |
910 | |
870 | |
911 | pay_player (pl, amount); |
871 | pay_player (pl, amount); |
912 | |
872 | |
913 | 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)); |
873 | 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)); |
|
|
874 | pl->play_sound (sound_find ("shop_sell")); |
914 | |
875 | |
915 | SET_FLAG (op, FLAG_UNPAID); |
876 | SET_FLAG (op, FLAG_UNPAID); |
916 | identify (op); |
877 | identify (op); |
917 | } |
878 | } |
918 | |
|
|
919 | |
879 | |
920 | /* returns a double that is the ratio of the price that a shop will offer for |
880 | /* returns a double that is the ratio of the price that a shop will offer for |
921 | * item based on the shops specialisation. Does not take account of greed, |
881 | * item based on the shops specialisation. Does not take account of greed, |
922 | * returned value is between SPECIALISATION_EFFECT and 1. |
882 | * returned value is between SPECIALISATION_EFFECT and 1. |
923 | */ |
883 | */ |
… | |
… | |
1268 | return false; |
1228 | return false; |
1269 | |
1229 | |
1270 | return is_in_shop (o->map, o->x, o->y); |
1230 | return is_in_shop (o->map, o->x, o->y); |
1271 | } |
1231 | } |
1272 | |
1232 | |
1273 | /* elmex: this function checks whether we are in a shop or not */ |
1233 | /* elmex: this function checks whether we are in a shop or not |
|
|
1234 | - change 2007-11-26: enhanced the O(n) case by stopping at the first |
|
|
1235 | floor tile. this possibly will make map bugs where shopfloors are above |
|
|
1236 | floors more obvious. |
|
|
1237 | */ |
|
|
1238 | |
1274 | bool |
1239 | bool |
1275 | is_in_shop (maptile *map, int x, int y) |
1240 | is_in_shop (maptile *map, int x, int y) |
1276 | { |
1241 | { |
1277 | for (object *floor = GET_MAP_OB (map, x, y); floor; floor = floor->above) |
1242 | for (object *floor = GET_MAP_OB (map, x, y); floor; floor = floor->above) |
|
|
1243 | if (QUERY_FLAG (floor, FLAG_IS_FLOOR)) |
1278 | if (floor->type == SHOP_FLOOR) |
1244 | return floor->type == SHOP_FLOOR; |
1279 | return true; |
|
|
1280 | |
|
|
1281 | return false; |
1245 | return false; |
1282 | } |
1246 | } |
|
|
1247 | |