1 | |
|
|
2 | /* |
|
|
3 | * static char *rcsid_shop_c = |
|
|
4 | * "$Id: shop.C,v 1.14 2006/09/12 19:20:08 root Exp $"; |
|
|
5 | */ |
|
|
6 | |
|
|
7 | /* |
1 | /* |
8 | CrossFire, A Multiplayer game for X-windows |
2 | CrossFire, A Multiplayer game for X-windows |
9 | |
3 | |
10 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
11 | Copyright (C) 1992 Frank Tore Johansen |
5 | Copyright (C) 1992 Frank Tore Johansen |
… | |
… | |
22 | |
16 | |
23 | You should have received a copy of the GNU General Public License |
17 | You should have received a copy of the GNU General Public License |
24 | along with this program; if not, write to the Free Software |
18 | along with this program; if not, write to the Free Software |
25 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
26 | |
20 | |
27 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
28 | */ |
22 | */ |
29 | |
23 | |
30 | #include <global.h> |
24 | #include <global.h> |
31 | #include <spells.h> |
25 | #include <spells.h> |
32 | #include <skills.h> |
26 | #include <skills.h> |
… | |
… | |
49 | /* price a shopkeeper will give someone they neither like nor dislike */ |
43 | /* price a shopkeeper will give someone they neither like nor dislike */ |
50 | #define NEUTRAL_RATIO 0.8 |
44 | #define NEUTRAL_RATIO 0.8 |
51 | |
45 | |
52 | static void pay_from_container (object *pl, object *pouch, sint64 &to_pay); |
46 | static void pay_from_container (object *pl, object *pouch, sint64 &to_pay); |
53 | static sint64 value_limit (sint64 val, int quantity, const object *who, int isshop); |
47 | static sint64 value_limit (sint64 val, int quantity, const object *who, int isshop); |
54 | static double shop_specialisation_ratio (const object *item, const mapstruct *map); |
48 | static double shop_specialisation_ratio (const object *item, const maptile *map); |
55 | static double shop_greed (const mapstruct *map); |
49 | static double shop_greed (const maptile *map); |
56 | |
50 | |
57 | #define NUM_COINS 4 /* number of coin types */ |
51 | #define NUM_COINS 4 /* number of coin types */ |
58 | static const char *const coins[] = { "royalty", "platinacoin", "goldcoin", "silvercoin", NULL }; |
52 | static const char *const coins[] = { "royalty", "platinacoin", "goldcoin", "silvercoin", NULL }; |
59 | |
53 | |
60 | /* Added F_TRUE flag to define.h to mean that the price should not |
54 | /* Added F_TRUE flag to define.h to mean that the price should not |
… | |
… | |
334 | |
328 | |
335 | do |
329 | do |
336 | { |
330 | { |
337 | if (coins[*cointype] == NULL) |
331 | if (coins[*cointype] == NULL) |
338 | return NULL; |
332 | return NULL; |
339 | coin = find_archetype (coins[*cointype]); |
333 | coin = archetype::find (coins[*cointype]); |
340 | if (coin == NULL) |
334 | if (coin == NULL) |
341 | return NULL; |
335 | return NULL; |
342 | *cointype += 1; |
336 | *cointype += 1; |
343 | } |
337 | } |
344 | while (coin->clone.value > c); |
338 | while (coin->clone.value > c); |
… | |
… | |
596 | { |
590 | { |
597 | // This should not happen, but if it does, just merge the two. |
591 | // This should not happen, but if it does, just merge the two. |
598 | if (coin_objs [i]) |
592 | if (coin_objs [i]) |
599 | { |
593 | { |
600 | LOG (llevError, "%s has two money entries of (%s)\n", &pouch->name, coins[NUM_COINS - 1 - i]); |
594 | LOG (llevError, "%s has two money entries of (%s)\n", &pouch->name, coins[NUM_COINS - 1 - i]); |
601 | remove_ob (tmp); |
595 | tmp->remove (); |
602 | coin_objs[i]->nrof += tmp->nrof; |
596 | coin_objs[i]->nrof += tmp->nrof; |
603 | esrv_del_item (pl->contr, tmp->count); |
597 | esrv_del_item (pl->contr, tmp->count); |
604 | free_object (tmp); |
598 | tmp->destroy (); |
605 | } |
599 | } |
606 | else |
600 | else |
607 | { |
601 | { |
608 | remove_ob (tmp); |
602 | tmp->remove (); |
609 | |
603 | |
610 | if (pouch->type == PLAYER) |
604 | if (pouch->type == PLAYER) |
611 | esrv_del_item (pl->contr, tmp->count); |
605 | esrv_del_item (pl->contr, tmp->count); |
612 | |
606 | |
613 | coin_objs[i] = tmp; |
607 | coin_objs[i] = tmp; |
… | |
… | |
625 | /* Fill in any gaps in the coin_objs array - needed to make change. */ |
619 | /* Fill in any gaps in the coin_objs array - needed to make change. */ |
626 | /* Note that the coin_objs array goes from least value to greatest value */ |
620 | /* Note that the coin_objs array goes from least value to greatest value */ |
627 | for (i = 0; i < NUM_COINS; i++) |
621 | for (i = 0; i < NUM_COINS; i++) |
628 | if (!coin_objs[i]) |
622 | if (!coin_objs[i]) |
629 | { |
623 | { |
630 | at = find_archetype (coins[NUM_COINS - 1 - i]); |
624 | at = archetype::find (coins[NUM_COINS - 1 - i]); |
631 | |
625 | |
632 | if (at == NULL) |
626 | if (at == NULL) |
633 | LOG (llevError, "Could not find %s archetype\n", coins[NUM_COINS - 1 - i]); |
627 | LOG (llevError, "Could not find %s archetype\n", coins[NUM_COINS - 1 - i]); |
634 | |
628 | |
635 | coin_objs[i] = arch_to_object (at); |
629 | coin_objs[i] = arch_to_object (at); |
… | |
… | |
672 | |
666 | |
673 | if (pl->type != PLAYER) |
667 | if (pl->type != PLAYER) |
674 | esrv_send_item (pl, pl); |
668 | esrv_send_item (pl, pl); |
675 | } |
669 | } |
676 | else |
670 | else |
677 | free_object (coin_objs[i]); |
671 | coin_objs[i]->destroy (); |
678 | } |
672 | } |
679 | } |
673 | } |
680 | |
674 | |
681 | /* Checks all unpaid items in op's inventory, adds up all the money they |
675 | /* Checks all unpaid items in op's inventory, adds up all the money they |
682 | * have, and checks that they can actually afford what they want to buy. |
676 | * have, and checks that they can actually afford what they want to buy. |
… | |
… | |
687 | can_pay (object *pl) |
681 | can_pay (object *pl) |
688 | { |
682 | { |
689 | int unpaid_count = 0; |
683 | int unpaid_count = 0; |
690 | sint64 unpaid_price = 0; |
684 | sint64 unpaid_price = 0; |
691 | sint64 player_wealth = query_money (pl); |
685 | sint64 player_wealth = query_money (pl); |
692 | object *item; |
|
|
693 | |
686 | |
694 | if (!pl || pl->type != PLAYER) |
687 | if (!pl || pl->type != PLAYER) |
695 | { |
688 | { |
696 | LOG (llevError, "can_pay(): called against something that isn't a player\n"); |
689 | LOG (llevError, "can_pay(): called against something that isn't a player\n"); |
697 | return 0; |
690 | return 0; |
… | |
… | |
753 | return 0; |
746 | return 0; |
754 | } |
747 | } |
755 | else |
748 | else |
756 | { |
749 | { |
757 | object *tmp; |
750 | object *tmp; |
758 | tag_t c = op->count; |
|
|
759 | |
751 | |
760 | CLEAR_FLAG (op, FLAG_UNPAID); |
752 | CLEAR_FLAG (op, FLAG_UNPAID); |
761 | CLEAR_FLAG (op, FLAG_PLAYER_SOLD); |
753 | CLEAR_FLAG (op, FLAG_PLAYER_SOLD); |
762 | new_draw_info_format (NDI_UNIQUE, 0, op, "You paid %s for %s.", buf, query_name (op)); |
754 | new_draw_info_format (NDI_UNIQUE, 0, op, "You paid %s for %s.", buf, query_name (op)); |
763 | tmp = merge_ob (op, NULL); |
755 | tmp = merge_ob (op, NULL); |
764 | |
756 | |
765 | if (pl->type == PLAYER) |
757 | if (pl->type == PLAYER) |
766 | { |
758 | { |
767 | if (tmp) |
759 | if (tmp) |
768 | { /* it was merged */ |
760 | { /* it was merged */ |
769 | esrv_del_item (pl->contr, c); |
761 | esrv_del_item (pl->contr, op->count); |
770 | op = tmp; |
762 | op = tmp; |
771 | } |
763 | } |
772 | |
764 | |
773 | esrv_send_item (pl, op); |
765 | esrv_send_item (pl, op); |
774 | } |
766 | } |
… | |
… | |
800 | archetype *at = 0; |
792 | archetype *at = 0; |
801 | object *pouch = 0, *tmp = 0; |
793 | object *pouch = 0, *tmp = 0; |
802 | |
794 | |
803 | for (count = 0; coins[count] != NULL; count++) |
795 | for (count = 0; coins[count] != NULL; count++) |
804 | { |
796 | { |
805 | at = find_archetype (coins[count]); |
797 | at = archetype::find (coins[count]); |
806 | |
798 | |
807 | if (at == NULL) |
799 | if (at == NULL) |
808 | LOG (llevError, "Could not find %s archetype\n", coins[count]); |
800 | LOG (llevError, "Could not find %s archetype\n", coins[count]); |
809 | else if ((amount / at->clone.value) > 0) |
801 | else if ((amount / at->clone.value) > 0) |
810 | { |
802 | { |
… | |
… | |
846 | } |
838 | } |
847 | } |
839 | } |
848 | } |
840 | } |
849 | |
841 | |
850 | if (amount != 0) |
842 | if (amount != 0) |
851 | #ifndef WIN32 |
|
|
852 | LOG (llevError, "Warning - payment in pay_player () not zero: %llu\n", amount); |
843 | LOG (llevError, "Warning - payment in pay_player () not zero: %llu\n", amount); |
853 | #else |
|
|
854 | LOG (llevError, "Warning - payment in pay_player () not zero: %I64u\n", amount); |
|
|
855 | #endif |
|
|
856 | } |
844 | } |
857 | |
845 | |
858 | /* elmex: this is for the bank plugin :( */ |
846 | /* elmex: this is for the bank plugin :( */ |
859 | sint64 |
847 | sint64 |
860 | pay_player_arch (object *pl, const char *arch, sint64 amount) |
848 | pay_player_arch (object *pl, const char *arch, sint64 amount) |
861 | { |
849 | { |
862 | archetype *at = find_archetype (arch); |
850 | archetype *at = archetype::find (arch); |
863 | object *tmp = NULL; |
851 | object *tmp = NULL; |
864 | |
852 | |
865 | if (at == NULL) |
853 | if (at == NULL) |
866 | return 0; |
854 | return 0; |
867 | |
855 | |
… | |
… | |
937 | * item based on the shops specialisation. Does not take account of greed, |
925 | * item based on the shops specialisation. Does not take account of greed, |
938 | * returned value is between (2*SPECIALISATION_EFFECT-1) and 1 and in any |
926 | * returned value is between (2*SPECIALISATION_EFFECT-1) and 1 and in any |
939 | * event is never less than 0.1 (calling functions divide by it) |
927 | * event is never less than 0.1 (calling functions divide by it) |
940 | */ |
928 | */ |
941 | static double |
929 | static double |
942 | shop_specialisation_ratio (const object *item, const mapstruct *map) |
930 | shop_specialisation_ratio (const object *item, const maptile *map) |
943 | { |
931 | { |
944 | shopitems *items = map->shopitems; |
932 | shopitems *items = map->shopitems; |
945 | double ratio = SPECIALISATION_EFFECT, likedness = 0.001; |
933 | double ratio = SPECIALISATION_EFFECT, likedness = 0.001; |
946 | int i; |
934 | int i; |
947 | |
935 | |
… | |
… | |
988 | return ratio; |
976 | return ratio; |
989 | } |
977 | } |
990 | |
978 | |
991 | /*returns the greed of the shop on map, or 1 if it isn't specified. */ |
979 | /*returns the greed of the shop on map, or 1 if it isn't specified. */ |
992 | static double |
980 | static double |
993 | shop_greed (const mapstruct *map) |
981 | shop_greed (const maptile *map) |
994 | { |
982 | { |
995 | double greed = 1.0; |
983 | double greed = 1.0; |
996 | |
984 | |
997 | if (map->shopgreed) |
985 | if (map->shopgreed) |
998 | return map->shopgreed; |
986 | return map->shopgreed; |
… | |
… | |
1001 | |
989 | |
1002 | /* Returns a double based on how much the shopkeeper approves of the player. |
990 | /* Returns a double based on how much the shopkeeper approves of the player. |
1003 | * this is based on the race of the shopkeeper and that of the player. |
991 | * this is based on the race of the shopkeeper and that of the player. |
1004 | */ |
992 | */ |
1005 | double |
993 | double |
1006 | shopkeeper_approval (const mapstruct *map, const object *player) |
994 | shopkeeper_approval (const maptile *map, const object *player) |
1007 | { |
995 | { |
1008 | double approval = 1.0; |
996 | double approval = 1.0; |
1009 | |
997 | |
1010 | if (map->shoprace) |
998 | if (map->shoprace) |
1011 | { |
999 | { |
… | |
… | |
1026 | */ |
1014 | */ |
1027 | static sint64 |
1015 | static sint64 |
1028 | value_limit (sint64 val, int quantity, const object *who, int isshop) |
1016 | value_limit (sint64 val, int quantity, const object *who, int isshop) |
1029 | { |
1017 | { |
1030 | sint64 newval, unit_price, tmpshopmax; |
1018 | sint64 newval, unit_price, tmpshopmax; |
1031 | mapstruct *map; |
1019 | maptile *map; |
1032 | |
1020 | |
1033 | unit_price = val / quantity; |
1021 | unit_price = val / quantity; |
1034 | |
1022 | |
1035 | if (!isshop || !who) |
1023 | if (!isshop || !who) |
1036 | { |
1024 | { |
… | |
… | |
1066 | |
1054 | |
1067 | /* gives a desciption of the shop on their current map to the player op. */ |
1055 | /* gives a desciption of the shop on their current map to the player op. */ |
1068 | int |
1056 | int |
1069 | describe_shop (const object *op) |
1057 | describe_shop (const object *op) |
1070 | { |
1058 | { |
1071 | mapstruct *map = op->map; |
1059 | maptile *map = op->map; |
1072 | |
1060 | |
1073 | /*shopitems *items=map->shopitems; */ |
1061 | /*shopitems *items=map->shopitems; */ |
1074 | int pos = 0, i; |
1062 | int pos = 0, i; |
1075 | double opinion = 0; |
1063 | double opinion = 0; |
1076 | char tmp[MAX_BUF] = "\0"; |
1064 | char tmp[MAX_BUF] = "\0"; |
… | |
… | |
1302 | return is_in_shop (o->map, o->x, o->y); |
1290 | return is_in_shop (o->map, o->x, o->y); |
1303 | } |
1291 | } |
1304 | |
1292 | |
1305 | /* elmex: this function checks whether we are in a shop or not */ |
1293 | /* elmex: this function checks whether we are in a shop or not */ |
1306 | bool |
1294 | bool |
1307 | is_in_shop (mapstruct *map, int x, int y) |
1295 | is_in_shop (maptile *map, int x, int y) |
1308 | { |
1296 | { |
1309 | for (object *floor = get_map_ob (map, x, y); floor; floor = floor->above) |
1297 | for (object *floor = get_map_ob (map, x, y); floor; floor = floor->above) |
1310 | if (floor->type == SHOP_FLOOR) |
1298 | if (floor->type == SHOP_FLOOR) |
1311 | return true; |
1299 | return true; |
1312 | |
1300 | |