… | |
… | |
43 | /* price a shopkeeper will give someone they neither like nor dislike */ |
43 | /* price a shopkeeper will give someone they neither like nor dislike */ |
44 | #define NEUTRAL_RATIO 0.8 |
44 | #define NEUTRAL_RATIO 0.8 |
45 | |
45 | |
46 | 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); |
47 | 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); |
48 | static double shop_specialisation_ratio (const object *item, const mapstruct *map); |
48 | static double shop_specialisation_ratio (const object *item, const maptile *map); |
49 | static double shop_greed (const mapstruct *map); |
49 | static double shop_greed (const maptile *map); |
50 | |
50 | |
51 | #define NUM_COINS 4 /* number of coin types */ |
51 | #define NUM_COINS 4 /* number of coin types */ |
52 | static const char *const coins[] = { "royalty", "platinacoin", "goldcoin", "silvercoin", NULL }; |
52 | static const char *const coins[] = { "royalty", "platinacoin", "goldcoin", "silvercoin", NULL }; |
53 | |
53 | |
54 | /* 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 |
… | |
… | |
590 | { |
590 | { |
591 | // 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. |
592 | if (coin_objs [i]) |
592 | if (coin_objs [i]) |
593 | { |
593 | { |
594 | 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]); |
595 | remove_ob (tmp); |
595 | tmp->remove (); |
596 | coin_objs[i]->nrof += tmp->nrof; |
596 | coin_objs[i]->nrof += tmp->nrof; |
597 | esrv_del_item (pl->contr, tmp->count); |
597 | esrv_del_item (pl->contr, tmp->count); |
598 | free_object (tmp); |
598 | tmp->destroy (); |
599 | } |
599 | } |
600 | else |
600 | else |
601 | { |
601 | { |
602 | remove_ob (tmp); |
602 | tmp->remove (); |
603 | |
603 | |
604 | if (pouch->type == PLAYER) |
604 | if (pouch->type == PLAYER) |
605 | esrv_del_item (pl->contr, tmp->count); |
605 | esrv_del_item (pl->contr, tmp->count); |
606 | |
606 | |
607 | coin_objs[i] = tmp; |
607 | coin_objs[i] = tmp; |
… | |
… | |
666 | |
666 | |
667 | if (pl->type != PLAYER) |
667 | if (pl->type != PLAYER) |
668 | esrv_send_item (pl, pl); |
668 | esrv_send_item (pl, pl); |
669 | } |
669 | } |
670 | else |
670 | else |
671 | free_object (coin_objs[i]); |
671 | coin_objs[i]->destroy (); |
672 | } |
672 | } |
673 | } |
673 | } |
674 | |
674 | |
675 | /* 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 |
676 | * 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. |
… | |
… | |
681 | can_pay (object *pl) |
681 | can_pay (object *pl) |
682 | { |
682 | { |
683 | int unpaid_count = 0; |
683 | int unpaid_count = 0; |
684 | sint64 unpaid_price = 0; |
684 | sint64 unpaid_price = 0; |
685 | sint64 player_wealth = query_money (pl); |
685 | sint64 player_wealth = query_money (pl); |
686 | object *item; |
|
|
687 | |
686 | |
688 | if (!pl || pl->type != PLAYER) |
687 | if (!pl || pl->type != PLAYER) |
689 | { |
688 | { |
690 | 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"); |
691 | return 0; |
690 | return 0; |
… | |
… | |
839 | } |
838 | } |
840 | } |
839 | } |
841 | } |
840 | } |
842 | |
841 | |
843 | if (amount != 0) |
842 | if (amount != 0) |
844 | #ifndef WIN32 |
|
|
845 | 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); |
846 | #else |
|
|
847 | LOG (llevError, "Warning - payment in pay_player () not zero: %I64u\n", amount); |
|
|
848 | #endif |
|
|
849 | } |
844 | } |
850 | |
845 | |
851 | /* elmex: this is for the bank plugin :( */ |
846 | /* elmex: this is for the bank plugin :( */ |
852 | sint64 |
847 | sint64 |
853 | pay_player_arch (object *pl, const char *arch, sint64 amount) |
848 | pay_player_arch (object *pl, const char *arch, sint64 amount) |
… | |
… | |
930 | * 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, |
931 | * 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 |
932 | * 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) |
933 | */ |
928 | */ |
934 | static double |
929 | static double |
935 | shop_specialisation_ratio (const object *item, const mapstruct *map) |
930 | shop_specialisation_ratio (const object *item, const maptile *map) |
936 | { |
931 | { |
937 | shopitems *items = map->shopitems; |
932 | shopitems *items = map->shopitems; |
938 | double ratio = SPECIALISATION_EFFECT, likedness = 0.001; |
933 | double ratio = SPECIALISATION_EFFECT, likedness = 0.001; |
939 | int i; |
934 | int i; |
940 | |
935 | |
… | |
… | |
981 | return ratio; |
976 | return ratio; |
982 | } |
977 | } |
983 | |
978 | |
984 | /*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. */ |
985 | static double |
980 | static double |
986 | shop_greed (const mapstruct *map) |
981 | shop_greed (const maptile *map) |
987 | { |
982 | { |
988 | double greed = 1.0; |
983 | double greed = 1.0; |
989 | |
984 | |
990 | if (map->shopgreed) |
985 | if (map->shopgreed) |
991 | return map->shopgreed; |
986 | return map->shopgreed; |
… | |
… | |
994 | |
989 | |
995 | /* 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. |
996 | * 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. |
997 | */ |
992 | */ |
998 | double |
993 | double |
999 | shopkeeper_approval (const mapstruct *map, const object *player) |
994 | shopkeeper_approval (const maptile *map, const object *player) |
1000 | { |
995 | { |
1001 | double approval = 1.0; |
996 | double approval = 1.0; |
1002 | |
997 | |
1003 | if (map->shoprace) |
998 | if (map->shoprace) |
1004 | { |
999 | { |
… | |
… | |
1019 | */ |
1014 | */ |
1020 | static sint64 |
1015 | static sint64 |
1021 | value_limit (sint64 val, int quantity, const object *who, int isshop) |
1016 | value_limit (sint64 val, int quantity, const object *who, int isshop) |
1022 | { |
1017 | { |
1023 | sint64 newval, unit_price, tmpshopmax; |
1018 | sint64 newval, unit_price, tmpshopmax; |
1024 | mapstruct *map; |
1019 | maptile *map; |
1025 | |
1020 | |
1026 | unit_price = val / quantity; |
1021 | unit_price = val / quantity; |
1027 | |
1022 | |
1028 | if (!isshop || !who) |
1023 | if (!isshop || !who) |
1029 | { |
1024 | { |
… | |
… | |
1059 | |
1054 | |
1060 | /* 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. */ |
1061 | int |
1056 | int |
1062 | describe_shop (const object *op) |
1057 | describe_shop (const object *op) |
1063 | { |
1058 | { |
1064 | mapstruct *map = op->map; |
1059 | maptile *map = op->map; |
1065 | |
1060 | |
1066 | /*shopitems *items=map->shopitems; */ |
1061 | /*shopitems *items=map->shopitems; */ |
1067 | int pos = 0, i; |
1062 | int pos = 0, i; |
1068 | double opinion = 0; |
1063 | double opinion = 0; |
1069 | char tmp[MAX_BUF] = "\0"; |
1064 | char tmp[MAX_BUF] = "\0"; |
… | |
… | |
1183 | case RING: |
1178 | case RING: |
1184 | case AMULET: |
1179 | case AMULET: |
1185 | case BRACERS: |
1180 | case BRACERS: |
1186 | case GIRDLE: |
1181 | case GIRDLE: |
1187 | sprintf (buf, "%s %s", query_base_name (tmp, 0), describe_item (tmp, NULL)); |
1182 | sprintf (buf, "%s %s", query_base_name (tmp, 0), describe_item (tmp, NULL)); |
1188 | items[*numitems].item_sort = strdup_local (buf); |
1183 | items[*numitems].item_sort = strdup (buf); |
1189 | sprintf (buf, "%s %s", query_name (tmp), describe_item (tmp, NULL)); |
1184 | sprintf (buf, "%s %s", query_name (tmp), describe_item (tmp, NULL)); |
1190 | items[*numitems].item_real = strdup_local (buf); |
1185 | items[*numitems].item_real = strdup (buf); |
1191 | (*numitems)++; |
1186 | (*numitems)++; |
1192 | break; |
1187 | break; |
1193 | #endif |
1188 | #endif |
1194 | |
1189 | |
1195 | default: |
1190 | default: |
1196 | items[*numitems].item_sort = strdup_local (query_base_name (tmp, 0)); |
1191 | items[*numitems].item_sort = strdup (query_base_name (tmp, 0)); |
1197 | items[*numitems].item_real = strdup_local (query_base_name (tmp, 1)); |
1192 | items[*numitems].item_real = strdup (query_base_name (tmp, 1)); |
1198 | (*numitems)++; |
1193 | (*numitems)++; |
1199 | break; |
1194 | break; |
1200 | } |
1195 | } |
1201 | SET_FLAG (tmp, FLAG_UNPAID); |
1196 | SET_FLAG (tmp, FLAG_UNPAID); |
1202 | } |
1197 | } |
… | |
… | |
1295 | return is_in_shop (o->map, o->x, o->y); |
1290 | return is_in_shop (o->map, o->x, o->y); |
1296 | } |
1291 | } |
1297 | |
1292 | |
1298 | /* 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 */ |
1299 | bool |
1294 | bool |
1300 | is_in_shop (mapstruct *map, int x, int y) |
1295 | is_in_shop (maptile *map, int x, int y) |
1301 | { |
1296 | { |
1302 | 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) |
1303 | if (floor->type == SHOP_FLOOR) |
1298 | if (floor->type == SHOP_FLOOR) |
1304 | return true; |
1299 | return true; |
1305 | |
1300 | |