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 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> |
… | |
… | |
33 | * offer a range of prices around it such that the maximum price is always one |
33 | * offer a range of prices around it such that the maximum price is always one |
34 | * therefore making this number higher, makes specialisation less effective. |
34 | * therefore making this number higher, makes specialisation less effective. |
35 | * setting this value above 1 or to a negative value would have interesting, |
35 | * setting this value above 1 or to a negative value would have interesting, |
36 | * (though not useful) effects. |
36 | * (though not useful) effects. |
37 | */ |
37 | */ |
38 | #define SPECIALISATION_EFFECT 0.5 |
38 | #define SPECIALISATION_EFFECT .5 |
39 | |
39 | |
40 | /* price a shopkeeper will give someone they neither like nor dislike */ |
40 | // price a shopkeeper will give someone that is not of their race |
41 | #define NEUTRAL_RATIO 0.8 |
41 | #define DISLIKE_RATIO 0.8 |
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 |
… | |
… | |
786 | { |
783 | { |
787 | int count = 0; |
784 | int count = 0; |
788 | archetype *at = 0; |
785 | archetype *at = 0; |
789 | object *pouch = 0, *tmp = 0; |
786 | object *pouch = 0, *tmp = 0; |
790 | |
787 | |
791 | for (count = 0; coins[count] != NULL; count++) |
788 | for (count = 0; coins[count]; count++) |
792 | { |
789 | { |
793 | at = archetype::find (coins[count]); |
790 | at = archetype::find (coins[count]); |
794 | |
791 | |
795 | if (at == NULL) |
792 | if (at == NULL) |
796 | LOG (llevError, "Could not find %s archetype\n", coins[count]); |
793 | LOG (llevError, "Could not find %s archetype\n", coins[count]); |
… | |
… | |
842 | /* elmex: this is for the bank plugin :( */ |
839 | /* elmex: this is for the bank plugin :( */ |
843 | sint64 |
840 | sint64 |
844 | pay_player_arch (object *pl, const char *arch, sint64 amount) |
841 | pay_player_arch (object *pl, const char *arch, sint64 amount) |
845 | { |
842 | { |
846 | archetype *at = archetype::find (arch); |
843 | archetype *at = archetype::find (arch); |
847 | object *tmp = NULL; |
|
|
848 | |
844 | |
849 | if (at == NULL) |
845 | if (!at) |
850 | return 0; |
846 | return 0; |
851 | |
847 | |
852 | if (amount > 0) |
848 | if (amount > 0) |
853 | { |
849 | { |
854 | tmp = arch_to_object (at); |
850 | object *tmp = arch_to_object (at); |
855 | tmp->nrof = amount; |
851 | tmp->nrof = amount; |
856 | tmp = insert_ob_in_ob (tmp, pl); |
852 | tmp = insert_ob_in_ob (tmp, pl); |
857 | esrv_send_item (pl, tmp); |
853 | esrv_send_item (pl, tmp); |
858 | esrv_send_item (pl, pl); |
854 | esrv_send_item (pl, pl); |
859 | } |
855 | } |
… | |
… | |
909 | change_exp (pl, extra_gain / 10, "bargaining", SK_EXP_NONE); |
905 | change_exp (pl, extra_gain / 10, "bargaining", SK_EXP_NONE); |
910 | |
906 | |
911 | pay_player (pl, amount); |
907 | pay_player (pl, amount); |
912 | |
908 | |
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)); |
909 | 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)); |
|
|
910 | pl->play_sound (sound_find ("shop_sell")); |
914 | |
911 | |
915 | SET_FLAG (op, FLAG_UNPAID); |
912 | SET_FLAG (op, FLAG_UNPAID); |
916 | identify (op); |
913 | identify (op); |
917 | } |
914 | } |
918 | |
915 | |
919 | |
|
|
920 | /* returns a double that is the ratio of the price that a shop will offer for |
916 | /* 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, |
917 | * item based on the shops specialisation. Does not take account of greed, |
922 | * returned value is between (2*SPECIALISATION_EFFECT-1) and 1 and in any |
918 | * returned value is between SPECIALISATION_EFFECT and 1. |
923 | * event is never less than 0.1 (calling functions divide by it) |
|
|
924 | */ |
919 | */ |
925 | static double |
920 | static double |
926 | shop_specialisation_ratio (const object *item, const maptile *map) |
921 | shop_specialisation_ratio (const object *item, const maptile *map) |
927 | { |
922 | { |
928 | shopitems *items = map->shopitems; |
923 | shopitems *items = map->shopitems; |
929 | double ratio = SPECIALISATION_EFFECT, likedness = 0.001; |
924 | double likedness = 0.; |
930 | int i; |
925 | int i; |
931 | |
926 | |
932 | if (item == NULL) |
927 | if (item == NULL) |
933 | { |
928 | { |
934 | LOG (llevError, "shop_specialisation_ratio: passed a NULL item for map %s\n", &map->path); |
929 | LOG (llevError, "shop_specialisation_ratio: passed a NULL item for map %s\n", &map->path); |
… | |
… | |
940 | LOG (llevError, "shop_specialisation_ratio: passed an item with an invalid type\n"); |
935 | LOG (llevError, "shop_specialisation_ratio: passed an item with an invalid type\n"); |
941 | /* |
936 | /* |
942 | * I'm not really sure what the /right/ thing to do here is, these types of |
937 | * I'm not really sure what the /right/ thing to do here is, these types of |
943 | * item shouldn't exist anyway, but returning the ratio is probably the best bet.." |
938 | * item shouldn't exist anyway, but returning the ratio is probably the best bet.." |
944 | */ |
939 | */ |
945 | return ratio; |
940 | return SPECIALISATION_EFFECT; |
946 | } |
941 | } |
947 | |
942 | |
948 | if (map->shopitems) |
943 | if (map->shopitems) |
949 | { |
944 | { |
950 | for (i = 0; i < items[0].index; i++) |
945 | for (i = 0; i < items[0].index; i++) |
… | |
… | |
962 | { |
957 | { |
963 | LOG (llevDebug, "shop_specialisation ratio: item type %d on map %s is below -100%%\n", item->type, &map->path); |
958 | LOG (llevDebug, "shop_specialisation ratio: item type %d on map %s is below -100%%\n", item->type, &map->path); |
964 | likedness = -1.0; |
959 | likedness = -1.0; |
965 | } |
960 | } |
966 | |
961 | |
967 | ratio = ratio + (1.0 - ratio) * likedness; |
962 | return lerp (likedness, -1., 1., SPECIALISATION_EFFECT, 1.); |
968 | |
|
|
969 | if (ratio <= 0.1) |
|
|
970 | ratio = 0.1; /* if the ratio were much lower than this, we would get silly prices */ |
|
|
971 | |
|
|
972 | return ratio; |
|
|
973 | } |
963 | } |
974 | |
964 | |
975 | /*returns the greed of the shop on map, or 1 if it isn't specified. */ |
965 | /*returns the greed of the shop on map, or 1 if it isn't specified. */ |
976 | static double |
966 | static double |
977 | shop_greed (const maptile *map) |
967 | shop_greed (const maptile *map) |
978 | { |
968 | { |
979 | double greed = 1.0; |
|
|
980 | |
|
|
981 | if (map->shopgreed) |
|
|
982 | return map->shopgreed; |
969 | return map->shopgreed |
983 | return greed; |
970 | ? map->shopgreed |
|
|
971 | : 1.; |
984 | } |
972 | } |
985 | |
973 | |
986 | /* Returns a double based on how much the shopkeeper approves of the player. |
974 | /* Returns a double based on how much the shopkeeper approves of the player. |
987 | * this is based on the race of the shopkeeper and that of the player. |
975 | * this is based on the race of the shopkeeper and that of the player. |
988 | */ |
976 | */ |
989 | double |
977 | double |
990 | shopkeeper_approval (const maptile *map, const object *player) |
978 | shopkeeper_approval (const maptile *map, const object *player) |
991 | { |
979 | { |
992 | double approval = 1.0; |
980 | return map->shoprace && player->race != map->shoprace |
993 | |
981 | ? DISLIKE_RATIO |
994 | if (map->shoprace) |
982 | : 1.; |
995 | { |
|
|
996 | approval = NEUTRAL_RATIO; |
|
|
997 | if (player->race && !strcmp (player->race, map->shoprace)) |
|
|
998 | approval = 1.0; |
|
|
999 | } |
|
|
1000 | |
|
|
1001 | return approval; |
|
|
1002 | } |
983 | } |
1003 | |
984 | |
1004 | /* limit the value of items based on the wealth of the shop. If the item is close |
985 | /* limit the value of items based on the wealth of the shop. If the item is close |
1005 | * to the maximum value a shop will offer, we start to reduce it, if the item is |
986 | * to the maximum value a shop will offer, we start to reduce it, if the item is |
1006 | * below the minimum value the shop is prepared to trade in, then we don't |
987 | * below the minimum value the shop is prepared to trade in, then we don't |
… | |
… | |
1283 | return false; |
1264 | return false; |
1284 | |
1265 | |
1285 | return is_in_shop (o->map, o->x, o->y); |
1266 | return is_in_shop (o->map, o->x, o->y); |
1286 | } |
1267 | } |
1287 | |
1268 | |
1288 | /* elmex: this function checks whether we are in a shop or not */ |
1269 | /* elmex: this function checks whether we are in a shop or not |
|
|
1270 | - change 2007-11-26: enhanced the O(n) case by stopping at the first |
|
|
1271 | floor tile. this possibly will make map bugs where shopfloors are above |
|
|
1272 | floors more obvious. |
|
|
1273 | */ |
|
|
1274 | |
1289 | bool |
1275 | bool |
1290 | is_in_shop (maptile *map, int x, int y) |
1276 | is_in_shop (maptile *map, int x, int y) |
1291 | { |
1277 | { |
1292 | for (object *floor = GET_MAP_OB (map, x, y); floor; floor = floor->above) |
1278 | for (object *floor = GET_MAP_OB (map, x, y); floor; floor = floor->above) |
|
|
1279 | if (QUERY_FLAG (floor, FLAG_IS_FLOOR)) |
1293 | if (floor->type == SHOP_FLOOR) |
1280 | return floor->type == SHOP_FLOOR; |
1294 | return true; |
|
|
1295 | |
|
|
1296 | return false; |
1281 | return false; |
1297 | } |
1282 | } |
|
|
1283 | |