1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game |
3 | |
3 | * |
|
|
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | |
7 | * |
7 | This program is free software; you can redistribute it and/or modify |
8 | * This program is free software; you can redistribute it and/or modify |
8 | 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 |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. |
11 | * (at your option) any later version. |
11 | |
12 | * |
12 | 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, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
16 | |
17 | * |
17 | 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 |
18 | along with this program; if not, write to the Free Software |
19 | * along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | |
21 | * |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | #include <global.h> |
25 | #include <global.h> |
25 | #include <spells.h> |
26 | #include <spells.h> |
26 | #include <skills.h> |
27 | #include <skills.h> |
27 | #include <living.h> |
28 | #include <living.h> |
28 | #include <newclient.h> |
|
|
29 | #ifndef __CEXTRACT__ |
|
|
30 | # include <sproto.h> |
29 | #include <sproto.h> |
31 | #endif |
|
|
32 | #include <math.h> |
30 | #include <math.h> |
33 | |
31 | |
34 | /* this is a measure of how effective store specialisation is. A general store |
32 | /* this is a measure of how effective store specialisation is. A general store |
35 | * will offer this proportion of the 'maximum' price, a specialised store will |
33 | * will offer this proportion of the 'maximum' price, a specialised store will |
36 | * offer a range of prices around it such that the maximum price is always one |
34 | * offer a range of prices around it such that the maximum price is always one |
… | |
… | |
43 | /* price a shopkeeper will give someone they neither like nor dislike */ |
41 | /* price a shopkeeper will give someone they neither like nor dislike */ |
44 | #define NEUTRAL_RATIO 0.8 |
42 | #define NEUTRAL_RATIO 0.8 |
45 | |
43 | |
46 | static void pay_from_container (object *pl, object *pouch, sint64 &to_pay); |
44 | 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); |
45 | 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); |
46 | static double shop_specialisation_ratio (const object *item, const maptile *map); |
49 | static double shop_greed (const mapstruct *map); |
47 | static double shop_greed (const maptile *map); |
50 | |
48 | |
51 | #define NUM_COINS 4 /* number of coin types */ |
49 | #define NUM_COINS 4 /* number of coin types */ |
52 | static const char *const coins[] = { "royalty", "platinacoin", "goldcoin", "silvercoin", NULL }; |
50 | static const char *const coins[] = { "royalty", "platinacoin", "goldcoin", "silvercoin", NULL }; |
53 | |
51 | |
54 | /* Added F_TRUE flag to define.h to mean that the price should not |
52 | /* Added F_TRUE flag to define.h to mean that the price should not |
… | |
… | |
250 | * the rest will come from the level in bargaining skill |
248 | * the rest will come from the level in bargaining skill |
251 | */ |
249 | */ |
252 | const double cha_ratio = 0.40; |
250 | const double cha_ratio = 0.40; |
253 | |
251 | |
254 | diff = no_bargain ? 1.0 : 1. - pow (lev_bargain / (double) settings.max_level, 0.25); |
252 | diff = no_bargain ? 1.0 : 1. - pow (lev_bargain / (double) settings.max_level, 0.25); |
255 | |
|
|
256 | diff = (1. - cha_ratio) * diff + cha_ratio * (cha_bonus[who->stats.Cha] - 1.) / (cha_bonus[who->stats.Cha] + 1.); |
253 | diff = (1. - cha_ratio) * diff + cha_ratio * (cha_bonus[who->stats.Cha] - 1.) / (cha_bonus[who->stats.Cha] + 1.); |
257 | |
|
|
258 | diff = .02 + (.80 - .02) * diff; |
254 | diff = .02 + (.80 - .02) * diff; |
259 | |
255 | |
260 | if (flag == F_BUY) |
256 | if (flag == F_BUY) |
261 | val += (val * diff); |
257 | val += val * diff; |
262 | else if (flag == F_SELL) |
258 | else if (flag == F_SELL) |
263 | val -= (val * diff); |
259 | val -= val * diff; |
264 | |
260 | |
265 | // now find a price range. the less good we can judge, the larger the range is |
261 | // now find a price range. the less good we can judge, the larger the range is |
266 | // then the range is adjusted randomly around the correct value |
262 | // then the range is adjusted randomly around the correct value |
267 | if (approximate) |
263 | if (approximate) |
268 | approx_range = sint64 (val / sqrt (lev_identify * 3 + 1)); |
264 | approx_range = sint64 (val / sqrt (lev_identify * 3 + 1)); |
269 | } |
265 | } |
270 | |
266 | |
271 | /* I don't think this should really happen - if it does, it indicates and |
267 | /* I don't think this should really happen - if it does, it indicates and |
272 | * overflow of diff above. That shoudl only happen if |
268 | * overflow of diff above. That should only happen if |
273 | * we are selling objects - in that case, the person just |
269 | * we are selling objects - in that case, the person just |
274 | * gets no money. |
270 | * gets no money. |
275 | */ |
271 | */ |
276 | if ((sint64) val < 0) |
272 | if ((sint64) val < 0) |
277 | val = 0; |
273 | val = 0; |
… | |
… | |
305 | if (QUERY_FLAG (tmp, FLAG_PLAYER_SOLD)) |
301 | if (QUERY_FLAG (tmp, FLAG_PLAYER_SOLD)) |
306 | val = (val * shop_greed (who->map) * shop_specialisation_ratio (tmp, who->map) / shopkeeper_approval (who->map, who)); |
302 | val = (val * shop_greed (who->map) * shop_specialisation_ratio (tmp, who->map) / shopkeeper_approval (who->map, who)); |
307 | else |
303 | else |
308 | val = (val * shop_greed (who->map) / (shop_specialisation_ratio (tmp, who->map) * shopkeeper_approval (who->map, who))); |
304 | val = (val * shop_greed (who->map) / (shop_specialisation_ratio (tmp, who->map) * shopkeeper_approval (who->map, who))); |
309 | } |
305 | } |
|
|
306 | |
310 | /* we will also have an extra 0-5% variation between shops of the same type |
307 | /* we will also have an extra 0-5% variation between shops of the same type |
311 | * for valuable items (below a value of 50 this effect wouldn't be very |
308 | * for valuable items (below a value of 50 this effect wouldn't be very |
312 | * pointful, and could give fun with rounding. |
309 | * pointful, and could give fun with rounding. |
313 | */ |
310 | */ |
314 | if (who->map->path != NULL && val > 50) |
311 | //TODO: why use cosf at all, just % and scale linearly, gives more even distribution |
315 | val = (val + 0.05 * (sint64) val * cos (tmp->count + strlen (who->map->path))); |
312 | if (val > 50) |
|
|
313 | val += float (val) * .05f * cosf ((tmp->uuid.seq & 0xffff) * float (M_PI * 2. / 0x10000)); |
316 | } |
314 | } |
|
|
315 | |
317 | return (sint64) val; |
316 | return (sint64) val; |
318 | } |
317 | } |
319 | |
318 | |
320 | /* Find the coin type that is worth more the 'c'. Starts at the |
319 | /* Find the coin type that is worth more the 'c'. Starts at the |
321 | * cointype placement. |
320 | * cointype placement. |
… | |
… | |
505 | |
504 | |
506 | for (pouch = pl->inv; pouch && to_pay; pouch = pouch->below) |
505 | for (pouch = pl->inv; pouch && to_pay; pouch = pouch->below) |
507 | if (pouch->type == CONTAINER && QUERY_FLAG (pouch, FLAG_APPLIED) && (pouch->race == NULL || strstr (pouch->race, "gold"))) |
506 | if (pouch->type == CONTAINER && QUERY_FLAG (pouch, FLAG_APPLIED) && (pouch->race == NULL || strstr (pouch->race, "gold"))) |
508 | pay_from_container (pl, pouch, to_pay); |
507 | pay_from_container (pl, pouch, to_pay); |
509 | |
508 | |
510 | fix_player (pl); |
509 | pl->update_stats (); |
511 | return 1; |
510 | return 1; |
512 | } |
511 | } |
513 | |
512 | |
514 | /* DAMN: This is now a wrapper for pay_from_container, which is |
513 | /* DAMN: This is now a wrapper for pay_from_container, which is |
515 | * called for the player, then for each active container that can hold |
514 | * called for the player, then for each active container that can hold |
… | |
… | |
542 | |
541 | |
543 | for (pouch = pl->inv; pouch && to_pay; pouch = pouch->below) |
542 | for (pouch = pl->inv; pouch && to_pay; pouch = pouch->below) |
544 | if (pouch->type == CONTAINER && QUERY_FLAG (pouch, FLAG_APPLIED) && (pouch->race == NULL || strstr (pouch->race, "gold"))) |
543 | if (pouch->type == CONTAINER && QUERY_FLAG (pouch, FLAG_APPLIED) && (pouch->race == NULL || strstr (pouch->race, "gold"))) |
545 | pay_from_container (pl, pouch, to_pay); |
544 | pay_from_container (pl, pouch, to_pay); |
546 | |
545 | |
547 | if (settings.real_wiz == FALSE && QUERY_FLAG (pl, FLAG_WAS_WIZ)) |
546 | pl->update_stats (); |
548 | SET_FLAG (op, FLAG_WAS_WIZ); |
|
|
549 | |
547 | |
550 | fix_player (pl); |
|
|
551 | return 1; |
548 | return 1; |
552 | } |
549 | } |
553 | |
550 | |
554 | /* This pays for the item, and takes the proper amount of money off |
551 | /* This pays for the item, and takes the proper amount of money off |
555 | * the player. |
552 | * the player. |
… | |
… | |
590 | { |
587 | { |
591 | // This should not happen, but if it does, just merge the two. |
588 | // This should not happen, but if it does, just merge the two. |
592 | if (coin_objs [i]) |
589 | if (coin_objs [i]) |
593 | { |
590 | { |
594 | LOG (llevError, "%s has two money entries of (%s)\n", &pouch->name, coins[NUM_COINS - 1 - i]); |
591 | LOG (llevError, "%s has two money entries of (%s)\n", &pouch->name, coins[NUM_COINS - 1 - i]); |
595 | remove_ob (tmp); |
592 | tmp->remove (); |
596 | coin_objs[i]->nrof += tmp->nrof; |
593 | coin_objs[i]->nrof += tmp->nrof; |
597 | esrv_del_item (pl->contr, tmp->count); |
594 | esrv_del_item (pl->contr, tmp->count); |
598 | free_object (tmp); |
595 | tmp->destroy (); |
599 | } |
596 | } |
600 | else |
597 | else |
601 | { |
598 | { |
602 | remove_ob (tmp); |
599 | tmp->remove (); |
603 | |
600 | |
604 | if (pouch->type == PLAYER) |
601 | if (pouch->type == PLAYER) |
605 | esrv_del_item (pl->contr, tmp->count); |
602 | esrv_del_item (pl->contr, tmp->count); |
606 | |
603 | |
607 | coin_objs[i] = tmp; |
604 | coin_objs[i] = tmp; |
… | |
… | |
666 | |
663 | |
667 | if (pl->type != PLAYER) |
664 | if (pl->type != PLAYER) |
668 | esrv_send_item (pl, pl); |
665 | esrv_send_item (pl, pl); |
669 | } |
666 | } |
670 | else |
667 | else |
671 | free_object (coin_objs[i]); |
668 | coin_objs[i]->destroy (); |
672 | } |
669 | } |
673 | } |
670 | } |
674 | |
671 | |
675 | /* Checks all unpaid items in op's inventory, adds up all the money they |
672 | /* 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. |
673 | * have, and checks that they can actually afford what they want to buy. |
… | |
… | |
681 | can_pay (object *pl) |
678 | can_pay (object *pl) |
682 | { |
679 | { |
683 | int unpaid_count = 0; |
680 | int unpaid_count = 0; |
684 | sint64 unpaid_price = 0; |
681 | sint64 unpaid_price = 0; |
685 | sint64 player_wealth = query_money (pl); |
682 | sint64 player_wealth = query_money (pl); |
686 | object *item; |
|
|
687 | |
683 | |
688 | if (!pl || pl->type != PLAYER) |
684 | if (!pl || pl->type != PLAYER) |
689 | { |
685 | { |
690 | LOG (llevError, "can_pay(): called against something that isn't a player\n"); |
686 | LOG (llevError, "can_pay(): called against something that isn't a player\n"); |
691 | return 0; |
687 | return 0; |
… | |
… | |
839 | } |
835 | } |
840 | } |
836 | } |
841 | } |
837 | } |
842 | |
838 | |
843 | if (amount != 0) |
839 | if (amount != 0) |
844 | #ifndef WIN32 |
|
|
845 | LOG (llevError, "Warning - payment in pay_player () not zero: %llu\n", amount); |
840 | 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 | } |
841 | } |
850 | |
842 | |
851 | /* elmex: this is for the bank plugin :( */ |
843 | /* elmex: this is for the bank plugin :( */ |
852 | sint64 |
844 | sint64 |
853 | pay_player_arch (object *pl, const char *arch, sint64 amount) |
845 | pay_player_arch (object *pl, const char *arch, sint64 amount) |
… | |
… | |
930 | * item based on the shops specialisation. Does not take account of greed, |
922 | * 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 |
923 | * 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) |
924 | * event is never less than 0.1 (calling functions divide by it) |
933 | */ |
925 | */ |
934 | static double |
926 | static double |
935 | shop_specialisation_ratio (const object *item, const mapstruct *map) |
927 | shop_specialisation_ratio (const object *item, const maptile *map) |
936 | { |
928 | { |
937 | shopitems *items = map->shopitems; |
929 | shopitems *items = map->shopitems; |
938 | double ratio = SPECIALISATION_EFFECT, likedness = 0.001; |
930 | double ratio = SPECIALISATION_EFFECT, likedness = 0.001; |
939 | int i; |
931 | int i; |
940 | |
932 | |
941 | if (item == NULL) |
933 | if (item == NULL) |
942 | { |
934 | { |
943 | LOG (llevError, "shop_specialisation_ratio: passed a NULL item for map %s\n", map->path); |
935 | LOG (llevError, "shop_specialisation_ratio: passed a NULL item for map %s\n", &map->path); |
944 | return 0; |
936 | return 0; |
945 | } |
937 | } |
946 | |
938 | |
947 | if (!item->type) |
939 | if (!item->type) |
948 | { |
940 | { |
… | |
… | |
961 | likedness = items[i].strength / 100.0; |
953 | likedness = items[i].strength / 100.0; |
962 | } |
954 | } |
963 | |
955 | |
964 | if (likedness > 1.0) |
956 | if (likedness > 1.0) |
965 | { /* someone has been rather silly with the map headers. */ |
957 | { /* someone has been rather silly with the map headers. */ |
966 | LOG (llevDebug, "shop_specialisation ratio: item type %d on map %s is above 100%%\n", item->type, map->path); |
958 | LOG (llevDebug, "shop_specialisation ratio: item type %d on map %s is above 100%%\n", item->type, &map->path); |
967 | likedness = 1.0; |
959 | likedness = 1.0; |
968 | } |
960 | } |
969 | |
961 | |
970 | if (likedness < -1.0) |
962 | if (likedness < -1.0) |
971 | { |
963 | { |
972 | LOG (llevDebug, "shop_specialisation ratio: item type %d on map %s is below -100%%\n", item->type, map->path); |
964 | LOG (llevDebug, "shop_specialisation ratio: item type %d on map %s is below -100%%\n", item->type, &map->path); |
973 | likedness = -1.0; |
965 | likedness = -1.0; |
974 | } |
966 | } |
975 | |
967 | |
976 | ratio = ratio + (1.0 - ratio) * likedness; |
968 | ratio = ratio + (1.0 - ratio) * likedness; |
977 | |
969 | |
… | |
… | |
981 | return ratio; |
973 | return ratio; |
982 | } |
974 | } |
983 | |
975 | |
984 | /*returns the greed of the shop on map, or 1 if it isn't specified. */ |
976 | /*returns the greed of the shop on map, or 1 if it isn't specified. */ |
985 | static double |
977 | static double |
986 | shop_greed (const mapstruct *map) |
978 | shop_greed (const maptile *map) |
987 | { |
979 | { |
988 | double greed = 1.0; |
980 | double greed = 1.0; |
989 | |
981 | |
990 | if (map->shopgreed) |
982 | if (map->shopgreed) |
991 | return map->shopgreed; |
983 | return map->shopgreed; |
… | |
… | |
994 | |
986 | |
995 | /* Returns a double based on how much the shopkeeper approves of the player. |
987 | /* 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. |
988 | * this is based on the race of the shopkeeper and that of the player. |
997 | */ |
989 | */ |
998 | double |
990 | double |
999 | shopkeeper_approval (const mapstruct *map, const object *player) |
991 | shopkeeper_approval (const maptile *map, const object *player) |
1000 | { |
992 | { |
1001 | double approval = 1.0; |
993 | double approval = 1.0; |
1002 | |
994 | |
1003 | if (map->shoprace) |
995 | if (map->shoprace) |
1004 | { |
996 | { |
… | |
… | |
1019 | */ |
1011 | */ |
1020 | static sint64 |
1012 | static sint64 |
1021 | value_limit (sint64 val, int quantity, const object *who, int isshop) |
1013 | value_limit (sint64 val, int quantity, const object *who, int isshop) |
1022 | { |
1014 | { |
1023 | sint64 newval, unit_price, tmpshopmax; |
1015 | sint64 newval, unit_price, tmpshopmax; |
1024 | mapstruct *map; |
1016 | maptile *map; |
1025 | |
1017 | |
1026 | unit_price = val / quantity; |
1018 | unit_price = val / quantity; |
1027 | |
1019 | |
1028 | if (!isshop || !who) |
1020 | if (!isshop || !who) |
1029 | { |
1021 | { |
… | |
… | |
1059 | |
1051 | |
1060 | /* gives a desciption of the shop on their current map to the player op. */ |
1052 | /* gives a desciption of the shop on their current map to the player op. */ |
1061 | int |
1053 | int |
1062 | describe_shop (const object *op) |
1054 | describe_shop (const object *op) |
1063 | { |
1055 | { |
1064 | mapstruct *map = op->map; |
1056 | maptile *map = op->map; |
1065 | |
1057 | |
1066 | /*shopitems *items=map->shopitems; */ |
1058 | /*shopitems *items=map->shopitems; */ |
1067 | int pos = 0, i; |
1059 | int pos = 0, i; |
1068 | double opinion = 0; |
1060 | double opinion = 0; |
1069 | char tmp[MAX_BUF] = "\0"; |
1061 | char tmp[MAX_BUF] = "\0"; |
… | |
… | |
1183 | case RING: |
1175 | case RING: |
1184 | case AMULET: |
1176 | case AMULET: |
1185 | case BRACERS: |
1177 | case BRACERS: |
1186 | case GIRDLE: |
1178 | case GIRDLE: |
1187 | sprintf (buf, "%s %s", query_base_name (tmp, 0), describe_item (tmp, NULL)); |
1179 | sprintf (buf, "%s %s", query_base_name (tmp, 0), describe_item (tmp, NULL)); |
1188 | items[*numitems].item_sort = strdup_local (buf); |
1180 | items[*numitems].item_sort = strdup (buf); |
1189 | sprintf (buf, "%s %s", query_name (tmp), describe_item (tmp, NULL)); |
1181 | sprintf (buf, "%s %s", query_name (tmp), describe_item (tmp, NULL)); |
1190 | items[*numitems].item_real = strdup_local (buf); |
1182 | items[*numitems].item_real = strdup (buf); |
1191 | (*numitems)++; |
1183 | (*numitems)++; |
1192 | break; |
1184 | break; |
1193 | #endif |
1185 | #endif |
1194 | |
1186 | |
1195 | default: |
1187 | default: |
1196 | items[*numitems].item_sort = strdup_local (query_base_name (tmp, 0)); |
1188 | items[*numitems].item_sort = strdup (query_base_name (tmp, 0)); |
1197 | items[*numitems].item_real = strdup_local (query_base_name (tmp, 1)); |
1189 | items[*numitems].item_real = strdup (query_base_name (tmp, 1)); |
1198 | (*numitems)++; |
1190 | (*numitems)++; |
1199 | break; |
1191 | break; |
1200 | } |
1192 | } |
1201 | SET_FLAG (tmp, FLAG_UNPAID); |
1193 | SET_FLAG (tmp, FLAG_UNPAID); |
1202 | } |
1194 | } |
1203 | |
1195 | |
1204 | void |
1196 | void |
1205 | shop_listing (object *op) |
1197 | shop_listing (object *sign, object *op) |
1206 | { |
1198 | { |
1207 | int i, j, numitems = 0, numallocated = 0, nx, ny; |
1199 | int i, j, numitems = 0, numallocated = 0, x1, x2, y1, y2; |
1208 | char *map_mark = (char *) calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1); |
1200 | const char *shop_coords = get_ob_key_value (sign, "shop_coords"); |
1209 | object *stack; |
1201 | object *stack; |
1210 | shopinv *items; |
1202 | shopinv *items; |
1211 | |
1203 | |
1212 | /* Should never happen, but just in case a monster does apply a sign */ |
1204 | /* Should never happen, but just in case a monster does apply a sign */ |
1213 | if (op->type != PLAYER) |
1205 | if (op->type != PLAYER) |
1214 | return; |
1206 | return; |
1215 | |
1207 | |
1216 | new_draw_info (NDI_UNIQUE, 0, op, "\nThe shop contains:"); |
1208 | if (!(shop_coords && sscanf (shop_coords, "%d,%d,%d,%d", &x1, &y1, &x2, &y2))) |
|
|
1209 | { |
|
|
1210 | x1 = 0; |
|
|
1211 | y1 = 0; |
|
|
1212 | x2 = op->map->width - 1; |
|
|
1213 | y2 = op->map->height - 1; |
|
|
1214 | } |
1217 | |
1215 | |
1218 | magic_mapping_mark (op, map_mark, 3); |
|
|
1219 | items = (shopinv *) malloc (40 * sizeof (shopinv)); |
1216 | items = (shopinv *) malloc (40 * sizeof (shopinv)); |
1220 | numallocated = 40; |
1217 | numallocated = 40; |
1221 | |
1218 | |
1222 | /* Find all the appropriate items */ |
1219 | /* Find all the appropriate items */ |
1223 | for (i = 0; i < MAP_WIDTH (op->map); i++) |
1220 | for (i = x1; i <= x2; i++) |
1224 | { |
1221 | { |
1225 | for (j = 0; j < MAP_HEIGHT (op->map); j++) |
1222 | for (j = y1; j < y2; j++) |
1226 | { |
|
|
1227 | /* magic map code now centers the map on the object at MAGIC_MAP_HALF. |
|
|
1228 | * |
1223 | { |
1229 | */ |
1224 | if (is_in_shop (op->map, i, j)) |
1230 | nx = i - op->x + MAGIC_MAP_HALF; |
|
|
1231 | ny = j - op->y + MAGIC_MAP_HALF; |
|
|
1232 | /* unlikely, but really big shops could run into this issue */ |
|
|
1233 | if (nx < 0 || ny < 0 || nx > MAGIC_MAP_SIZE || ny > MAGIC_MAP_SIZE) |
|
|
1234 | continue; |
|
|
1235 | |
|
|
1236 | if (map_mark[nx + MAGIC_MAP_SIZE * ny] & FACE_FLOOR) |
|
|
1237 | { |
1225 | { |
1238 | stack = get_map_ob (op->map, i, j); |
1226 | stack = GET_MAP_OB (op->map, i, j); |
1239 | |
1227 | |
1240 | while (stack) |
1228 | while (stack) |
1241 | { |
1229 | { |
1242 | if (QUERY_FLAG (stack, FLAG_UNPAID)) |
1230 | if (QUERY_FLAG (stack, FLAG_UNPAID)) |
1243 | { |
1231 | { |
1244 | if (numitems == numallocated) |
1232 | if (numitems == numallocated) |
1245 | { |
1233 | { |
1246 | items = (shopinv *) realloc (items, sizeof (shopinv) * (numallocated + 10)); |
1234 | items = (shopinv *) realloc (items, sizeof (shopinv) * (numallocated + 10)); |
1247 | numallocated += 10; |
1235 | numallocated += 10; |
1248 | } |
1236 | } |
|
|
1237 | |
1249 | add_shop_item (stack, items, &numitems, &numallocated); |
1238 | add_shop_item (stack, items, &numitems, &numallocated); |
1250 | } |
1239 | } |
|
|
1240 | |
1251 | stack = stack->above; |
1241 | stack = stack->above; |
1252 | } |
1242 | } |
1253 | } |
1243 | } |
1254 | } |
1244 | } |
1255 | } |
1245 | } |
1256 | |
1246 | |
1257 | free (map_mark); |
|
|
1258 | |
|
|
1259 | if (numitems == 0) |
1247 | if (numitems == 0) |
1260 | { |
1248 | { |
1261 | new_draw_info (NDI_UNIQUE, 0, op, "The shop is currently empty.\n"); |
1249 | new_draw_info (NDI_UNIQUE, 0, op, "The shop is currently empty.\n"); |
1262 | free (items); |
1250 | free (items); |
1263 | return; |
1251 | return; |
1264 | } |
1252 | } |
1265 | |
1253 | |
1266 | qsort (items, numitems, sizeof (shopinv), (int (*)(const void *, const void *)) shop_sort); |
1254 | qsort (items, numitems, sizeof (shopinv), (int (*)(const void *, const void *)) shop_sort); |
|
|
1255 | |
|
|
1256 | new_draw_info (NDI_UNIQUE, 0, op, "\nThe shop contains:"); |
1267 | |
1257 | |
1268 | for (i = 0; i < numitems; i++) |
1258 | for (i = 0; i < numitems; i++) |
1269 | { |
1259 | { |
1270 | /* Collapse items of the same name together */ |
1260 | /* Collapse items of the same name together */ |
1271 | if ((i + 1) < numitems && !strcmp (items[i].item_real, items[i + 1].item_real)) |
1261 | if ((i + 1) < numitems && !strcmp (items[i].item_real, items[i + 1].item_real)) |
… | |
… | |
1280 | items[i].nrof ? items[i].nrof : 1, items[i].nrof == 1 ? items[i].item_sort : items[i].item_real); |
1270 | items[i].nrof ? items[i].nrof : 1, items[i].nrof == 1 ? items[i].item_sort : items[i].item_real); |
1281 | free (items[i].item_sort); |
1271 | free (items[i].item_sort); |
1282 | free (items[i].item_real); |
1272 | free (items[i].item_real); |
1283 | } |
1273 | } |
1284 | } |
1274 | } |
|
|
1275 | |
1285 | free (items); |
1276 | free (items); |
1286 | } |
1277 | } |
1287 | |
1278 | |
1288 | /* elmex: this function checks whether the object is in a shop */ |
1279 | /* elmex: this function checks whether the object is in a shop */ |
1289 | bool |
1280 | bool |
… | |
… | |
1295 | return is_in_shop (o->map, o->x, o->y); |
1286 | return is_in_shop (o->map, o->x, o->y); |
1296 | } |
1287 | } |
1297 | |
1288 | |
1298 | /* elmex: this function checks whether we are in a shop or not */ |
1289 | /* elmex: this function checks whether we are in a shop or not */ |
1299 | bool |
1290 | bool |
1300 | is_in_shop (mapstruct *map, int x, int y) |
1291 | is_in_shop (maptile *map, int x, int y) |
1301 | { |
1292 | { |
1302 | for (object *floor = get_map_ob (map, x, y); floor; floor = floor->above) |
1293 | for (object *floor = GET_MAP_OB (map, x, y); floor; floor = floor->above) |
1303 | if (floor->type == SHOP_FLOOR) |
1294 | if (floor->type == SHOP_FLOOR) |
1304 | return true; |
1295 | return true; |
1305 | |
1296 | |
1306 | return false; |
1297 | return false; |
1307 | } |
1298 | } |