ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/shop.C
(Generate patch)

Comparing deliantra/server/server/shop.C (file contents):
Revision 1.42 by root, Sat Jul 21 19:18:02 2007 UTC vs.
Revision 1.51 by root, Fri Apr 25 11:40:34 2008 UTC

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
43static void pay_from_container (object *pl, object *pouch, sint64 &to_pay); 43static void pay_from_container (object *pl, object *pouch, sint64 &to_pay);
44static sint64 value_limit (sint64 val, int quantity, const object *who, int isshop); 44static sint64 value_limit (sint64 val, int quantity, const object *who, int isshop);
45static double shop_specialisation_ratio (const object *item, const maptile *map); 45static double shop_specialisation_ratio (const object *item, const maptile *map);
46static double shop_greed (const maptile *map); 46static double shop_greed (const maptile *map);
47
48#define NUM_COINS 4 /* number of coin types */
49static 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
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 }
649 } 633 }
650 634
651 for (i = 0; i < NUM_COINS; i++) 635 for (i = 0; i < NUM_COINS; i++)
652 { 636 {
653 if (coin_objs[i]->nrof) 637 if (coin_objs[i]->nrof)
654 {
655 object *tmp = insert_ob_in_ob (coin_objs[i], pouch); 638 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 639 else
667 coin_objs[i]->destroy (); 640 coin_objs[i]->destroy ();
668 } 641 }
669} 642}
670 643
741 SET_FLAG (op, FLAG_UNPAID); 714 SET_FLAG (op, FLAG_UNPAID);
742 return 0; 715 return 0;
743 } 716 }
744 else 717 else
745 { 718 {
746 object *tmp;
747
748 CLEAR_FLAG (op, FLAG_UNPAID); 719 CLEAR_FLAG (op, FLAG_UNPAID);
749 CLEAR_FLAG (op, FLAG_PLAYER_SOLD); 720 CLEAR_FLAG (op, FLAG_PLAYER_SOLD);
750 new_draw_info_format (NDI_UNIQUE, 0, op, "You paid %s for %s.", buf, query_name (op)); 721 new_draw_info_format (NDI_UNIQUE, 0, op, "You paid %s for %s.", buf, query_name (op));
751 tmp = merge_ob (op, NULL);
752 722
753 if (pl->type == PLAYER) 723 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); 724 esrv_update_item (UPD_FLAGS, pl, op);
762 }
763 725
764 goto next_item; 726 goto next_item;
765 } 727 }
766 } 728 }
767 } 729 }
786{ 748{
787 int count = 0; 749 int count = 0;
788 archetype *at = 0; 750 archetype *at = 0;
789 object *pouch = 0, *tmp = 0; 751 object *pouch = 0, *tmp = 0;
790 752
791 for (count = 0; coins[count] != NULL; count++) 753 for (count = 0; coins[count]; count++)
792 { 754 {
793 at = archetype::find (coins[count]); 755 at = archetype::find (coins[count]);
794 756
795 if (at == NULL) 757 if (at == NULL)
796 LOG (llevError, "Could not find %s archetype\n", coins[count]); 758 LOG (llevError, "Could not find %s archetype\n", coins[count]);
809 if (n > 0 && (!pouch->weight_limit || pouch->carrying + w <= pouch->weight_limit)) 771 if (n > 0 && (!pouch->weight_limit || pouch->carrying + w <= pouch->weight_limit))
810 { 772 {
811 if (pouch->weight_limit && (pouch->weight_limit - pouch->carrying) / w < n) 773 if (pouch->weight_limit && (pouch->weight_limit - pouch->carrying) / w < n)
812 n = (pouch->weight_limit - pouch->carrying) / w; 774 n = (pouch->weight_limit - pouch->carrying) / w;
813 775
814 tmp = arch_to_object (at); 776 object *tmp = arch_to_object (at);
815 tmp->nrof = n; 777 tmp->nrof = n;
816 amount -= tmp->nrof * tmp->value; 778 amount -= tmp->nrof * tmp->value;
817 tmp = insert_ob_in_ob (tmp, pouch); 779 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 } 780 }
823 } 781 }
824 } 782 }
825 783
826 if (amount / at->value > 0) 784 if (amount / at->value > 0)
827 { 785 {
828 tmp = arch_to_object (at); 786 object *tmp = arch_to_object (at);
829 tmp->nrof = amount / tmp->value; 787 tmp->nrof = amount / tmp->value;
830 amount -= tmp->nrof * tmp->value; 788 amount -= tmp->nrof * tmp->value;
831 tmp = insert_ob_in_ob (tmp, pl); 789 pl->insert (tmp);
832 esrv_send_item (pl, tmp);
833 esrv_send_item (pl, pl);
834 } 790 }
835 } 791 }
836 } 792 }
837 793
838 if (amount != 0) 794 if (amount != 0)
842/* elmex: this is for the bank plugin :( */ 798/* elmex: this is for the bank plugin :( */
843sint64 799sint64
844pay_player_arch (object *pl, const char *arch, sint64 amount) 800pay_player_arch (object *pl, const char *arch, sint64 amount)
845{ 801{
846 archetype *at = archetype::find (arch); 802 archetype *at = archetype::find (arch);
847 object *tmp = NULL;
848 803
849 if (at == NULL) 804 if (!at)
850 return 0; 805 return 0;
851 806
852 if (amount > 0) 807 if (amount > 0)
853 { 808 {
854 tmp = arch_to_object (at); 809 object *tmp = arch_to_object (at);
855 tmp->nrof = amount; 810 tmp->nrof = amount;
856 tmp = insert_ob_in_ob (tmp, pl); 811 insert_ob_in_ob (tmp, pl);
857 esrv_send_item (pl, tmp);
858 esrv_send_item (pl, pl);
859 } 812 }
860 813
861 return 1; 814 return 1;
862} 815}
863 816
866 * buy item. 819 * buy item.
867 * 820 *
868 * Modified to fill available race: gold containers before dumping 821 * Modified to fill available race: gold containers before dumping
869 * remaining coins in character's inventory. 822 * remaining coins in character's inventory.
870 */ 823 */
871void 824bool
872sell_item (object *op, object *pl) 825sell_item (object *op, object *pl)
873{ 826{
874 sint64 amount = query_cost (op, pl, F_SELL | F_SHOP), extra_gain; 827 sint64 amount = query_cost (op, pl, F_SELL | F_SHOP), extra_gain;
875 828
876 if (pl == NULL || pl->type != PLAYER) 829 if (pl == NULL || pl->type != PLAYER)
877 { 830 {
878 LOG (llevDebug, "Object other than player tried to sell something.\n"); 831 LOG (llevDebug, "Object other than player tried to sell something.\n");
879 return; 832 return false;
880 } 833 }
881 834
882 op->custom_name = 0; 835 op->custom_name = 0;
883 836
884 if (!amount) 837 if (!amount)
885 { 838 {
886 new_draw_info_format (NDI_UNIQUE, 0, pl, "We're not interested in %s.", query_name (op)); 839 new_draw_info_format (NDI_UNIQUE, 0, pl, "We're not interested in %s.",
887 840 query_name (op));
888 /* Even if the character doesn't get anything for it, it may still be 841 // elmex: change: the player now gets the item back if the shop is not
889 * worth something. If so, make it unpaid 842 // 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; 843 return false;
899 } 844 }
900 845
901 /* We compare the price with the one for a player 846 /* We compare the price with the one for a player
902 * without bargaining skill. 847 * without bargaining skill.
903 * This determins the amount of exp (if any) gained for bargaining. 848 * This determins the amount of exp (if any) gained for bargaining.
908 if (extra_gain > 0) 853 if (extra_gain > 0)
909 change_exp (pl, extra_gain / 10, "bargaining", SK_EXP_NONE); 854 change_exp (pl, extra_gain / 10, "bargaining", SK_EXP_NONE);
910 855
911 pay_player (pl, amount); 856 pay_player (pl, amount);
912 857
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)); 858 new_draw_info_format (NDI_UNIQUE, 0, pl, "You receive %s for %s.",
859 query_cost_string (op, pl, F_SELL | F_SHOP), query_name (op));
860 pl->play_sound (sound_find ("shop_sell"));
914 861
915 SET_FLAG (op, FLAG_UNPAID); 862 SET_FLAG (op, FLAG_UNPAID);
916 identify (op); 863 identify (op);
917}
918 864
865 return true;
866}
919 867
920/* returns a double that is the ratio of the price that a shop will offer for 868/* 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, 869 * item based on the shops specialisation. Does not take account of greed,
922 * returned value is between SPECIALISATION_EFFECT and 1. 870 * returned value is between SPECIALISATION_EFFECT and 1.
923 */ 871 */
1268 return false; 1216 return false;
1269 1217
1270 return is_in_shop (o->map, o->x, o->y); 1218 return is_in_shop (o->map, o->x, o->y);
1271} 1219}
1272 1220
1273/* elmex: this function checks whether we are in a shop or not */ 1221/* elmex: this function checks whether we are in a shop or not
1222 - change 2007-11-26: enhanced the O(n) case by stopping at the first
1223 floor tile. this possibly will make map bugs where shopfloors are above
1224 floors more obvious.
1225*/
1226
1274bool 1227bool
1275is_in_shop (maptile *map, int x, int y) 1228is_in_shop (maptile *map, int x, int y)
1276{ 1229{
1277 for (object *floor = GET_MAP_OB (map, x, y); floor; floor = floor->above) 1230 for (object *floor = GET_MAP_OB (map, x, y); floor; floor = floor->above)
1231 if (QUERY_FLAG (floor, FLAG_IS_FLOOR))
1278 if (floor->type == SHOP_FLOOR) 1232 return floor->type == SHOP_FLOOR;
1279 return true;
1280
1281 return false; 1233 return false;
1282} 1234}
1235

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines