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 |
… | |
… | |
129 | { |
126 | { |
130 | if (tmp->arch != NULL) |
127 | if (tmp->arch != NULL) |
131 | { |
128 | { |
132 | if (flag == F_BUY) |
129 | if (flag == F_BUY) |
133 | { |
130 | { |
134 | LOG (llevError, "Asking for buy-value of unidentified object.\n"); |
131 | LOG (llevError | logBacktrace, "Asking for buy-value of unidentified object.\n"); |
135 | val = tmp->arch->value * 50 * number; |
132 | val = tmp->arch->value * 50 * number; |
136 | } |
133 | } |
137 | else |
134 | else |
138 | { /* Trying to sell something, or get true value */ |
135 | { /* Trying to sell something, or get true value */ |
139 | if (tmp->type == POTION) |
136 | if (tmp->type == POTION) |
… | |
… | |
153 | else |
150 | else |
154 | { /* No archetype with this object */ |
151 | { /* No archetype with this object */ |
155 | LOG (llevDebug, "In sell item: Have object with no archetype: %s\n", &tmp->name); |
152 | LOG (llevDebug, "In sell item: Have object with no archetype: %s\n", &tmp->name); |
156 | if (flag == F_BUY) |
153 | if (flag == F_BUY) |
157 | { |
154 | { |
158 | LOG (llevError, "Asking for buy-value of unidentified object without arch.\n"); |
155 | LOG (llevError | logBacktrace, "Asking for buy-value of unidentified object without arch.\n"); |
159 | val = number * tmp->value * 10; |
156 | val = number * tmp->value * 10; |
160 | } |
157 | } |
161 | else |
158 | else |
162 | val = number * tmp->value / 5; |
159 | val = number * tmp->value / 5; |
163 | } |
160 | } |
… | |
… | |
209 | * AND Cha = 30 will get optimal price. |
206 | * AND Cha = 30 will get optimal price. |
210 | * Thus charisma will never get useless. |
207 | * Thus charisma will never get useless. |
211 | * -b.e. edler@heydernet.de |
208 | * -b.e. edler@heydernet.de |
212 | */ |
209 | */ |
213 | |
210 | |
214 | if (who != NULL && who->type == PLAYER) |
211 | if (who && who->type == PLAYER) |
215 | { |
212 | { |
216 | int lev_bargain = 0; |
213 | int lev_bargain = 0; |
217 | int lev_identify = 0; |
214 | int lev_identify = 0; |
218 | int idskill1 = 0; |
|
|
219 | int idskill2 = 0; |
|
|
220 | const typedata *tmptype; |
|
|
221 | |
|
|
222 | tmptype = get_typedata (tmp->type); |
|
|
223 | |
215 | |
224 | if (find_skill_by_number (who, SK_BARGAINING)) |
216 | if (find_skill_by_number (who, SK_BARGAINING)) |
225 | lev_bargain = find_skill_by_number (who, SK_BARGAINING)->level; |
217 | lev_bargain = find_skill_by_number (who, SK_BARGAINING)->level; |
226 | |
218 | |
227 | if (tmptype) |
219 | if (const typedata *tmptype = get_typedata (tmp->type)) |
228 | { |
220 | { |
229 | idskill1 = tmptype->identifyskill; |
221 | if (int idskill1 = tmptype->identifyskill) |
230 | |
|
|
231 | if (idskill1) |
|
|
232 | { |
222 | { |
233 | idskill2 = tmptype->identifyskill2; |
223 | int idskill2 = tmptype->identifyskill2; |
234 | |
224 | |
235 | if (find_skill_by_number (who, idskill1)) |
225 | if (find_skill_by_number (who, idskill1)) |
236 | lev_identify = find_skill_by_number (who, idskill1)->level; |
226 | lev_identify = find_skill_by_number (who, idskill1)->level; |
237 | |
227 | |
238 | if (idskill2 && find_skill_by_number (who, idskill2)) |
228 | if (idskill2 && find_skill_by_number (who, idskill2)) |
239 | lev_identify += find_skill_by_number (who, idskill2)->level; |
229 | lev_identify += find_skill_by_number (who, idskill2)->level; |
240 | } |
230 | } |
241 | } |
231 | } |
242 | else |
|
|
243 | LOG (llevError, "Query_cost: item %s hasn't got a valid type\n", tmp->debug_desc ()); |
|
|
244 | |
232 | |
245 | /* ratio determines how much of the price modification |
233 | /* ratio determines how much of the price modification |
246 | * will come from the basic stat charisma |
234 | * will come from the basic stat charisma |
247 | * the rest will come from the level in bargaining skill |
235 | * the rest will come from the level in bargaining skill |
248 | */ |
236 | */ |
… | |
… | |
421 | |
409 | |
422 | if (coin == NULL) |
410 | if (coin == NULL) |
423 | return "nothing"; |
411 | return "nothing"; |
424 | |
412 | |
425 | num = real_value / coin->value; |
413 | num = real_value / coin->value; |
|
|
414 | |
426 | if (num == 1) |
415 | if (num == 1) |
427 | sprintf (buf, "about one %s", &coin->object::name); |
416 | sprintf (buf, "about one %s", &coin->object::name); |
428 | else if (num < 5) |
417 | else if (num < 5) |
429 | sprintf (buf, "a few %s", &coin->object::name_pl); |
418 | sprintf (buf, "a few %s", &coin->object::name_pl); |
430 | else if (num < 10) |
419 | else if (num < 10) |
… | |
… | |
435 | sprintf (buf, "lots of %s", &coin->object::name_pl); |
424 | sprintf (buf, "lots of %s", &coin->object::name_pl); |
436 | else if (num < 1000) |
425 | else if (num < 1000) |
437 | sprintf (buf, "a great many %s", &coin->object::name_pl); |
426 | sprintf (buf, "a great many %s", &coin->object::name_pl); |
438 | else |
427 | else |
439 | sprintf (buf, "a vast quantity of %s", &coin->object::name_pl); |
428 | sprintf (buf, "a vast quantity of %s", &coin->object::name_pl); |
|
|
429 | |
440 | return buf; |
430 | return buf; |
441 | } |
431 | } |
442 | } |
432 | } |
443 | } |
433 | } |
444 | |
434 | |
… | |
… | |
586 | { |
576 | { |
587 | // This should not happen, but if it does, just merge the two. |
577 | // This should not happen, but if it does, just merge the two. |
588 | if (coin_objs [i]) |
578 | if (coin_objs [i]) |
589 | { |
579 | { |
590 | LOG (llevError, "%s has two money entries of (%s)\n", &pouch->name, coins[NUM_COINS - 1 - i]); |
580 | 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; |
581 | coin_objs[i]->nrof += tmp->nrof; |
593 | esrv_del_item (pl->contr, tmp->count); |
|
|
594 | tmp->destroy (); |
582 | tmp->destroy (); |
595 | } |
583 | } |
596 | else |
584 | else |
597 | { |
585 | { |
598 | tmp->remove (); |
586 | tmp->remove (); |
599 | |
|
|
600 | if (pouch->type == PLAYER) |
|
|
601 | esrv_del_item (pl->contr, tmp->count); |
|
|
602 | |
|
|
603 | coin_objs[i] = tmp; |
587 | coin_objs[i] = tmp; |
604 | } |
588 | } |
605 | |
589 | |
606 | break; |
590 | break; |
607 | } |
591 | } |
… | |
… | |
647 | count--; |
631 | count--; |
648 | } |
632 | } |
649 | } |
633 | } |
650 | |
634 | |
651 | for (i = 0; i < NUM_COINS; i++) |
635 | for (i = 0; i < NUM_COINS; i++) |
652 | { |
|
|
653 | if (coin_objs[i]->nrof) |
636 | if (coin_objs[i]->nrof) |
654 | { |
|
|
655 | object *tmp = insert_ob_in_ob (coin_objs[i], pouch); |
637 | 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 |
638 | else |
667 | coin_objs[i]->destroy (); |
639 | coin_objs[i]->destroy (); |
668 | } |
|
|
669 | } |
640 | } |
670 | |
641 | |
671 | /* Checks all unpaid items in op's inventory, adds up all the money they |
642 | /* Checks all unpaid items in op's inventory, adds up all the money they |
672 | * have, and checks that they can actually afford what they want to buy. |
643 | * have, and checks that they can actually afford what they want to buy. |
673 | * Returns 1 if they can, and 0 if they can't. also prints an appropriate message |
644 | * Returns 1 if they can, and 0 if they can't. also prints an appropriate message |
… | |
… | |
693 | unpaid_price += query_cost (item, pl, F_BUY | F_SHOP); |
664 | unpaid_price += query_cost (item, pl, F_BUY | F_SHOP); |
694 | } |
665 | } |
695 | |
666 | |
696 | if (unpaid_price > player_wealth) |
667 | if (unpaid_price > player_wealth) |
697 | { |
668 | { |
698 | char buf[MAX_BUF]; |
669 | dynbuf_text buf; |
699 | char cost[MAX_BUF]; |
|
|
700 | char missing[MAX_BUF]; |
|
|
701 | |
670 | |
702 | snprintf (cost, MAX_BUF, "%s", cost_string_from_value (unpaid_price, 0)); |
671 | buf << "You have " << unpaid_count |
703 | snprintf (missing, MAX_BUF, "%s", cost_string_from_value (unpaid_price - player_wealth, 0)); |
672 | << " unpaid item(s) that would cost you " << cost_string_from_value (unpaid_price, 0) |
|
|
673 | << ". You need another " << cost_string_from_value (unpaid_price - player_wealth, 0) |
|
|
674 | << " to be able to afford that. " |
|
|
675 | "H<You cannot leave a shop without paying - drop unpaid items first to be able to leave.>"; |
704 | |
676 | |
705 | snprintf (buf, MAX_BUF, "You have %d unpaid items that would cost you %s. You need another %s to be able to afford that.", |
677 | pl->failmsg (buf); |
706 | unpaid_count, cost, missing); |
|
|
707 | new_draw_info (NDI_UNIQUE, 0, pl, buf); |
|
|
708 | |
678 | |
709 | return 0; |
679 | return 0; |
710 | } |
680 | } |
711 | else |
681 | else |
712 | return 1; |
682 | return 1; |
… | |
… | |
741 | SET_FLAG (op, FLAG_UNPAID); |
711 | SET_FLAG (op, FLAG_UNPAID); |
742 | return 0; |
712 | return 0; |
743 | } |
713 | } |
744 | else |
714 | else |
745 | { |
715 | { |
746 | object *tmp; |
|
|
747 | |
|
|
748 | CLEAR_FLAG (op, FLAG_UNPAID); |
716 | CLEAR_FLAG (op, FLAG_UNPAID); |
749 | CLEAR_FLAG (op, FLAG_PLAYER_SOLD); |
717 | CLEAR_FLAG (op, FLAG_PLAYER_SOLD); |
750 | new_draw_info_format (NDI_UNIQUE, 0, op, "You paid %s for %s.", buf, query_name (op)); |
718 | new_draw_info_format (NDI_UNIQUE, 0, op, "You paid %s for %s.", buf, query_name (op)); |
751 | tmp = merge_ob (op, NULL); |
|
|
752 | |
719 | |
753 | if (pl->type == PLAYER) |
720 | 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); |
721 | esrv_update_item (UPD_FLAGS, pl, op); |
762 | } |
|
|
763 | |
722 | |
764 | goto next_item; |
723 | goto next_item; |
765 | } |
724 | } |
766 | } |
725 | } |
767 | } |
726 | } |
… | |
… | |
786 | { |
745 | { |
787 | int count = 0; |
746 | int count = 0; |
788 | archetype *at = 0; |
747 | archetype *at = 0; |
789 | object *pouch = 0, *tmp = 0; |
748 | object *pouch = 0, *tmp = 0; |
790 | |
749 | |
791 | for (count = 0; coins[count] != NULL; count++) |
750 | for (count = 0; coins[count]; count++) |
792 | { |
751 | { |
793 | at = archetype::find (coins[count]); |
752 | at = archetype::find (coins[count]); |
794 | |
753 | |
795 | if (at == NULL) |
754 | if (at == NULL) |
796 | LOG (llevError, "Could not find %s archetype\n", coins[count]); |
755 | LOG (llevError, "Could not find %s archetype\n", coins[count]); |
… | |
… | |
809 | if (n > 0 && (!pouch->weight_limit || pouch->carrying + w <= pouch->weight_limit)) |
768 | if (n > 0 && (!pouch->weight_limit || pouch->carrying + w <= pouch->weight_limit)) |
810 | { |
769 | { |
811 | if (pouch->weight_limit && (pouch->weight_limit - pouch->carrying) / w < n) |
770 | if (pouch->weight_limit && (pouch->weight_limit - pouch->carrying) / w < n) |
812 | n = (pouch->weight_limit - pouch->carrying) / w; |
771 | n = (pouch->weight_limit - pouch->carrying) / w; |
813 | |
772 | |
814 | tmp = arch_to_object (at); |
773 | object *tmp = arch_to_object (at); |
815 | tmp->nrof = n; |
774 | tmp->nrof = n; |
816 | amount -= tmp->nrof * tmp->value; |
775 | amount -= tmp->nrof * tmp->value; |
817 | tmp = insert_ob_in_ob (tmp, pouch); |
776 | 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 | } |
777 | } |
823 | } |
778 | } |
824 | } |
779 | } |
825 | |
780 | |
826 | if (amount / at->value > 0) |
781 | if (amount / at->value > 0) |
827 | { |
782 | { |
828 | tmp = arch_to_object (at); |
783 | object *tmp = arch_to_object (at); |
829 | tmp->nrof = amount / tmp->value; |
784 | tmp->nrof = amount / tmp->value; |
830 | amount -= tmp->nrof * tmp->value; |
785 | amount -= tmp->nrof * tmp->value; |
831 | tmp = insert_ob_in_ob (tmp, pl); |
786 | pl->insert (tmp); |
832 | esrv_send_item (pl, tmp); |
|
|
833 | esrv_send_item (pl, pl); |
|
|
834 | } |
787 | } |
835 | } |
788 | } |
836 | } |
789 | } |
837 | |
790 | |
838 | if (amount != 0) |
791 | if (amount != 0) |
… | |
… | |
841 | |
794 | |
842 | /* elmex: this is for the bank plugin :( */ |
795 | /* elmex: this is for the bank plugin :( */ |
843 | sint64 |
796 | sint64 |
844 | pay_player_arch (object *pl, const char *arch, sint64 amount) |
797 | pay_player_arch (object *pl, const char *arch, sint64 amount) |
845 | { |
798 | { |
846 | archetype *at = archetype::find (arch); |
|
|
847 | object *tmp = NULL; |
|
|
848 | |
|
|
849 | if (at == NULL) |
|
|
850 | return 0; |
|
|
851 | |
|
|
852 | if (amount > 0) |
799 | if (amount) |
853 | { |
800 | { |
854 | tmp = arch_to_object (at); |
801 | object *ob = archetype::get (arch); |
|
|
802 | |
|
|
803 | if (!ob) |
|
|
804 | return 0; |
|
|
805 | |
855 | tmp->nrof = amount; |
806 | ob->nrof = amount; |
856 | tmp = insert_ob_in_ob (tmp, pl); |
807 | pl->insert (ob); |
857 | esrv_send_item (pl, tmp); |
|
|
858 | esrv_send_item (pl, pl); |
|
|
859 | } |
808 | } |
860 | |
809 | |
861 | return 1; |
810 | return 1; |
862 | } |
811 | } |
863 | |
812 | |
… | |
… | |
866 | * buy item. |
815 | * buy item. |
867 | * |
816 | * |
868 | * Modified to fill available race: gold containers before dumping |
817 | * Modified to fill available race: gold containers before dumping |
869 | * remaining coins in character's inventory. |
818 | * remaining coins in character's inventory. |
870 | */ |
819 | */ |
871 | void |
820 | bool |
872 | sell_item (object *op, object *pl) |
821 | sell_item (object *op, object *pl) |
873 | { |
822 | { |
874 | sint64 amount = query_cost (op, pl, F_SELL | F_SHOP), extra_gain; |
823 | sint64 amount = query_cost (op, pl, F_SELL | F_SHOP), extra_gain; |
875 | |
824 | |
876 | if (pl == NULL || pl->type != PLAYER) |
825 | if (pl == NULL || pl->type != PLAYER) |
877 | { |
826 | { |
878 | LOG (llevDebug, "Object other than player tried to sell something.\n"); |
827 | LOG (llevDebug, "Object other than player tried to sell something.\n"); |
879 | return; |
828 | return false; |
880 | } |
829 | } |
881 | |
830 | |
882 | op->custom_name = 0; |
831 | op->custom_name = 0; |
883 | |
832 | |
884 | if (!amount) |
833 | if (!amount) |
885 | { |
834 | { |
886 | new_draw_info_format (NDI_UNIQUE, 0, pl, "We're not interested in %s.", query_name (op)); |
835 | new_draw_info_format (NDI_UNIQUE, 0, pl, "We're not interested in %s.", |
887 | |
836 | query_name (op)); |
888 | /* Even if the character doesn't get anything for it, it may still be |
837 | // elmex: change: the player now gets the item back if the shop is not |
889 | * worth something. If so, make it unpaid |
838 | // interested in it. |
890 | */ |
|
|
891 | if (op->value) |
|
|
892 | { |
|
|
893 | SET_FLAG (op, FLAG_UNPAID); |
|
|
894 | SET_FLAG (op, FLAG_PLAYER_SOLD); |
|
|
895 | } |
|
|
896 | |
|
|
897 | identify (op); |
|
|
898 | return; |
839 | return false; |
899 | } |
840 | } |
900 | |
841 | |
901 | /* We compare the price with the one for a player |
842 | /* We compare the price with the one for a player |
902 | * without bargaining skill. |
843 | * without bargaining skill. |
903 | * This determins the amount of exp (if any) gained for bargaining. |
844 | * This determins the amount of exp (if any) gained for bargaining. |
… | |
… | |
908 | if (extra_gain > 0) |
849 | if (extra_gain > 0) |
909 | change_exp (pl, extra_gain / 10, "bargaining", SK_EXP_NONE); |
850 | change_exp (pl, extra_gain / 10, "bargaining", SK_EXP_NONE); |
910 | |
851 | |
911 | pay_player (pl, amount); |
852 | pay_player (pl, amount); |
912 | |
853 | |
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)); |
854 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You receive %s for %s.", |
|
|
855 | query_cost_string (op, pl, F_SELL | F_SHOP), query_name (op)); |
|
|
856 | pl->play_sound (sound_find ("shop_sell")); |
914 | |
857 | |
915 | SET_FLAG (op, FLAG_UNPAID); |
858 | SET_FLAG (op, FLAG_UNPAID); |
916 | identify (op); |
859 | identify (op); |
917 | } |
|
|
918 | |
860 | |
|
|
861 | return true; |
|
|
862 | } |
919 | |
863 | |
920 | /* returns a double that is the ratio of the price that a shop will offer for |
864 | /* 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, |
865 | * item based on the shops specialisation. Does not take account of greed, |
922 | * returned value is between SPECIALISATION_EFFECT and 1. |
866 | * returned value is between SPECIALISATION_EFFECT and 1. |
923 | */ |
867 | */ |
… | |
… | |
1120 | { |
1064 | { |
1121 | shopinv *s1 = (shopinv *) a1, *s2 = (shopinv *) a2; |
1065 | shopinv *s1 = (shopinv *) a1, *s2 = (shopinv *) a2; |
1122 | |
1066 | |
1123 | if (s1->type < s2->type) |
1067 | if (s1->type < s2->type) |
1124 | return -1; |
1068 | return -1; |
|
|
1069 | |
1125 | if (s1->type > s2->type) |
1070 | if (s1->type > s2->type) |
1126 | return 1; |
1071 | return 1; |
1127 | |
1072 | |
1128 | /* the type is the same (what atoi gets), so do a strcasecmp to sort |
1073 | /* the type is the same (what atoi gets), so do a strcasecmp to sort |
1129 | * via alphabetical order |
1074 | * via alphabetical order |
… | |
… | |
1179 | |
1124 | |
1180 | void |
1125 | void |
1181 | shop_listing (object *sign, object *op) |
1126 | shop_listing (object *sign, object *op) |
1182 | { |
1127 | { |
1183 | int i, j, numitems = 0, numallocated = 0, x1, x2, y1, y2; |
1128 | int i, j, numitems = 0, numallocated = 0, x1, x2, y1, y2; |
1184 | const char *shop_coords = get_ob_key_value (sign, "shop_coords"); |
1129 | const char *shop_coords = sign->kv (shstr_shop_coords); |
1185 | object *stack; |
1130 | object *stack; |
1186 | shopinv *items; |
1131 | shopinv *items; |
1187 | |
1132 | |
1188 | /* Should never happen, but just in case a monster does apply a sign */ |
1133 | /* Should never happen, but just in case a monster does apply a sign */ |
1189 | if (op->type != PLAYER) |
1134 | if (op->type != PLAYER) |
… | |
… | |
1262 | |
1207 | |
1263 | /* elmex: this function checks whether the object is in a shop */ |
1208 | /* elmex: this function checks whether the object is in a shop */ |
1264 | bool |
1209 | bool |
1265 | is_in_shop (object *o) |
1210 | is_in_shop (object *o) |
1266 | { |
1211 | { |
1267 | if (!o->map) |
1212 | if (!o->is_on_map ()) |
1268 | return false; |
1213 | return false; |
1269 | |
1214 | |
1270 | return is_in_shop (o->map, o->x, o->y); |
1215 | return is_in_shop (o->map, o->x, o->y); |
1271 | } |
1216 | } |
1272 | |
1217 | |
1273 | /* elmex: this function checks whether we are in a shop or not */ |
1218 | /* elmex: this function checks whether we are in a shop or not |
|
|
1219 | - change 2007-11-26: enhanced the O(n) case by stopping at the first |
|
|
1220 | floor tile. this possibly will make map bugs where shopfloors are above |
|
|
1221 | floors more obvious. |
|
|
1222 | */ |
|
|
1223 | |
1274 | bool |
1224 | bool |
1275 | is_in_shop (maptile *map, int x, int y) |
1225 | is_in_shop (maptile *map, int x, int y) |
1276 | { |
1226 | { |
1277 | for (object *floor = GET_MAP_OB (map, x, y); floor; floor = floor->above) |
1227 | for (object *floor = GET_MAP_OB (map, x, y); floor; floor = floor->above) |
|
|
1228 | if (QUERY_FLAG (floor, FLAG_IS_FLOOR)) |
1278 | if (floor->type == SHOP_FLOOR) |
1229 | return floor->type == SHOP_FLOOR; |
1279 | return true; |
|
|
1280 | |
1230 | |
1281 | return false; |
1231 | return false; |
1282 | } |
1232 | } |
|
|
1233 | |